Skip to content

Commit 4a28c76

Browse files
ij-intelshuahkh
authored andcommitted
selftests/resctrl: Ensure the benchmark commands fits to its array
Benchmark command is copied into an array in the stack. The array is BENCHMARK_ARGS items long but the command line could try to provide a longer command. Argument size is also fixed by BENCHMARK_ARG_SIZE (63 bytes of space after fitting the terminating \0 character) and user could have inputted argument longer than that. Return error in case the benchmark command does not fit to the space allocated for it. Fixes: ecdbb91 ("selftests/resctrl: Add MBM test") Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Tested-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: Shaopeng Tan <tan.shaopeng@jp.fujitsu.com> Reviewed-by: "Wieczor-Retman, Maciej" <maciej.wieczor-retman@intel.com> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent 27c734f commit 4a28c76

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

tools/testing/selftests/resctrl/resctrl_tests.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,14 @@ int main(int argc, char **argv)
255255
return ksft_exit_skip("Not running as root. Skipping...\n");
256256

257257
if (has_ben) {
258+
if (argc - ben_ind >= BENCHMARK_ARGS)
259+
ksft_exit_fail_msg("Too long benchmark command.\n");
260+
258261
/* Extract benchmark command from command line. */
259262
for (i = ben_ind; i < argc; i++) {
260263
benchmark_cmd[i - ben_ind] = benchmark_cmd_area[i];
264+
if (strlen(argv[i]) >= BENCHMARK_ARG_SIZE)
265+
ksft_exit_fail_msg("Too long benchmark command argument.\n");
261266
sprintf(benchmark_cmd[i - ben_ind], "%s", argv[i]);
262267
}
263268
benchmark_cmd[ben_count] = NULL;

0 commit comments

Comments
 (0)