From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
"Willy Tarreau" <w@1wt.eu>, "Sasha Levin" <sashal@kernel.org>,
shuah@kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH AUTOSEL 6.5 16/16] selftests/nolibc: prevent out of bounds access in expect_vfprintf
Date: Fri, 8 Sep 2023 13:59:53 -0400 [thread overview]
Message-ID: <20230908175953.3457942-16-sashal@kernel.org> (raw)
In-Reply-To: <20230908175953.3457942-1-sashal@kernel.org>
From: Thomas Weißschuh <linux@weissschuh.net>
[ Upstream commit 9c5e490093e83e165022e0311bd7df5aa06cc860 ]
If read() fails and returns -1 (or returns garbage for some other
reason) buf would be accessed out of bounds.
Only use the return value of read() after it has been validated.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
tools/testing/selftests/nolibc/nolibc-test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 55628a25df0a3..8e7750e2eb97c 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -769,7 +769,6 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char
lseek(fd, 0, SEEK_SET);
r = read(fd, buf, sizeof(buf) - 1);
- buf[r] = '\0';
fclose(memfile);
@@ -779,6 +778,7 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char
return 1;
}
+ buf[r] = '\0';
llen += printf(" \"%s\" = \"%s\"", expected, buf);
ret = strncmp(expected, buf, c);
--
2.40.1
prev parent reply other threads:[~2023-09-08 18:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-08 17:59 [PATCH AUTOSEL 6.5 01/16] ACPICA: Add AML_NO_OPERAND_RESOLVE flag to Timer Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 02/16] kernel/fork: beware of __put_task_struct() calling context Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 03/16] rcuscale: Move rcu_scale_writer() schedule_timeout_uninterruptible() to _idle() Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 04/16] scftorture: Forgive memory-allocation failure if KASAN Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 05/16] ACPI: video: Add backlight=native DMI quirk for Lenovo Ideapad Z470 Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 06/16] platform/chrome: cros_ec_lpc: Remove EC panic shutdown timeout Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 07/16] x86/amd_nb: Add PCI IDs for AMD Family 1Ah-based models Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 08/16] perf/smmuv3: Enable HiSilicon Erratum 162001900 quirk for HIP08/09 Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 09/16] s390/boot: cleanup number of page table levels setup Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 10/16] kselftest/arm64: fix a memleak in zt_regs_run() Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 11/16] perf/imx_ddr: speed up overflow frequency of cycle Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 12/16] ACPI: video: Add backlight=native DMI quirk for Apple iMac12,1 and iMac12,2 Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 13/16] hw_breakpoint: fix single-stepping when using bpf_overflow_handler Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 14/16] ACPI: x86: s2idle: Catch multiple ACPI_TYPE_PACKAGE objects Sasha Levin
2023-09-08 17:59 ` [PATCH AUTOSEL 6.5 15/16] selftests/nolibc: fix up kernel parameters support Sasha Levin
2023-09-08 17:59 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230908175953.3457942-16-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox