All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Mauro Matteo Cascella <mcascell@redhat.com>,
	qemu-devel@nongnu.org, bin.meng@windriver.com
Cc: XRivenDell@outlook.com, coc.cyqh@gmail.com, ningqiang1@huawei.com
Subject: Re: [PATCH] hw/sd/sdhci: reset data count in sdhci_buff_access_is_sequential()
Date: Mon, 7 Nov 2022 20:12:22 +0100	[thread overview]
Message-ID: <0864b291-c9b7-bdff-bda4-124ff7c8d957@linaro.org> (raw)
In-Reply-To: <20221107103510.34588-1-mcascell@redhat.com>

On 7/11/22 11:35, Mauro Matteo Cascella wrote:
> Make sure to reset data_count if it's equal to (or exceeds) block_size.
> This prevents an off-by-one read / write when accessing s->fifo_buffer
> in sdhci_read_dataport / sdhci_write_dataport, both called right after
> sdhci_buff_access_is_sequential.
> 
> Fixes: CVE-2022-3872
> Reported-by: RivenDell <XRivenDell@outlook.com>
> Reported-by: Siqi Chen <coc.cyqh@gmail.com>
> Reported-by: ningqiang <ningqiang1@huawei.com>
> Signed-off-by: Mauro Matteo Cascella <mcascell@redhat.com>
> ---
>   hw/sd/sdhci.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
> index 306070c872..aa2fd79df2 100644
> --- a/hw/sd/sdhci.c
> +++ b/hw/sd/sdhci.c
> @@ -978,6 +978,10 @@ static bool sdhci_can_issue_command(SDHCIState *s)
>   static inline bool
>   sdhci_buff_access_is_sequential(SDHCIState *s, unsigned byte_num)
>   {
> +    if (s->data_count >= (s->blksize & BLOCK_SIZE_MASK)) {
> +        s->data_count = 0;
> +    }

You avoid an off-by-one but now the model doesn't work per the spec.
Not really what the best fix IMHO.

>       if ((s->data_count & 0x3) != byte_num) {
>           trace_sdhci_error("Non-sequential access to Buffer Data Port register"
>                             "is prohibited\n");

I wonder why sdhci_data_transfer() indiscriminately sets
SDHC_SPACE_AVAILABLE in the write path (at least without
clearing the FIFO first).

The fix could be:

-- >8 --
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
@@ -955,5 +955,5 @@ static void sdhci_data_transfer(void *opaque)
          } else {
              s->prnsts |= SDHC_DOING_WRITE | SDHC_DAT_LINE_ACTIVE |
-                    SDHC_SPACE_AVAILABLE | SDHC_DATA_INHIBIT;
+                                           SDHC_DATA_INHIBIT;
              sdhci_write_block_to_card(s);
          }
---

Bin, what do you think?

Regards,

Phil.


  parent reply	other threads:[~2022-11-07 19:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 10:35 [PATCH] hw/sd/sdhci: reset data count in sdhci_buff_access_is_sequential() Mauro Matteo Cascella
2022-11-07 11:06 ` Mauro Matteo Cascella
2022-11-09  9:29   ` Bin Meng
2022-11-09  9:44     ` Siqi Chen
2022-11-09 10:10       ` Mauro Matteo Cascella
2022-11-09 16:18         ` Bin Meng
2022-11-10 18:51           ` Mauro Matteo Cascella
2022-11-11  0:21             ` Bin Meng
2022-11-07 19:12 ` Philippe Mathieu-Daudé [this message]
2022-11-08  9:11   ` Mauro Matteo Cascella
  -- strict thread matches above, loose matches on Subject: below --
2023-05-27  9:00 Michael Tokarev
2023-05-29  7:22 ` Mauro Matteo Cascella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0864b291-c9b7-bdff-bda4-124ff7c8d957@linaro.org \
    --to=philmd@linaro.org \
    --cc=XRivenDell@outlook.com \
    --cc=bin.meng@windriver.com \
    --cc=coc.cyqh@gmail.com \
    --cc=mcascell@redhat.com \
    --cc=ningqiang1@huawei.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.