From 247576bf624a200b9d4dba6126e760af0d5ebe0e Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Fri, 10 May 2024 11:39:53 +0200 Subject: [PATCH] s390/ipl: Do not accept z/VM CP diag X'008' cmds longer than max length The old implementation of vmcmd sysfs string attributes truncated passed z/VM CP diagnose X'008' commands which were longer than the max allowed number of characters but the reported number of written characters was still equal to the entire length of a given string. This can result in silent failures of some s390-tools (e.g. dumpconf) which can be very hard to detect. Therefore, this commit makes a write attempt to a vmcmd sysfs attribute * fail with E2BIG error if a given string is longer than the maximum allowed one * never destroy the old data in the vmcmd sysfs attribute if the new data doesn't fit into it entirely * return the actual number of written characters if it succeeds Reviewed-by: Heiko Carstens Signed-off-by: Alexander Egorenkov Signed-off-by: Alexander Gordeev --- arch/s390/kernel/ipl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c index eb3fd130ee81..f78c40e2b631 100644 --- a/arch/s390/kernel/ipl.c +++ b/arch/s390/kernel/ipl.c @@ -266,7 +266,11 @@ static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \ struct kobj_attribute *attr, \ const char *buf, size_t len) \ { \ - strscpy(_value, buf, sizeof(_value)); \ + if (len >= sizeof(_value)) \ + return -E2BIG; \ + len = strscpy(_value, buf, sizeof(_value)); \ + if (len < 0) \ + return len; \ strim(_value); \ return len; \ } \