[PATCH] MMC: Prevent MMC block driver from trying to access password-locked cards

From: Anderson Lizardo
Date: Sat Nov 05 2005 - 15:44:42 EST


Hi,

We are working on adding support for password-locked MMC cards on
Linux, using the Kernel Key Retention Service for password management.
This is the first patch we will be sending to add such support. Any
comments/suggestions are welcome.

The patch itself:

Prevent the MMC block driver from trying to access password-locked MMC cards.

Signed-off-by: Anderson Lizardo <anderson.lizardo@xxxxxxxxxxx>
Signed-off-by: Carlos Eduardo Aguiar <carlos.aguiar@xxxxxxxxxxx>
Signed-off-by: David Brownell <david-b@xxxxxxxxxxx>
---
commit 7dd244db4842d8d8741c9a1c4a37760d16d07a80
tree 4a4b6843cc9db67454365dec420f2af46b705834
parent 06024f217d607369f0ee0071034ebb03071d5fb2
author Anderson Lizardo <anderson.lizardo@xxxxxxxxxxx> Thu, 03 Nov
2005 19:48:48 -0500
committer Anderson Lizardo <anderson.lizardo@xxxxxxxxxxx> Thu, 03 Nov
2005 19:48:48 -0500

drivers/mmc/mmc.c | 7 +++++--
drivers/mmc/mmc_sysfs.c | 18 +++++++++++++++---
include/linux/mmc/card.h | 5 +++++
3 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -986,10 +986,13 @@ static void mmc_check_cards(struct mmc_h
cmd.flags = MMC_RSP_R1;

err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);
- if (err == MMC_ERR_NONE)
+ if (err != MMC_ERR_NONE) {
+ mmc_card_set_dead(card);
continue;
+ }

- mmc_card_set_dead(card);
+ if (cmd.resp[0] & R1_CARD_IS_LOCKED)
+ mmc_card_set_locked(card);
}
}

diff --git a/drivers/mmc/mmc_sysfs.c b/drivers/mmc/mmc_sysfs.c
--- a/drivers/mmc/mmc_sysfs.c
+++ b/drivers/mmc/mmc_sysfs.c
@@ -16,6 +18,7 @@

#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
+#include <linux/mmc/protocol.h>

#include "mmc.h"

@@ -69,13 +72,22 @@ static void mmc_release_card(struct devi
}

/*
- * This currently matches any MMC driver to any MMC card - drivers
- * themselves make the decision whether to drive this card in their
- * probe method. However, we force "bad" cards to fail.
+ * This currently matches any MMC driver to any MMC card - drivers themselves
+ * make the decision whether to drive this card in their probe method. However,
+ * we force "bad" cards to fail.
+ *
+ * We also fail for all locked cards; drivers expect to be able to do I/O still
+ * on probe(), which is not possible while the card is locked. mmc_rescan()
+ * must then be triggered sometime later to unlock the card and make it
+ * available to the block driver.
*/
static int mmc_bus_match(struct device *dev, struct device_driver *drv)
{
struct mmc_card *card = dev_to_mmc_card(dev);
+ if (mmc_card_lockable(card) && mmc_card_locked(card)) {
+ dev_dbg(&card->dev, "card is locked; binding is deferred\n");
+ return 0;
+ }
return !mmc_card_bad(card);
}

diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -56,6 +56,7 @@ struct mmc_card {
#define MMC_STATE_BAD (1<<2) /* unrecognised device */
#define MMC_STATE_SDCARD (1<<3) /* is an SD card */
#define MMC_STATE_READONLY (1<<4) /* card is read-only */
+#define MMC_STATE_LOCKED (1<<5) /* card is currently locked */
u32 raw_cid[4]; /* raw card CID */
u32 raw_csd[4]; /* raw card CSD */
u32 raw_scr[2]; /* raw card SCR */
@@ -69,12 +70,16 @@ struct mmc_card {
#define mmc_card_bad(c) ((c)->state & MMC_STATE_BAD)
#define mmc_card_sd(c) ((c)->state & MMC_STATE_SDCARD)
#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
+#define mmc_card_locked(c) ((c)->state & MMC_STATE_LOCKED)
+
+#define mmc_card_lockable(c) ((c)->csd.cmdclass & CCC_LOCK_CARD)

#define mmc_card_set_present(c) ((c)->state |= MMC_STATE_PRESENT)
#define mmc_card_set_dead(c) ((c)->state |= MMC_STATE_DEAD)
#define mmc_card_set_bad(c) ((c)->state |= MMC_STATE_BAD)
#define mmc_card_set_sd(c) ((c)->state |= MMC_STATE_SDCARD)
#define mmc_card_set_readonly(c) ((c)->state |= MMC_STATE_READONLY)
+#define mmc_card_set_locked(c) ((c)->state |= MMC_STATE_LOCKED)

#define mmc_card_name(c) ((c)->cid.prod_name)
#define mmc_card_id(c) ((c)->dev.bus_id)


--
Anderson Lizardo
Embedded Linux Lab - 10LE
Nokia Institute of Technology - INdT
Manaus - Brazil
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/