mmc: block: ioctl: Add PROG-error aggregation
PATCH v3 1/1 mmc: block: ioctl: Add PROG-error aggregation
Userspace currently has no way of checking for error bits of detection mode X. These are error bits that are only detected by the card when executing the command. For e.g. a sanitize operation this may be minutes after the RSP was seen by the host.
Currently userspace programs cannot see these error bits reliably. They could issue a multi ioctl cmd with a CMD13 immediately following it, but since errors of detection mode X are automatically cleared (they are all clear condition B).mmc_poll_for_busy of the first ioctl may have already hidden such an error flag.
In case of the security operations: sanitize, secure erases and RPMB writes, this could lead to the operation not being performed successfully by the card with the user not knowing.
If the user trusts that this operation is completed (e.g. their data is sanitized), this could be a security issue. An attacker could e.g. provoke a eMMC (VCC) flash fail, where a successful sanitize of a card is not possible. A card may move out of PROG state but issue a bit 19 R1 error.
This patch therefore will also have the consequence of a mmc-utils patch, which enables the bit for the security-sensitive operations.
--- drivers/mmc/core/block.c | 26 +++++++++++++++----------- drivers/mmc/core/mmc_ops.c | 14 +++++++------- drivers/mmc/core/mmc_ops.h | 9 +++++++++ 3 files changed, 31 insertions(+), 18 deletions(-)
drivers/mmc/core/block.c +15 -11
@@ -470,7 +470,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,struct mmc_data data = {};struct mmc_request mrq = {};struct scatterlist sg; -bool r1b_resp, use_r1b_resp = false; +bool r1b_resp;unsigned int busy_timeout_ms;int err;unsigned int target_part;
@@ -551,8 +551,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, busy_timeout_ms = idata->ic.cmd_timeout_ms ? :MMC_BLK_TIMEOUT_MS ; r1b_resp = (cmd.flags &MMC_RSP_R1B ) ==MMC_RSP_R1B ;if (r1b_resp) - use_r1b_resp =mmc_prepare_busy_cmd (card->host, &cmd, - busy_timeout_ms); +mmc_prepare_busy_cmd (card->host, &cmd, busy_timeout_ms);mmc_wait_for_req (card->host, &mrq);memcpy (&idata->ic.response, cmd.resp,sizeof (cmd.resp));
@@ -605,19 +604,24 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,if (idata->ic.postsleep_min_us)usleep_range (idata->ic.postsleep_min_us, idata->ic.postsleep_max_us); -/* No need to poll when using HW busy detection. */ -if ((card->host->caps &MMC_CAP_WAIT_WHILE_BUSY ) && use_r1b_resp) -return 0 ; -if (mmc_host_is_spi (card->host)) {if (idata->ic.write_flag || r1b_resp || cmd.flags &MMC_RSP_SPI_BUSY )return mmc_spi_err_check (card);return err; } -/* Ensure RPMB/R1B command has completed by polling with CMD13. */ -if (idata->rpmb || r1b_resp) - err =mmc_poll_for_busy (card, busy_timeout_ms, false, -MMC_BUSY_IO ); +/* Poll for RPMB/write/R1B execution errors */ +if (idata->rpmb || idata->ic.write_flag || r1b_resp) { +struct mmc_busy_data cb_data; + + cb_data.card = card; + cb_data.retry_crc_err = false; + cb_data.aggregate_err_flags = true; + cb_data.busy_cmd =MMC_BUSY_IO ; + cb_data.status = &idata->ic.response[0 ]; + err =__mmc_poll_for_busy (card->host,0 , busy_timeout_ms, + &mmc_busy_cb, &cb_data); + + }return err; }
drivers/mmc/core/mmc_ops.c +7 -7
@@ -54,11 +54,6 @@ static const u8 tuning_blk_pattern_8bit[] = { 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, }; -struct mmc_busy_data { -struct mmc_card *card; -bool retry_crc_err; -enum mmc_busy_cmd busy_cmd; -};struct mmc_op_cond_busy_data {struct mmc_host *host;
@@ -457,14 +452,15 @@ int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal)return mmc_switch_status_error (card->host, status); } -static int mmc_busy_cb (void *cb_data,bool *busy) +int mmc_busy_cb (void *cb_data,bool *busy) {struct mmc_busy_data *data = cb_data;struct mmc_host *host = data->card->host;u32 status =0 ;int err; -if (data->busy_cmd !=MMC_BUSY_IO && host->ops->card_busy) { +if (data->busy_cmd !=MMC_BUSY_IO && host->ops->card_busy && + !data->aggregate_err_flags) { *busy = host->ops->card_busy (host);return 0 ; }
@@ -477,6 +473,9 @@ static int mmc_busy_cb(void *cb_data, bool *busy)if (err)return err; +if (data->aggregate_err_flags) + *data->status =R1_STATUS (*data->status) | status; +switch (data->busy_cmd) {case MMC_BUSY_CMD6 : err =mmc_switch_status_error (host, status);
@@ -549,6 +548,7 @@ int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, cb_data.card = card; cb_data.retry_crc_err = retry_crc_err; + cb_data.aggregate_err_flags = false; cb_data.busy_cmd = busy_cmd;return __mmc_poll_for_busy (host,0 , timeout_ms, &mmc_busy_cb, &cb_data);
drivers/mmc/core/mmc_ops.h +9 -0
@@ -18,6 +18,14 @@ enum mmc_busy_cmd { MMC_BUSY_IO, }; +struct mmc_busy_data { +struct mmc_card *card; +bool retry_crc_err; +bool aggregate_err_flags; +enum mmc_busy_cmd busy_cmd; +u32 *status; +}; +struct mmc_host ;struct mmc_card ;struct mmc_command ;
@@ -41,6 +49,7 @@ int mmc_can_ext_csd(struct mmc_card *card);int mmc_switch_status (struct mmc_card *card,bool crc_err_fatal);bool mmc_prepare_busy_cmd (struct mmc_host *host,struct mmc_command *cmd,unsigned int timeout_ms); +int mmc_busy_cb (void *cb_data,bool *busy); int __mmc_poll_for_busy(struct mmc_host *host, unsigned int period_us, unsigned int timeout_ms, int (*busy_cb)(void *cb_data, bool *busy),
--
2.37.3
Quoted 21 lines
Userspace currently has no way of checking for error bits of detection mode X. These are error bits that are only detected by the card when executing the command. For e.g. a sanitize operation this may be minutes after the RSP was seen by the host.
Currently userspace programs cannot see these error bits reliably. They could issue a multi ioctl cmd with a CMD13 immediately following it, but since errors of detection mode X are automatically cleared (they are all clear condition B).
mmc_poll_for_busyof the first ioctl may have already hidden such an error flag.In case of the security operations: sanitize, secure erases and RPMB writes, this could lead to the operation not being performed successfully by the card with the user not knowing.
If the user trusts that this operation is completed (e.g. their data is sanitized), this could be a security issue. An attacker could e.g. provoke a eMMC (VCC) flash fail, where a successful sanitize of a card is not possible. A card may move out of PROG state but issue a bit 19 R1 error.
Quoted 4 lines
This patch therefore will also have the consequence of a mmc-utils patch, which enables the bit for the security-sensitive operations.
Signed-off-by Christian Loehle <[email protected]>
Quoted 47 lines
--- drivers/mmc/core/block.c | 26 +++++++++++++++----------- drivers/mmc/core/mmc_ops.c | 14 +++++++------- drivers/mmc/core/mmc_ops.h | 9 +++++++++ 3 files changed, 31 insertions(+), 18 deletions(-)drivers/mmc/core/block.c +1
-1@@ -470,7 +470,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, struct mmc_data data = {};struct mmc_request mrq = {};struct scatterlist sg; -bool r1b_resp, use_r1b_resp = false; +bool r1b_resp;unsigned int busy_timeout_ms;int err;drivers/mmc/core/block.c +1
-2unsigned int target_part;@@ -551,8 +551,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, busy_timeout_ms = idata->ic.cmd_timeout_ms ? :MMC_BLK_TIMEOUT_MS ; r1b_resp = (cmd.flags &MMC_RSP_R1B ) ==MMC_RSP_R1B ;if (r1b_resp) - use_r1b_resp =mmc_prepare_busy_cmd (card->host, &cmd, - busy_timeout_ms); +mmc_prepare_busy_cmd (card->host, &cmd, busy_timeout_ms);drivers/mmc/core/block.c +0
-4mmc_wait_for_req (card->host, &mrq);memcpy (&idata->ic.response, cmd.resp,sizeof (cmd.resp));@@ -605,19 +604,24 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, if (idata->ic.postsleep_min_us)usleep_range (idata->ic.postsleep_min_us, idata- >ic.postsleep_max_us); -/* No need to poll when using HW busy detection. */ -if ((card->host->caps &MMC_CAP_WAIT_WHILE_BUSY ) && use_r1b_resp) -return 0 ; -if (mmc_host_is_spi (card->host)) {if (idata->ic.write_flag || r1b_resp || cmd.flags &MMC_RSP_SPI_BUSY )
drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card · line 613
Quoted 10 lines
drivers/mmc/core/block.c +2
-4return mmc_spi_err_check(card); return err; } -/* Ensure RPMB/R1B command has completed by polling with CMD13. */ -if (idata->rpmb || r1b_resp) - err =mmc_poll_for_busy (card, busy_timeout_ms, false, -MMC_BUSY_IO ); +/* Poll for RPMB/write/R1B execution errors */ +if (idata->rpmb || idata->ic.write_flag || r1b_resp) {
AFAIK write_flag and r1b_resp are set together (in mmc-utils that is)? As for rpmb read operations you were pondering about -
the rpmb read-counter is one example, because you use it to sign write operations. So restoring all rpmb operations is in place - all should be monitored.
drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, · line 614
Quoted 1 line
drivers/mmc/core/block.c +1
-0+struct mmc_busy_data cb_data;
Maybe use designated initializing?
Thanks,
Avri
Quoted 98 lines
drivers/mmc/core/block.c +10
-0+ + cb_data.card = card; + cb_data.retry_crc_err = false; + cb_data.aggregate_err_flags = true; + cb_data.busy_cmd =MMC_BUSY_IO ; + cb_data.status = &idata->ic.response[0 ]; + err =__mmc_poll_for_busy (card->host,0 , busy_timeout_ms, + &mmc_busy_cb, &cb_data); + + }return err; }drivers/mmc/core/mmc_ops.c +3
-7@@ -54,11 +54,6 @@ static const u8 tuning_blk_pattern_8bit[] = { 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, }; -struct mmc_busy_data { -struct mmc_card *card; -bool retry_crc_err; -enum mmc_busy_cmd busy_cmd; -};struct mmc_op_cond_busy_data {struct mmc_host *host;@@ -457,14 +452,15 @@ int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal)return mmc_switch_status_error (card->host, status); } -static int mmc_busy_cb (void *cb_data,bool *busy) +int mmc_busy_cb (void *cb_data,bool *busy) {struct mmc_busy_data *data = cb_data;struct mmc_host *host = data->card->host;u32 status =0 ;int err; -if (data->busy_cmd !=MMC_BUSY_IO && host->ops->card_busy) { +if (data->busy_cmd !=MMC_BUSY_IO && host->ops->card_busy && + !data->aggregate_err_flags) { *busy = host->ops->card_busy (host);return 0 ;drivers/mmc/core/mmc_ops.c +4
-0}@@ -477,6 +473,9 @@ static int mmc_busy_cb(void *cb_data, bool *busy)if (err)return err; +if (data->aggregate_err_flags) + *data->status =R1_STATUS (*data->status) | status; +switch (data->busy_cmd) {case MMC_BUSY_CMD6 : err =mmc_switch_status_error (host, status);@@ -549,6 +548,7 @@ int mmc_poll_for_busy(struct mmc_card *card,unsigned int timeout_ms, cb_data.card = card; cb_data.retry_crc_err = retry_crc_err; + cb_data.aggregate_err_flags = false; cb_data.busy_cmd = busy_cmd;return __mmc_poll_for_busy(host, 0,
timeout_ms,&mmc_busy_cb,&cb_data);drivers/mmc/core/mmc_ops.h +9
-0@@ -18,6 +18,14 @@ enum mmc_busy_cmd { MMC_BUSY_IO, }; +struct mmc_busy_data { +struct mmc_card *card; +bool retry_crc_err; +bool aggregate_err_flags; +enum mmc_busy_cmd busy_cmd; +u32 *status; +}; +struct mmc_host ;struct mmc_card ;struct mmc_command ;@@ -41,6 +49,7 @@ int mmc_can_ext_csd(struct mmc_card *card);int mmc_switch_status (struct mmc_card *card,bool crc_err_fatal);bool mmc_prepare_busy_cmd (struct mmc_host *host,struct mmc_command *cmd,unsigned int timeout_ms); +int mmc_busy_cb (void *cb_data,bool *busy); int __mmc_poll_for_busy(struct mmc_host *host, unsigned int period_us, unsigned int timeout_ms,int (*busy_cb)(void
*cb_data, bool *busy),
--
2.37.3
Quoted 98 lines
-----Original Message-----
From: Avri Altman <[email protected]>
Sent: Wednesday, June 21, 2023 9:31 AM
To: Christian Loehle <[email protected]>; [email protected]; [email protected]; Ulf Hansson <[email protected]>; Adrian Hunter <[email protected]>
Subject: RE: [PATCHv3 1/1] mmc: block: ioctl: Add PROG-error aggregationCAUTION: this mail comes from external!/ACHTUNG: Diese Mail kommt von extern!
Quoted 21 lines
Userspace currently has no way of checking for error bits of detection mode X. These are error bits that are only detected by the card when executing the command. For e.g. a sanitize operation this may be minutes after the RSP was seen by the host.
Currently userspace programs cannot see these error bits reliably. They could issue a multi ioctl cmd with a CMD13 immediately following it, but since errors of detection mode X are automatically cleared (they are all clear condition B).
mmc_poll_for_busyof the first ioctl may have already hidden such an error flag.In case of the security operations: sanitize, secure erases and RPMB writes, this could lead to the operation not being performed successfully by the card with the user not knowing.
If the user trusts that this operation is completed (e.g. their data is sanitized), this could be a security issue.
An attacker could e.g. provoke a eMMC (VCC) flash fail, where a successful sanitize of a card is not possible. A card may move out of PROG state but issue a bit 19 R1 error.Quoted 4 lines
This patch therefore will also have the consequence of a mmc-utils patch, which enables the bit for the security-sensitive operations.
Signed-off-by Christian Loehle <[email protected]>Acked-by Avri Altman <[email protected]>Quoted 52 lines
--- drivers/mmc/core/block.c | 26 +++++++++++++++----------- drivers/mmc/core/mmc_ops.c | 14 +++++++------- drivers/mmc/core/mmc_ops.h | 9 +++++++++ 3 files changed, 31 insertions(+), 18 deletions(-)drivers/mmc/core/block.c index renamed from drivers/mmc/core/block.c +0
-0
e46330815484..c7e2b8ae58a9100644drivers/mmc/core/block.c +1
-1@@ -470,7 +470,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, struct mmc_data data = {};struct mmc_request mrq = {};struct scatterlist sg; -bool r1b_resp, use_r1b_resp = false; +bool r1b_resp;unsigned int busy_timeout_ms;int err;unsigned int target_part;drivers/mmc/core/block.c +1
-2@@ -551,8 +551,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, busy_timeout_ms = idata->ic.cmd_timeout_ms ? :MMC_BLK_TIMEOUT_MS ; r1b_resp = (cmd.flags &MMC_RSP_R1B ) ==MMC_RSP_R1B ;if (r1b_resp) - use_r1b_resp =mmc_prepare_busy_cmd (card->host, &cmd, - busy_timeout_ms); +mmc_prepare_busy_cmd (card->host, &cmd, busy_timeout_ms);mmc_wait_for_req(card->host, &mrq); memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp)); @@ -605,19 +604,24 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, if (idata->ic.postsleep_min_us) usleep_range(idata->ic.postsleep_min_us, idata-Quoted 1 line
ic.postsleep_max_us);
drivers/mmc/core/block.c +0
-2-/* No need to poll when using HW busy detection. */ - if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) &&
use_r1b_resp)drivers/mmc/core/block.c +0
-2-return 0 ; - if (mmc_host_is_spi(card->host)) { if (idata->ic.write_flag || r1b_resp || cmd.flags &
MMC_RSP_SPI_BUSY)return mmc_spi_err_check(card); return err; }- /* Ensure RPMB/R1B command has completed by polling with CMD13.
*/drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, · line 613
Quoted 5 lines
drivers/mmc/core/block.c +2
-3-if (idata->rpmb || r1b_resp) - err =mmc_poll_for_busy (card, busy_timeout_ms, false, -MMC_BUSY_IO ); +/* Poll for RPMB/write/R1B execution errors */ +if (idata->rpmb || idata->ic.write_flag || r1b_resp) {
Quoted 1 line
AFAIK
write_flagandr1b_respare set together (in mmc-utils that is)?
Not sure what you're trying to say, that write_flag -> r1b_resp? If so that is not true for all cases, e.g. CMD56
Quoted 2 lines
As for rpmb read operations you were pondering about - the rpmb read- counter is one example, because you use it to sign write operations.
But the read counter (the actual read direction part), doesn't really need post transfer polling IMO.
If the card encounters a problem during that operation, it hopefully doesn't send valid counter read packet response.
The read counter doesn't change any state inside the card, and if it does for some vendor-specific reason, I would hope it does this before the read data is executed. So I would say we're in the clear without polling.
Checking the validity of the received read counter packet data is responsibility of the ioctl-client, and I would say they already have everything they need.
Quoted 4 lines
So restoring all rpmb operations is in place - all should be monitored.
Quoted 1 line
+ struct
mmc_busy_datacb_data;Maybe use designated initializing?
Can do that, thanks.
I will wait for Uffe's comment about the style before resubmitting.
Regards,
Christian
Quoted 63 lines · Christian Loehle
Userspace currently has no way of checking for error bits of detection mode X. These are error bits that are only detected by the card when executing the command. For e.g. a sanitize operation this may be minutes after the RSP was seen by the host.
Currently userspace programs cannot see these error bits reliably. They could issue a multi ioctl cmd with a CMD13 immediately following it, but since errors of detection mode X are automatically cleared (they are all clear condition B).
mmc_poll_for_busyof the first ioctl may have already hidden such an error flag.In case of the security operations: sanitize, secure erases and RPMB writes, this could lead to the operation not being performed successfully by the card with the user not knowing.
If the user trusts that this operation is completed (e.g. their data is sanitized), this could be a security issue. An attacker could e.g. provoke a eMMC (VCC) flash fail, where a successful sanitize of a card is not possible. A card may move out of PROG state but issue a bit 19 R1 error.This patch therefore will also have the consequence of a mmc-utils patch, which enables the bit for the security-sensitive operations.
Signed-off-by Christian Loehle <[email protected]>--- drivers/mmc/core/block.c | 26 +++++++++++++++----------- drivers/mmc/core/mmc_ops.c | 14 +++++++------- drivers/mmc/core/mmc_ops.h | 9 +++++++++ 3 files changed, 31 insertions(+), 18 deletions(-)drivers/mmc/core/block.c +2
-7@@ -470,7 +470,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,struct mmc_data data = {};struct mmc_request mrq = {};struct scatterlist sg; -bool r1b_resp, use_r1b_resp = false; +bool r1b_resp;unsigned int busy_timeout_ms;int err;unsigned int target_part;@@ -551,8 +551,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, busy_timeout_ms = idata->ic.cmd_timeout_ms ? :MMC_BLK_TIMEOUT_MS ; r1b_resp = (cmd.flags &MMC_RSP_R1B ) ==MMC_RSP_R1B ;if (r1b_resp) - use_r1b_resp =mmc_prepare_busy_cmd (card->host, &cmd, - busy_timeout_ms); +mmc_prepare_busy_cmd (card->host, &cmd, busy_timeout_ms);mmc_wait_for_req (card->host, &mrq);memcpy (&idata->ic.response, cmd.resp,sizeof (cmd.resp));@@ -605,19 +604,24 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,if (idata->ic.postsleep_min_us)usleep_range (idata->ic.postsleep_min_us, idata->ic.postsleep_max_us); -/* No need to poll when using HW busy detection. */ -if ((card->host->caps &MMC_CAP_WAIT_WHILE_BUSY ) && use_r1b_resp) -return 0 ; -
drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, · line 612
Quoted 10 lines
drivers/mmc/core/block.c +1
-4if (mmc_host_is_spi (card->host)) {if (idata->ic.write_flag || r1b_resp || cmd.flags &MMC_RSP_SPI_BUSY )return mmc_spi_err_check (card);return err; } -/* Ensure RPMB/R1B command has completed by polling with CMD13. */ -if (idata->rpmb || r1b_resp) - err =mmc_poll_for_busy (card, busy_timeout_ms, false, -MMC_BUSY_IO ); +/* Poll for RPMB/write/R1B execution errors */
Except for the other comments that I had on v2 (which isn't addressed in v3), I would like this comment to be extended a bit.
More precisely, we somehow need to state that even if the host supports HW busy signaling (MMC_CAP_WAIT_WHILE_BUSY) we need to send a CMD13 to get the internal error status of the card.
Quoted 5 lines
drivers/mmc/core/block.c +5
-0+if (idata->rpmb || idata->ic.write_flag || r1b_resp) { +struct mmc_busy_data cb_data; + + cb_data.card = card; + cb_data.retry_crc_err = false;
drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, · line 627
Quoted 10 lines
drivers/mmc/core/block.c +7
-0+ cb_data.aggregate_err_flags = true; + cb_data.busy_cmd =MMC_BUSY_IO ; + cb_data.status = &idata->ic.response[0 ]; + err =__mmc_poll_for_busy (card->host,0 , busy_timeout_ms, + &mmc_busy_cb, &cb_data); + + }return err; }
[...]
Kind regards
Uffe
Quoted 92 lines
-----Original Message-----
From: Ulf Hansson <[email protected]>
Sent: Donnerstag, 22. Juni 2023 11:46
To: Christian Loehle <[email protected]>
Cc: [email protected]; [email protected]; Adrian Hunter <[email protected]>; Avri Altman <[email protected]>
Subject: Re: [PATCHv3 1/1] mmc: block: ioctl: Add PROG-error aggregationCAUTION: this mail comes from external!/ACHTUNG: Diese Mail kommt von extern!
drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card
Quoted 37 lines · Christian Loehle
Userspace currently has no way of checking for error bits of detection mode X. These are error bits that are only detected by the card when executing the command. For e.g. a sanitize operation this may be minutes after the RSP was seen by the host.
Currently userspace programs cannot see these error bits reliably. They could issue a multi ioctl cmd with a CMD13 immediately following it, but since errors of detection mode X are automatically cleared (they are all clear condition B).
mmc_poll_for_busyof the first ioctl may have already hidden such an error flag.In case of the security operations: sanitize, secure erases and RPMB writes, this could lead to the operation not being performed successfully by the card with the user not knowing.
If the user trusts that this operation is completed (e.g. their data is sanitized), this could be a security issue.
An attacker could e.g. provoke a eMMC (VCC) flash fail, where a successful sanitize of a card is not possible. A card may move out of PROG state but issue a bit 19 R1 error.This patch therefore will also have the consequence of a mmc-utils patch, which enables the bit for the security-sensitive operations.
Signed-off-by Christian Loehle <[email protected]>--- drivers/mmc/core/block.c | 26 +++++++++++++++----------- drivers/mmc/core/mmc_ops.c | 14 +++++++------- drivers/mmc/core/mmc_ops.h | 9 +++++++++ 3 files changed, 31 insertions(+), 18 deletions(-)drivers/mmc/core/block.c index renamed from drivers/mmc/core/block.c +0
-0
e46330815484..c7e2b8ae58a9100644drivers/mmc/core/block.c +0
-0@@ -470,7 +470,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card*card, struct
mmc_blk_data*md,drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card
Quoted 9 lines
drivers/mmc/core/block.c +1
-1struct mmc_data data = {};struct mmc_request mrq = {};struct scatterlist sg; -bool r1b_resp, use_r1b_resp = false; +bool r1b_resp;unsigned int busy_timeout_ms;int err;unsigned int target_part;@@ -551,8 +551,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card*card, struct
mmc_blk_data*md,drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card · line 551
Quoted 1 line
drivers/mmc/core/block.c +0
-0busy_timeout_ms = idata->ic.cmd_timeout_ms ? :
MMC_BLK_TIMEOUT_MS;drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
Quoted 10 lines
drivers/mmc/core/block.c +2
-3r1b_resp = (cmd.flags &MMC_RSP_R1B ) ==MMC_RSP_R1B ;if (r1b_resp) - use_r1b_resp =mmc_prepare_busy_cmd (card->host, &cmd, - busy_timeout_ms); +mmc_prepare_busy_cmd (card->host, &cmd, + busy_timeout_ms);mmc_wait_for_req (card->host, &mrq); memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp)); @@ -605,19 +604,24 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card*card, struct
mmc_blk_data*md,drivers/mmc/core/block.c
Quoted 6 lines
if (idata->ic.postsleep_min_us) usleep_range(idata->ic.postsleep_min_us,
idata->ic.postsleep_max_us);drivers/mmc/core/block.c +0
-2-/* No need to poll when using HW busy detection. */ - if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) &&
use_r1b_resp)drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
Quoted 4 lines
drivers/mmc/core/block.c +0
-2-return 0 ; - if (mmc_host_is_spi(card->host)) { if (idata->ic.write_flag || r1b_resp || cmd.flags &
MMC_RSP_SPI_BUSY)Quoted 4 lines
return mmc_spi_err_check(card); return err; }- /* Ensure RPMB/R1B command has completed by polling with CMD13.
Quoted 8 lines
*/
drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, · line 612
Quoted 4 lines
drivers/mmc/core/block.c +1
-3-if (idata->rpmb || r1b_resp) - err =mmc_poll_for_busy (card, busy_timeout_ms, false, -MMC_BUSY_IO ); +/* Poll for RPMB/write/R1B execution errors */ Except for the other comments that I had on v2 (which isn't addressed in v3), I would like this comment to be extended a bit.
Sorry, could you elaborate on the comments I haven't addressed? What I sent as v3 was what I understood from your comments.
Quoted 4 lines
More precisely, we somehow need to state that even if the host supports HW busy signaling (
MMC_CAP_WAIT_WHILE_BUSY) we need to send a CMD13 to get the internal error status of the card.
Will do
Quoted 21 lines
Quoted 6 lines
drivers/mmc/core/block.c +5
-0+if (idata->rpmb || idata->ic.write_flag || r1b_resp) { +struct mmc_busy_data cb_data; + + cb_data.card = card; + cb_data.retry_crc_err = false;drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, · line 627
Quoted 10 lines
drivers/mmc/core/block.c +7
-0+ cb_data.aggregate_err_flags = true; + cb_data.busy_cmd =MMC_BUSY_IO ; + cb_data.status = &idata->ic.response[0 ]; + err =__mmc_poll_for_busy (card->host,0 , busy_timeout_ms, + &mmc_busy_cb, &cb_data); + + }return err; }[...]
Kind regards
Uffe
Quoted 99 lines · Christian Loehle
Quoted 99 lines
-----Original Message-----
From: Ulf Hansson <[email protected]>
Sent: Donnerstag, 22. Juni 2023 11:46
To: Christian Loehle <[email protected]>
Cc: [email protected]; [email protected]; Adrian Hunter <[email protected]>; Avri Altman <[email protected]>
Subject: Re: [PATCHv3 1/1] mmc: block: ioctl: Add PROG-error aggregationCAUTION: this mail comes from external!/ACHTUNG: Diese Mail kommt von extern!
drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card
Quoted 37 lines · Christian Loehle
Userspace currently has no way of checking for error bits of detection mode X. These are error bits that are only detected by the card when executing the command. For e.g. a sanitize operation this may be minutes after the RSP was seen by the host.
Currently userspace programs cannot see these error bits reliably. They could issue a multi ioctl cmd with a CMD13 immediately following it, but since errors of detection mode X are automatically cleared (they are all clear condition B).
mmc_poll_for_busyof the first ioctl may have already hidden such an error flag.In case of the security operations: sanitize, secure erases and RPMB writes, this could lead to the operation not being performed successfully by the card with the user not knowing.
If the user trusts that this operation is completed (e.g. their data is sanitized), this could be a security issue.
An attacker could e.g. provoke a eMMC (VCC) flash fail, where a successful sanitize of a card is not possible. A card may move out of PROG state but issue a bit 19 R1 error.This patch therefore will also have the consequence of a mmc-utils patch, which enables the bit for the security-sensitive operations.
Signed-off-by Christian Loehle <[email protected]>--- drivers/mmc/core/block.c | 26 +++++++++++++++----------- drivers/mmc/core/mmc_ops.c | 14 +++++++------- drivers/mmc/core/mmc_ops.h | 9 +++++++++ 3 files changed, 31 insertions(+), 18 deletions(-)drivers/mmc/core/block.c index renamed from drivers/mmc/core/block.c +0
-0
e46330815484..c7e2b8ae58a9100644drivers/mmc/core/block.c +0
-0@@ -470,7 +470,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card*card, struct
mmc_blk_data*md,drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card
Quoted 9 lines
drivers/mmc/core/block.c +1
-1struct mmc_data data = {};struct mmc_request mrq = {};struct scatterlist sg; -bool r1b_resp, use_r1b_resp = false; +bool r1b_resp;unsigned int busy_timeout_ms;int err;unsigned int target_part;@@ -551,8 +551,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card*card, struct
mmc_blk_data*md,drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card · line 551
Quoted 1 line
drivers/mmc/core/block.c +0
-0busy_timeout_ms = idata->ic.cmd_timeout_ms ? :
MMC_BLK_TIMEOUT_MS;drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
Quoted 10 lines
drivers/mmc/core/block.c +2
-3r1b_resp = (cmd.flags &MMC_RSP_R1B ) ==MMC_RSP_R1B ;if (r1b_resp) - use_r1b_resp =mmc_prepare_busy_cmd (card->host, &cmd, - busy_timeout_ms); +mmc_prepare_busy_cmd (card->host, &cmd, + busy_timeout_ms);mmc_wait_for_req (card->host, &mrq); memcpy(&idata->ic.response, cmd.resp, sizeof(cmd.resp)); @@ -605,19 +604,24 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card*card, struct
mmc_blk_data*md,drivers/mmc/core/block.c
Quoted 6 lines
if (idata->ic.postsleep_min_us) usleep_range(idata->ic.postsleep_min_us,
idata->ic.postsleep_max_us);drivers/mmc/core/block.c +0
-2-/* No need to poll when using HW busy detection. */ - if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) &&
use_r1b_resp)drivers/mmc/core/block.c static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
Quoted 4 lines
drivers/mmc/core/block.c +0
-2-return 0 ; - if (mmc_host_is_spi(card->host)) { if (idata->ic.write_flag || r1b_resp || cmd.flags &
MMC_RSP_SPI_BUSY)Quoted 4 lines
return mmc_spi_err_check(card); return err; }- /* Ensure RPMB/R1B command has completed by polling with CMD13.
*/
Quoted 4 lines
drivers/mmc/core/block.c +1
-3-if (idata->rpmb || r1b_resp) - err =mmc_poll_for_busy (card, busy_timeout_ms, false, -MMC_BUSY_IO ); +/* Poll for RPMB/write/R1B execution errors */
Quoted 4 lines
Quoted 2 lines
Except for the other comments that I had on v2 (which isn't addressed in v3), I would like this comment to be extended a bit.
Sorry, could you elaborate on the comments I haven't addressed? What I sent as v3 was what I understood from your comments.
No problem, it's probably me that was not clear enough.
Anyway, to help mode this forward, let me amend the patch and submit a new version of it. Then you can have a look and confirm that it looks good to you.
[...]
Kind regards
Uffe