From patchwork Mon Nov 20 00:16:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuran Pereira X-Patchwork-Id: 13460713 X-Patchwork-Delegate: rostedt@goodmis.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hotmail.com header.i=@hotmail.com header.b="JW9AihYv" Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03olkn2091.outbound.protection.outlook.com [40.92.58.91]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9455AE0; Sun, 19 Nov 2023 16:16:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bRLFzLf5WtbW6QEVvhwP/sKWVuNaVNPTa9PWPDaPR5xxM49wrjbQ7kbwKJczyCwibTy9aBm/32CFHidIG07clbbiEZn7oc9cc9MyDnWq0hZKrJ8X6+QvX32apOvqgOiWpV2jIedOC6iYorjxDdPetGmUYSdrym3aFU6CmxjJALp5/jISbsI5M3AA5zH7A3sKThtag5FGn2J2384MWBngSYpPm20y/s7WJpGYxHjrY3UP+uWHPe1EABk7a6JS7ObHteu04E5YVG9+F1W80lhToERY5/Oh3IeoOjNRDvgsW1rtdftAXmNDc4MMGi+HITDYn6zh/WdbmF6KVOdzvTWpSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vKyGSTBshSrHVqtfP2b0GRbfEL/kphFRDy62xCa35Lo=; b=Ogy8N2E6LOLKRnX+gE81Hp8Ko18RmfB475M5lHlZEmYO8p0puRVJrNuu1er0QF4OyZD6lUCYHsfuGX482WmU+r72v7/XMr1Km1PIg1qHkA6EivHIFt4Yhha674BKrjpqCpBWhHWhAEsL8tDWNHFqIVuFyDkZrthrXv/QHNk2vU1o5Kselse6cWIzNqpT4Zx57AvbCE2KchJ+nWU9JAXgKaUdjCFuPxvc0XKdHnMvmPD8u0Nzz/SJ70+AfHnuA9kEgW9BetNEybrrQO8HydraXdiZgCIqG774Bl5BWSZFFYaBHqg5G5Trgkwptj9In1/JfR6csCivgkSq/NfZfIZdCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vKyGSTBshSrHVqtfP2b0GRbfEL/kphFRDy62xCa35Lo=; b=JW9AihYvgbBIAKWf4TjxvUtjOwzX1WAPX94u+v6nbjGxDcCkd2WdTNJsZTvud0pd16NioDDeqaQtZmoGSROyyoV7ZYe/VtGVSs9b8wb+CZlxJPjiKgQZ92f1xm4vjfR823fMhMU4R+Q30Ljt0/OJ6hNmQ5RF+kCtBAUiouUw0gWB2jHyUlmedi7uFfrQTIg9Lgwl2PsT4Q0IpuSgQp3QKwpVx3+UblSpBoc4DJiACaso0yVGNs8OWe3bc+6eMd0EmnbSBQkOwqzL29OcLRhCKH2dvAgjbNrrd/O3yKWkBRI6mrBquv30CuxxlIReCiCE9yOduOkJ3hIlph2Jvb62Xw== Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) by AS2PR10MB7297.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:607::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.27; Mon, 20 Nov 2023 00:16:30 +0000 Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450]) by GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM ([fe80::6c45:bfdf:a384:5450%7]) with mapi id 15.20.7002.026; Mon, 20 Nov 2023 00:16:30 +0000 From: Yuran Pereira To: linux-trace-kernel@vger.kernel.org Cc: Yuran Pereira , mark.rutland@arm.com, rostedt@goodmis.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH] ftrace: Replaces simple_strtoul in ftrace Date: Mon, 20 Nov 2023 05:46:13 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 X-TMN: [+IK25jmwXmVxrmBUqUF9m5jPMVeT1u8/] X-ClientProxiedBy: JNAP275CA0027.ZAFP275.PROD.OUTLOOK.COM (2603:1086:0:4d::17) To GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) X-Microsoft-Original-Message-ID: <20231120001613.361195-1-yuran.pereira@hotmail.com> Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1PR10MB6563:EE_|AS2PR10MB7297:EE_ X-MS-Office365-Filtering-Correlation-Id: 77ec996e-9167-48e5-8c98-08dbe95df1fe X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ch/IfEWQnwsgKP8DjruYs4aHnC5wPv4FkYEYxmw450OO67ME62J7q78RoZVQdWc7HpsbijPUbDPsj5IaFHBIZxRcVFz75Ivhf2LqA5Ylbnj7Pjhaw04+AoAqaGtvSsFzMepDYTi867M1FAB2N0nYi6wrzQSqXjTrGqX+Bqpg6irRfMcHRvRtsaUD30FmVWyytvaxCebgxUnRwPhxej+7qcikQUH6D9o8amrU3n+FBFGeOK/6GYn+DJTHuO+IZrRNqV0Wqwg2bBvXdspV2dVEzGHwkYIvFr6wZSYLoAdxPLCp5svGK8ePjb4NvUjeFaN0pIaHPt/J8NQ6FxxrWUtLo20ezxqt46jtUv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vqJ2M9ChuCljsxWlALa+HYOWr2xH/7HmP9vajCwOXKAFUSqKPMa9fd//tbD1dh+dYj2A5UQPICxkQtu/a5XLqcTvkHz4ZA79VFThQGAjOHGYm4U6LQHWMbiBbXx6Mz8Kn+Xa5tUgG3o+sKyrw39y4y+ar0lOCVypSlKhGA3xMheqlxSTB+dxYANYiP+AEY383d6ay9gfczX3w0IUKp+/nDTsQX4p7D9QGogkCyMgQMb4jGjXCj61OFsn8Vtjpx9z1Nb3w75fS/XQbH2YZuJqLM7Jc925JFinfAiJl1LUSjOGRlxMNswZ3i+XSVN8G1IO5z2k0m2hdRFJx3mK4jCpJe+sPc1E3VYZjkwna3AMI9BDUSb0dHnSpT4oaDc8o+MieFHKIxTbMooWtugN4gbhJSlQ1j6uyXc4iBNfTBbmsQEdn8neslyftBzJKgGQuLluk4VwJP3XhTTdg7OAPysM97B3tWLWWyEOfaosz5OINhlIWMG1o5Lv2782k2H+7m1EXIauOfhsX4hpXyRk/jfQdxg= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 77ec996e-9167-48e5-8c98-08dbe95df1fe X-MS-Exchange-CrossTenant-AuthSource: GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2023 00:16:30.7419 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR10MB7297 The function simple_strtoul performs no error checking in scenarios where the input value overflows the intended output variable. This results in this function successfully returning, even when the output does not match the input string (aka the function returns successfully even when the result is wrong). Or as it was mentioned [1], "...simple_strtol(), simple_strtoll(), simple_strtoul(), and simple_strtoull() functions explicitly ignore overflows, which may lead to unexpected results in callers." Hence, the use of those functions is discouraged. This patch replaces all uses of the simple_strtoul with the safer alternatives kstrtoul and kstruint. Callers affected: - add_rec_by_index - set_graph_max_depth_function Side effects of this patch: - Since `fgraph_max_depth` is an `unsigned int`, this patch uses kstrtouint instead of kstrtoul to avoid any compiler warnings that could originate from calling the latter. - This patch ensures that the callers of kstrtou* return accordingly when kstrtoul and kstruint fail for some reason. In this case, both callers this patch is addressing return 0 on error. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull Signed-off-by: Yuran Pereira Reviewed-by: Masami Hiramatsu (Google) --- kernel/trace/ftrace.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 8de8bec5f366..70217ee97322 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4233,12 +4233,12 @@ static int add_rec_by_index(struct ftrace_hash *hash, struct ftrace_glob *func_g, int clear_filter) { - long index = simple_strtoul(func_g->search, NULL, 0); + long index; struct ftrace_page *pg; struct dyn_ftrace *rec; /* The index starts at 1 */ - if (--index < 0) + if (kstrtoul(func_g->search, 0, &index) || --index < 0) return 0; do_for_each_ftrace_rec(pg, rec) { @@ -5810,9 +5810,8 @@ __setup("ftrace_graph_notrace=", set_graph_notrace_function); static int __init set_graph_max_depth_function(char *str) { - if (!str) + if (!str || kstrtouint(str, 0, &fgraph_max_depth)) return 0; - fgraph_max_depth = simple_strtoul(str, NULL, 0); return 1; } __setup("ftrace_graph_max_depth=", set_graph_max_depth_function);