Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp230165pxp; Sat, 19 Mar 2022 00:30:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGrnAoXNB5tr71eLT/BGhGAkNZGHC66YGMQXTLyhYxhtYa67Og1u5OJJbazCyla2BiKuwO X-Received: by 2002:a17:906:a152:b0:6cd:3098:18c9 with SMTP id bu18-20020a170906a15200b006cd309818c9mr12535404ejb.422.1647675019027; Sat, 19 Mar 2022 00:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647675019; cv=none; d=google.com; s=arc-20160816; b=B4T18HoZk61YKcPTjvbIQwzqJ6aVa9T3EQr4uPsDy6t6RF9MvDRG1WEvCzVp+A29Yg G35GzVPFqhSABV/AftXdyDqfOcYoQdJnLhgH2LyabxXDxDfWWDGfC66b198BDGJAnGFR LQBs5dI1kIPmn7cViAOQ66d46XtDgkmEnJrQPBjlEMxmcwrgJiwWb3AzGesltOEXxHrn CgUUhJrTReRwgHWKNg1VVDoALv4tNihOTP97OvIJMtyoMee6Tiz7ko3zCe2fZIpyiYqk +mjlzmChDq/LjvoxRrleImoLHQVFQLAx6JMZGBK2FIgNakZNy/sLYjUaTd+c4VIa1YKv Zzrw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xDf7SF2Fra40bZaEdvr7u9jw/RZ02CEurbENm/arAE4=; b=EuguPGXl8BuEtLUpHpcvOjzEklDS3hQk3RXRd/n9ooN0mOv2R1JW0Un69kB+u2JO03 C5X8wLJjvtxBObYUdYqTJqzzVtNfXS9g2GyOdIVqGupausNcowNOxvfI10I60GojmVpA Mcsc6sTNEJPSJ7F31d6CX8i7OTfZAtL3ZGs+ch+9cSubx5L5LefRRxAs3FohcAj50YjJ Z7qqtpqb2gwUI0bUPGISvf5pMVwqYaSRJ8I9wnF3a//BXJUR7SiOXrY7N2LemvizCTa6 YVMpZOQ7a2sqyvGqFXe/wm1C6are5SB9SNn0v9YLYuy3v0GYOCKQp7tagmlzlfPuEhhL z+mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=M5fuQGoX; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l18-20020a170907915200b006df76385e7bsi2567449ejs.795.2022.03.19.00.29.53; Sat, 19 Mar 2022 00:30:19 -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=@redhat.com header.s=mimecast20190719 header.b=M5fuQGoX; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238709AbiCRQR2 (ORCPT + 99 others); Fri, 18 Mar 2022 12:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238708AbiCRQR0 (ORCPT ); Fri, 18 Mar 2022 12:17:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E91E139AF4 for ; Fri, 18 Mar 2022 09:16:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647620166; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xDf7SF2Fra40bZaEdvr7u9jw/RZ02CEurbENm/arAE4=; b=M5fuQGoX50zm2Np+INw9PGr6EP3NIG/Od3pTUzuGJijJHfxwoiO32ccBVwHQH17FCFa4gC 4abMwjIargH1Lu14przdB2fAfeZB1oPVv827WaaYYWqliA4lgA+ZiPYNBYkAiKzD+pX8Bn GKiuDl69ODIiQckYMyf7Yvr4r5pVlrM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-uvKNlS3pNXaCQvW5KvtJmw-1; Fri, 18 Mar 2022 12:16:03 -0400 X-MC-Unique: uvKNlS3pNXaCQvW5KvtJmw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2D1F803524; Fri, 18 Mar 2022 16:16:01 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.192.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B90A33250; Fri, 18 Mar 2022 16:15:44 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , Dave Marchevsky , Joe Stringer , Jonathan Corbet Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Benjamin Tissoires , Sean Young Subject: [PATCH bpf-next v3 01/17] bpf: add new is_sys_admin_prog_type() helper Date: Fri, 18 Mar 2022 17:15:12 +0100 Message-Id: <20220318161528.1531164-2-benjamin.tissoires@redhat.com> In-Reply-To: <20220318161528.1531164-1-benjamin.tissoires@redhat.com> References: <20220318161528.1531164-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 LIRC_MODE2 does not really need net_admin capability, but only sys_admin. Extract a new helper for it, it will be also used for the HID bpf implementation. Cc: Sean Young Acked-by: Sean Young Signed-off-by: Benjamin Tissoires --- changes in v3: - dropped BPF_PROG_TYPE_EXT from the new helper new in v2 --- kernel/bpf/syscall.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 9beb585be5a6..b88688264ad0 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2165,7 +2165,6 @@ static bool is_net_admin_prog_type(enum bpf_prog_type prog_type) case BPF_PROG_TYPE_LWT_SEG6LOCAL: case BPF_PROG_TYPE_SK_SKB: case BPF_PROG_TYPE_SK_MSG: - case BPF_PROG_TYPE_LIRC_MODE2: case BPF_PROG_TYPE_FLOW_DISSECTOR: case BPF_PROG_TYPE_CGROUP_DEVICE: case BPF_PROG_TYPE_CGROUP_SOCK: @@ -2202,6 +2201,16 @@ static bool is_perfmon_prog_type(enum bpf_prog_type prog_type) } } +static bool is_sys_admin_prog_type(enum bpf_prog_type prog_type) +{ + switch (prog_type) { + case BPF_PROG_TYPE_LIRC_MODE2: + return true; + default: + return false; + } +} + /* last field in 'union bpf_attr' used by this command */ #define BPF_PROG_LOAD_LAST_FIELD core_relo_rec_size @@ -2252,6 +2261,8 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr) return -EPERM; if (is_perfmon_prog_type(type) && !perfmon_capable()) return -EPERM; + if (is_sys_admin_prog_type(type) && !capable(CAP_SYS_ADMIN)) + return -EPERM; /* attach_prog_fd/attach_btf_obj_fd can specify fd of either bpf_prog * or btf, we need to check which one it is -- 2.35.1