Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp1999540rdb; Sun, 19 Nov 2023 21:07:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsG9pGXLDHR7heda3KmJPKmMxdyOZ5Y43P5w1ltzpigULizC4omKAZmuJNH0x1lLqRmiEQ X-Received: by 2002:a17:902:f54a:b0:1cc:6906:c016 with SMTP id h10-20020a170902f54a00b001cc6906c016mr5417802plf.9.1700456840070; Sun, 19 Nov 2023 21:07:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700456840; cv=none; d=google.com; s=arc-20160816; b=NNP1zVQsyqeh33tUjxsYyAJI9tCbYYn2mI2ma58yctTF6zh7Y73LW/I8Q50YJQpUuD 5EjNBZYiQnjFX4+OxprEiNDdPheJvPFD+9XL32d3A0RNSRV8uTWks/ZZFPIFzBz2QxaS 5A4KGS5hiwTjGotj8XGZMXt7RwGEZI9ZL3iSTcmzcWdrVMco0UD5MXBGXCjgBTe6wkLn LxrCJRYS33g6/NnLpvdphu5ZtYWEGOWWMa9Wnr5bux8RHTOl2z61ihVE+gL7Hn4OlEKR 5Cs09wFyZtMqL8kkhd4c227YxsepRE4g9vDzukV6c//utZ613vf3Efi8uqVU2DiMJtuQ uiMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=/f4s4esmwTNBD+QyfOpvjYDTQ1VzgNa8nl98+Mnbg8w=; fh=1AefFCle44z1m+L88U/mZelekmctvM30hjAkoySia38=; b=TeYPEaDDYKeUdWZ0lNcBq0dNVuYB8puGhIECTwYShdeU2nKdekTXcnJ4iOOe9j3Fvq nRwz4qO4fOjMCL2ESkiCqyeKi/718yaH2M1V7/jleaYvSR8GMzY/5iceMirTpqIuBule h1pOYmiFcuIOHdfn5uMdyJvRTL3fSB44dEl4r/GmK2S1povP/9Fx9l1aXXtuSD6YzcNO khUkAdNPVOcGiui5iUYEZUS686tZlI8EtQ9wy1wH+Otft/6UXRfP3dFjuxvZKjrw+ko7 v29Td+/4AilLcOz682tHqAbwSAelDgf0gJHe8WrcKyDEe2GxjV6dDDOSPuFqP0oK57X1 PqsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ap4gfEVJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o19-20020a170902779300b001c604fdbb14si7138074pll.81.2023.11.19.21.07.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 21:07:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ap4gfEVJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 67DF080A4F71; Sun, 19 Nov 2023 21:07:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231807AbjKTE5v (ORCPT + 99 others); Sun, 19 Nov 2023 23:57:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjKTE5u (ORCPT ); Sun, 19 Nov 2023 23:57:50 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A4FAD3 for ; Sun, 19 Nov 2023 20:57:47 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05502C433C7; Mon, 20 Nov 2023 04:57:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700456266; bh=D8GkFkadiMvyfeHxVlRTuBngO0W+nbZFP1V6zF4gWgY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ap4gfEVJl+R+eIh1mutUrAjpACp5P0jiwpxn/rx78T/sultv9oQKN/7Da6gpCcusv 037av/hc14u38aufL6LrpScArXelj8mceylftyLmIlYfBu9bD1y9OHR6TnG320DooP dFOZrgzVGRmYh6/j4UCu2mgfyElARiKd9UvsnL8bP/rWoiogK5tSngLLZ8hg8iiQ1t V+ygjmbszOjGa+qvtEEgtT0yec1c5TNAYr6H9jF0lSBj+UpheeqtLEKMTsxnEO41jG 9Cj6UpuJVeoFqa5HQpp8kyr0G7GOEDKMUa2EFhwkEYto150rFFDFSgFqWbxAjKOg8n SuxGIQYEf86FA== Date: Mon, 20 Nov 2023 13:57:42 +0900 From: Masami Hiramatsu (Google) To: Yuran Pereira Cc: linux-trace-kernel@vger.kernel.org, mark.rutland@arm.com, rostedt@goodmis.org, mhiramat@kernel.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org Subject: Re: [PATCH] ftrace: Replaces simple_strtoul in ftrace Message-Id: <20231120135742.0abfc6bb7ccdd985990c68a4@kernel.org> In-Reply-To: References: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.0 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 19 Nov 2023 21:07:17 -0800 (PST) On Mon, 20 Nov 2023 05:46:13 +0530 Yuran Pereira wrote: > 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 > This looks good to me. Reviewed-by: Masami Hiramatsu (Google) Thank you! > Signed-off-by: Yuran Pereira > --- > 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); > -- > 2.25.1 > -- Masami Hiramatsu (Google)