From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 013BAECAAD5 for ; Tue, 6 Sep 2022 14:02:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240740AbiIFOCn (ORCPT ); Tue, 6 Sep 2022 10:02:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240970AbiIFN7O (ORCPT ); Tue, 6 Sep 2022 09:59:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7022832DC; Tue, 6 Sep 2022 06:43:17 -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 87923B818DF; Tue, 6 Sep 2022 13:42:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB0EEC433D6; Tue, 6 Sep 2022 13:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471730; bh=ZBs+Pnl56LuP62f2/5Od+2i6/C2P4iDjFoXFcwde8iQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eyXfILC33i17tbtc6cDK6sy2SueOvyiPV1fnmaQWUeVyjpBGi2OBKkXjxX/bFCr6t /tfdwSrvHiqK974cZYdn3Ou9HWBKQG+EKxHxiODTnmYHHsfzjRGPycBtRpLWqyB8N6 +PvPL9Rb5bmJJYCrE6sp43q27qaZdm55WlL57iN8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kuniyuki Iwashima , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.19 019/155] bpf: Fix a data-race around bpf_jit_limit. Date: Tue, 6 Sep 2022 15:29:27 +0200 Message-Id: <20220906132830.235883991@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kuniyuki Iwashima [ Upstream commit 0947ae1121083d363d522ff7518ee72b55bd8d29 ] While reading bpf_jit_limit, it can be changed concurrently via sysctl, WRITE_ONCE() in __do_proc_doulongvec_minmax(). The size of bpf_jit_limit is long, so we need to add a paired READ_ONCE() to avoid load-tearing. Fixes: ede95a63b5e8 ("bpf: add bpf_jit_limit knob to restrict unpriv allocations") Signed-off-by: Kuniyuki Iwashima Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20220823215804.2177-1-kuniyu@amazon.com Signed-off-by: Sasha Levin --- kernel/bpf/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index fb6bd57228a84..cf44ff50b1f23 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1005,7 +1005,7 @@ pure_initcall(bpf_jit_charge_init); int bpf_jit_charge_modmem(u32 size) { - if (atomic_long_add_return(size, &bpf_jit_current) > bpf_jit_limit) { + if (atomic_long_add_return(size, &bpf_jit_current) > READ_ONCE(bpf_jit_limit)) { if (!bpf_capable()) { atomic_long_sub(size, &bpf_jit_current); return -EPERM; -- 2.35.1