From patchwork Mon Nov 20 00:07:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuran Pereira X-Patchwork-Id: 13460710 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hotmail.com header.i=@hotmail.com header.b="Gnpf+8o3" Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2043.outbound.protection.outlook.com [40.92.91.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E57F8139; Sun, 19 Nov 2023 16:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AmO7kUXIQXs66/gj22HLG/y05IQy6Fr7K7k31GjSyc6MpOtSbxeNzQHhm22xcugHcl4xZ3Z5KMXlylOm8ONyfsO8RhTsb3FZMm+jG5DHH2OGiDCrEZFwNf7wQ53mzuqxw9PAETd8KMRjTVAL8FKjDHsLIqlVe3Za+hWBuze1+zuU/B8V4TufjDOEuzPookf88gtbaQHu3m2mF5PvENRoor4FBSvUlkK6SoJH/V/JuZIGW7A2KCT6lFzdDvC2Q6zwIodZTZr3zxZ8K/6oM7a0RNYJGXUzDeP0bN9zfrCs25zUDSPs3YOkPeTP770BhFUrPk4rXSnkK7ZIysm9df8Fww== 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=1Rkp2+I3Utyu/eHj+COHMWxecxo6bl7BCcTTJMZuNOI=; b=Em2LzzvY6aG9tz+7KEgC8D2cqkoxiIbbp2EPXPLqqN/5C00gQ+Bvb3iP+wFAIdW5Lo4Nj6LlZ1mH0R+qpQo9VRDn9F9DDqrk0yjKJ0kFc5kcbiBWj1sfXSaUtrGG+XDcr9xPkjqWOI+W1maU1i8uKGAKcmxkqfvBvd5EgvuJwdWpzDeJg3mbv/ylw8cq0xs1mxxJl3g3NoS7BJbkj/evkj9Fudr74HdtbDhgZrpA951mAu+dMCS/GPSphG0GpQYeehKrfXZ2+9HnrsGRZfthu7tGuDiUJetFNdHyYt9tNxtqPTloqgL7qacNkltsdbBbIAz5OFfVvbjkB8vGdS1gfQ== 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=1Rkp2+I3Utyu/eHj+COHMWxecxo6bl7BCcTTJMZuNOI=; b=Gnpf+8o3aAWGCQRbHeZzWsTunjMTUbAZ/TPp2+oofI/GrjHVRXFQpgMSLT7+jP3Cl8lXfdWOSlTn4g1fsbYLnPZ2Z2GE3POygVq/Bic3QZoD/656eC1Nq9e0ggZa+tGwEmN2R5OTY7Tb5n1SOQUe0rjtvlwgRWHr+/G1yWPsT52S3xl2KSEzp3QNW382e/Vg0j8jedafrbMCsNfyw7yvNmR8B5D2QIfwKjz0ZqZ7Rlopr/A9Xp5l8EISIHxueVa7MjRQeMSJNxkstiPpT2nE/htBcGXPVtPV+/3YOchoGMyWoF7j6J5kLU9NPxPxqyBRHGD8m0TUVjdC0xtc3JLCUA== Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) by AS8PR10MB6173.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:54a::17) 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:07:50 +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:07:50 +0000 From: Yuran Pereira To: kgdb-bugreport@lists.sourceforge.net, linux-trace-kernel@vger.kernel.org Cc: Yuran Pereira , jason.wessel@windriver.com, daniel.thompson@linaro.org, dianders@chromium.org, rostedt@goodmis.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH 1/2] kdb: Replace the use of simple_strto with safer kstrto in kdb_main Date: Mon, 20 Nov 2023 05:37:23 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-TMN: [psuvO/RxnQfAktTkYNRR2vXB7b3sNwWI] X-ClientProxiedBy: JN2P275CA0017.ZAFP275.PROD.OUTLOOK.COM (2603:1086:0:3::29) To GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) X-Microsoft-Original-Message-ID: <20231120000723.360560-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_|AS8PR10MB6173:EE_ X-MS-Office365-Filtering-Correlation-Id: 16a542e1-b425-4184-e0b5-08dbe95cbbfd X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eLJpYYQeM6jMKkug0EVTRZcnTu3PfzlJMGYr8/l28+A420PjUkbt7PUzzTPoCH23fOoXjqk4IpSDdOxZaQHlZvYKstPpX59R32AH/9qpzgSG6FYg7zmmubDtuIlGUVzBv30PuXrOcMYehv2oBkRwkHhGtKcGX3MKc0P1/NYVqfXWRrI882LEdvv1yzV8wnNt0Ya+iPxwAWnPEpnhtjm/HZAhk8qRWwOgMWzwwomkeGH5tmMAbF44exl3X4zFHRyg7tVzdx4g9mKfsXjGWb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Q1w40/lcdNanOSmHpSYGw5ZpXesdKQXJfC7M8PQJ2zVLNPV3H/Q7ACtuov35E0fersWBgDbH36SXmnd3pIPj7p/X6nuROrBnjqekcTWb3AUjkCzdOHpzDwMbTvKMtVxVltPAzbTk0dO+nEQQqGKIlkKkIzSOcYooFyM2+6RmxBjiDexfRtRBoTuiK+fBxpsry2V7Y+am34etv20wCNY2Y8a3IPoMuKUwmYPSOsHOnZpAlREfnKAb6gIeXmkDQFSoL6mB2R/aSR+mlXZ9DhfSJ4slbSqyMPxsCC4aQgJ1zAob+W2Sc+8yQwlpoPqkr3OME+wXyoqk8GHeUmH1C930Bfuoi5QUu6jJAQpakQNJvh6U/XfupgOwgixlJgyJzClbtsKOo77P3iKBNLwoxKfV2eUwztNCyKVi1EbfbtGVBW9axNTS2kbbz9hLXmPpwpVcSvFqYpIFfgppIKw/0x24nV/hpDbBuc9pMuQbGUvjUFITg/pT72c6EzaNmtYV2E1cQdnt25j7/nszI8H1CIIadoMwQ9hclxBzRX1PoYzdEpmn8bvaodOMn61sOFKyRYO/a19QtlOlFz6+SlPXPdSg= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 16a542e1-b425-4184-e0b5-08dbe95cbbfd 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:07:50.8469 (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: AS8PR10MB6173 The simple_str* family of functions perform no error checking in scenarios where the input value overflows the intended output variable. This results in these functions successfully returning even when the output does not match the input string. 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_strto* series of functions with their safer kstrto* alternatives. Side effects of this patch: - Every string to long or long long conversion using kstrto* is now checked for failure. - kstrto* errors are handled with appropriate `KDB_BADINT` wherever applicable. - A good side effect is that we end up saving a few lines of code since unlike in simple_strto* functions, kstrto functions do not need an additional "end pointer" variable, and the return values of the latter can be directly checked in an "if" statement without the need to define additional `ret` or `err` variables. This, of course, results in cleaner, yet still easy to understand code. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#simple-strtol-simple-strtoll-simple-strtoul-simple-strtoull Signed-off-by: Yuran Pereira --- kernel/debug/kdb/kdb_main.c | 70 +++++++++++-------------------------- 1 file changed, 21 insertions(+), 49 deletions(-) diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 6b213c8252d6..a6e4bec7854d 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -316,8 +316,8 @@ static int kdbgetulenv(const char *match, unsigned long *value) return KDB_NOTENV; if (strlen(ep) == 0) return KDB_NOENVVALUE; - - *value = simple_strtoul(ep, NULL, 0); + if (kstrtoul(ep, 0, value)) + return KDB_BADINT; return 0; } @@ -412,42 +412,21 @@ static void kdb_printenv(void) */ int kdbgetularg(const char *arg, unsigned long *value) { - char *endp; - unsigned long val; - - val = simple_strtoul(arg, &endp, 0); - - if (endp == arg) { - /* - * Also try base 16, for us folks too lazy to type the - * leading 0x... - */ - val = simple_strtoul(arg, &endp, 16); - if (endp == arg) + /* + * If the first fails, also try base 16, for us + * folks too lazy to type the leading 0x... + */ + if (kstrtoul(arg, 0, value)) + if (kstrtoul(arg, 16, value)) return KDB_BADINT; - } - - *value = val; - return 0; } int kdbgetu64arg(const char *arg, u64 *value) { - char *endp; - u64 val; - - val = simple_strtoull(arg, &endp, 0); - - if (endp == arg) { - - val = simple_strtoull(arg, &endp, 16); - if (endp == arg) + if (kstrtou64(arg, 0, value)) + if (kstrtou64(arg, 16, value)) return KDB_BADINT; - } - - *value = val; - return 0; } @@ -483,10 +462,10 @@ int kdb_set(int argc, const char **argv) */ if (strcmp(argv[1], "KDBDEBUG") == 0) { unsigned int debugflags; - char *cp; + int ret; - debugflags = simple_strtoul(argv[2], &cp, 0); - if (cp == argv[2] || debugflags & ~KDB_DEBUG_FLAG_MASK) { + ret = kstrtouint(argv[2], 0, &debugflags); + if (ret || debugflags & ~KDB_DEBUG_FLAG_MASK) { kdb_printf("kdb: illegal debug flags '%s'\n", argv[2]); return 0; @@ -1631,10 +1610,10 @@ static int kdb_md(int argc, const char **argv) if (!argv[0][3]) valid = 1; else if (argv[0][3] == 'c' && argv[0][4]) { - char *p; - repeat = simple_strtoul(argv[0] + 4, &p, 10); + if (kstrtouint(argv[0] + 4, 10, &repeat)) + return KDB_BADINT; mdcount = ((repeat * bytesperword) + 15) / 16; - valid = !*p; + valid = 1; } last_repeat = repeat; } else if (strcmp(argv[0], "md") == 0) @@ -2095,15 +2074,11 @@ static int kdb_dmesg(int argc, const char **argv) if (argc > 2) return KDB_ARGCOUNT; if (argc) { - char *cp; - lines = simple_strtol(argv[1], &cp, 0); - if (*cp) + if (kstrtoint(argv[1], 0, &lines)) lines = 0; - if (argc > 1) { - adjust = simple_strtoul(argv[2], &cp, 0); - if (*cp || adjust < 0) + if (argc > 1) + if (kstrtouint(argv[2], 0, &adjust) || adjust < 0) adjust = 0; - } } /* disable LOGGING if set */ @@ -2440,14 +2415,12 @@ static int kdb_help(int argc, const char **argv) static int kdb_kill(int argc, const char **argv) { long sig, pid; - char *endp; struct task_struct *p; if (argc != 2) return KDB_ARGCOUNT; - sig = simple_strtol(argv[1], &endp, 0); - if (*endp) + if (kstrtol(argv[1], 0, &sig)) return KDB_BADINT; if ((sig >= 0) || !valid_signal(-sig)) { kdb_printf("Invalid signal parameter.<-signal>\n"); @@ -2455,8 +2428,7 @@ static int kdb_kill(int argc, const char **argv) } sig = -sig; - pid = simple_strtol(argv[2], &endp, 0); - if (*endp) + if (kstrtol(argv[2], 0, &pid)) return KDB_BADINT; if (pid <= 0) { kdb_printf("Process ID must be large than 0.\n"); From patchwork Mon Nov 20 00:09:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuran Pereira X-Patchwork-Id: 13460711 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=hotmail.com header.i=@hotmail.com header.b="vE8K0F9a" Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2073.outbound.protection.outlook.com [40.92.91.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DC3EE0; Sun, 19 Nov 2023 16:10:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MKL/4vcWGBLsA8DjJiSyerjTUIAGZR7fB1cKN+axB4WvLXN4fKKDwRaWp7qNks/nVBtXQP31IKpcCzimVP914d0iFccQEVaj/AAr6nmJkxwZ+qGjP2FrquO5jWqYjzGILEhY2BjOfD7ZQr6tWEO5+1V6QRGsg4cnWzUpGe7nc9VrLn6GXPh/zHKjDumSmEjxFACBnQkSJIAfHk8CFE9Y8tlhVcfvtY/mImXoieycjQ04syGoPVojnNK2rRm+nRR7/ltxBr6Fm1+pCqdmq+OYdwjQugpn1jP4ZdfNFJOyVw7siMar5PMnFbpJZ7Qn6kM5NewcxacOaZnfN7MRKy3CHw== 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=P4QOcl+PaZFuwDi0ESKom6kyt9j6tcui8KvDKr3F7U4=; b=nWSnLM8Lkw7VHfNC5zDymVSTD7uJLQgjPZHfBW/lePZHizMF84otwN0E0uozgy8MxMP7Wds8NJC/FagUxj0Nn1yFDTEG0ucDe5WuQI2D/aHtbtnYgvwKcOUi064K/OpVLE5s5lZokAENWEVZTAbyjRmXK61sWkfNEXB5z1c7X3XNTy+uI8dz6RMVxEbdSoLAIp/+rpKNLytKWgtXTqoG95tmKCKG/NBe+Bo+sQ6g4Aj3vZ26f6+vYypitSRo1p7XEKVUf9CWdIGyu8K8ATZ9E7TncYmlOZL5IVCfAR5r7kfqw6G6c5LNPKUriKTR9n/HnJzNnn9k5qyeUY/0DUQsUA== 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=P4QOcl+PaZFuwDi0ESKom6kyt9j6tcui8KvDKr3F7U4=; b=vE8K0F9aiYHuCgHK8fYxZAGXVBS99NS607O5aF0gaDg4TdZaJmVFzYTLz33A2xWx0Z3diJ2+xkJp/2Mcy45usxWoz2+KxDQ6MQcbUyQfkqAISSsROeJ/6MxDwbS+YbfNfJNimbW12FnGsVTmdl4RpCR4r5nxdunLA5VOeKaLDlvNRjH9BjGovArC/H/j8W2pqZ2zZY7Ezbe+7/WppU642dZbq0shKB+rL9mO7vQ21FdfBxq0HAuVfirUdL2CM5NDUUgVD7y82HH4lngQ+l3poV1D3EKSJHtkz88GE2A3cNq5FJKYr2i3it1mGFf62bTmITMxzox5C9tmphC0u678PQ== Received: from GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) by AS8PR10MB6173.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:54a::17) 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:09:58 +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:09:58 +0000 From: Yuran Pereira To: kgdb-bugreport@lists.sourceforge.net, linux-trace-kernel@vger.kernel.org Cc: Yuran Pereira , jason.wessel@windriver.com, daniel.thompson@linaro.org, dianders@chromium.org, rostedt@goodmis.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: [PATCH 2/2] trace: kdb: Replace simple_strtoul with kstrtoul in kdb_ftdump Date: Mon, 20 Nov 2023 05:39:31 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: X-TMN: [WHg10UELG6kZDo+wax9DDRTZrHhq9GOA] X-ClientProxiedBy: JN2P275CA0016.ZAFP275.PROD.OUTLOOK.COM (2603:1086:0:3::28) To GV1PR10MB6563.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:150:83::20) X-Microsoft-Original-Message-ID: <20231120000931.360749-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_|AS8PR10MB6173:EE_ X-MS-Office365-Filtering-Correlation-Id: 0043e2f8-305c-43e9-eb33-08dbe95d0827 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lXrK6pfk9eMDSXua+6UMg6vLTYb5DgQTL3zbC5fEfj/WwsbRKOrx+o4zv9Vc1cBs7WqvGMXbWVgzpC4/fn9py4nNiCKa437uOk+QaxIuNuWgGp4JTLwAUjIFRBuB5tkK3Z95ffmUmfnJB9UnMz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fjGkR41krB4ie+7Soig6JYuDLxOP4sBbyENWFGUsP21qDpI5x78ZWhlUz7+tGcaP/25GZKbSMkPHZYJnLVgWfKajkp+3/v6qhwSXLGojji0/FE3TSZt0y/nXRcuOJn/h/Ptvl0Xq2G10fSDSnAOeoJO21rx2I791UVxA57ZBB1P8yFBvNG8mZEiV3O6w/KBP3eh4WwILyUpJ5MhGaBc8Cm5ewJDVTvv0f7G6v2kKPzQG00EzLEWUwp8wAzsACkdwvsWv53b47feQ5wf/I1x1zhO5sJMBl29nFTA3fwswy2OahltNEhn344PN04DyuuglvzdTkWZQALg+eZ0BUHjW1poEQGyJFhyhXASO1Mj/ZEszxWQDpEB/ffVsTBFNPj0Oei2wMBRF0dAnVE4zym5CXNq7FnRADLEVwSteUFiUllgunez0yIF7gHSziU4wfvGez2KrLGf3kyml3Z3Y8guZxfV8aLbvmiBwKg+09Gi+pX0FBtA5LP3+LDq2aukBlBdpA8ncTxXA7JRIwu/kr51JUkwdLDHC2QkmsQ0i8R+du7/UvgEpCdRlgC2vuJW5NOstsckF7GbmOPaM0okv1vja9AnurylTjXh9w+ziDBcKUPD9f1SVxsvOykRV7s70N3nPiA3Q0lCEmgv7SMdCnng1OBuMCq94HIozZyKJty+efsyJ8bTf+kCRS9jSPZ/sV0WwDT0cNcjGmVkWLprTq8SvOotZ8= X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-6b909.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: 0043e2f8-305c-43e9-eb33-08dbe95d0827 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:09:58.4302 (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: AS8PR10MB6173 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 kstrtoint and kstrtol. [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: Douglas Anderson --- kernel/trace/trace_kdb.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c index 59857a1ee44c..3891f885e4a6 100644 --- a/kernel/trace/trace_kdb.c +++ b/kernel/trace/trace_kdb.c @@ -96,23 +96,21 @@ static int kdb_ftdump(int argc, const char **argv) { int skip_entries = 0; long cpu_file; - char *cp; + int err; int cnt; int cpu; if (argc > 2) return KDB_ARGCOUNT; - if (argc) { - skip_entries = simple_strtol(argv[1], &cp, 0); - if (*cp) + if (argc) + if (kstrtoint(argv[1], 0, &skip_entries)) skip_entries = 0; - } if (argc == 2) { - cpu_file = simple_strtol(argv[2], &cp, 0); - if (*cp || cpu_file >= NR_CPUS || cpu_file < 0 || - !cpu_online(cpu_file)) + err = kstrtol(argv[2], 0, &cpu_file); + if (err || cpu_file >= NR_CPUS || cpu_file < 0 || + !cpu_online(cpu_file)) return KDB_BADINT; } else { cpu_file = RING_BUFFER_ALL_CPUS;