Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4737142iob; Sun, 8 May 2022 23:46:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbhCPo0fKNKrDGac7/e3om5H6v7vwM1Lif64rc0JXZm/4in8iLt7ulVDNsl422WQY1GyZo X-Received: by 2002:a17:902:a406:b0:158:260d:1ed2 with SMTP id p6-20020a170902a40600b00158260d1ed2mr14869096plq.49.1652078778250; Sun, 08 May 2022 23:46:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652078778; cv=none; d=google.com; s=arc-20160816; b=WXlbpW3JdVtFzNh2Yqk/C8/VOxABwi/D0nSexg2IujHmSlC6kYXohJtSYLXkLdxKJV UorwBoH4lpSNfCZzDgfEkg1Q5fEdkcfbW8SBp/FcgBXoZRf85/ydIOq4h644yi7zpmaA BiEcqqb4Ndf+FyHKyQ6GNI0cxmerT/WxSt2n0MxhPcvoNUVIuffslfxJ7OE5LMCDsJro sHDACnWEKsmmNluB2PGcNdiPel/DwajBfRdo6AK7RlqxP4rEqo67XrHeU2FOEaZkmU0U sUIkQ3AOUEv28OWWuuQ8y4AzVzoPC4Lkw50FAZ1yuSYvruBIFz83L7AVCDM0ql9HOvCj p/Hg== 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 :user-agent:message-id:date:subject:cc:to:from:dkim-signature; bh=o0q+d5QrRP5BHTQVv50+ejBWcHZx9Dgba9wlu8mqVhM=; b=X0A2UQinq/k3yLAaw3La6PrnBjQpL/wiT21XMi5IgrJURla5OwBah2m3/RBdYk1om3 PaXTdN+02E2tjLcD0TwDFC2txZ560vSNgWmLRb3raPrevW/U9v9Fu5w4kuW+sanZKmM5 uCbRx9xwOmY1bUkwLRUkZlR2q2SG9kQDDIdeLxDUY5pZGOXkwsTzEnzvFBiBVowHncIF dIx1paYljGmhnmg0QOmEzGHujewBcia/YRtk4efQY7TpTfeuojKVYjWNbUoJ73Jw7vX9 z/uwqyo4hDT4bVhGRNA2lE00kZzJs7hOa7016epNBrnxZhmHEf8278NymDbzm3ktg7s7 +xDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UQNMCUEE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id n16-20020a170902f61000b0015e95edda4csi10290791plg.606.2022.05.08.23.46.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:46:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UQNMCUEE; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A0149A88A8; Sun, 8 May 2022 23:40:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1445512AbiEGEuv (ORCPT + 99 others); Sat, 7 May 2022 00:50:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239457AbiEGEus (ORCPT ); Sat, 7 May 2022 00:50:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C3B469CE8; Fri, 6 May 2022 21:46:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 47687B83ABC; Sat, 7 May 2022 04:46:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91B7CC385A6; Sat, 7 May 2022 04:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651898816; bh=nCKZYzPsjKkho5w7h4bpzf8tjClGnfHBkruyaF3rEaU=; h=From:To:Cc:Subject:Date:From; b=UQNMCUEE9Ja6+cJ4Ij5YLK4BK25Gj66eEJ6Idh4yOrzJOGD8jF/SL+efrSzwkrLlr VqJMQbcmPmMthgYZUhiq0eqeeETYMhririXF4YHVUWWhiqErr7zkdA44wkJmHDThQQ b92EAUZ8QbFVt9mEIyyWV3kVul1W5dsztLAd5afOW4o0flO5D39jsE3ImXP+Usq0zu 6Al7vGverSspIHzddJCZJTazcsKZvBwRvPCZg9VPxXqVFS+9Wnrs6qFiPbXwLpVAkn 6rxFF3fpJyQqz9PzGMIVE8Olvb1t6+lIRzrdHJgssWRuNX8smPxBuQOqT3wCoNaK6Q AAHlQ9Xqci0lQ== From: Masami Hiramatsu To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Masami Hiramatsu , Jiri Olsa , Steven Rostedt , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH] rethook: Reject getting a rethook if RCU is not watching Date: Sat, 7 May 2022 13:46:52 +0900 Message-Id: <165189881197.175864.14757002789194211860.stgit@devnote2> X-Mailer: git-send-email 2.25.1 User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the rethook_recycle() will involve the call_rcu() for reclaiming the rethook_instance, the rethook must be set up at the RCU available context (non idle). This rethook_recycle() in the rethook trampoline handler is inevitable, thus the RCU available check must be done before setting the rethook trampoline. This adds a rcu_is_watching() check in the rethook_try_get() so that it will return NULL if it is called when !rcu_is_watching(). Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook") Signed-off-by: Masami Hiramatsu --- kernel/trace/rethook.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c index b56833700d23..c69d82273ce7 100644 --- a/kernel/trace/rethook.c +++ b/kernel/trace/rethook.c @@ -154,6 +154,15 @@ struct rethook_node *rethook_try_get(struct rethook *rh) if (unlikely(!handler)) return NULL; + /* + * This expects the caller will set up a rethook on a function entry. + * When the function returns, the rethook will eventually be reclaimed + * or released in the rethook_recycle() with call_rcu(). + * This means the caller must be run in the RCU-availabe context. + */ + if (unlikely(!rcu_is_watching())) + return NULL; + fn = freelist_try_get(&rh->pool); if (!fn) return NULL;