Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3989676pxb; Mon, 4 Oct 2021 14:34:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9sUHwPSyKB0ScxG8Z0P3O73GSjTZwBRujkuOuULBEAKzblAqFhztLDFANwFv79phLI428 X-Received: by 2002:a05:6402:16d8:: with SMTP id r24mr20678149edx.47.1633383286238; Mon, 04 Oct 2021 14:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633383286; cv=none; d=google.com; s=arc-20160816; b=uPE7+EJ+3LFErEnjy1jent3kp2Hs1nBA0Ym/wVP2M5m9nYfMUYiiVuxr6Bho5si5V8 Hp46K2IgppdA7tIE16kna1fJdAWWQxTCRgzx69UzdpDKv2P1N65pQJjc5VEAAlBhyAh0 ySa21lBSMu+W0yPxvCDRbZ17nJw1XYLhh3tjl1Xfw0KHFhZOb3j7Mzf4qU1cd7UYc9aN 2+qcRHhpAu1B3DZX0cdkDpQ7yYUxmx9Gno1qtxRWjtKwCgfzWnIrgbIYeo+AJDaf1Pk7 PokKfMivahYYglf+b9uD4bG2LEoV7j1Uo8pHST+dzJB91xoXQhCNWeOxhhiZ9M4ZGw2E cD7g== 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=cVQAVsxndCrtUBgjsEoP3z7xDRK9mr3nsKTOA8yAfVs=; b=K7bz1KVvnsmM7zyvwjAooidbqpy+/K+sSjJAwj1zChQQf6mjJ72+7nUGDMKVpgYdDw UtFmWDrwEURGKXSOnwIAEZki0dflaVjQldB61lrBQ1WYYPL0yOAgpvJ7cxwPjdLlHtun AGndUlLedZ0jHEsxLHIj/9GyT0/IaQba3BYzKfghSAWmplloi1E0wO/Q1+cW/jZteISU Sk7pN6hTqZZgvOHuYs0+XLh0q0wWKCHa7zA5eRzunz+tnHXbPRUwqbYJc4q0ikAKfdWF RP7gtSwq9L1qFGk3RyWlG31TMxoGVCDNSEd5k0nbhfbghrcvQPRk6UQApGf5+2MtR4H8 W/Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HVV2Fczh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si11696edb.85.2021.10.04.14.34.22; Mon, 04 Oct 2021 14:34:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HVV2Fczh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S238042AbhJDNjt (ORCPT + 99 others); Mon, 4 Oct 2021 09:39:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:51850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237873AbhJDNhE (ORCPT ); Mon, 4 Oct 2021 09:37:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7AD256120F; Mon, 4 Oct 2021 13:16:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353402; bh=a6ZFMMWe7gwV5i/FMaeYi4FvW1cQbUUCRxS8J9SJy34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HVV2FczhEg1G3qh+y3+v7CJHyhCiXbQyW+yPcRvl6FW7Q9Vux9C0/hRQhntJWYOYA YfGz7PRhZV2EjJuRT1n52WS+RErQS+SuEi9IB1ackZ3Wu/Yp+1DchMWz9moUcRjd8E GM6frytai0Z6CdLNZ2KCb60Q+8tUz9VdbA8ZH8GE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenz Bauer , Daniel Borkmann , Sasha Levin Subject: [PATCH 5.14 114/172] bpf: Exempt CAP_BPF from checks against bpf_jit_limit Date: Mon, 4 Oct 2021 14:52:44 +0200 Message-Id: <20211004125048.661492042@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 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: Lorenz Bauer [ Upstream commit 8a98ae12fbefdb583a7696de719a1d57e5e940a2 ] When introducing CAP_BPF, bpf_jit_charge_modmem() was not changed to treat programs with CAP_BPF as privileged for the purpose of JIT memory allocation. This means that a program without CAP_BPF can block a program with CAP_BPF from loading a program. Fix this by checking bpf_capable() in bpf_jit_charge_modmem(). Fixes: 2c78ee898d8f ("bpf: Implement CAP_BPF") Signed-off-by: Lorenz Bauer Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20210922111153.19843-1-lmb@cloudflare.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 0a28a8095d3e..c019611fbc8f 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -827,7 +827,7 @@ int bpf_jit_charge_modmem(u32 pages) { if (atomic_long_add_return(pages, &bpf_jit_current) > (bpf_jit_limit >> PAGE_SHIFT)) { - if (!capable(CAP_SYS_ADMIN)) { + if (!bpf_capable()) { atomic_long_sub(pages, &bpf_jit_current); return -EPERM; } -- 2.33.0