Skip to content

Commit 247576b

Browse files
eaibmzAlexander Gordeev
authored andcommitted
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 <[email protected]> Signed-off-by: Alexander Egorenkov <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]>
1 parent 72935e3 commit 247576b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

arch/s390/kernel/ipl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ static ssize_t sys_##_prefix##_##_name##_store(struct kobject *kobj, \
266266
struct kobj_attribute *attr, \
267267
const char *buf, size_t len) \
268268
{ \
269-
strscpy(_value, buf, sizeof(_value)); \
269+
if (len >= sizeof(_value)) \
270+
return -E2BIG; \
271+
len = strscpy(_value, buf, sizeof(_value)); \
272+
if (len < 0) \
273+
return len; \
270274
strim(_value); \
271275
return len; \
272276
} \

0 commit comments

Comments
 (0)