dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: fbtft: fix len<=0 buffer overflow in define_fbtft_write_reg()
@ 2026-09-02  4:50 Anshika Jain
  2026-09-02  5:58 ` Greg Kroah-Hartman
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Anshika Jain @ 2026-09-02  4:50 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Greg Kroah-Hartman, sashiko-bot, dri-devel, linux-fbdev,
	linux-staging, Anshika Jain

If len is 0 or negative when a define_fbtft_write_reg()-generated
function is called, len-- underflows to -1, causing the subsequent
while (i--) loop to run approximately 2^31 times and write far past
the end of buf.

This is a latent bug: nothing in the current code prevents two
adjacent negative values in an init_sequence from producing len=0,
and there is no guarantee future or out-of-tree panel definitions
won't do so.

Add an early return for len <= 0, matching the existing guard already
present in the sibling function fbtft_write_reg8_bus9().

Reported-by: sashiko-bot <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/patchset/20260830161529.14500-1-anshikajain196872@gmail.com?part=1

Signed-off-by: Anshika Jain <anshikajain196872@gmail.com>
---
 drivers/staging/fbtft/fbtft-bus.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/staging/fbtft/fbtft-bus.c b/drivers/staging/fbtft/fbtft-bus.c
index e03aa251c..7d7135571 100644
--- a/drivers/staging/fbtft/fbtft-bus.c
+++ b/drivers/staging/fbtft/fbtft-bus.c
@@ -20,6 +20,9 @@ void func(struct fbtft_par *par, int len, ...)                                \
 	int offset = 0;                                                       \
 	buffer_type *buf = (buffer_type *)par->buf;                           \
 									      \
+	if (len <= 0)                                                         \
+		return;                                                       \
+									      \
 	if (unlikely(par->debug & DEBUG_WRITE_REGISTER)) {                    \
 		va_start(args, len);                                          \
 		for (i = 0; i < len; i++) {                                   \
-- 
2.34.1


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

end of thread, other threads:[~2026-09-03  8:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  4:50 [PATCH] staging: fbtft: fix len<=0 buffer overflow in define_fbtft_write_reg() Anshika Jain
2026-09-02  5:58 ` Greg Kroah-Hartman
2026-09-02 12:25 ` Nam Cao
2026-09-02 19:03   ` Anshika Jain
2026-09-03  8:24     ` Nam Cao
2026-09-03  8:29       ` Greg Kroah-Hartman
2026-09-03  7:47 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox