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 CDEA5C6FA83 for ; Tue, 6 Sep 2022 14:00:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240585AbiIFOAi (ORCPT ); Tue, 6 Sep 2022 10:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240674AbiIFN6N (ORCPT ); Tue, 6 Sep 2022 09:58:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C4C48274A; Tue, 6 Sep 2022 06:42:44 -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 980FDB81637; Tue, 6 Sep 2022 13:37:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1092C433C1; Tue, 6 Sep 2022 13:37:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471456; bh=EIGJU1CjX7emB/H81IMdaXbPyh4lZ7J3aUh+bT0rHsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pu+pyKV4KlVtxZAodBn0Wp4ghuFFhldMz+rqvqzjVDHbBdrYlBn7mZvz5LvX8sJym I+icKRPtVtPko7U6HReMt3rafWm4p+OOM8Lkr3edJesuLf8k7lAEpZTZ8j5L2+bMV+ WF08xtFYJV8fTSsGx7yEkneXBLXyM3Uyb51Qhh54= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, YiFei Zhu , Daniel Borkmann , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.15 008/107] bpf: Restrict bpf_sys_bpf to CAP_PERFMON Date: Tue, 6 Sep 2022 15:29:49 +0200 Message-Id: <20220906132822.091054233@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132821.713989422@linuxfoundation.org> References: <20220906132821.713989422@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: stable@vger.kernel.org From: YiFei Zhu [ Upstream commit 14b20b784f59bdd95f6f1cfb112c9818bcec4d84 ] The verifier cannot perform sufficient validation of any pointers passed into bpf_attr and treats them as integers rather than pointers. The helper will then read from arbitrary pointers passed into it. Restrict the helper to CAP_PERFMON since the security model in BPF of arbitrary kernel read is CAP_BPF + CAP_PERFMON. Fixes: af2ac3e13e45 ("bpf: Prepare bpf syscall to be used from kernel and user space.") Signed-off-by: YiFei Zhu Signed-off-by: Daniel Borkmann Acked-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20220816205517.682470-1-zhuyifei@google.com Signed-off-by: Sasha Levin --- kernel/bpf/syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 48e02a725563f..99ce46f518893 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -4785,7 +4785,7 @@ syscall_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { switch (func_id) { case BPF_FUNC_sys_bpf: - return &bpf_sys_bpf_proto; + return !perfmon_capable() ? NULL : &bpf_sys_bpf_proto; case BPF_FUNC_btf_find_by_name_kind: return &bpf_btf_find_by_name_kind_proto; case BPF_FUNC_sys_close: -- 2.35.1