mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [tip: ras/core] x86/mce/inject: Avoid out-of-bounds write when setting flags
@ 2021-12-28 11:07 tip-bot2 for Zhang Zixun
  0 siblings, 0 replies; only message in thread
From: tip-bot2 for Zhang Zixun @ 2021-12-28 11:07 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Zhang Zixun, Borislav Petkov, x86, linux-kernel

The following commit has been merged into the ras/core branch of tip:

Commit-ID:     de768416b203ac84e02a757b782a32efb388476f
Gitweb:        https://git.kernel.org/tip/de768416b203ac84e02a757b782a32efb388476f
Author:        Zhang Zixun <zhang133010@icloud.com>
AuthorDate:    Mon, 27 Dec 2021 22:02:49 +01:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Tue, 28 Dec 2021 11:45:36 +01:00

x86/mce/inject: Avoid out-of-bounds write when setting flags

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: 0451d14d0561 ("EDAC, mce_amd_inj: Modify flags attribute to use string arguments")
Signed-off-by: Zhang Zixun <zhang133010@icloud.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/linux-edac/YcnePfF1OOqoQwrX@zn.tnic/
---
 arch/x86/kernel/cpu/mce/inject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/inject.c b/arch/x86/kernel/cpu/mce/inject.c
index 6eac840..5fbd7ff 100644
--- a/arch/x86/kernel/cpu/mce/inject.c
+++ b/arch/x86/kernel/cpu/mce/inject.c
@@ -363,7 +363,7 @@ static ssize_t flags_write(struct file *filp, const char __user *ubuf,
 	char buf[MAX_FLAG_OPT_SIZE], *__buf;
 	int err;
 
-	if (cnt > MAX_FLAG_OPT_SIZE)
+	if (!cnt || cnt > MAX_FLAG_OPT_SIZE)
 		return -EINVAL;
 
 	if (copy_from_user(&buf, ubuf, cnt))

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-12-28 11:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-28 11:07 [tip: ras/core] x86/mce/inject: Avoid out-of-bounds write when setting flags tip-bot2 for Zhang Zixun

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

all inboxes | Powered by JetHome®