qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/sd/sdhci: reset data count in sdhci_buff_access_is_sequential()
@ 2022-11-07 10:35 Mauro Matteo Cascella
  2022-11-07 11:06 ` Mauro Matteo Cascella
  2022-11-07 19:12 ` Philippe Mathieu-Daudé
  0 siblings, 2 replies; 12+ messages in thread
From: Mauro Matteo Cascella @ 2022-11-07 10:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: philmd, bin.meng, mcascell, XRivenDell, coc.cyqh, ningqiang1

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



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* Re: [PATCH] hw/sd/sdhci: reset data count in sdhci_buff_access_is_sequential()
@ 2023-05-27  9:00 Michael Tokarev
  2023-05-29  7:22 ` Mauro Matteo Cascella
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Tokarev @ 2023-05-27  9:00 UTC (permalink / raw)
  To: Mauro Matteo Cascella, QEMU Developers

Mon, 7 Nov 2022 11:35:10 +0100, you 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

..

Has this been forgotten, or maybe a better fix is needed?

https://lists.nongnu.org/archive/html/qemu-devel/2022-11/msg01068.html

Thanks,

/mjt


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-05-29  7:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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é
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).