Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1411702lqm; Thu, 2 May 2024 14:07:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1IG1mLkrmsF4H406/ptJB9wmyjzQijWDO/XThqBu0vusEJdMjIrn9Ms8ezIRb9WN2vnSclolrrbCTp9y/h0Lao0s80iRdh7iM9Kihiw== X-Google-Smtp-Source: AGHT+IFBtGOytaEQPx3XCl+qTdndik7NAH4UMGXaJgAQBwmcS+wK9R6gXwQUYQVghjlvOQXRcAMK X-Received: by 2002:a17:906:4aca:b0:a59:6856:cbcf with SMTP id u10-20020a1709064aca00b00a596856cbcfmr374388ejt.73.1714684033540; Thu, 02 May 2024 14:07:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714684033; cv=pass; d=google.com; s=arc-20160816; b=nqASuwCSkV92zM5GHDgzknn33E13kP3G7xZVyc6IWeZYZmdA2WaVS6ssyFti2Ld3H8 ls96dq1wf+D1KJ83MCHyc18xWCb/ocIXesXNzYUL+9uVmeaD1Af2WbySoMJvYicMGuQL CjMVSAHp6lbpP0IKd7AgWicSUwkO/RCrZuAEA8IJLnsZGeogtckWLR8gStZK5KRCvMLu BG/5jw2AjiiFDpqoVl0JXWxHhaPcAhdScWaCSWytzvposBtuyfrDEQQN92uU5hMkEVB2 KkQqqgzAN+OhuTlO5Kz2zXjSJBtifhg6miIAk5WzOdi4F8Wb3WK2jqzDVBD6OCjhZFpU Joow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=9dUo5satVjEs3W4MyhAwMJSXnai8ueIXNHszDAK9yHE=; fh=iU6GCUSFC/neu02qjPOf+2J3p7EzjAA9RBof22r5Tko=; b=Rq4TL5L1F95dZTzyN3f6X4mAVlMmtfbeBOToql/x4ky8eK3ljK3zsP9klyzdtg4AEi uA8TjzBFns3I7ou+gguDGe0iLteK8DLB1yMkHMuGB0dLSLNMD7tWP4YSC3/0rv4LfOAO 57kD8XGJ77NrFyCxTjEAJA+upIkX4FgMPUHfwRMvdw0oRxCVxXWpKnl2JzFIpS3gM9GQ txqN094CqdndnNh44tfqgKJ/sjfeEjOl83K6RnmTC96B38JfZMulBlUrwJYkVKiFBPMF uFb86g3lniZpjAlPy5BdeRonYxZSm7g3jATSyM5RVmwXkrIY5KaSNt1+EU3ARHsZqdIl zPbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-166910-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166910-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v8-20020a170906564800b00a5538817584si842407ejr.19.2024.05.02.14.07.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 14:07:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166910-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-166910-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166910-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 221C71F232A3 for ; Thu, 2 May 2024 21:07:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A8408181301; Thu, 2 May 2024 21:06:59 +0000 (UTC) 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 2CEAB16D4C2; Thu, 2 May 2024 21:06:58 +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=1714684019; cv=none; b=BFQc7gOGRaWhkmXAMhCdF086IrjT0lk3zmkZiCWEtEUgV4EM5pGeVX0ml0jaoeY0ESHKYk16bkMwfUAb2vp3iAwMKp/1FM2T3IRUfbLM0yskyRGqHH2NW18d3681eUGEzJSUuhWZBG4+LdPY4QH9YEi1+RfRdoAyruAnp+b6IA8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714684019; c=relaxed/simple; bh=y64jK/AUuv5FzhPuBOwbPsWYnjoJ4kXGIYP8XVguRw8=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JiY3EXPexzCmC//kLxLBiTjI5EBPid3SZ0WxfP0pxnsqPD7hbRIooqAyVQ9bu9US2IXQIUe2BzcAhmA1OCy4Eac5i2BbKXPKunya5gM0z1jfROLEYBLtVEGNRIiB2uFTJwPWP7K81wzFYf2iYRRD5PP38WaJkZzuPYGuAaMJc+E= 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 8D84AC113CC; Thu, 2 May 2024 21:06:57 +0000 (UTC) Date: Thu, 2 May 2024 17:07:43 -0400 From: Steven Rostedt To: Zheng Yejian Cc: , , , , , Subject: Re: [PATCH v3] ftrace: Fix possible use-after-free issue in ftrace_location() Message-ID: <20240502170743.15a5ff1c@gandalf.local.home> In-Reply-To: <20240417032830.1764690-1-zhengyejian1@huawei.com> References: <20240401125543.1282845-1-zhengyejian1@huawei.com> <20240417032830.1764690-1-zhengyejian1@huawei.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 17 Apr 2024 11:28:30 +0800 Zheng Yejian wrote: > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index da1710499698..e05d3e3dc06a 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -1581,7 +1581,7 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) > } > > /** > - * ftrace_location_range - return the first address of a traced location > + * ftrace_location_range_rcu - return the first address of a traced location kerneldoc comments are for external functions. You need to move this down to ftrace_location_range() as here you are commenting a local static function. But I have to ask, why did you create this static function anyway? There's only one user of it (the ftrace_location_range()). Why didn't you just simply add the rcu locking there? unsigned long ftrace_location_range(unsigned long start, unsigned long end) { struct dyn_ftrace *rec; unsigned long ip = 0; rcu_read_lock(); rec = lookup_rec(start, end); if (rec) ip = rec->ip; rcu_read_unlock(); return ip; } -- Steve > * if it touches the given ip range > * @start: start of range to search. > * @end: end of range to search (inclusive). @end points to the last byte > @@ -1592,7 +1592,7 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) > * that is either a NOP or call to the function tracer. It checks the ftrace > * internal tables to determine if the address belongs or not. > */ > -unsigned long ftrace_location_range(unsigned long start, unsigned long end) > +static unsigned long ftrace_location_range_rcu(unsigned long start, unsigned long end) > { > struct dyn_ftrace *rec; > > @@ -1603,6 +1603,16 @@ unsigned long ftrace_location_range(unsigned long start, unsigned long end) > return 0; > } > > +unsigned long ftrace_location_range(unsigned long start, unsigned long end) > +{ > + unsigned long loc; > + > + rcu_read_lock(); > + loc = ftrace_location_range_rcu(start, end); > + rcu_read_unlock(); > + return loc; > +}