Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp160179lqs; Thu, 13 Jun 2024 06:53:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUvV3u4j/fYUiAzvtPs/OGK9+jYrBtk61DbtHGY9Vs3c3INF99CiCE1CeIqakEzMG0Yv6ZDfyVRBcXHOIbBkZ469CnZTbQ9fKPyyUyhqw== X-Google-Smtp-Source: AGHT+IFKX3zVwMgM/kp2GqjpxBUfKOR4tJKDng9KO9TBD9RO8zPKUdLUwKUIfCvAISrDnHryyoU5 X-Received: by 2002:a05:620a:2688:b0:795:59ca:5066 with SMTP id af79cd13be357-797f60f6ebfmr526567985a.53.1718286835270; Thu, 13 Jun 2024 06:53:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718286835; cv=pass; d=google.com; s=arc-20160816; b=YHs/ndK8sam7VN5FYRob01ORb2xzo6IUcazn6RfFW8gjndkt5LO+DkwIuoMb1IRHSt 1DGlQycRJzG8diOrqqpem8/CbHJCHgUmfbziP57nQR2mMCg7GT76ZO8avg8XHUeWyve3 nJ/AkOSM2T6Is1kTAV13/IExnHHRdfYntsZ0NVRQa8on3oAwW6eA9W+brihLXfJvwivI 9A5Pepg5QWt6bFFPxoPaGLsfyMsyZeaWvWGYpEZf76r/cUoikNYI4FS+1wLfnK2bqITK B65R9W62ppE+AYgVrnX/I0lI3yNIhKCD8YgLJfRKRW+MIhFfvPOEiXkCKYmVjImlF9wK RtAw== 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:message-id:subject:cc:to:from :date; bh=PObfmbUaNImYzSvt+pw9cRGQISco4KyDQN/ntB+cvk0=; fh=S7GbJL1QuPhiYziEdRxXrjJLdlYH5o2JvyRVzQsMD3I=; b=wbh6C0J4HE9Iw+jpet+Yyfv9j1vYYfUYnmXwwJP+uA/yMnJARvt2dEuq+c5nymGp0U 5kNwhi/2DgKvqEb20jUipMyL07F3lDrI9yGLKjblIMfbZcepBHPMsz6op16A8czOCMXa 8erbQWu6w8SAKt6YD0LpHkr/cY7bWUBwP09/aK29csGaolbHO++CvfpakN07pK14D1ku KsQcmjk8UTjEyk/xfARns9srF10bYOvhqe/dk5KAMyorj9bxv6uRMSd3/5YdurWJqGqp xFxu0LIl8qSfXvdLw/Jld/MKsioAk6of5gjjdLI6Tu70kwguT6+7PZ+Fmadib+PfDEoB yTsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-213379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213379-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-798abd23418si151282585a.479.2024.06.13.06.53.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 06:53:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-213379-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213379-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6EC1E1C2490A for ; Thu, 13 Jun 2024 13:53:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E31E81465BA; Thu, 13 Jun 2024 13:52:27 +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 61952161; Thu, 13 Jun 2024 13:52:26 +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=1718286747; cv=none; b=F+Uf0/1lFu0UzgH+kC3p31tGnhMFP+K+CyGEgxnR/0/y86MlUde8hWzSXt2DjFM3Ns1IBHkzNGWennR7nTMl83jHWGyrZ6gzFQZcPpZmDH0WaeiqkpfHmmHIAdaUrPS33ZKGB9uyJVAaoxma8lZJ2WUv8J5rjBHgS8+8lmtSlNs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718286747; c=relaxed/simple; bh=9dHSMOKqQ7eHeWqhAwwz31AHL3NqJp2gEZYZPH2vk4Y=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=Fxrgx+g2+S6WxZSgSFf4hC22+pF+WIcQgxl4xsQDBI2QPWBZ2BJ3U64LXC9HwJYsKVj0ZzeW07NFmLowWf2YjJZ5s3iNzT+N9+A6s1EavqF0ZeHf+BaBJ6Ug+s+YCMaKtVvflVPPCwZAg2gF00PFgmFKlA7z84iwSjb7D0Jbrlk= 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 293EEC2BBFC; Thu, 13 Jun 2024 13:52:25 +0000 (UTC) Date: Thu, 13 Jun 2024 09:52:23 -0400 From: Steven Rostedt To: LKML , Linux trace kernel Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Naresh Kamboju Subject: [PATCH] function_graph: Add READ_ONCE() when accessing fgraph_array[] Message-ID: <20240613095223.1f07e3a4@rorschach.local.home> X-Mailer: Claws Mail 3.17.8 (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 From: "Steven Rostedt (Google)" In function_graph_enter() there's a loop that looks at fgraph_array[] elements which are fgraph_ops. It first tests if it is a fgraph_stub op, and if so skips it, as that's just there as a place holder. Then it checks the fgraph_ops filters to see if the ops wants to trace the current function. But if the compiler reloads the fgraph_array[] after the check against fgraph_stub, it could race with the fgraph_array[] being updated with the fgraph_stub. That would cause the stub to be processed. But the stub has a null "func_hash" field which will cause a NULL pointer dereference. Add a READ_ONCE() so that the gops that is compared against the fgraph_stub is also the gops that is processed later. Link: https://lore.kernel.org/all/CA+G9fYsSVJQZH=nM=1cjTc94PgSnMF9y65BnOv6XSoCG_b6wmw@mail.gmail.com/ Fixes: cc60ee813b503 ("function_graph: Use static_call and branch to optimize entry function") Reported-by: Naresh Kamboju Signed-off-by: Steven Rostedt (Google) --- kernel/trace/fgraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 8317d1a7f43a..fc205ad167a9 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -641,7 +641,7 @@ int function_graph_enter(unsigned long ret, unsigned long func, { for_each_set_bit(i, &fgraph_array_bitmask, sizeof(fgraph_array_bitmask) * BITS_PER_BYTE) { - struct fgraph_ops *gops = fgraph_array[i]; + struct fgraph_ops *gops = READ_ONCE(fgraph_array[i]); int save_curr_ret_stack; if (gops == &fgraph_stub) -- 2.43.0