lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Mon, 2 Jan 2012 09:42:59 +0200
From:	"Alon Ziv" <alonz@...cretix.com>
To:	"Chris Ball" <cjb@...top.org>
Cc:	"Alon Ziv" <alonz@...cretix.com>, "Chris Ball" <cjb@...top.org>,
	"Andrei Warkentin" <awarkentin@...are.com>,
	"Kyungmin Park" <kyungmin.park@...sung.com>,
	"Arnd Bergmann" <arnd@...db.de>, "Venkatraman S" <svenkatr@...com>,
	<linux-mmc@...r.kernel.org>, <linux-kernel@...r.kernel.org>
Subject: [PATCH] Properly support MMC_IOC_CMD operations without a data payload

Some MMC/SD host controllers require the "data" member of
"struct mmc_request" to be NULL when the command has no data attached.
Change the MMC ioctl method to not initialize the "data" member when
the supplied data size (blksz * blocks) is zero.

Signed-off-by: Alon Ziv <alonz@...cretix.com>
---
 drivers/mmc/card/block.c |   45
+++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 1e0e27c..a0ab6c1 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -266,16 +266,18 @@ static struct mmc_blk_ioc_data
*mmc_blk_ioctl_copy_from_user(
 		goto idata_err;
 	}
 
-	idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL);
-	if (!idata->buf) {
-		err = -ENOMEM;
-		goto idata_err;
-	}
+	if (idata->buf_bytes != 0) {
+		idata->buf = kzalloc(idata->buf_bytes, GFP_KERNEL);
+		if (!idata->buf) {
+			err = -ENOMEM;
+			goto idata_err;
+		}
 
-	if (copy_from_user(idata->buf, (void __user *)(unsigned long)
-					idata->ic.data_ptr,
idata->buf_bytes)) {
-		err = -EFAULT;
-		goto copy_err;
+		if (copy_from_user(idata->buf, (void __user *)(unsigned
long)
+						idata->ic.data_ptr,
idata->buf_bytes)) {
+			err = -EFAULT;
+			goto copy_err;
+		}
 	}
 
 	return idata;
@@ -315,21 +317,23 @@ static int mmc_blk_ioctl_cmd(struct block_device
*bdev,
 	cmd.opcode = idata->ic.opcode;
 	cmd.arg = idata->ic.arg;
 	cmd.flags = idata->ic.flags;
+	mrq.cmd = &cmd;
 
-	data.sg = &sg;
-	data.sg_len = 1;
-	data.blksz = idata->ic.blksz;
-	data.blocks = idata->ic.blocks;
+	if (idata->buf_bytes != 0) {
+		data.sg = &sg;
+		data.sg_len = 1;
+		data.blksz = idata->ic.blksz;
+		data.blocks = idata->ic.blocks;
 
-	sg_init_one(data.sg, idata->buf, idata->buf_bytes);
+		sg_init_one(data.sg, idata->buf, idata->buf_bytes);
 
-	if (idata->ic.write_flag)
-		data.flags = MMC_DATA_WRITE;
-	else
-		data.flags = MMC_DATA_READ;
+		if (idata->ic.write_flag)
+			data.flags = MMC_DATA_WRITE;
+		else
+			data.flags = MMC_DATA_READ;
 
-	mrq.cmd = &cmd;
-	mrq.data = &data;
+		mrq.data = &data;
+	}
 
 	md = mmc_blk_get(bdev->bd_disk);
 	if (!md) {
@@ -353,6 +357,7 @@ static int mmc_blk_ioctl_cmd(struct block_device
*bdev,
 
 	/* data.flags must already be set before doing this. */
 	mmc_set_data_timeout(&data, card);
+
 	/* Allow overriding the timeout_ns for empirical tuning. */
 	if (idata->ic.data_timeout_ns)
 		data.timeout_ns = idata->ic.data_timeout_ns;
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ