From patchwork Mon May 2 16:00:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 12834342 X-Patchwork-Delegate: kuba@kernel.org 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 C5C93C4321E for ; Mon, 2 May 2022 16:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386098AbiEBQEX (ORCPT ); Mon, 2 May 2022 12:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386076AbiEBQEU (ORCPT ); Mon, 2 May 2022 12:04:20 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24F0CBC2B; Mon, 2 May 2022 09:00:51 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id d6so17121294ede.8; Mon, 02 May 2022 09:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aLDcUxz3GuWsYBElhW2059fIPwppem/EwWmuSm4Ac4s=; b=p2mMHYdm4s0Fe8eLp8ERpUnJyX4PhGrwmqIwslSk6X+INW0IxkvEzoXFPk5VwYyO1a xgug13nZSLsUz2buOHh61+6dEuIB0yNvD1GJRLUTd4rXVHTtZ2bQm7uI52hbmW9lz92I G3g70LDEbT3ChfGiaqyV0ueg72L/6JiMzGNWSua1CDj2q46MAD5Vo3Qj0FjZacUxjx+L irnzdPDPT3QjIzAMCxMVVPmNAZqGsF8AJh9T3H21jyPG8BZSlEorhoD078aLr8QEPsxY ehrVFar8Jdye0i/es4zJWKuaEZK/vAsj/r9ha9j8p+B4ewbP19nc3pcIs2Fu0m3lZW9I tlKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aLDcUxz3GuWsYBElhW2059fIPwppem/EwWmuSm4Ac4s=; b=CVFopP47hjifR1DTvxq6Et+N0UUQPiC4lVRWArAB6uYFE5ioriDSnI5WqSLuo6Ub4G IGc+ENkNDzXqVgKQfpJfxjw2qZ53TYLZiyocarVTmq0UGbIUtxz6CcLPl9o/FY8sxaKk cM2qVxAp9VszFT3UpTukwf1ARMVQfiWh6st3dT3hNKYEdMM8IRweOoEFdZRUSwKXkQAn essgGfp6WPJgESYzUbgzZ5ajCp9gJN5HrTUeS9UJP6IX4574gidbbrIjvIjiN+Xxwqp8 AoS9ysJRVEhou112JuzbCKJ4INnDT/m9ExsaT+d1u/Dpy6fYD3J22oVMKK57hsxrEnF0 H8jg== X-Gm-Message-State: AOAM531W3o8lzkt1YtnB3eAlxzJy0lhx/vQvP3y01z6CS0JuvSMVCgyp 3GVsdF/u4HfHEkKIoyQ1l/e9p1SZlfZsUQ== X-Google-Smtp-Source: ABdhPJxEIZ3VG0JCxGGF6OC6lyuVM4utpAI+bDEKxf+HczJGz8fO+DWFU6VtPAlp6gvFM43q022t0A== X-Received: by 2002:a05:6402:5107:b0:427:ded9:9234 with SMTP id m7-20020a056402510700b00427ded99234mr410981edd.275.1651507249567; Mon, 02 May 2022 09:00:49 -0700 (PDT) Received: from debianHome.localdomain (dynamic-077-001-135-067.77.1.pool.telefonica.de. [77.1.135.67]) by smtp.gmail.com with ESMTPSA id h18-20020a1709070b1200b006f3ef214dd3sm3689996ejl.57.2022.05.02.09.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:00:49 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Hans Verkuil , Mauro Carvalho Chehab , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Stefan Haberland , Jan Hoeppner , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Serge Hallyn , Arnd Bergmann , Zhen Lei , Ondrej Zary , David Yang , Laurent Pinchart , Colin Ian King , Yang Guang , Julia Lawall , Greg Kroah-Hartman , Jiri Slaby , Du Cheng , Sebastian Andrzej Siewior , Pavel Skripkin , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-s390@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v2 4/8] drivers: use new capable_or functionality Date: Mon, 2 May 2022 18:00:25 +0200 Message-Id: <20220502160030.131168-3-cgzones@googlemail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220502160030.131168-1-cgzones@googlemail.com> References: <20220217145003.78982-2-cgzones@googlemail.com> <20220502160030.131168-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use the new added capable_or function in appropriate cases, where a task is required to have any of two capabilities. Reorder CAP_SYS_ADMIN last. Signed-off-by: Christian Göttsche Reviewed-by: Jiri Slaby Acked-by: Hans Verkuil --- drivers/media/common/saa7146/saa7146_video.c | 2 +- drivers/media/pci/bt8xx/bttv-driver.c | 3 +-- drivers/media/pci/saa7134/saa7134-video.c | 3 +-- drivers/media/platform/nxp/fsl-viu.c | 2 +- drivers/media/test-drivers/vivid/vivid-vid-cap.c | 2 +- drivers/net/caif/caif_serial.c | 2 +- drivers/s390/block/dasd_eckd.c | 2 +- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/media/common/saa7146/saa7146_video.c b/drivers/media/common/saa7146/saa7146_video.c index 66215d9106a4..5eabc2e77cc2 100644 --- a/drivers/media/common/saa7146/saa7146_video.c +++ b/drivers/media/common/saa7146/saa7146_video.c @@ -470,7 +470,7 @@ static int vidioc_s_fbuf(struct file *file, void *fh, const struct v4l2_framebuf DEB_EE("VIDIOC_S_FBUF\n"); - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) + if (!capable_or(CAP_SYS_RAWIO, CAP_SYS_ADMIN)) return -EPERM; /* check args */ diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c index 5ca3d0cc653a..4143f380d44d 100644 --- a/drivers/media/pci/bt8xx/bttv-driver.c +++ b/drivers/media/pci/bt8xx/bttv-driver.c @@ -2569,8 +2569,7 @@ static int bttv_s_fbuf(struct file *file, void *f, const struct bttv_format *fmt; int retval; - if (!capable(CAP_SYS_ADMIN) && - !capable(CAP_SYS_RAWIO)) + if (!capable_or(CAP_SYS_RAWIO, CAP_SYS_ADMIN)) return -EPERM; /* check args */ diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c index 48543ad3d595..684208ebfdbd 100644 --- a/drivers/media/pci/saa7134/saa7134-video.c +++ b/drivers/media/pci/saa7134/saa7134-video.c @@ -1798,8 +1798,7 @@ static int saa7134_s_fbuf(struct file *file, void *f, struct saa7134_dev *dev = video_drvdata(file); struct saa7134_format *fmt; - if (!capable(CAP_SYS_ADMIN) && - !capable(CAP_SYS_RAWIO)) + if (!capable_or(CAP_SYS_RAWIO, CAP_SYS_ADMIN)) return -EPERM; /* check args */ diff --git a/drivers/media/platform/nxp/fsl-viu.c b/drivers/media/platform/nxp/fsl-viu.c index afc96f6db2a1..c5ed4c4a1587 100644 --- a/drivers/media/platform/nxp/fsl-viu.c +++ b/drivers/media/platform/nxp/fsl-viu.c @@ -803,7 +803,7 @@ static int vidioc_s_fbuf(struct file *file, void *priv, const struct v4l2_frameb const struct v4l2_framebuffer *fb = arg; struct viu_fmt *fmt; - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) + if (!capable_or(CAP_SYS_RAWIO, CAP_SYS_ADMIN)) return -EPERM; /* check args */ diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c index b9caa4b26209..a0cfcf6c22c4 100644 --- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c @@ -1253,7 +1253,7 @@ int vivid_vid_cap_s_fbuf(struct file *file, void *fh, if (dev->multiplanar) return -ENOTTY; - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) + if (!capable_or(CAP_SYS_RAWIO, CAP_SYS_ADMIN)) return -EPERM; if (dev->overlay_cap_owner) diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c index 688075859ae4..f17b618d8858 100644 --- a/drivers/net/caif/caif_serial.c +++ b/drivers/net/caif/caif_serial.c @@ -326,7 +326,7 @@ static int ldisc_open(struct tty_struct *tty) /* No write no play */ if (tty->ops->write == NULL) return -EOPNOTSUPP; - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_TTY_CONFIG)) + if (!capable_or(CAP_SYS_TTY_CONFIG, CAP_SYS_ADMIN)) return -EPERM; /* release devices to avoid name collision */ diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index 8410a25a65c1..9b5d22dd3e7b 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c @@ -5319,7 +5319,7 @@ static int dasd_symm_io(struct dasd_device *device, void __user *argp) char psf0, psf1; int rc; - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO)) + if (!capable_or(CAP_SYS_RAWIO, CAP_SYS_ADMIN)) return -EACCES; psf0 = psf1 = 0; From patchwork Mon May 2 16:00:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 12834353 X-Patchwork-Delegate: bpf@iogearbox.net 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 36E27C433F5 for ; Mon, 2 May 2022 16:01:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382073AbiEBQEx (ORCPT ); Mon, 2 May 2022 12:04:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386150AbiEBQEf (ORCPT ); Mon, 2 May 2022 12:04:35 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77A7FBCBA; Mon, 2 May 2022 09:00:55 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id a1so17137924edt.3; Mon, 02 May 2022 09:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N3AME3IcPE8G01jSuTBFGfb2u7+rTRdyuYIo50HVTEg=; b=BgtDFtCxqx/FN6/+BjsXXaKHaLn+ihBUfE5b+bIVc+wk821dSW3bFKNEVB7Q6ypQ5v D242HfeafW05VEfKAo9l+Ijc5DyyfjEsZOarGM/2zSvIJB9EruKM/plp38cwhHcgJ0WO k9SZWJE4wn6AuFK92SkXbDNi9OHtz4DKDcqmNzU8tSM94UgbJiGsn3nBFCvw/Sdu/DBS Snr1GOkFl5FtN8t04fe/O5sF6tUC/9+e2/2QX/LXzWuoP0rHnDAysSAydmaNv1wVFTOu WFwhuJUvHxBSlT0VgQRxRjE41n/xVjw1/LuuvYsnXON3Kh7iGQmvA2RtV6UbVM003aYX 7EAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N3AME3IcPE8G01jSuTBFGfb2u7+rTRdyuYIo50HVTEg=; b=4ult8OEWfth1odpgUsNNDZynmlQSqtqtQhykxI59gre/g03/qFd+3whHFC4v4qWypP nmKZwaDQ/WnDmHuInKWuRQaAM46t2RvIfoKeF53TJocYhLP6jJGV2UTlDx4WwvbR0bvL 6UrP+5Y3mp8IXDqyKKF2l9Ca3Uk154A6D/+8FOqKEkOYhY+jZQlN06cgUZd9kdkhr6Nf GilsU/Sn9VufZP9wgoOQvzarkyRAJcPY2tCS8bGnlaFWsOad4wAm0HYwtjw3/UuTwBmV QqD6YcCcA+RJw35N10ZiSMlH5q5u1FVaBQluDv/CSZ4P9H7kc9dJ8+8In6LfKo58WLrt RDHg== X-Gm-Message-State: AOAM530TMGUNqLcUePAPGA03Nc6dWpSVeZ2CWzjUKUEn10NxMX8Fa5V8 CTkZZyaKDbAKrooyr/mh0CrN7CSeopmV1w== X-Google-Smtp-Source: ABdhPJznJdmRHvGijkQSObAClombdDNVzKY2UjTJqgKqhfMTLfZKvR9cH4mQxnXdWmlxHCAxcsSCLA== X-Received: by 2002:a05:6402:10d5:b0:408:f881:f0f3 with SMTP id p21-20020a05640210d500b00408f881f0f3mr13971727edu.112.1651507253898; Mon, 02 May 2022 09:00:53 -0700 (PDT) Received: from debianHome.localdomain (dynamic-077-001-135-067.77.1.pool.telefonica.de. [77.1.135.67]) by smtp.gmail.com with ESMTPSA id h18-20020a1709070b1200b006f3ef214dd3sm3689996ejl.57.2022.05.02.09.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:00:53 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Serge Hallyn , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH v2 7/8] kernel/bpf: use new capable_or functionality Date: Mon, 2 May 2022 18:00:28 +0200 Message-Id: <20220502160030.131168-6-cgzones@googlemail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220502160030.131168-1-cgzones@googlemail.com> References: <20220217145003.78982-2-cgzones@googlemail.com> <20220502160030.131168-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Use the new added capable_or function in appropriate cases, where a task is required to have any of two capabilities. Signed-off-by: Christian Göttsche --- 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 cdaa1152436a..95a2cf3e78c9 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2249,7 +2249,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr) !bpf_capable()) return -EPERM; - if (is_net_admin_prog_type(type) && !capable(CAP_NET_ADMIN) && !capable(CAP_SYS_ADMIN)) + if (is_net_admin_prog_type(type) && !capable_or(CAP_NET_ADMIN, CAP_SYS_ADMIN)) return -EPERM; if (is_perfmon_prog_type(type) && !perfmon_capable()) return -EPERM; From patchwork Mon May 2 16:00:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 12834354 X-Patchwork-Delegate: kuba@kernel.org 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 B4E4DC433FE for ; Mon, 2 May 2022 16:01:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386181AbiEBQFH (ORCPT ); Mon, 2 May 2022 12:05:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386090AbiEBQEq (ORCPT ); Mon, 2 May 2022 12:04:46 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9995BF54; Mon, 2 May 2022 09:00:57 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id m20so28560189ejj.10; Mon, 02 May 2022 09:00:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KuyoIlIApfDNylQxsxLqOG93Y5qx/DVrf9MJXzcFL/U=; b=R5Iy5psjxqH2GgT/e1iENDAc3xqCefkZjoaoEk5r8+zg/n+AIDN7kFsruknjg8dNd7 0YD9y9lJrAxCQSg13mYoQiLlXNH5kydADxDPCa6b1TzxfQejVlmocpZ1LXy0xheAgDdt h/6ssW5w7KoqOCo3GN7WQL1p6NgsHNvjC0jH7gEJnt3M7e8OLaONhh7ygsoC90kkj4St nonuabwm8EqCyk3PPsYPl4m4eRcK/fXJrCA6SQjRDR9U+1GFEvbk3/YvRwQXQ1trZa0b UBo0LaBxRkD4HqkJv3WODq1k0docbQy8SA712vY30qc+8faOA5UkaCQJQot7SL8uouNh lksg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KuyoIlIApfDNylQxsxLqOG93Y5qx/DVrf9MJXzcFL/U=; b=b3maeRGmrki4RIhvUFL0aiQa+lNVQWCvC1GqOiDn5CLIizZwwm9HN/dCVN4bfalFgx cWEFpx3rnXWkLdToPEpRxJX85kfUFW68eU9slQXOkzqHcldBTnrjSvVcwG5Usx1nhplU fcq+oowODSloTZR4bJ5A63XrV0UGxKdXzzyhlXI3ZM/PfQqjQjW1xwt6QyuZBhI4xcVZ MKDnF+sH8A/16PS6I7x6X/ggpTIa+CqU3BEZ3cy4DrE26Gj4C6q2ffHsFbKBJnuQWe2L JqPsTDRYGUFqXpHXbnJZxEBpXdIiL0FXnLgtv7Hc7Ge/hezkcNr5WLRwpdDleB85GeEv JDhw== X-Gm-Message-State: AOAM530hSXtS6G4k4QbLEc0zRrPzcFHGpS7CCTbGf8t1az5dkHX+H6h2 yTEAEvsVEhPMrdndjYt2o9vo6y/35QfYeA== X-Google-Smtp-Source: ABdhPJzGK2405DY2mEONZyM9fQQIz5NdAobznRL20qUOJnFfJuhFvLS8SItKXwNNyb8umG6nNMCSng== X-Received: by 2002:a17:906:9b87:b0:6f3:a51e:80c9 with SMTP id dd7-20020a1709069b8700b006f3a51e80c9mr12127785ejc.362.1651507256303; Mon, 02 May 2022 09:00:56 -0700 (PDT) Received: from debianHome.localdomain (dynamic-077-001-135-067.77.1.pool.telefonica.de. [77.1.135.67]) by smtp.gmail.com with ESMTPSA id h18-20020a1709070b1200b006f3ef214dd3sm3689996ejl.57.2022.05.02.09.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 09:00:55 -0700 (PDT) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Serge Hallyn , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Alexander Aring , Ziyang Xuan , Eric Dumazet , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 8/8] net: use new capable_or functionality Date: Mon, 2 May 2022 18:00:29 +0200 Message-Id: <20220502160030.131168-7-cgzones@googlemail.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220502160030.131168-1-cgzones@googlemail.com> References: <20220217145003.78982-2-cgzones@googlemail.com> <20220502160030.131168-1-cgzones@googlemail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use the new added capable_or function in appropriate cases, where a task is required to have any of two capabilities. Reorder CAP_SYS_ADMIN last. Signed-off-by: Christian Göttsche Reviewed-by: Serge Hallyn --- net/caif/caif_socket.c | 2 +- net/unix/scm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c index 2b8892d502f7..60498148126c 100644 --- a/net/caif/caif_socket.c +++ b/net/caif/caif_socket.c @@ -1036,7 +1036,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol, .usersize = sizeof_field(struct caifsock, conn_req.param) }; - if (!capable(CAP_SYS_ADMIN) && !capable(CAP_NET_ADMIN)) + if (!capable_or(CAP_NET_ADMIN, CAP_SYS_ADMIN)) return -EPERM; /* * The sock->type specifies the socket type to use. diff --git a/net/unix/scm.c b/net/unix/scm.c index aa27a02478dc..821be80e6c85 100644 --- a/net/unix/scm.c +++ b/net/unix/scm.c @@ -99,7 +99,7 @@ static inline bool too_many_unix_fds(struct task_struct *p) struct user_struct *user = current_user(); if (unlikely(user->unix_inflight > task_rlimit(p, RLIMIT_NOFILE))) - return !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN); + return !capable_or(CAP_SYS_RESOURCE, CAP_SYS_ADMIN); return false; }