Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: block: fix updating ext_csd caches on ioctl call

PARTITION_CONFIG is cached in mmc_card->ext_csd.part_config and the
currently active partition in mmc_blk_data->part_curr. These caches do
not always reflect changes if the ioctl call modifies the
PARTITION_CONFIG registers, e.g. by changing BOOT_PARTITION_ENABLE.

Write the PARTITION_CONFIG value extracted from the ioctl call to the
cache and update the currently active partition accordingly. This
ensures that the user space cannot change the values behind the
kernel's back. The next call to mmc_blk_part_switch() will operate on
the data set by the ioctl and reflect the changes appropriately.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
Cc: stable@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>

authored by

Bastian Stender and committed by
Ulf Hansson
e74ef219 c7151602

+19
+19
drivers/mmc/core/block.c
··· 72 72 #define MMC_BLK_TIMEOUT_MS (10 * 1000) 73 73 #define MMC_SANITIZE_REQ_TIMEOUT 240000 74 74 #define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16) 75 + #define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8) 75 76 76 77 #define mmc_req_rel_wr(req) ((req->cmd_flags & REQ_FUA) && \ 77 78 (rq_data_dir(req) == WRITE)) ··· 585 584 dev_err(mmc_dev(card->host), "%s: data error %d\n", 586 585 __func__, data.error); 587 586 return data.error; 587 + } 588 + 589 + /* 590 + * Make sure the cache of the PARTITION_CONFIG register and 591 + * PARTITION_ACCESS bits is updated in case the ioctl ext_csd write 592 + * changed it successfully. 593 + */ 594 + if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_PART_CONFIG) && 595 + (cmd.opcode == MMC_SWITCH)) { 596 + struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev); 597 + u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg); 598 + 599 + /* 600 + * Update cache so the next mmc_blk_part_switch call operates 601 + * on up-to-date data. 602 + */ 603 + card->ext_csd.part_config = value; 604 + main_md->part_curr = value & EXT_CSD_PART_CONFIG_ACC_MASK; 588 605 } 589 606 590 607 /*