LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 6/7] powerpc/papr_scm: Return the string length from the sysfs show functions
       [not found] <20260917002312.i.923-kees@kernel.org>
@ 2026-09-17  0:23 ` Kees Cook
  2026-09-17 12:50   ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2026-09-17  0:23 UTC (permalink / raw)
  To: Bill Wendling
  Cc: Kees Cook, Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy (CS GROUP), Uwe Kleine-König, Thorsten Blum,
	Shivaprasad G Bhat, linuxppc-dev, Steven Rostedt, Andy Shevchenko,
	linux-hardening

perf_stats_show() and 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.

Build tested ARCH=powerpc ppc64_defconfig with GCC powerpc64-linux-gnu
16.1.0:
arch/powerpc/platforms/pseries/papr_scm.o

Assisted-by: LLM
Signed-off-by: Kees Cook <kees@kernel.org>
---
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Cc: "Uwe Kleine-König" <u.kleine-koenig@baylibre.com>
Cc: Thorsten Blum <blum@kernel.org>
Cc: Shivaprasad G Bhat <sbhat@linux.ibm.com>
Cc: <linuxppc-dev@lists.ozlabs.org>
---
 arch/powerpc/platforms/pseries/papr_scm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/papr_scm.c b/arch/powerpc/platforms/pseries/papr_scm.c
index 75da96c08cdd..6c87c8b4de8e 100644
--- a/arch/powerpc/platforms/pseries/papr_scm.c
+++ b/arch/powerpc/platforms/pseries/papr_scm.c
@@ -1108,7 +1108,7 @@ static ssize_t perf_stats_show(struct device *dev,
 
 free_stats:
 	kfree(stats);
-	return rc ? rc : (ssize_t)seq_buf_used(&s);
+	return rc ? rc : (ssize_t)seq_buf_strlen(&s);
 }
 static DEVICE_ATTR_ADMIN_RO(perf_stats);
 
@@ -1150,7 +1150,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);
 }
 DEVICE_ATTR_RO(flags);
 
-- 
2.34.1



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

* Re: [PATCH 6/7] powerpc/papr_scm: Return the string length from the sysfs show functions
  2026-09-17  0:23 ` [PATCH 6/7] powerpc/papr_scm: Return the string length from the sysfs show functions Kees Cook
@ 2026-09-17 12:50   ` Andy Shevchenko
  2026-09-17 21:19     ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2026-09-17 12:50 UTC (permalink / raw)
  To: Kees Cook
  Cc: Bill Wendling, Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy (CS GROUP),
	Uwe Kleine-König, Thorsten Blum, Shivaprasad G Bhat,
	linuxppc-dev, Steven Rostedt, linux-hardening

On Wed, Sep 16, 2026 at 05:23:18PM -0700, Kees Cook wrote:
> perf_stats_show() and 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.
> 
> Build tested ARCH=powerpc ppc64_defconfig with GCC powerpc64-linux-gnu
> 16.1.0:
> arch/powerpc/platforms/pseries/papr_scm.o

...

>  free_stats:
>  	kfree(stats);
> -	return rc ? rc : (ssize_t)seq_buf_used(&s);
> +	return rc ? rc : (ssize_t)seq_buf_strlen(&s);
>  }

On a brief look it's a single ternary like this in the file, perhaps while at
it move to Elvis op?

	return rc ?: (ssize_t)seq_buf_strlen(&s);

-- 
With Best Regards,
Andy Shevchenko




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

* Re: [PATCH 6/7] powerpc/papr_scm: Return the string length from the sysfs show functions
  2026-09-17 12:50   ` Andy Shevchenko
@ 2026-09-17 21:19     ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2026-09-17 21:19 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Bill Wendling, Madhavan Srinivasan, Michael Ellerman,
	Nicholas Piggin, Christophe Leroy (CS GROUP),
	Uwe Kleine-König, Thorsten Blum, Shivaprasad G Bhat,
	linuxppc-dev, Steven Rostedt, linux-hardening

On Thu, Sep 17, 2026 at 03:50:23PM +0300, Andy Shevchenko wrote:
> On Wed, Sep 16, 2026 at 05:23:18PM -0700, Kees Cook wrote:
> > perf_stats_show() and 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.
> > 
> > Build tested ARCH=powerpc ppc64_defconfig with GCC powerpc64-linux-gnu
> > 16.1.0:
> > arch/powerpc/platforms/pseries/papr_scm.o
> 
> ...
> 
> >  free_stats:
> >  	kfree(stats);
> > -	return rc ? rc : (ssize_t)seq_buf_used(&s);
> > +	return rc ? rc : (ssize_t)seq_buf_strlen(&s);
> >  }
> 
> On a brief look it's a single ternary like this in the file, perhaps while at
> it move to Elvis op?
> 
> 	return rc ?: (ssize_t)seq_buf_strlen(&s);

Sure! I've updated this for v2.

-- 
Kees Cook


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

end of thread, other threads:[~2026-09-17 21:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20260917002312.i.923-kees@kernel.org>
2026-09-17  0:23 ` [PATCH 6/7] powerpc/papr_scm: Return the string length from the sysfs show functions Kees Cook
2026-09-17 12:50   ` Andy Shevchenko
2026-09-17 21:19     ` Kees Cook

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