All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Matteo Cascella <mcascell@redhat.com>
To: qemu-devel@nongnu.org
Cc: philmd@linaro.org, bin.meng@windriver.com, mcascell@redhat.com,
	XRivenDell@outlook.com, coc.cyqh@gmail.com,
	ningqiang1@huawei.com
Subject: [PATCH] hw/sd/sdhci: reset data count in sdhci_buff_access_is_sequential()
Date: Mon,  7 Nov 2022 11:35:10 +0100	[thread overview]
Message-ID: <20221107103510.34588-1-mcascell@redhat.com> (raw)

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;
+    }
+
     if ((s->data_count & 0x3) != byte_num) {
         trace_sdhci_error("Non-sequential access to Buffer Data Port register"
                           "is prohibited\n");
-- 
2.38.1



             reply	other threads:[~2022-11-07 10:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 10:35 Mauro Matteo Cascella [this message]
2022-11-07 11:06 ` [PATCH] hw/sd/sdhci: reset data count in sdhci_buff_access_is_sequential() 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é
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=20221107103510.34588-1-mcascell@redhat.com \
    --to=mcascell@redhat.com \
    --cc=XRivenDell@outlook.com \
    --cc=bin.meng@windriver.com \
    --cc=coc.cyqh@gmail.com \
    --cc=ningqiang1@huawei.com \
    --cc=philmd@linaro.org \
    --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.