* [PATCH v2 1/2] mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL
@ 2017-07-05 15:09 Geert Uytterhoeven
2017-07-05 15:09 ` [PATCH v2 2/2] mmc: block: Let MMC_IOC_MULTI_CMD return zero again for zero entries Geert Uytterhoeven
2017-07-11 14:44 ` [PATCH v2 1/2] mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL Ulf Hansson
0 siblings, 2 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2017-07-05 15:09 UTC (permalink / raw)
To: Ulf Hansson, Linus Walleij
Cc: Arnd Bergmann, linux-mmc, linux-kernel, Geert Uytterhoeven
With gcc 4.1.2:
drivers/mmc/core/block.c: In function ‘mmc_blk_issue_drv_op’:
drivers/mmc/core/block.c:1178: warning: ‘ret’ may be used uninitialized in this function
Indeed, for MMC_DRV_OP_IOCTL, if mq_rq->ioc_count is zero, an
uninitialized value will be stored in mq_rq->drv_op_result and passed to
blk_end_request_all().
Can mq_rq->ioc_count be zero?
- mmc_blk_ioctl_cmd() sets ioc_count to 1, so this is safe,
- mmc_blk_ioctl_multi_cmd() obtains ioc_count from user space in
response to the MMC_IOC_MULTI_CMD ioctl, and does allow zero.
Initialize ret to zero to fix this for current and future callers.
Fixes: 0493f6fe5bdee8ac ("mmc: block: Move boot partition locking into a driver op")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
v2, as suggested by Arnd:
- Move the assignment after "case MMC_DRV_OP_IOCTL", to keep getting
compile-time checks on the state of the 'ret' variable,
- Initialize ret to zero instead of -EINVAL.
---
drivers/mmc/core/block.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 0cfac2d391073922..4920ea1ece38a9b6 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -1182,7 +1182,7 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req)
switch (mq_rq->drv_op) {
case MMC_DRV_OP_IOCTL:
- for (i = 0; i < mq_rq->ioc_count; i++) {
+ for (i = 0, ret = 0; i < mq_rq->ioc_count; i++) {
ret = __mmc_blk_ioctl_cmd(card, md, mq_rq->idata[i]);
if (ret)
break;
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 2/2] mmc: block: Let MMC_IOC_MULTI_CMD return zero again for zero entries
2017-07-05 15:09 [PATCH v2 1/2] mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL Geert Uytterhoeven
@ 2017-07-05 15:09 ` Geert Uytterhoeven
2017-07-11 14:44 ` Ulf Hansson
2017-07-11 14:44 ` [PATCH v2 1/2] mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL Ulf Hansson
1 sibling, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2017-07-05 15:09 UTC (permalink / raw)
To: Ulf Hansson, Linus Walleij
Cc: Arnd Bergmann, linux-mmc, linux-kernel, Geert Uytterhoeven
With gcc 4.1.2:
drivers/mmc/core/block.c: In function ‘mmc_blk_ioctl_cmd_issue’:
drivers/mmc/core/block.c:630: warning: ‘ioc_err’ may be used uninitialized in this function
Indeed, if mq_rq->ioc_count is zero, an uninitialized value will be
stored in mq_rq->drv_op_result and passed to blk_end_request_all().
Can mq_rq->ioc_count be zero?
- mmc_blk_ioctl_cmd() sets ioc_count to 1, so this is safe,
- mmc_blk_ioctl_multi_cmd() obtains ioc_count from user space in
response to the MMC_IOC_MULTI_CMD ioctl, and does allow zero.
To avoid returning an uninitialized value, and as it is pointless to do
all this work when the MMC_IOC_MULTI_CMD ioctl is used with zero
entries, check for this early in mmc_blk_ioctl_multi_cmd(), and return
zero, like was returned before.
Fixes: 3ecd8cf23f88d5df ("mmc: block: move multi-ioctl() to use block layer")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Should mmc_blk_ioctl_multi_cmd() return -EINVAL instead for this case?
That would change behavior as seen from userspace, though.
Feel free to fold in the previous patch if deemed appropriate.
v2:
- No changes.
---
drivers/mmc/core/block.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 4920ea1ece38a9b6..e0363223996e6096 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -637,6 +637,9 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
sizeof(num_of_cmds)))
return -EFAULT;
+ if (!num_of_cmds)
+ return 0;
+
if (num_of_cmds > MMC_IOC_MAX_CMDS)
return -EINVAL;
--
2.7.4
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2 2/2] mmc: block: Let MMC_IOC_MULTI_CMD return zero again for zero entries
2017-07-05 15:09 ` [PATCH v2 2/2] mmc: block: Let MMC_IOC_MULTI_CMD return zero again for zero entries Geert Uytterhoeven
@ 2017-07-11 14:44 ` Ulf Hansson
0 siblings, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2017-07-11 14:44 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Linus Walleij, Arnd Bergmann, linux-mmc, linux-kernel
On 5 July 2017 at 17:09, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> With gcc 4.1.2:
>
> drivers/mmc/core/block.c: In function ‘mmc_blk_ioctl_cmd_issue’:
> drivers/mmc/core/block.c:630: warning: ‘ioc_err’ may be used uninitialized in this function
>
> Indeed, if mq_rq->ioc_count is zero, an uninitialized value will be
> stored in mq_rq->drv_op_result and passed to blk_end_request_all().
>
> Can mq_rq->ioc_count be zero?
> - mmc_blk_ioctl_cmd() sets ioc_count to 1, so this is safe,
> - mmc_blk_ioctl_multi_cmd() obtains ioc_count from user space in
> response to the MMC_IOC_MULTI_CMD ioctl, and does allow zero.
>
> To avoid returning an uninitialized value, and as it is pointless to do
> all this work when the MMC_IOC_MULTI_CMD ioctl is used with zero
> entries, check for this early in mmc_blk_ioctl_multi_cmd(), and return
> zero, like was returned before.
>
> Fixes: 3ecd8cf23f88d5df ("mmc: block: move multi-ioctl() to use block layer")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Thanks, applied for fixes!
Kind regards
Uffe
> ---
> Should mmc_blk_ioctl_multi_cmd() return -EINVAL instead for this case?
> That would change behavior as seen from userspace, though.
>
> Feel free to fold in the previous patch if deemed appropriate.
>
> v2:
> - No changes.
> ---
> drivers/mmc/core/block.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 4920ea1ece38a9b6..e0363223996e6096 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -637,6 +637,9 @@ static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
> sizeof(num_of_cmds)))
> return -EFAULT;
>
> + if (!num_of_cmds)
> + return 0;
> +
> if (num_of_cmds > MMC_IOC_MAX_CMDS)
> return -EINVAL;
>
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL
2017-07-05 15:09 [PATCH v2 1/2] mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL Geert Uytterhoeven
2017-07-05 15:09 ` [PATCH v2 2/2] mmc: block: Let MMC_IOC_MULTI_CMD return zero again for zero entries Geert Uytterhoeven
@ 2017-07-11 14:44 ` Ulf Hansson
1 sibling, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2017-07-11 14:44 UTC (permalink / raw)
To: Geert Uytterhoeven; +Cc: Linus Walleij, Arnd Bergmann, linux-mmc, linux-kernel
On 5 July 2017 at 17:09, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> With gcc 4.1.2:
>
> drivers/mmc/core/block.c: In function ‘mmc_blk_issue_drv_op’:
> drivers/mmc/core/block.c:1178: warning: ‘ret’ may be used uninitialized in this function
>
> Indeed, for MMC_DRV_OP_IOCTL, if mq_rq->ioc_count is zero, an
> uninitialized value will be stored in mq_rq->drv_op_result and passed to
> blk_end_request_all().
>
> Can mq_rq->ioc_count be zero?
> - mmc_blk_ioctl_cmd() sets ioc_count to 1, so this is safe,
> - mmc_blk_ioctl_multi_cmd() obtains ioc_count from user space in
> response to the MMC_IOC_MULTI_CMD ioctl, and does allow zero.
>
> Initialize ret to zero to fix this for current and future callers.
>
> Fixes: 0493f6fe5bdee8ac ("mmc: block: Move boot partition locking into a driver op")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Thanks, applied for fixes!
Kind regards
Uffe
> ---
> v2, as suggested by Arnd:
> - Move the assignment after "case MMC_DRV_OP_IOCTL", to keep getting
> compile-time checks on the state of the 'ret' variable,
> - Initialize ret to zero instead of -EINVAL.
> ---
> drivers/mmc/core/block.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 0cfac2d391073922..4920ea1ece38a9b6 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -1182,7 +1182,7 @@ static void mmc_blk_issue_drv_op(struct mmc_queue *mq, struct request *req)
>
> switch (mq_rq->drv_op) {
> case MMC_DRV_OP_IOCTL:
> - for (i = 0; i < mq_rq->ioc_count; i++) {
> + for (i = 0, ret = 0; i < mq_rq->ioc_count; i++) {
> ret = __mmc_blk_ioctl_cmd(card, md, mq_rq->idata[i]);
> if (ret)
> break;
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-07-11 14:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-05 15:09 [PATCH v2 1/2] mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL Geert Uytterhoeven
2017-07-05 15:09 ` [PATCH v2 2/2] mmc: block: Let MMC_IOC_MULTI_CMD return zero again for zero entries Geert Uytterhoeven
2017-07-11 14:44 ` Ulf Hansson
2017-07-11 14:44 ` [PATCH v2 1/2] mmc: block: Initialize ret in mmc_blk_issue_drv_op() for MMC_DRV_OP_IOCTL Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®