* [PATCH] nvmem: core: Fix OOB read for bit offsets of more than one byte
@ 2025-09-01 7:29 Janne Grunau
2025-09-01 7:40 ` Greg Kroah-Hartman
2026-09-19 18:56 ` Dmitry Sinyavin
0 siblings, 2 replies; 3+ messages in thread
From: Janne Grunau @ 2025-09-01 7:29 UTC (permalink / raw)
To: Srinivas Kandagatla, Dmitry Baryshkov, Greg Kroah-Hartman
Cc: linux-kernel, Janne Grunau
When the bit offset is BITS_PER_BYTE or larger the read position is
advanced by `bytes_offset`. This is not taken into account in the
per-byte read loop which still reads `cell->bytes` resulting in an out of
bounds read of `bytes_offset` bytes. The information read OOB does not
leak directly as the erroneously read bits are cleared.
Detected by KASAN while looking for a use-after-free in simplefb.c.
Fixes: 7a06ef7510779 ("nvmem: core: fix bit offsets of more than one byte")
Signed-off-by: Janne Grunau <j@jannau.net>
---
drivers/nvmem/core.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 387c88c55259541446901f0e539bbb0dd8c4c3de..19be16943ee66e845860192b8f008539873f6f7f 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -1618,12 +1618,14 @@ static void nvmem_shift_read_buffer_in_place(struct nvmem_cell_entry *cell, void
*p = *b++ >> bit_offset;
/* setup rest of the bytes if any */
- for (i = 1; i < cell->bytes; i++) {
+ for (i = 1; i < (cell->bytes - bytes_offset); i++) {
/* Get bits from next byte and shift them towards msb */
*p++ |= *b << (BITS_PER_BYTE - bit_offset);
*p = *b++ >> bit_offset;
}
+ /* point to end of the buffer unused bits will be cleared */
+ p = buf + cell->bytes - 1;
} else if (p != b) {
memmove(p, b, cell->bytes - bytes_offset);
p += cell->bytes - 1;
---
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
change-id: 20250901-nvmem-read-oob-bit-offset-dc1c2f39af6c
Best regards,
--
Janne Grunau <j@jannau.net>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] nvmem: core: Fix OOB read for bit offsets of more than one byte
2025-09-01 7:29 [PATCH] nvmem: core: Fix OOB read for bit offsets of more than one byte Janne Grunau
@ 2025-09-01 7:40 ` Greg Kroah-Hartman
2026-09-19 18:56 ` Dmitry Sinyavin
1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2025-09-01 7:40 UTC (permalink / raw)
To: Janne Grunau; +Cc: Srinivas Kandagatla, Dmitry Baryshkov, linux-kernel
On Mon, Sep 01, 2025 at 09:29:43AM +0200, Janne Grunau wrote:
> When the bit offset is BITS_PER_BYTE or larger the read position is
> advanced by `bytes_offset`. This is not taken into account in the
> per-byte read loop which still reads `cell->bytes` resulting in an out of
> bounds read of `bytes_offset` bytes. The information read OOB does not
> leak directly as the erroneously read bits are cleared.
>
> Detected by KASAN while looking for a use-after-free in simplefb.c.
>
> Fixes: 7a06ef7510779 ("nvmem: core: fix bit offsets of more than one byte")
> Signed-off-by: Janne Grunau <j@jannau.net>
> ---
> drivers/nvmem/core.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him
a patch that has triggered this response. He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created. Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.
You are receiving this message because of the following common error(s)
as indicated below:
- You have marked a patch with a "Fixes:" tag for a commit that is in an
older released kernel, yet you do not have a cc: stable line in the
signed-off-by area at all, which means that the patch will not be
applied to any older kernel releases. To properly fix this, please
follow the documented rules in the
Documentation/process/stable-kernel-rules.rst file for how to resolve
this.
If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.
thanks,
greg k-h's patch email bot
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] nvmem: core: Fix OOB read for bit offsets of more than one byte
2025-09-01 7:29 [PATCH] nvmem: core: Fix OOB read for bit offsets of more than one byte Janne Grunau
2025-09-01 7:40 ` Greg Kroah-Hartman
@ 2026-09-19 18:56 ` Dmitry Sinyavin
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Sinyavin @ 2026-09-19 18:56 UTC (permalink / raw)
To: Janne Grunau
Cc: Dmitry Sinyavin, Srinivas Kandagatla, Greg Kroah-Hartman,
Dmitry Baryshkov, linux-kernel
Hi Janne,
Thanks for the patch. I independently ran into this bug while testing
Qualcomm MDM9607 TSENS calibration. I tested the exact change against the
current NVMEM for-fixes branch at cee9395acd80.
Without the patch, a focused KUnit case with a 26-bit offset returned the
expected value but produced three KASAN out-of-bounds reports. On the
MF283V, the unmodified kernel produced exactly seven reports from four
TSENS calibration cells, matching the accesses predicted from their bit
offsets.
With the patch, the focused test and a 16,384-case extraction matrix pass
under KASAN. A hardware A/B test using otherwise identical Linux 6.18.44
kernels produced no KASAN report with the fix, and all five TSENS zones
reported plausible temperatures between 36 and 38 degrees Celsius.
Tested-by: Dmitry Sinyavin <sinyavin@gmail.com>
I could not find the patch in the current NVMEM for-fixes or for-next
branches. Are you planning to send a v2 with the stable Cc requested in
the earlier reply? I can send the KUnit coverage separately if useful.
Regards,
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-19 18:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-01 7:29 [PATCH] nvmem: core: Fix OOB read for bit offsets of more than one byte Janne Grunau
2025-09-01 7:40 ` Greg Kroah-Hartman
2026-09-19 18:56 ` Dmitry Sinyavin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®