mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] base: devcoredump: Replace simple_strtol with kstrtol
@ 2026-07-20 12:50 Jiangshan Yi
  2026-07-20 12:55 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Jiangshan Yi @ 2026-07-20 12:50 UTC (permalink / raw)
  To: johannes, gregkh, rafael, dakr
  Cc: linux-kernel, driver-core, 13667453960, Jiangshan Yi

The disabled_store() function uses simple_strtol(), which is marked
obsolete. simple_strtol() does not provide error handling on invalid
input - it silently returns a partial parse result or 0, which the
'if (tmp != 1) return -EINVAL' check then accepts as a legitimate
non-1 value.

Replace simple_strtol(buf, NULL, 10) with kstrtol(buf, 10, &tmp),
which returns an error code on invalid input. This makes the write-once
lockdown attribute stricter: malformed input (e.g. trailing garbage)
now returns -EINVAL instead of being silently treated as a non-1 value
that the caller wanted to reject anyway.

The behaviour for the legitimate '1' input is unchanged.

Signed-off-by: Jiangshan Yi <yijiangshan@kylinos.cn>
---
 drivers/base/devcoredump.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/base/devcoredump.c b/drivers/base/devcoredump.c
index 8bb1763083dd..f346729bee1b 100644
--- a/drivers/base/devcoredump.c
+++ b/drivers/base/devcoredump.c
@@ -210,7 +210,12 @@ static ssize_t disabled_show(const struct class *class, const struct class_attri
 static ssize_t disabled_store(const struct class *class, const struct class_attribute *attr,
 			      const char *buf, size_t count)
 {
-	long tmp = simple_strtol(buf, NULL, 10);
+	long tmp;
+	int ret;
+
+	ret = kstrtol(buf, 10, &tmp);
+	if (ret < 0)
+		return ret;
 
 	/*
 	 * This essentially makes the attribute write-once, since you can't
-- 
2.25.1


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

* Re: [PATCH] base: devcoredump: Replace simple_strtol with kstrtol
  2026-07-20 12:50 [PATCH] base: devcoredump: Replace simple_strtol with kstrtol Jiangshan Yi
@ 2026-07-20 12:55 ` Greg KH
  2026-07-21  3:36   ` Jiangshan Yi
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2026-07-20 12:55 UTC (permalink / raw)
  To: Jiangshan Yi
  Cc: johannes, rafael, dakr, linux-kernel, driver-core, 13667453960

On Mon, Jul 20, 2026 at 08:50:35PM +0800, Jiangshan Yi wrote:
> The disabled_store() function uses simple_strtol(), which is marked
> obsolete. simple_strtol() does not provide error handling on invalid
> input - it silently returns a partial parse result or 0, which the
> 'if (tmp != 1) return -EINVAL' check then accepts as a legitimate
> non-1 value.
> 
> Replace simple_strtol(buf, NULL, 10) with kstrtol(buf, 10, &tmp),
> which returns an error code on invalid input. This makes the write-once
> lockdown attribute stricter: malformed input (e.g. trailing garbage)
> now returns -EINVAL instead of being silently treated as a non-1 value
> that the caller wanted to reject anyway.

Be careful, we are rejecting ABI changes like this as there is no real
reason to change this at this point in time, right?

thanks,

greg k-h

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

* Re: Re: [PATCH] base: devcoredump: Replace simple_strtol with kstrtol
  2026-07-20 12:55 ` Greg KH
@ 2026-07-21  3:36   ` Jiangshan Yi
  0 siblings, 0 replies; 3+ messages in thread
From: Jiangshan Yi @ 2026-07-21  3:36 UTC (permalink / raw)
  To: gregkh
  Cc: 13667453960, dakr, driver-core, johannes, linux-kernel, rafael,
	yijiangshan

> Be careful, we are rejecting ABI changes like this as there is no real
> reason to change this at this point in time, right?
>
> thanks,
>
> greg k-h

Hi Greg,

You're right, thanks for catching this.

The intent was only to drop the obsolete simple_strtol() call. I
didn't properly consider that switching to kstrtol() also tightens
the accepted input for the sysfs store path - e.g. "1<garbage>"
currently parses as 1 and enables lockdown, while with kstrtol() it
would return -EINVAL. That's a userspace-visible behavior change in a
long-stable interface, which isn't justified by just cleaning up an
obsolete helper.

I'll drop this patch.

If on the other hand you'd prefer the stricter behavior as a
deliberate ABI change, I can resend it, but I won't unless you want
it.

thanks,
Jiangshan Yi

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

end of thread, other threads:[~2026-07-21  3:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-20 12:50 [PATCH] base: devcoredump: Replace simple_strtol with kstrtol Jiangshan Yi
2026-07-20 12:55 ` Greg KH
2026-07-21  3:36   ` Jiangshan Yi

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

all inboxes | Powered by JetHome®