From patchwork Sat Oct 22 07:21:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093317wrr; Sat, 22 Oct 2022 00:56:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4JpxTYiBfdbi7GsXEAQShS0+Ke3O7rYxOSKJAfAh1MDVjrPZo2Kpmm8IxXjevzow1uWstA X-Received: by 2002:a17:902:a508:b0:181:2875:3b09 with SMTP id s8-20020a170902a50800b0018128753b09mr22650248plq.45.1666425409354; Sat, 22 Oct 2022 00:56:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425409; cv=none; d=google.com; s=arc-20160816; b=suB75QGRrVhVulHI/hQ2EWW5dk14a+vP2nZmYUWH6EYm7dip/y7gu38r+EniorAFgd EI2B6bhy26P0TWa7ji6mDIsKGiGs/UeGY3mFxA1NzHX56lFCSQjoE1bI/NoN7PpMXBJB F0BSfKwYFjv4X6GmG/GSZ9CRNnOLI/CxGinlAVBYcqGSFgNAmfBW/LChyb3rBPLqwarc gkBDSO63MMAwmEJgoo03mRIIglzBPJIxOxnZ6/nZq+iqEueUmyp0Kdp3SltE3V7x5qv3 PhgU9RvmmzmlSYt6tX/ff2Khp3QmGrCYDZr2NsaZKRdrkldt3hnWJAc2JdjGvrMdaQGQ zqOQ== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MQzSTSETcp7kHGAbY0+NIIQtNWr2Jk+RL9zuq32GKwQ=; b=T/ZMtDFPp6k8fIuJpDkppdRms7oETuiM3jOK/x0fOL8DvGqxigoK1LrZIqWvI6CV4+ cckFDKdVwwLGeAHlXRIJPO8vH84aXoj6pSvns+faTlvY4QOcbslhaVWBQfcR8r3Cmebw Cp4bMZS5dyIkWW6qicOQvRtYbqCBCTfho2Qz3wgr9cQUxUE/mX9guHt/eUD+dP3l4Rzg IiohbgZAv5g+dS0C8xt62R2E/aO7LbxRJSHvK46c1OVQ9c1JhHEeNxPtiMdzxQlKWrjW d47fnVR8z0xL5rvR9VZXtqNHpt8M6slFTL7oAGs4Xk5A+UGY1pRHraRRaghyB+Et6bk6 2Q8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Qte8nB/3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a8-20020a1709027d8800b0017f914799b4si24892353plm.175.2022.10.22.00.56.37; Sat, 22 Oct 2022 00:56:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Qte8nB/3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232243AbiJVH4M (ORCPT + 99 others); Sat, 22 Oct 2022 03:56:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231795AbiJVHwk (ORCPT ); Sat, 22 Oct 2022 03:52:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 763362C5035; Sat, 22 Oct 2022 00:46:32 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 650F660BAA; Sat, 22 Oct 2022 07:44:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76D55C433D6; Sat, 22 Oct 2022 07:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424643; bh=paWKtYTyYvMynckSb7l/wvrQRez0ic+BTjI/PbHFihA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qte8nB/3jz1qz1zrJvzwWet/4k5Nq7wyJnXVNQ/DV0evldXl1GEtKUmrSmPAgGrnQ cwTYDbeA9k8eAWxkCi1gSOT2jzaNHomBtrcSfXZJYlyyS5YMRVtdmzeaQFaeycbCyo KmTJrUoQdZDwQaICGVsZkkWFMuId+/hMENr5LSKY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hou Tao , Alexei Starovoitov , Martin KaFai Lau , Sasha Levin Subject: [PATCH 5.19 222/717] bpf: Use this_cpu_{inc_return|dec} for prog->active Date: Sat, 22 Oct 2022 09:21:41 +0200 Message-Id: <20221022072454.422004579@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373689708963512?= X-GMAIL-MSGID: =?utf-8?q?1747373689708963512?= From: Hou Tao [ Upstream commit c89e843a11f1075d27684f6b42256213e4592383 ] Both __this_cpu_inc_return() and __this_cpu_dec() are not preemption safe and now migrate_disable() doesn't disable preemption, so the update of prog-active is not atomic and in theory under fully preemptible kernel recurisve prevention may do not work. Fixing by using the preemption-safe and IRQ-safe variants. Fixes: ca06f55b9002 ("bpf: Add per-program recursion prevention mechanism") Signed-off-by: Hou Tao Acked-by: Alexei Starovoitov Link: https://lore.kernel.org/r/20220901061938.3789460-3-houtao@huaweicloud.com Signed-off-by: Martin KaFai Lau Signed-off-by: Sasha Levin --- kernel/bpf/trampoline.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index 93c7675f0c9e..fe4f4d9d043b 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -585,7 +585,7 @@ u64 notrace __bpf_prog_enter(struct bpf_prog *prog, struct bpf_tramp_run_ctx *ru run_ctx->saved_run_ctx = bpf_set_run_ctx(&run_ctx->run_ctx); - if (unlikely(__this_cpu_inc_return(*(prog->active)) != 1)) { + if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) { inc_misses_counter(prog); return 0; } @@ -620,7 +620,7 @@ void notrace __bpf_prog_exit(struct bpf_prog *prog, u64 start, struct bpf_tramp_ bpf_reset_run_ctx(run_ctx->saved_run_ctx); update_prog_stats(prog, start); - __this_cpu_dec(*(prog->active)); + this_cpu_dec(*(prog->active)); migrate_enable(); rcu_read_unlock(); } @@ -631,7 +631,7 @@ u64 notrace __bpf_prog_enter_sleepable(struct bpf_prog *prog, struct bpf_tramp_r migrate_disable(); might_fault(); - if (unlikely(__this_cpu_inc_return(*(prog->active)) != 1)) { + if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) { inc_misses_counter(prog); return 0; } @@ -647,7 +647,7 @@ void notrace __bpf_prog_exit_sleepable(struct bpf_prog *prog, u64 start, bpf_reset_run_ctx(run_ctx->saved_run_ctx); update_prog_stats(prog, start); - __this_cpu_dec(*(prog->active)); + this_cpu_dec(*(prog->active)); migrate_enable(); rcu_read_unlock_trace(); }