From: Suraj Sonawane <surajsonawane0215@gmail.com>
To: Helge Deller <deller@gmx.de>
Cc: linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
Suraj Sonawane <surajsonawane0215@gmail.com>
Subject: [PATCH] video: fbdev: metronomefb: Fix buffer overflow in load_waveform()
Date: Wed, 13 Nov 2024 01:58:25 +0530 [thread overview]
Message-ID: <20241112202825.17322-1-surajsonawane0215@gmail.com> (raw)
Fix an error detected by the Smatch tool:
drivers/video/fbdev/metronomefb.c:220 load_waveform() error:
buffer overflow 'wfm_hdr->stuff2a' 2 <= 4
drivers/video/fbdev/metronomefb.c:220 load_waveform() error:
buffer overflow 'wfm_hdr->stuff2a' 2 <= 4
The access to wfm_hdr->stuff2a in the loop can lead to a buffer
overflow if stuff2a is not large enough. To fix this, a check was
added to ensure that stuff2a has sufficient space before accessing
it. This prevents the overflow and improves the safety of the code.
Signed-off-by: Suraj Sonawane <surajsonawane0215@gmail.com>
---
drivers/video/fbdev/metronomefb.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/video/fbdev/metronomefb.c b/drivers/video/fbdev/metronomefb.c
index 6f0942c6e..9da55cef2 100644
--- a/drivers/video/fbdev/metronomefb.c
+++ b/drivers/video/fbdev/metronomefb.c
@@ -210,6 +210,12 @@ static int load_waveform(u8 *mem, size_t size, int m, int t,
}
wfm_hdr->mc += 1;
wfm_hdr->trc += 1;
+
+ if (sizeof(wfm_hdr->stuff2a) < 5) {
+ dev_err(dev, "Error: insufficient space in stuff2a\n");
+ return -EINVAL;
+ }
+
for (i = 0; i < 5; i++) {
if (*(wfm_hdr->stuff2a + i) != 0) {
dev_err(dev, "Error: unexpected value in padding\n");
--
2.34.1
next reply other threads:[~2024-11-12 20:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 20:28 Suraj Sonawane [this message]
2024-11-14 14:43 ` [PATCH] video: fbdev: metronomefb: Fix buffer overflow in load_waveform() Helge Deller
2024-11-15 13:12 ` Suraj Sonawane
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=20241112202825.17322-1-surajsonawane0215@gmail.com \
--to=surajsonawane0215@gmail.com \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox