* [PATCH v2 8/9] nvdimm: ndtest: Return the string length from flags_show()
[not found] <20260919002658.stay.929-kees@kernel.org>
@ 2026-09-19 0:27 ` Kees Cook
0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2026-09-19 0:27 UTC (permalink / raw)
To: Bill Wendling
Cc: Kees Cook, Andy Shevchenko, Dave Jiang, nvdimm, Alison Schofield,
Greg Kroah-Hartman, Guangshuo Li, Ira Weiny,
Uwe Kleine-König, Vishal Verma, Steven Rostedt,
nikitash.mariiaw, linux-kernel, linux-hardening
flags_show() build their output with a seq_buf and return seq_buf_used(),
which may include the trailing NUL byte when the seq_buf has
overflowed. Use seq_buf_strlen() instead.
The flag names are far shorter than the PAGE_SIZE buffer sysfs
provides, so this cannot overflow today.
Build tested ARCH=x86_64 with GCC 16.2.0, built out of tree with
make M=tools/testing/nvdimm:
tools/testing/nvdimm/test/ndtest.o
Assisted-by: LLM
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: <nvdimm@lists.linux.dev>
Cc: Alison Schofield <alison.schofield@intel.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Guangshuo Li <lgs201920130244@gmail.com>
Cc: Ira Weiny <iweiny@kernel.org>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Cc: Vishal Verma <vishal.l.verma@intel.com>
---
tools/testing/nvdimm/test/ndtest.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/nvdimm/test/ndtest.c b/tools/testing/nvdimm/test/ndtest.c
index 2051ad5d4882..f097f2992966 100644
--- a/tools/testing/nvdimm/test/ndtest.c
+++ b/tools/testing/nvdimm/test/ndtest.c
@@ -693,7 +693,7 @@ static ssize_t flags_show(struct device *dev,
if (seq_buf_used(&s))
seq_buf_printf(&s, "\n");
- return seq_buf_used(&s);
+ return seq_buf_strlen(&s);
}
static DEVICE_ATTR_RO(flags);
--
2.34.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-19 0:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260919002658.stay.929-kees@kernel.org>
2026-09-19 0:27 ` [PATCH v2 8/9] nvdimm: ndtest: Return the string length from flags_show() Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox