Linux driver-core infrastructure
 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; 2+ 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 related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-20 13:03 UTC | newest]

Thread overview: 2+ 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

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