From patchwork Mon Aug 21 10:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 715608 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ABCC1EE49A6 for ; Mon, 21 Aug 2023 10:23:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234632AbjHUKXL (ORCPT ); Mon, 21 Aug 2023 06:23:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231754AbjHUKXK (ORCPT ); Mon, 21 Aug 2023 06:23:10 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 911F18F; Mon, 21 Aug 2023 03:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1692613389; x=1724149389; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dIZOCpZjGIosGR9hEbRXO2VXgXsR2o3Brc7nxbfgOpA=; b=nIG/zUN5nhgRj3KURR5/Cnv+0yS8234NXgxgOr2dWNNsUwUOaOw+Xop8 hP6lzgKVna77e0GbK/8zGODX7IK0Di1DnJjAZPINH8b6qGyK8O5pFNd1H FmKYh5f9G2fr0hxKYR4T/NeHUsU+5IVpvjyRzsEt7s0ir/GMLBQHf2M29 DUUOj47TmZMYjgo3h2QrQSmw00MNoM3mEf/WAb+gt5onO2eZ1Eh7Ze3Gv fTGyjToc4b2hIFVFkXvwXyPmmhaGI3mg3tUg0a2W18wGARxs/W5ZF2p77 HN0ji2grMPJn75G+wnO/tshqXQLj2zLJmApz5bhKlMDgl13TCjCsPzP3g g==; X-IronPort-AV: E=McAfee;i="6600,9927,10808"; a="358530266" X-IronPort-AV: E=Sophos;i="6.01,189,1684825200"; d="scan'208";a="358530266" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 03:23:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10808"; a="735798089" X-IronPort-AV: E=Sophos;i="6.01,189,1684825200"; d="scan'208";a="735798089" Received: from nsnaveen-mobl.gar.corp.intel.com (HELO ijarvine-mobl2.ger.corp.intel.com) ([10.252.54.252]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Aug 2023 03:23:06 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Reinette Chatre , Shuah Khan , linux-kselftest@vger.kernel.org, Shuah Khan , Maciej Wieczor-Retman Cc: Fenghua Yu , Babu Moger , LKML , Shaopeng Tan , =?utf-8?q?Ilpo_J=C3=A4rvinen?= Subject: [PATCH v2 1/7] selftests/resctrl: Ensure the benchmark commands fits to its array Date: Mon, 21 Aug 2023 13:22:39 +0300 Message-Id: <20230821102245.14430-2-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230821102245.14430-1-ilpo.jarvinen@linux.intel.com> References: <20230821102245.14430-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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: ecdbb911f22d ("selftests/resctrl: Add MBM test") Signed-off-by: Ilpo Järvinen --- tools/testing/selftests/resctrl/resctrl_tests.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c index d511daeb6851..1e464ebeac47 100644 --- a/tools/testing/selftests/resctrl/resctrl_tests.c +++ b/tools/testing/selftests/resctrl/resctrl_tests.c @@ -255,9 +255,14 @@ int main(int argc, char **argv) return ksft_exit_skip("Not running as root. Skipping...\n"); if (has_ben) { + if (argc - ben_ind >= BENCHMARK_ARGS - 1) + ksft_exit_fail_msg("Too long benchmark command.\n"); + /* Extract benchmark command from command line. */ for (i = ben_ind; i < argc; i++) { benchmark_cmd[i - ben_ind] = benchmark_cmd_area[i]; + if (strlen(argv[i]) >= BENCHMARK_ARG_SIZE - 1) + ksft_exit_fail_msg("Too long benchmark command argument.\n"); sprintf(benchmark_cmd[i - ben_ind], "%s", argv[i]); } benchmark_cmd[ben_count] = NULL;