Skip to contentSkip to conversation

Add MMC Password Protection (lock/unlock) support V5

RFC PATCH Pierre Ossman 3 participants 9 messages Oct 23, 2006 – Oct 30, 2006 7 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 3 lines · Carlos Aguiar

Hi folks,

Hi Carlos,

This is very nice work and it is something that should be in the kernel.

Unfortunately, I won't have time to look at this until the end of the week. So just hang tight, I haven't overlooked you. :)

Rgds

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org
#2 lore raw
Quoted 9 lines · Pierre Ossman
Quoted 1 line · Carlos Aguiar

Hi folks,

Hi Carlos,

This is very nice work and it is something that should be in the kernel.

Unfortunately, I won't have time to look at this until the end of the week. So just hang tight, I haven't overlooked you. :)

Just make sure that it checks for MMC_CAP_BYTEBLOCK - if that flag isn't set, the host can't do non-power of two transfers, so probably password support has to be refused on such hosts.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 7 lines · Carlos Aguiar

When a card is locked, only commands from the "basic" and "lock card" classes are accepted. To be able to use the other commands, the card must be unlocked first.

This patch prevents the block driver from trying to run privileged class commands on locked MMC cards, which will fail anyway.

Incorrect commit message. It stops driver probes (all of them).

Review struct mmc_host { · line 91

Quoted 11 lines

20 11:41:54.000000000 -0400

(quoted diff) +1 -0
@@ -85,6 +85,7 @@ struct mmc_host {
 	unsigned long		caps;		/* Host capabilities */
 
 #define MMC_CAP_4_BIT_DATA	(1 << 0)	/* Can the host do 4 bit transfers */
+#define MMC_CAP_LOCK_UNLOCK	(1 << 1)	/* Host password support capability */
 
 	/* host specific block data */
 	unsigned int		max_seg_size;	/* see blk_queue_max_segment_size */

You need to rebase your patch set on a more recent kernel. This won't apply cleanly.

Rgds

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw
Quoted 2 lines · Carlos Aguiar

+int mmc_key_instantiate(struct key *key, const void *data, size_t datalen)

static

Quoted 2 lines

+int mmc_key_match(const struct key *key, const void *description)

static

Quoted 2 lines

+void mmc_key_destroy(struct key *key)

static

Quoted 7 lines
(quoted diff) +2 -0
@@ -335,6 +403,15 @@ static int __init mmc_init(void)
 		ret = class_register(&mmc_host_class);
 		if (ret)
 			bus_unregister(&mmc_bus_type);
+#ifdef	CONFIG_MMC_PASSWORDS
+		else {

Review static int __init mmc_init(void) · line 417

Quoted 10 lines
(quoted diff) +7 -0
+			ret = register_key_type(&mmc_key_type);
+			if (ret) {
+				class_unregister(&mmc_host_class);
+				bus_unregister(&mmc_bus_type);
+			}
+		}
+#endif
 	}
 	return ret;
 }

We're starting to get a bit of code duplication here. Perhaps an error handling section at the end of the function would be better.

Rgds

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 5 lines · Carlos Aguiar
(quoted diff) +0 -0
@@ -1071,10 +1074,10 @@ static void mmc_check_cards(struct mmc_h
 		cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
 
 		err = mmc_wait_for_cmd(host, &cmd, CMD_RETRIES);

Review static void mmc_check_cards(struct mmc_h · line 1083

Quoted 10 lines
(quoted diff) +3 -3
-		if (err == MMC_ERR_NONE)
+		if (err != MMC_ERR_NONE) {
+			mmc_card_set_dead(card);
 			continue;
-
-		mmc_card_set_dead(card);
+		}
 	}
 }
 

This seems like a pointless change.

Review static void mmc_setup(struct mmc_host *h · line 1172

Quoted 11 lines
(quoted diff) +6 -0
@@ -1160,6 +1163,139 @@ static void mmc_setup(struct mmc_host *h
 		mmc_read_scrs(host);
 }
 
+/* Calculate the minimal blksz_bits to hold x bytes. */
+static inline int blksz_bits(unsigned x)
+{
+	return fls(x-1);
+}
+
 

blksz_bits is gone, so this is superfluous. Note Russell's comment about looking at the MMC_CAP_BYTEBLOCK capability, something you do not do right now.

Quoted 17 lines
(quoted diff) +17 -0
+/**
+ *	mmc_lock_unlock - send LOCK_UNLOCK command to a specific card.
+ *	@card: card to which the LOCK_UNLOCK command should be sent
+ *	@key: key containing the MMC password
+ *	@mode: LOCK_UNLOCK mode
+ *
+ */
+int mmc_lock_unlock(struct mmc_card *card, struct key *key, int mode)
+{
+	struct mmc_request mrq;
+	struct mmc_command cmd;
+	struct mmc_data data;
+	struct scatterlist sg;
+	struct mmc_key_payload *mpayload;
+	unsigned long erase_timeout;
+	int err, data_size;
+	u8 *data_buf;

Review static void mmc_setup(struct mmc_host *h · line 1199

Quoted 10 lines
(quoted diff) +9 -0
+
+	mpayload = NULL;
+	data_size = 1;
+	if (mode != MMC_LOCK_MODE_ERASE) {
+		mpayload = rcu_dereference(key->payload.data);
+		data_size = 2 + mpayload->datalen;
+	}
+
+	data_buf = kmalloc(data_size, GFP_KERNEL);
 

For something that can be at most 34 bytes, a kmalloc seems excessive. Put it on the stack. Just remember to have checks so we do not overflow.

Quoted 6 lines
(quoted diff) +6 -0
+	if (!data_buf)
+		return -ENOMEM;
+	memset(data_buf, 0, data_size);
+
+	data_buf[0] = mode;
+	if (mode != MMC_LOCK_MODE_ERASE) {

Review static void mmc_setup(struct mmc_host *h · line 1215

Quoted 10 lines
(quoted diff) +9 -0
+		data_buf[1] = mpayload->datalen;
+		memcpy(data_buf + 2, mpayload->data, mpayload->datalen);
+	}
+
+	err = mmc_card_claim_host(card);
+	if (err != MMC_ERR_NONE) {
+		mmc_card_set_dead(card);
+		goto out;
+	}
 

Locking should be done outside this function to avoid races.

Also, why mark the card as dead because you cannot select it? It might just be a temporary failure.

Review static void mmc_setup(struct mmc_host *h · line 1226

Quoted 12 lines
(quoted diff) +11 -0
+
+	memset(&cmd, 0, sizeof(struct mmc_command));
+
+	cmd.opcode = MMC_SET_BLOCKLEN;
+	cmd.arg = data_size;
+	cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
+	err = mmc_wait_for_cmd(card->host, &cmd, CMD_RETRIES);
+	if (err != MMC_ERR_NONE) {
+		mmc_card_set_dead(card);
+		goto error;
+	}

Same here.

Review static void mmc_setup(struct mmc_host *h · line 1234

Quoted 9 lines
(quoted diff) +8 -0
+
+	sg_init_one(&sg, data_buf, data_size);
+	err = mmc_wait_for_req(card->host, &mrq);
+	if (err != MMC_ERR_NONE) {
+		if(err != MMC_ERR_INVALID)
+			mmc_card_set_dead(card);
+		goto error;
+	}

Dito.

Review static void mmc_setup(struct mmc_host *h · line 1236

Quoted 3 lines
(quoted diff) +2 -0
+
+EXPORT_SYMBOL(mmc_lock_unlock);

Why would anything but mmc_core need to use this?

Quoted 9 lines

/**
* mmc_detect_change - process change of state on a MMC socket
Index: linux-2.6.18/include/linux/mmc/card.h
===================================================================

include/linux/mmc/card.h static inline int mmc_card_claim_host(st · line 124

Quoted 8 lines
include/linux/mmc/card.h +4 -0
@@ -117,4 +117,8 @@ static inline int mmc_card_claim_host(st
 
 #define mmc_card_release_host(c)	mmc_release_host((c)->host)
 
+struct key;
+
+extern int mmc_lock_unlock(struct mmc_card *card, struct key *key, int mode);
+
 #endif

Which means this should go away (and put in drivers/mmc/mmc.h).

Rgds

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org
#9 lore raw
Quoted 5 lines · Pierre Ossman

Review

Quoted 2 lines
(quoted diff) +1 -0
+	data_buf = kmalloc(data_size, GFP_KERNEL);

For something that can be at most 34 bytes, a kmalloc seems excessive. Put it on the stack. Just remember to have checks so we do not overflow.

It does seem excessive, but stack-allocated buffers are not guaranteed to be DMA-safe. See Documentation/DMA-mapping.txt right in the first major section "What memory is DMA'able?"...

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw
Quoted 2 lines · Carlos Aguiar

Patch to add the host MMC lock/unlock capability support for OMAP platform.

Now what could possibly be the purpose of this? What hardware feature is required to support these commands?

Rgds

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw
Quoted 4 lines · Carlos Aguiar

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.

There are some indentation problems with this patch.

Also, what's the difference between "change" and "assign"? The code seems to do the same thing.

Rgds

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org

A message that is not in the archive (sent off-list or not yet received): [email protected]

#15 lore raw
Quoted 3 lines · Carlos Aguiar

Removes an unused function: mmc_omap_switch_callback() and changed IRQ comparison in omap.c

This looks completely unrelated to password support.

Rgds

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org