Skip to content

Commit 49e7940

Browse files
StarryShadowZSaeed Mirzamohammadi
authored and
Saeed Mirzamohammadi
committed
x86/mce/inject: Avoid out-of-bounds write when setting flags
[ Upstream commit de76841 ] A contrived zero-length write, for example, by using write(2): ... ret = write(fd, str, 0); ... to the "flags" file causes: BUG: KASAN: stack-out-of-bounds in flags_write Write of size 1 at addr ffff888019be7ddf by task writefile/3787 CPU: 4 PID: 3787 Comm: writefile Not tainted 5.16.0-rc7+ #12 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 due to accessing buf one char before its start. Prevent such out-of-bounds access. [ bp: Productize into a proper patch. Link below is the next best thing because the original mail didn't get archived on lore. ] Fixes: 0451d14 ("EDAC, mce_amd_inj: Modify flags attribute to use string arguments") Signed-off-by: Zhang Zixun <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/linux-edac/[email protected]/ Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit b287eb85e51a04fb26ad3db1b73a17fbdaa11e17) (cherry picked from commit 6d61a17a34a83f1cefa40cabdc3b8473f487a81e)
1 parent b6f752a commit 49e7940

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/x86/kernel/cpu/mce/inject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static ssize_t flags_write(struct file *filp, const char __user *ubuf,
354354
char buf[MAX_FLAG_OPT_SIZE], *__buf;
355355
int err;
356356

357-
if (cnt > MAX_FLAG_OPT_SIZE)
357+
if (!cnt || cnt > MAX_FLAG_OPT_SIZE)
358358
return -EINVAL;
359359

360360
if (copy_from_user(&buf, ubuf, cnt))

0 commit comments

Comments
 (0)