LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
@ 2006-12-15 18:57 Anderson Briglia
2007-01-03 12:06 ` Anderson Briglia
0 siblings, 1 reply; 12+ messages in thread
From: Anderson Briglia @ 2006-12-15 18:57 UTC (permalink / raw)
To: Pierre Ossman
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
[-- Attachment #1: Type: text/plain, Size: 5 bytes --]
[-- Attachment #2: mmc_sysfs.diff --]
[-- Type: text/plain, Size: 4363 bytes --]
Implement MMC password force erase, remove password, change password,
unlock card and assign password operations. It uses the sysfs mechanism
to send commands to the MMC subsystem.
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar <at> indt.org.br>
Signed-off-by: Anderson Lizardo <anderson.lizardo <at> indt.org.br>
Signed-off-by: Anderson Briglia <anderson.briglia <at> indt.org.br>
Index: linux-linus-2.6/drivers/mmc/mmc_sysfs.c
===================================================================
--- linux-linus-2.6.orig/drivers/mmc/mmc_sysfs.c 2006-12-15 14:35:14.000000000 -0400
+++ linux-linus-2.6/drivers/mmc/mmc_sysfs.c 2006-12-15 14:35:27.000000000 -0400
@@ -17,6 +17,7 @@
#include <linux/idr.h>
#include <linux/workqueue.h>
#include <linux/key.h>
+#include <linux/err.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -65,6 +66,100 @@ static struct device_attribute mmc_dev_a
static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
+#ifdef CONFIG_MMC_PASSWORDS
+
+static ssize_t
+mmc_lockable_show(struct device *dev, struct device_attribute *att, char *buf)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+
+ if (!mmc_card_lockable(card))
+ return sprintf(buf, "unsupported\n");
+ else
+ return sprintf(buf, "%slocked\n", mmc_card_locked(card) ?
+ "" : "un");
+}
+
+/*
+ * implement MMC password functions: force erase, remove password, change
+ * password, unlock card and assign password.
+ */
+static ssize_t
+mmc_lockable_store(struct device *dev, struct device_attribute *att,
+ const char *data, size_t len)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+ int err = 0;
+
+ err = mmc_card_claim_host(card);
+ if (err != MMC_ERR_NONE)
+ return -EINVAL;
+
+ if (!mmc_card_lockable(card))
+ return -EINVAL;
+
+ if (mmc_card_locked(card) && !strncmp(data, "erase", 5)) {
+ /* forced erase only works while card is locked */
+ mmc_lock_unlock(card, NULL, MMC_LOCK_MODE_ERASE);
+ goto out;
+ } else if (!mmc_card_locked(card) && !strncmp(data, "remove", 6)) {
+ /* remove password only works while card is unlocked */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "remove");
+
+ if (!IS_ERR(mmc_key)) {
+ int err = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_CLR_PWD);
+ if (!err)
+ goto out;
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ } else if (!mmc_card_locked(card) && ((!strncmp(data, "assign", 6)) ||
+ (!strncmp(data, "change", 6)))) {
+
+ /* assign or change */
+ struct key *mmc_key;
+
+ if(!strncmp(data, "assign", 6))
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "assign");
+ else
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "change");
+
+ if (!IS_ERR(mmc_key)) {
+ int err = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_SET_PWD);
+ if (!err)
+ goto out;
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ } else if (mmc_card_locked(card) && !strncmp(data, "unlock", 6)) {
+ /* unlock */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "unlock");
+ if (!IS_ERR(mmc_key)) {
+ int err = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_UNLOCK);
+ if (err) {
+ dev_dbg(&card->dev, "Wrong password\n");
+ }
+ else {
+ mmc_card_release_host(card);
+ device_release_driver(dev);
+ device_attach(dev);
+ return len;
+ }
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ }
+
+ mmc_card_release_host(card);
+ return -EINVAL;
+out:
+ mmc_card_release_host(card);
+ return len;
+}
+
+static struct device_attribute mmc_dev_attr_lockable =
+ __ATTR(lockable, S_IWUSR | S_IRUGO,
+ mmc_lockable_show, mmc_lockable_store);
+
+#endif
+
static void mmc_release_card(struct device *dev)
{
@@ -234,6 +329,11 @@ int mmc_register_card(struct mmc_card *c
if (ret)
device_del(&card->dev);
}
+#ifdef CONFIG_MMC_PASSWORDS
+ ret = device_create_file(&card->dev, &mmc_dev_attr_lockable);
+ if (ret)
+ device_del(&card->dev);
+#endif
}
return ret;
}
@@ -248,6 +348,9 @@ void mmc_remove_card(struct mmc_card *ca
if (mmc_card_sd(card))
device_remove_file(&card->dev, &mmc_dev_attr_scr);
+#ifdef CONFIG_MMC_PASSWORDS
+ device_remove_file(&card->dev, &mmc_dev_attr_lockable);
+#endif
device_del(&card->dev);
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2006-12-15 18:57 [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff Anderson Briglia
@ 2007-01-03 12:06 ` Anderson Briglia
2007-01-06 13:35 ` Pierre Ossman
2007-01-06 22:24 ` Pierre Ossman
0 siblings, 2 replies; 12+ messages in thread
From: Anderson Briglia @ 2007-01-03 12:06 UTC (permalink / raw)
To: Pierre Ossman
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
[-- Attachment #1: Type: text/plain, Size: 121 bytes --]
Hi all,
I believe this code is following the latest Russel's comments.
Regards,
Anderson Briglia
---> cut here <----
[-- Attachment #2: mmc_sysfs.diff --]
[-- Type: text/plain, Size: 4351 bytes --]
Implement MMC password force erase, remove password, change password,
unlock card and assign password operations. It uses the sysfs mechanism
to send commands to the MMC subsystem.
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br>
Signed-off-by: Anderson Lizardo <anderson.lizardo@indt.org.br>
Signed-off-by: Anderson Briglia <anderson.briglia@indt.org.br>
Index: linux-linus-2.6/drivers/mmc/mmc_sysfs.c
===================================================================
--- linux-linus-2.6.orig/drivers/mmc/mmc_sysfs.c 2007-01-03 07:57:40.000000000 -0400
+++ linux-linus-2.6/drivers/mmc/mmc_sysfs.c 2007-01-03 07:58:14.000000000 -0400
@@ -17,6 +17,7 @@
#include <linux/idr.h>
#include <linux/workqueue.h>
#include <linux/key.h>
+#include <linux/err.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -65,6 +66,107 @@ static struct device_attribute mmc_dev_a
static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
+#ifdef CONFIG_MMC_PASSWORDS
+
+static ssize_t
+mmc_lockable_show(struct device *dev, struct device_attribute *att, char *buf)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+
+ if (!mmc_card_lockable(card))
+ return sprintf(buf, "unsupported\n");
+ else
+ return sprintf(buf, "%slocked\n", mmc_card_locked(card) ?
+ "" : "un");
+}
+
+/*
+ * implement MMC password functions: force erase, remove password, change
+ * password, unlock card and assign password.
+ */
+static ssize_t
+mmc_lockable_store(struct device *dev, struct device_attribute *att,
+ const char *data, size_t len)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+ int err;
+
+ err = mmc_card_claim_host(card);
+ if (err != MMC_ERR_NONE)
+ return -EINVAL;
+
+ err = mmc_card_lockable(card);
+ if (!err)
+ goto error;
+
+ if (mmc_card_locked(card) && !strncmp(data, "erase", 5)) {
+ /* forced erase only works while card is locked */
+ mmc_lock_unlock(card, NULL, MMC_LOCK_MODE_ERASE);
+ goto out;
+ } else if (!mmc_card_locked(card) && !strncmp(data, "remove", 6)) {
+ /* remove password only works while card is unlocked */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "remove");
+
+ if (!IS_ERR(mmc_key)) {
+ int err = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_CLR_PWD);
+ if (!err)
+ goto out;
+ } else
+ goto request_key_error;
+ } else if (!mmc_card_locked(card) && ((!strncmp(data, "assign", 6)) ||
+ (!strncmp(data, "change", 6)))) {
+
+ /* assign or change */
+ struct key *mmc_key;
+
+ if(!strncmp(data, "assign", 6))
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "assign");
+ else
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "change");
+
+ if (!IS_ERR(mmc_key)) {
+ int err = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_SET_PWD);
+ if (!err)
+ goto out;
+ } else
+ goto request_key_error;
+ } else if (mmc_card_locked(card) && !strncmp(data, "unlock", 6)) {
+ /* unlock */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "unlock");
+ if (!IS_ERR(mmc_key)) {
+ int err = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_UNLOCK);
+ if (err) {
+ dev_dbg(&card->dev, "Wrong password\n");
+ goto error;
+ }
+ else {
+ mmc_card_release_host(card);
+ goto out_unlocked;
+ }
+ } else
+ goto request_key_error;
+ }
+
+request_key_error:
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+error:
+ mmc_card_release_host(card);
+ return -EINVAL;
+out:
+ mmc_card_release_host(card);
+ return len;
+
+out_unlocked:
+ device_release_driver(dev);
+ device_attach(dev);
+ return len;
+}
+
+static struct device_attribute mmc_dev_attr_lockable =
+ __ATTR(lockable, S_IWUSR | S_IRUGO,
+ mmc_lockable_show, mmc_lockable_store);
+
+#endif
static void mmc_release_card(struct device *dev)
{
@@ -234,6 +336,11 @@ int mmc_register_card(struct mmc_card *c
if (ret)
device_del(&card->dev);
}
+#ifdef CONFIG_MMC_PASSWORDS
+ ret = device_create_file(&card->dev, &mmc_dev_attr_lockable);
+ if (ret)
+ device_del(&card->dev);
+#endif
}
return ret;
}
@@ -248,6 +355,9 @@ void mmc_remove_card(struct mmc_card *ca
if (mmc_card_sd(card))
device_remove_file(&card->dev, &mmc_dev_attr_scr);
+#ifdef CONFIG_MMC_PASSWORDS
+ device_remove_file(&card->dev, &mmc_dev_attr_lockable);
+#endif
device_del(&card->dev);
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-01-03 12:06 ` Anderson Briglia
@ 2007-01-06 13:35 ` Pierre Ossman
2007-01-06 22:24 ` Pierre Ossman
1 sibling, 0 replies; 12+ messages in thread
From: Pierre Ossman @ 2007-01-06 13:35 UTC (permalink / raw)
To: Anderson Briglia
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
Anderson Briglia wrote:
> Hi all,
>
> I believe this code is following the latest Russel's comments.
>
Afraid not. mmc_card_claim_host() is incredibly unintuitive in that it
requires an unlock on error (the lock always succeeds, the card select
might fail). I'll fix that up and commit the patch set.
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
PulseAudio, core developer http://pulseaudio.org
rdesktop, core developer http://www.rdesktop.org
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-01-03 12:06 ` Anderson Briglia
2007-01-06 13:35 ` Pierre Ossman
@ 2007-01-06 22:24 ` Pierre Ossman
2007-01-10 13:40 ` Anderson Briglia
2007-01-29 18:35 ` Anderson Briglia
1 sibling, 2 replies; 12+ messages in thread
From: Pierre Ossman @ 2007-01-06 22:24 UTC (permalink / raw)
To: Anderson Briglia
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
I've queued it up for -mm, but there a few more comments I want resolved
before this can move to Linus...
You need to clean up mmc_lockable_store(). It had a few broken variable
declarations that even prevented it from compiling, and after I fixed
that I still get:
drivers/mmc/mmc_sysfs.c: In function ‘mmc_lockable_store’:
drivers/mmc/mmc_sysfs.c:160: warning: ignoring return value of
‘device_attach’, declared with attribute warn_unused_result
drivers/mmc/mmc_sysfs.c:93: warning: ‘mmc_key’ may be used uninitialized
in this function
There's also no handling for an invalid string written to the sysfs node.
And third, you're a bit excessive on the goto:s. E.g. out_unlocked is
used in a single place, so it is completely unnecessary. Please do a
general cleanup of the control flow.
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
PulseAudio, core developer http://pulseaudio.org
rdesktop, core developer http://www.rdesktop.org
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-01-06 22:24 ` Pierre Ossman
@ 2007-01-10 13:40 ` Anderson Briglia
2007-01-10 19:25 ` Pierre Ossman
2007-01-29 18:35 ` Anderson Briglia
1 sibling, 1 reply; 12+ messages in thread
From: Anderson Briglia @ 2007-01-10 13:40 UTC (permalink / raw)
To: ext Pierre Ossman
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
ext Pierre Ossman wrote:
> I've queued it up for -mm, but there a few more comments I want resolved
> before this can move to Linus...
Ok, thanks for the revisions.
>
> You need to clean up mmc_lockable_store(). It had a few broken variable
> declarations that even prevented it from compiling, and after I fixed
> that I still get:
>
> drivers/mmc/mmc_sysfs.c: In function ‘mmc_lockable_store’:
> drivers/mmc/mmc_sysfs.c:160: warning: ignoring return value of
> ‘device_attach’, declared with attribute warn_unused_result
> drivers/mmc/mmc_sysfs.c:93: warning: ‘mmc_key’ may be used uninitialized
> in this function
I did a modification at this patch and did not get those warnings anymore.
>
> There's also no handling for an invalid string written to the sysfs node.
Is this really needed? I thought the function just ignored other values sent to itself that were not handled.
>
> And third, you're a bit excessive on the goto:s. E.g. out_unlocked is
> used in a single place, so it is completely unnecessary. Please do a
> general cleanup of the control flow.
Ok.
Regards,
Anderson Briglia
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-01-10 13:40 ` Anderson Briglia
@ 2007-01-10 19:25 ` Pierre Ossman
0 siblings, 0 replies; 12+ messages in thread
From: Pierre Ossman @ 2007-01-10 19:25 UTC (permalink / raw)
To: Anderson Briglia
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
Anderson Briglia wrote:
>> There's also no handling for an invalid string written to the sysfs node.
>>
>
> Is this really needed? I thought the function just ignored other values sent to itself that were not handled.
>
>
Well, returning an error on invalid data is the right<tm> thing to do.
And the warning about mmc_key is caused by this lack of error handling.
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
PulseAudio, core developer http://pulseaudio.org
rdesktop, core developer http://www.rdesktop.org
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-01-06 22:24 ` Pierre Ossman
2007-01-10 13:40 ` Anderson Briglia
@ 2007-01-29 18:35 ` Anderson Briglia
2007-01-30 18:10 ` Pierre Ossman
1 sibling, 1 reply; 12+ messages in thread
From: Anderson Briglia @ 2007-01-29 18:35 UTC (permalink / raw)
To: ext Pierre Ossman
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
[-- Attachment #1: Type: text/plain, Size: 1151 bytes --]
Hi Pierre,
Sorry about the delay.
I changed a bit the code to align with your latest suggestions.
ext Pierre Ossman wrote:
> I've queued it up for -mm, but there a few more comments I want resolved
> before this can move to Linus...
>
> You need to clean up mmc_lockable_store(). It had a few broken variable
> declarations that even prevented it from compiling, and after I fixed
> that I still get:
>
> drivers/mmc/mmc_sysfs.c: In function ‘mmc_lockable_store’:
> drivers/mmc/mmc_sysfs.c:160: warning: ignoring return value of
> ‘device_attach’, declared with attribute warn_unused_result
> drivers/mmc/mmc_sysfs.c:93: warning: ‘mmc_key’ may be used uninitialized
> in this function
I'm not getting those errors anymore.
>
> There's also no handling for an invalid string written to the sysfs node.
I believe now it is ok. If you send an invalid string to sysfs it will return -EINVAL.
>
> And third, you're a bit excessive on the goto:s. E.g. out_unlocked is
> used in a single place, so it is completely unnecessary. Please do a
> general cleanup of the control flow.
I believe now the number of goto's is ok.
Regards,
Anderson Briglia
[-- Attachment #2: mmc_sysfs.diff --]
[-- Type: text/plain, Size: 4393 bytes --]
Implement MMC password force erase, remove password, change password,
unlock card and assign password operations. It uses the sysfs mechanism
to send commands to the MMC subsystem.
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br>
Signed-off-by: Anderson Lizardo <anderson.lizardo@indt.org.br>
Signed-off-by: Anderson Briglia <anderson.briglia@indt.org.br>
Index: linux-linus-2.6/drivers/mmc/mmc_sysfs.c
===================================================================
--- linux-linus-2.6.orig/drivers/mmc/mmc_sysfs.c 2007-01-29 14:26:21.000000000 -0400
+++ linux-linus-2.6/drivers/mmc/mmc_sysfs.c 2007-01-29 14:28:19.000000000 -0400
@@ -17,6 +17,7 @@
#include <linux/idr.h>
#include <linux/workqueue.h>
#include <linux/key.h>
+#include <linux/err.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -65,6 +66,102 @@ static struct device_attribute mmc_dev_a
static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
+#ifdef CONFIG_MMC_PASSWORDS
+
+static ssize_t
+mmc_lockable_show(struct device *dev, struct device_attribute *att, char *buf)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+
+ if (!mmc_card_lockable(card))
+ return sprintf(buf, "unsupported\n");
+ else
+ return sprintf(buf, "%slocked\n", mmc_card_locked(card) ?
+ "" : "un");
+}
+
+/*
+ * implement MMC password functions: force erase, remove password, change
+ * password, unlock card and assign password.
+ */
+static ssize_t
+mmc_lockable_store(struct device *dev, struct device_attribute *att,
+ const char *data, size_t len)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+ int ret;
+
+ ret = mmc_card_claim_host(card);
+ if ((ret != MMC_ERR_NONE) || (!mmc_card_lockable(card)))
+ return -EINVAL;
+
+ ret = -EINVAL;
+ if (mmc_card_locked(card) && !strncmp(data, "erase", 5)) {
+ /* forced erase only works while card is locked */
+ mmc_lock_unlock(card, NULL, MMC_LOCK_MODE_ERASE);
+ ret = len;
+ goto out;
+ } else if (!mmc_card_locked(card) && !strncmp(data, "remove", 6)) {
+ /* remove password only works while card is unlocked */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "remove");
+
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_CLR_PWD);
+ if (!ret) {
+ ret = len;
+ } goto out;
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ } else if (!mmc_card_locked(card) && ((!strncmp(data, "assign", 6)) ||
+ (!strncmp(data, "change", 6)))) {
+ /* assign or change */
+ struct key *mmc_key;
+
+ if(!(strncmp(data, "assign", 6)))
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "assign");
+ else
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "change");
+
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_SET_PWD);
+ if (!ret) {
+ ret = len;
+ goto out;
+ }
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ } else if (mmc_card_locked(card) && !strncmp(data, "unlock", 6)) {
+ /* unlock */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "unlock");
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_UNLOCK);
+ if (ret) {
+ dev_dbg(&card->dev, "Wrong password\n");
+ ret = -EINVAL;
+ goto out;
+ }
+ else {
+ mmc_card_release_host(card);
+ device_release_driver(dev);
+ ret = device_attach(dev);
+ if(!ret)
+ return -EINVAL;
+ else
+ return len;
+ }
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ }
+out:
+ mmc_card_release_host(card);
+ return ret;
+}
+
+static struct device_attribute mmc_dev_attr_lockable =
+ __ATTR(lockable, S_IWUSR | S_IRUGO,
+ mmc_lockable_show, mmc_lockable_store);
+
+#endif
static void mmc_release_card(struct device *dev)
{
@@ -234,6 +331,11 @@ int mmc_register_card(struct mmc_card *c
if (ret)
device_del(&card->dev);
}
+#ifdef CONFIG_MMC_PASSWORDS
+ ret = device_create_file(&card->dev, &mmc_dev_attr_lockable);
+ if (ret)
+ device_del(&card->dev);
+#endif
}
return ret;
}
@@ -248,6 +350,9 @@ void mmc_remove_card(struct mmc_card *ca
if (mmc_card_sd(card))
device_remove_file(&card->dev, &mmc_dev_attr_scr);
+#ifdef CONFIG_MMC_PASSWORDS
+ device_remove_file(&card->dev, &mmc_dev_attr_lockable);
+#endif
device_del(&card->dev);
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-01-29 18:35 ` Anderson Briglia
@ 2007-01-30 18:10 ` Pierre Ossman
2007-01-30 21:26 ` Anderson Briglia
0 siblings, 1 reply; 12+ messages in thread
From: Pierre Ossman @ 2007-01-30 18:10 UTC (permalink / raw)
To: Anderson Briglia
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
Anderson Briglia wrote:
> Hi Pierre,
>
> Sorry about the delay.
> I changed a bit the code to align with your latest suggestions.
>
>
Nice, but the locking is broken again.
> I believe now the number of goto's is ok.
>
>
Actually, the ones you have left are completely useless. So you can just
remove the last bunch aswell.
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
PulseAudio, core developer http://pulseaudio.org
rdesktop, core developer http://www.rdesktop.org
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-01-30 18:10 ` Pierre Ossman
@ 2007-01-30 21:26 ` Anderson Briglia
2007-02-03 14:45 ` Pierre Ossman
0 siblings, 1 reply; 12+ messages in thread
From: Anderson Briglia @ 2007-01-30 21:26 UTC (permalink / raw)
To: ext Pierre Ossman
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
[-- Attachment #1: Type: text/plain, Size: 462 bytes --]
Hi Pierre,
How about now? Is better?
Regards,
Anderson Briglia
ext Pierre Ossman wrote:
> Anderson Briglia wrote:
>> Hi Pierre,
>>
>> Sorry about the delay.
>> I changed a bit the code to align with your latest suggestions.
>>
>>
>
> Nice, but the locking is broken again.
>
>> I believe now the number of goto's is ok.
>>
>>
>
> Actually, the ones you have left are completely useless. So you can just
> remove the last bunch aswell.
>
> Rgds
>
[-- Attachment #2: mmc_sysfs.diff --]
[-- Type: text/plain, Size: 4340 bytes --]
Implement MMC password force erase, remove password, change password,
unlock card and assign password operations. It uses the sysfs mechanism
to send commands to the MMC subsystem.
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br>
Signed-off-by: Anderson Lizardo <anderson.lizardo@indt.org.br>
Signed-off-by: Anderson Briglia <anderson.briglia@indt.org.br>
Index: linux-linus-2.6/drivers/mmc/mmc_sysfs.c
===================================================================
--- linux-linus-2.6.orig/drivers/mmc/mmc_sysfs.c 2007-01-30 16:28:38.000000000 -0400
+++ linux-linus-2.6/drivers/mmc/mmc_sysfs.c 2007-01-30 16:28:42.000000000 -0400
@@ -17,6 +17,7 @@
#include <linux/idr.h>
#include <linux/workqueue.h>
#include <linux/key.h>
+#include <linux/err.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -65,6 +66,100 @@ static struct device_attribute mmc_dev_a
static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
+#ifdef CONFIG_MMC_PASSWORDS
+
+static ssize_t
+mmc_lockable_show(struct device *dev, struct device_attribute *att, char *buf)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+
+ if (!mmc_card_lockable(card))
+ return sprintf(buf, "unsupported\n");
+ else
+ return sprintf(buf, "%slocked\n", mmc_card_locked(card) ?
+ "" : "un");
+}
+
+/*
+ * implement MMC password functions: force erase, remove password, change
+ * password, unlock card and assign password.
+ */
+static ssize_t
+mmc_lockable_store(struct device *dev, struct device_attribute *att,
+ const char *data, size_t len)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+ int ret;
+
+ if(!mmc_card_lockable(card))
+ return -EINVAL;
+
+ ret = mmc_card_claim_host(card);
+ if (ret != MMC_ERR_NONE)
+ return -EINVAL;
+
+ ret = -EINVAL;
+ if (mmc_card_locked(card) && !strncmp(data, "erase", 5)) {
+ /* forced erase only works while card is locked */
+ mmc_lock_unlock(card, NULL, MMC_LOCK_MODE_ERASE);
+ ret = len;
+ } else if (!mmc_card_locked(card) && !strncmp(data, "remove", 6)) {
+ /* remove password only works while card is unlocked */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "remove");
+
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_CLR_PWD);
+ if (!ret)
+ ret = len;
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ } else if (!mmc_card_locked(card) && ((!strncmp(data, "assign", 6)) ||
+ (!strncmp(data, "change", 6)))) {
+ /* assign or change */
+ struct key *mmc_key;
+
+ if(!(strncmp(data, "assign", 6)))
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "assign");
+ else
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "change");
+
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_SET_PWD);
+ if (!ret)
+ ret = len;
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ } else if (mmc_card_locked(card) && !strncmp(data, "unlock", 6)) {
+ /* unlock */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "unlock");
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_UNLOCK);
+ if (ret) {
+ dev_dbg(&card->dev, "Wrong password\n");
+ ret = -EINVAL;
+ }
+ else {
+ mmc_card_release_host(card);
+ device_release_driver(dev);
+ ret = device_attach(dev);
+ if(!ret)
+ return -EINVAL;
+ else
+ return len;
+ }
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ }
+
+ mmc_card_release_host(card);
+ return ret;
+}
+
+static struct device_attribute mmc_dev_attr_lockable =
+ __ATTR(lockable, S_IWUSR | S_IRUGO,
+ mmc_lockable_show, mmc_lockable_store);
+
+#endif
static void mmc_release_card(struct device *dev)
{
@@ -234,6 +329,11 @@ int mmc_register_card(struct mmc_card *c
if (ret)
device_del(&card->dev);
}
+#ifdef CONFIG_MMC_PASSWORDS
+ ret = device_create_file(&card->dev, &mmc_dev_attr_lockable);
+ if (ret)
+ device_del(&card->dev);
+#endif
}
return ret;
}
@@ -248,6 +348,9 @@ void mmc_remove_card(struct mmc_card *ca
if (mmc_card_sd(card))
device_remove_file(&card->dev, &mmc_dev_attr_scr);
+#ifdef CONFIG_MMC_PASSWORDS
+ device_remove_file(&card->dev, &mmc_dev_attr_lockable);
+#endif
device_del(&card->dev);
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-01-30 21:26 ` Anderson Briglia
@ 2007-02-03 14:45 ` Pierre Ossman
2007-02-05 21:33 ` Anderson Briglia
0 siblings, 1 reply; 12+ messages in thread
From: Pierre Ossman @ 2007-02-03 14:45 UTC (permalink / raw)
To: Anderson Briglia
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
Anderson Briglia wrote:
> Hi Pierre,
>
> How about now? Is better?
>
>
Locking problem is still there. You need to unclaim the host even when
claim fails.
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
PulseAudio, core developer http://pulseaudio.org
rdesktop, core developer http://www.rdesktop.org
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-02-03 14:45 ` Pierre Ossman
@ 2007-02-05 21:33 ` Anderson Briglia
2007-02-06 11:55 ` Pierre Ossman
0 siblings, 1 reply; 12+ messages in thread
From: Anderson Briglia @ 2007-02-05 21:33 UTC (permalink / raw)
To: ext Pierre Ossman
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
[-- Attachment #1: Type: text/plain, Size: 284 bytes --]
Hi Pierre,
ext Pierre Ossman wrote:
> Anderson Briglia wrote:
>> Hi Pierre,
>>
>> How about now? Is better?
>>
>>
>
> Locking problem is still there. You need to unclaim the host even when
> claim fails.
Bug fixed. Is there anything else to improve?
Regards,
Anderson Briglia
[-- Attachment #2: mmc_sysfs.diff --]
[-- Type: text/plain, Size: 4378 bytes --]
Implement MMC password force erase, remove password, change password,
unlock card and assign password operations. It uses the sysfs mechanism
to send commands to the MMC subsystem.
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar@indt.org.br>
Signed-off-by: Anderson Lizardo <anderson.lizardo@indt.org.br>
Signed-off-by: Anderson Briglia <anderson.briglia@indt.org.br>
Index: linux-linus-2.6/drivers/mmc/mmc_sysfs.c
===================================================================
--- linux-linus-2.6.orig/drivers/mmc/mmc_sysfs.c 2007-02-05 17:32:05.000000000 -0400
+++ linux-linus-2.6/drivers/mmc/mmc_sysfs.c 2007-02-05 17:32:19.000000000 -0400
@@ -17,6 +17,7 @@
#include <linux/idr.h>
#include <linux/workqueue.h>
#include <linux/key.h>
+#include <linux/err.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -65,6 +66,102 @@ static struct device_attribute mmc_dev_a
static struct device_attribute mmc_dev_attr_scr = MMC_ATTR_RO(scr);
+#ifdef CONFIG_MMC_PASSWORDS
+
+static ssize_t
+mmc_lockable_show(struct device *dev, struct device_attribute *att, char *buf)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+
+ if (!mmc_card_lockable(card))
+ return sprintf(buf, "unsupported\n");
+ else
+ return sprintf(buf, "%slocked\n", mmc_card_locked(card) ?
+ "" : "un");
+}
+
+/*
+ * implement MMC password functions: force erase, remove password, change
+ * password, unlock card and assign password.
+ */
+static ssize_t
+mmc_lockable_store(struct device *dev, struct device_attribute *att,
+ const char *data, size_t len)
+{
+ struct mmc_card *card = dev_to_mmc_card(dev);
+ int ret;
+
+ if(!mmc_card_lockable(card))
+ return -EINVAL;
+
+ ret = mmc_card_claim_host(card);
+ if (ret != MMC_ERR_NONE) {
+ mmc_card_release_host(card);
+ return -EINVAL;
+ }
+
+ ret = -EINVAL;
+ if (mmc_card_locked(card) && !strncmp(data, "erase", 5)) {
+ /* forced erase only works while card is locked */
+ mmc_lock_unlock(card, NULL, MMC_LOCK_MODE_ERASE);
+ ret = len;
+ } else if (!mmc_card_locked(card) && !strncmp(data, "remove", 6)) {
+ /* remove password only works while card is unlocked */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "remove");
+
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_CLR_PWD);
+ if (!ret)
+ ret = len;
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ } else if (!mmc_card_locked(card) && ((!strncmp(data, "assign", 6)) ||
+ (!strncmp(data, "change", 6)))) {
+ /* assign or change */
+ struct key *mmc_key;
+
+ if(!(strncmp(data, "assign", 6)))
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "assign");
+ else
+ mmc_key = request_key(&mmc_key_type, "mmc:key", "change");
+
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_SET_PWD);
+ if (!ret)
+ ret = len;
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ } else if (mmc_card_locked(card) && !strncmp(data, "unlock", 6)) {
+ /* unlock */
+ struct key *mmc_key = request_key(&mmc_key_type, "mmc:key", "unlock");
+ if (!IS_ERR(mmc_key)) {
+ ret = mmc_lock_unlock(card, mmc_key, MMC_LOCK_MODE_UNLOCK);
+ if (ret) {
+ dev_dbg(&card->dev, "Wrong password\n");
+ ret = -EINVAL;
+ }
+ else {
+ mmc_card_release_host(card);
+ device_release_driver(dev);
+ ret = device_attach(dev);
+ if(!ret)
+ return -EINVAL;
+ else
+ return len;
+ }
+ } else
+ dev_dbg(&card->dev, "request_key returned error %ld\n", PTR_ERR(mmc_key));
+ }
+
+ mmc_card_release_host(card);
+ return ret;
+}
+
+static struct device_attribute mmc_dev_attr_lockable =
+ __ATTR(lockable, S_IWUSR | S_IRUGO,
+ mmc_lockable_show, mmc_lockable_store);
+
+#endif
static void mmc_release_card(struct device *dev)
{
@@ -234,6 +331,11 @@ int mmc_register_card(struct mmc_card *c
if (ret)
device_del(&card->dev);
}
+#ifdef CONFIG_MMC_PASSWORDS
+ ret = device_create_file(&card->dev, &mmc_dev_attr_lockable);
+ if (ret)
+ device_del(&card->dev);
+#endif
}
return ret;
}
@@ -248,6 +350,9 @@ void mmc_remove_card(struct mmc_card *ca
if (mmc_card_sd(card))
device_remove_file(&card->dev, &mmc_dev_attr_scr);
+#ifdef CONFIG_MMC_PASSWORDS
+ device_remove_file(&card->dev, &mmc_dev_attr_lockable);
+#endif
device_del(&card->dev);
}
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff
2007-02-05 21:33 ` Anderson Briglia
@ 2007-02-06 11:55 ` Pierre Ossman
0 siblings, 0 replies; 12+ messages in thread
From: Pierre Ossman @ 2007-02-06 11:55 UTC (permalink / raw)
To: Anderson Briglia
Cc: Russell King, Lizardo Anderson (EXT-INdT/Manaus),
linux-kernel, Aguiar Carlos (EXT-INdT/Manaus),
Tony Lindgren, ext David Brownell
Anderson Briglia wrote:
> Bug fixed. Is there anything else to improve?
>
>
Great. All known issues should be fixed now.
I'm currently reorganising my -mm branch, so things might go missing
from there for a while. But it will be back eventually.
Btw, any progress on testing this with SD?
Rgds
--
-- Pierre Ossman
Linux kernel, MMC maintainer http://www.kernel.org
PulseAudio, core developer http://pulseaudio.org
rdesktop, core developer http://www.rdesktop.org
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2007-02-06 11:55 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-15 18:57 [PATCH 4/4] Add MMC Password Protection (lock/unlock) support V9: mmc_sysfs.diff Anderson Briglia
2007-01-03 12:06 ` Anderson Briglia
2007-01-06 13:35 ` Pierre Ossman
2007-01-06 22:24 ` Pierre Ossman
2007-01-10 13:40 ` Anderson Briglia
2007-01-10 19:25 ` Pierre Ossman
2007-01-29 18:35 ` Anderson Briglia
2007-01-30 18:10 ` Pierre Ossman
2007-01-30 21:26 ` Anderson Briglia
2007-02-03 14:45 ` Pierre Ossman
2007-02-05 21:33 ` Anderson Briglia
2007-02-06 11:55 ` Pierre Ossman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).