From nobody Thu Nov 28 17:07:37 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A0F819B5B8 for ; Fri, 1 Nov 2024 10:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; cv=none; b=H2M53z0r5RTgprr+DztWNpLn54RklE4/e+ZVSxf4czU/i3+0ToEN6wkYcz8imlDpQqBw1AQSnTA5zLxNsIcxs86RxEsWypXTuX0JaE4sHGFX6mqurXcft6ogwEKpIwOAWbIE5v9PPL75+l8CaYi17CT1bMSagYtEfwBNq7q9y8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730457369; c=relaxed/simple; bh=95zVCe3LTNyFUw2de0ZA5FJbzmALpCG7UjAKLiG8h3w=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=oyOvc6qTZx+8zlsnEUYQmUHXRsPMzYVJTqmRFYPhN0CypL835i65nsXKDquwe8UQBbi63n4pIgsXAJc08IVduoDLzbp95AmdelY3B2IBTEfNN+ADmwFqFs6vcIfnPC4nnNDvONb8Sy+wVIUq8N2c3S7J7Fii/Xr+f/lJp3LkPO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45DC6C4AF0F; Fri, 1 Nov 2024 10:36:09 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t6p1f-00000005S65-2SOk; Fri, 01 Nov 2024 06:37:07 -0400 Message-ID: <20241101103707.445466201@goodmis.org> User-Agent: quilt/0.68 Date: Fri, 01 Nov 2024 06:36:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Yuran Pereira , Douglas Anderson , Nir Lichtman Subject: [for-next][PATCH 04/11] trace: kdb: Replace simple_strtoul with kstrtoul in kdb_ftdump References: <20241101103647.011707614@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Yuran Pereira 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-s= trtol-simple-strtoll-simple-strtoul-simple-strtoull Link: https://lore.kernel.org/20241028192100.GB918454@lichtman.org Signed-off-by: Yuran Pereira Reviewed-by: Douglas Anderson Acked-by: Masami Hiramatsu (Google) [nir: style fixes] Signed-off-by: Nir Lichtman Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_kdb.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c index 59857a1ee44c..1e72d20b3c2f 100644 --- a/kernel/trace/trace_kdb.c +++ b/kernel/trace/trace_kdb.c @@ -96,22 +96,19 @@ static int kdb_ftdump(int argc, const char **argv) { int skip_entries =3D 0; long cpu_file; - char *cp; + int err; int cnt; int cpu; =20 if (argc > 2) return KDB_ARGCOUNT; =20 - if (argc) { - skip_entries =3D simple_strtol(argv[1], &cp, 0); - if (*cp) - skip_entries =3D 0; - } + if (argc && kstrtoint(argv[1], 0, &skip_entries)) + return KDB_BADINT; =20 if (argc =3D=3D 2) { - cpu_file =3D simple_strtol(argv[2], &cp, 0); - if (*cp || cpu_file >=3D NR_CPUS || cpu_file < 0 || + err =3D kstrtol(argv[2], 0, &cpu_file); + if (err || cpu_file >=3D NR_CPUS || cpu_file < 0 || !cpu_online(cpu_file)) return KDB_BADINT; } else { --=20 2.45.2