drivers/base/devcoredump.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
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
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
> 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
© 2016 - 2026 Red Hat, Inc.