Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2261902pxm; Fri, 4 Mar 2022 12:34:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHIuO09kOUEoz2ILXXEHnisKciKtIOlifgKgOlV8Yq649A49jIeCv+nBJSb/E68WpBrNjf X-Received: by 2002:a63:89:0:b0:37c:54f9:25b6 with SMTP id 131-20020a630089000000b0037c54f925b6mr158198pga.494.1646426098745; Fri, 04 Mar 2022 12:34:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646426098; cv=none; d=google.com; s=arc-20160816; b=nwlTaC1V9GB8n4HRP9I4zV+sndaZwoBrVFvcCrj4E9DH1pm7SCHCwPgH58xGatC1O6 tqpOzvD1h0UhlMHMSvKNAftRMXqNwqmI/Mbhhug3HZPvsyK6Vcj1twODJqGGZwwaSTwp W/TPb/DrA/KoQYQgKSmhToS+bcAIzqrepT97QSE+8WOmNAU4GpbgppHD1d9uLCOeh2/7 7qLoSiek8Mcz4UpE5AwtIdi7xs0HNkR8qAkYaTUcdh1qzTA5KmYsdcZRVr1TsS+R76hp ggA3uVZGM5V7U79RXzIJucEX/piAyPEDwPtRBsa5C7evBIAsa7zT30UNC1g2j008u4LI Cs9Q== 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=7ZanlT+mtaAIwjGwU2toplmlGf6ZuTIRandFY4G7p54=; b=pSMHsdWCAXJ5RlBqqDe954SELXMnDKT5k2yhucEo5dzgaNBoP9xgCQWv2wYu8tMF50 eopUXAfFm3L93HxbEYSHFeDxNNXkbcAZXGrDQY4RmcU6Iah5qsiu54otBjwdpbteSfJz 75lvDS9ZxFmGZHYI2sdS68qg0YKCQ4RMDe2QEa2v3R48Em0f0fYZBNj9aXw5oTCYQKju bdNB/i4u+TIunYF48zuoXeLhHD/obWlMIjNT1XDaGreXmZEXks2G3oJc7mEIiVrYpeac olGvAAV1cVrpG8B0eC6mr9RwaAe+Ks+JS+eI5q4XyjFHmRJBS48I+x8cCH2qxxP2fTvR VJ8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NbwZ7U0N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x69-20020a638648000000b0037c8fc803b3si3421883pgd.656.2022.03.04.12.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:34:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NbwZ7U0N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A0E88271570; Fri, 4 Mar 2022 11:39:36 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbiCDRb2 (ORCPT + 99 others); Fri, 4 Mar 2022 12:31:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239723AbiCDRbZ (ORCPT ); Fri, 4 Mar 2022 12:31:25 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 864D81BE12F for ; Fri, 4 Mar 2022 09:30:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646415036; 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=7ZanlT+mtaAIwjGwU2toplmlGf6ZuTIRandFY4G7p54=; b=NbwZ7U0NeGXLlFySUT3RipN6s9pKGJ1SBVOF/VjgbsOjbMM1bXof856eHzDzE92KYNxzwG CP4jLNampR0FKKgULVgByLCUVomarXSMCkshn31GDv0lZM3C8mP1yuIA7jh+n5/X1M5N9o UbSxF3SIu5IEzpGiTFhk771ILMnV/FA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-654-yu9FeJp1MuappFvdmDwWdQ-1; Fri, 04 Mar 2022 12:30:30 -0500 X-MC-Unique: yu9FeJp1MuappFvdmDwWdQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F9781854E37; Fri, 4 Mar 2022 17:30:18 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CC6286599; Fri, 4 Mar 2022 17:29:21 +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 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, Benjamin Tissoires , Sean Young Subject: [PATCH bpf-next v2 01/28] bpf: add new is_sys_admin_prog_type() helper Date: Fri, 4 Mar 2022 18:28:25 +0100 Message-Id: <20220304172852.274126-2-benjamin.tissoires@redhat.com> In-Reply-To: <20220304172852.274126-1-benjamin.tissoires@redhat.com> References: <20220304172852.274126-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_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 Signed-off-by: Benjamin Tissoires --- new in v2 --- kernel/bpf/syscall.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index db402ebc5570..cc570891322b 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,17 @@ 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: + case BPF_PROG_TYPE_EXT: /* extends any prog */ + 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 +2262,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