All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] printk: ringbuffer: Add KUnit test
@ 2025-06-25 15:22 Dan Carpenter
  2025-06-26  6:59 ` Thomas Weißschuh
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2025-06-25 15:22 UTC (permalink / raw)
  To: thomas.weissschuh; +Cc: John Ogness, Kees Cook, linux-hardening

Hello Thomas Weißschuh,

The patch 5ea2bcdfbf46: "printk: ringbuffer: Add KUnit test" from Jun
12, 2025, leads to the following static checker warning:

	kernel/printk/printk_ringbuffer_kunit_test.c:91 prbtest_check_data()
	(unpublished script worries this an off by one)

kernel/printk/printk_ringbuffer_kunit_test.c
    83 static bool prbtest_check_data(const struct prbtest_rbdata *dat)
    84 {
    85 	unsigned int len;
    86 
    87 	/* Sane length? */
    88 	if (dat->len < 1 || dat->len > MAX_RBDATA_TEXT_SIZE)
    89 		return false;
    90 
--> 91 	if (dat->text[dat->len] != '\0')
    92 		return false;
    93 

My question is that the prbtest_rbdata structure is declared like this:

    53  /* test data structure */
    54  struct prbtest_rbdata {
    55          unsigned int len;
    56          char text[] __counted_by(len);
    57  };

The size of text is not really counted by len, it's "MAX_RBDATA_TEXT_SIZE
+ 1".  The condition "if (dat->text[dat->len] != '\0')" is reading one
element beyond the __counted_by() value so something should complain if
we enable all the debugging, right?

regards,
dan carpenter

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

end of thread, other threads:[~2025-07-02 20:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-25 15:22 [bug report] printk: ringbuffer: Add KUnit test Dan Carpenter
2025-06-26  6:59 ` Thomas Weißschuh
2025-07-01 15:23   ` Dan Carpenter
2025-07-01 15:56   ` Petr Mladek
2025-07-02 20:22   ` Nathan Chancellor
2025-07-02 20:33     ` Dan Carpenter

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.