Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp861347lqo; Wed, 8 May 2024 18:39:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVT+Gh7yyTU19otV7W9oLfjgPOVU86qA/RmU3hrqKa7iSjm9uGaBwsgV26BeJ0ImEs0TizKasqvizQhGQKUvaLZFdHAWLxub2QIx5lcLw== X-Google-Smtp-Source: AGHT+IHR3jpAVvd85my4Oyvlc9jIqR4JmxyDJSzsw443dHysp+dlQdnU4rIGNYIQgVKQ37WPpFjr X-Received: by 2002:a17:906:714a:b0:a59:c944:de4 with SMTP id a640c23a62f3a-a5a115beb08mr96526166b.2.1715218758743; Wed, 08 May 2024 18:39:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715218758; cv=pass; d=google.com; s=arc-20160816; b=PcqwtJ9sX/vImrT0V8F5Rp2e+3H21Pc5ACkedTybq16FKQNGXUb+fkD0ptOe0YZ90D /m7It/DKm62FY7TImSS1efYkNhESIv1NuPO1MSd+eCh2sj/uvIm1pzJRDaMHVOWWubrb XRg6n/esV0y7ZwazaMM3sLm9EzaGE3QyGiFlqD7971NQSrxIyJQjUi5sKF0yfM8uTHZg hFrnPACE+EtDlZuxOl0Q8jWs6lF2k3owz7QwOwgjo4kXC30t0UrB05aJDa2x/EYyFjmX jPnWxA4e2FFZgF5+rH4e6iBKuEYDdYquAprXMjhxbFILDWs9t0ZC64ilVlc0vBmSEhs3 2IkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=/3VFRk+amb9fQS3tWX5wZIbNtZqp8UA4dtjEjgJmoms=; fh=8LYM+fsG36Vo/RmSvlypBdQ5CFx8huUUacHBBOL0kTI=; b=KDLOcTchZOtxm+grJd6pNgGj24nzoAbd3IcAmWuM/PNIuYzJosz369I81Z905C9JQi zChQfbGX5nyPTPdFi3/ToDCcP78xQt/WPdeuB5tK3nOtwnZf7nO5BujCCfIwzoBXQynY oyW8GlOykIq8Z6uOVMgBqkFYxZwiIQn9C2yW6p4xqlQUWRUvgT3U8M5X+uUw+ZskmF83 0DYrzrcZz/3B2tYkZotF/UbZD4JLMUN6+/f0Z7dva9yuGrKlbo5MDfh7nyMBUpJn0KsE JfYddmfBVW0fnQCuMC1pDhLvKMjwIOovt29r5DLovZdXvUR5ZNhGO+dsUIej3Cd0IO/G 6KqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-174019-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17b21a53si21560266b.323.2024.05.08.18.39.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 18:39:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174019-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-174019-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com 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 7B8061F220E9 for ; Thu, 9 May 2024 01:39:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66ED213A869; Thu, 9 May 2024 01:39:13 +0000 (UTC) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 29B9913C806; Thu, 9 May 2024 01:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715218752; cv=none; b=IGeDeIEVOgYzItvyXrI5ZSc/21U4p5bsw8Faf5ty7nYBEhAAxR0WyGamDht8oolBd/wLBcK4ZB8C6IsoXtMliB2O/XJYUd4GMDkaOg8aWsJHxnqe/vg70KL1DeGYq1mAPQ0Pw8CtN2FnnXw/OEuGZnmF85CPsopweqdHT4Q1CKo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715218752; c=relaxed/simple; bh=uV0uxdDdrSHErql95GNjG6bFDTq9DwASFsBPqw/Z8Is=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=hBTrMCguq/WivIA1mxYgo4IDiDQWRGRB7uMV0hk+8mmtifAf/A64AZeimBPukEmLOt9SMGbxAm1pOOJtAj05KScdos4iNom+H14vS2BKeffPIF6zGmsrl0voaXpdqs2288h/t7AbKC8nMZxSuDR2G45nkzU/lceTTFU+lWxLlZY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4VZZN16X0zzvSYj; Thu, 9 May 2024 09:35:45 +0800 (CST) Received: from dggpeml500012.china.huawei.com (unknown [7.185.36.15]) by mail.maildlp.com (Postfix) with ESMTPS id A97FD180A9F; Thu, 9 May 2024 09:39:06 +0800 (CST) Received: from [10.67.111.172] (10.67.111.172) by dggpeml500012.china.huawei.com (7.185.36.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 9 May 2024 09:39:06 +0800 Message-ID: Date: Thu, 9 May 2024 09:39:06 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v3] ftrace: Fix possible use-after-free issue in ftrace_location() Content-Language: en-US To: Steven Rostedt CC: , , , , , References: <20240401125543.1282845-1-zhengyejian1@huawei.com> <20240417032830.1764690-1-zhengyejian1@huawei.com> <20240502170743.15a5ff1c@gandalf.local.home> From: Zheng Yejian In-Reply-To: <20240502170743.15a5ff1c@gandalf.local.home> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml500012.china.huawei.com (7.185.36.15) On 2024/5/3 05:07, Steven Rostedt wrote: > 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. I'll do it in v4. > > 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? Yes, the only-one-user function looks ugly. At first thought that ftrace_location_range() needs to a lock, I just do like that, no specital reason. > > 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; >> +} >