Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4487678rwb; Tue, 6 Sep 2022 08:11:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR5pSIVj0HtaenzJFuYbLYryT6tXOfFHXm+8YnExKvYhL3IEmfp+kBE3v3Nz42it93vRbUyf X-Received: by 2002:a63:91ca:0:b0:434:d42e:be26 with SMTP id l193-20020a6391ca000000b00434d42ebe26mr768090pge.329.1662477092353; Tue, 06 Sep 2022 08:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662477092; cv=none; d=google.com; s=arc-20160816; b=fX5IZPZii9OvgwfZ8aHz5aE0res8jID4xSnjTtzkXVTe7rzJ4kwqLI29CKCAz8Zp9P BibggPJq9CPC1pfdyDHwjFMF18rmh4mf1WdUGHdvvUovpthdYI4fThFj1EPgXbwokWI5 Q3MKYzMutQZxD8eIGv90V0nqyFVx2ruieOzgusF4TcBNGKMh4thrDoaZ9qKT1UqxtIIe Uho6Ib51x8QDJk4tWfkVhmpy/AbheBhZYxp0JHBh6LMoe1vzmkDMvQ4uQ0GBSzDX1qZG GoNAMDQTC1ywW2z0t8DNlJMwlq/oXebpCM/3fwrOc1tb9rgXWYyImGkdo49ONBanyOwu nQog== 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=T8++mMuf+ZHheyXkLip6I93YaPhDKU+KwSPwh1GaUt8=; b=WWsdqG/2297OW24EnV1sMxVpV1X0vvtmRZsx4kNXqmFR+kDHopLaCiLfrCSdEtPJWB lS2+ac7WnoIgwajU8Q3KJQhjf8Rx42GLezyCfXgqOKj+t+SnV4ZwA8O+Qxz6hMmpD6rW lK9Qzng11HQ+oBX4TkdlX4w0bvWdMDdep81fzqrwXggcu5r7/LsvOKrIDhZl2sN2E3tL 3viPJYiquXK/eDOrS832YN2E1O070QxDcnuH03Bq3cSFWCmXk33DhhkUBWtVfMaELgmf U1p++kObizgsW+0+lPXbMzysPTfQdb7tBBu+7h7BVUCQ43Q8/iimIE2rMfqoLqmlzvlZ NsZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eyXfILC3; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a056a0021c200b00535fd435cf6si12554106pfj.208.2022.09.06.08.11.19; Tue, 06 Sep 2022 08:11:32 -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=eyXfILC3; 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 S240657AbiIFOCl (ORCPT + 99 others); Tue, 6 Sep 2022 10:02:41 -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 X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 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