From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Reinette Chatre" <reinette.chatre@intel.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Sasha Levin" <sashal@kernel.org>,
fenghua.yu@intel.com, shuah@kernel.org,
linux-kselftest@vger.kernel.org
Subject: [PATCH AUTOSEL 6.12 20/23] selftests/resctrl: Protect against array overflow when reading strings
Date: Sun, 24 Nov 2024 07:48:31 -0500 [thread overview]
Message-ID: <20241124124919.3338752-20-sashal@kernel.org> (raw)
In-Reply-To: <20241124124919.3338752-1-sashal@kernel.org>
From: Reinette Chatre <reinette.chatre@intel.com>
[ Upstream commit 46058430fc5d39c114f7e1b9c6ff14c9f41bd531 ]
resctrl selftests discover system properties via a variety of sysfs files.
The MBM and MBA tests need to discover the event and umask with which to
configure the performance event used to measure read memory bandwidth.
This is done by parsing the contents of
/sys/bus/event_source/devices/uncore_imc_<imc instance>/events/cas_count_read
Similarly, the resctrl selftests discover the cache size via
/sys/bus/cpu/devices/cpu<id>/cache/index<index>/size.
Take care to do bounds checking when using fscanf() to read the
contents of files into a string buffer because by default fscanf() assumes
arbitrarily long strings. If the file contains more bytes than the array
can accommodate then an overflow will occur.
Provide a maximum field width to the conversion specifier to protect
against array overflow. The maximum is one less than the array size because
string input stores a terminating null byte that is not covered by the
maximum field width.
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
tools/testing/selftests/resctrl/resctrl_val.c | 4 ++--
tools/testing/selftests/resctrl/resctrlfs.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/resctrl/resctrl_val.c b/tools/testing/selftests/resctrl/resctrl_val.c
index 8c275f6b4dd77..1bba85e4c0675 100644
--- a/tools/testing/selftests/resctrl/resctrl_val.c
+++ b/tools/testing/selftests/resctrl/resctrl_val.c
@@ -160,7 +160,7 @@ static int read_from_imc_dir(char *imc_dir, int count)
return -1;
}
- if (fscanf(fp, "%s", cas_count_cfg) <= 0) {
+ if (fscanf(fp, "%1023s", cas_count_cfg) <= 0) {
ksft_perror("Could not get iMC cas count read");
fclose(fp);
@@ -178,7 +178,7 @@ static int read_from_imc_dir(char *imc_dir, int count)
return -1;
}
- if (fscanf(fp, "%s", cas_count_cfg) <= 0) {
+ if (fscanf(fp, "%1023s", cas_count_cfg) <= 0) {
ksft_perror("Could not get iMC cas count write");
fclose(fp);
diff --git a/tools/testing/selftests/resctrl/resctrlfs.c b/tools/testing/selftests/resctrl/resctrlfs.c
index 250c320349a78..a53cd1cb6e0c6 100644
--- a/tools/testing/selftests/resctrl/resctrlfs.c
+++ b/tools/testing/selftests/resctrl/resctrlfs.c
@@ -182,7 +182,7 @@ int get_cache_size(int cpu_no, const char *cache_type, unsigned long *cache_size
return -1;
}
- if (fscanf(fp, "%s", cache_str) <= 0) {
+ if (fscanf(fp, "%63s", cache_str) <= 0) {
ksft_perror("Could not get cache_size");
fclose(fp);
--
2.43.0
next prev parent reply other threads:[~2024-11-24 12:50 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-24 12:48 [PATCH AUTOSEL 6.12 01/23] gpio: free irqs that are still requested when the chip is being removed Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 02/23] spi: spi-fsl-lpspi: Adjust type of scldiv Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 03/23] soc: qcom: llcc: Use designated initializers for LLC settings Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 04/23] HID: add per device quirk to force bind to hid-generic Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 05/23] firmware: qcom: scm: Allow QSEECOM on Lenovo Yoga Slim 7x Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 06/23] soc: qcom: pd-mapper: Add QCM6490 PD maps Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 07/23] media: v4l: Add luma 16-bit interlaced pixel format Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 08/23] media: uvcvideo: " Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 09/23] media: uvcvideo: RealSense D421 Depth module metadata Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 10/23] media: uvcvideo: Add a quirk for the Kaiweets KTI-W02 infrared camera Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 11/23] media: uvcvideo: Force UVC version to 1.0a for 0408:4033 Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 12/23] media: vb2: use lock if wait_prepare/finish are NULL Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 13/23] media: cx231xx: Add support for Dexatek USB Video Grabber 1d19:6108 Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 14/23] mmc: core: Add SD card quirk for broken poweroff notification Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 15/23] mmc: sdhci-esdhc-imx: enable quirks SDHCI_QUIRK_NO_LED Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 16/23] firmware: qcom: scm: Allow QSEECOM on Dell XPS 13 9345 Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 17/23] soc: imx8m: Probe the SoC driver as platform driver Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 18/23] HID: bpf: Fix NKRO on Mistel MD770 Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 19/23] regmap: maple: Provide lockdep (sub)class for maple tree's internal lock Sasha Levin
2024-11-24 12:48 ` Sasha Levin [this message]
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 21/23] USB: gadget: pxa27x_udc: Avoid using GPIOF_ACTIVE_LOW Sasha Levin
2024-11-26 12:41 ` Bartosz Golaszewski
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 22/23] sched_ext: add a missing rcu_read_lock/unlock pair at scx_select_cpu_dfl() Sasha Levin
2024-11-24 12:48 ` [PATCH AUTOSEL 6.12 23/23] HID: magicmouse: Apple Magic Trackpad 2 USB-C driver support Sasha Levin
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=20241124124919.3338752-20-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=fenghua.yu@intel.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=reinette.chatre@intel.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®