Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1426846pxb; Wed, 2 Feb 2022 04:55:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0QNZ0iUNPOQjrNhYm+sXF/bhAb11IkYeBgJUuEP6QYTqvFzw4FfU4BGylqm5xmFOfcSPi X-Received: by 2002:a17:902:ab43:: with SMTP id ij3mr26290920plb.102.1643806517425; Wed, 02 Feb 2022 04:55:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643806517; cv=none; d=google.com; s=arc-20160816; b=yCFMbkizjDvaITazfrI/3tCQIjI+S8ceD1JmVkDpVVLfiVFXrVaH5K1T7H/VeNw8Qa 57j3c8uRKx/VpJM0Xk9nmKWsx4CnHezQ9aXpV4hcTD0xOi2uMK7UPz9p725lZBK8xUPh O817/nndXjc5HpEzCag5/8y871ZmfuIVaynBJicPWXYplPDfduvcIhLUyQ7GJjKUs49J rpjHT4+A1M3s4rNe4yvB4s5ARFbp2reVkXUZJSWcXAKN45EPk1ZnX2tut6vcE3LNlnQW BietAc869x4jiF2KdZDpBd6Zas+ey3jA9XFDS5GGdOu0t2C5hYLMqPiInuXjarL3hE9D J+tw== 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=D8UffUQzijJ+QXO/z/Z9UQWLXwHGGuQIvhdz/1LGu+U=; b=xYKtZBbuB/7TVOTDEM72WSeypMIxpfTVLHIaUx50eS8hy8k6ZziBefc2PMQ9IVQ6Uu W6qKXkdRPIxiAmgdW6IgOvwPX3VmyfUMqa3oWNzanqOxBMfJnhhokkRFH2lNjbd4M5zO 9fXg+WNB/dgv/kFH5O6tIJT+Nz3A9qWE2aetxgDrNbcVOt7sjV/CTymIjBz4lKyOFsmL szfH8rVb6rLi/AHBBX5ZVOl39i3JpugMXcFXse7hZuz0Yw/k5FEBCR8wxAOFHtoYSp8L flf9KVXIzfd77yxStEwf7+RbEfAy8K+SIt7JK9zuFM/sDyAwmk5e1IgZ+kjQlmUyu4nE lx8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=AVM51Bxe; 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=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11si21257511plh.474.2022.02.02.04.55.06; Wed, 02 Feb 2022 04:55:17 -0800 (PST) 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=@ibm.com header.s=pp1 header.b=AVM51Bxe; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242557AbiBAUi4 (ORCPT + 99 others); Tue, 1 Feb 2022 15:38:56 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43502 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240321AbiBAUiQ (ORCPT ); Tue, 1 Feb 2022 15:38:16 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 211IP7Yk002366; Tue, 1 Feb 2022 20:37:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=D8UffUQzijJ+QXO/z/Z9UQWLXwHGGuQIvhdz/1LGu+U=; b=AVM51BxebOEdOQEqUgQenxOuoHu/vII3Qg2Els/Hb1eEUxE4ZVqj4vvBPOZwSsQU2oIJ 2kbJ0oE05tzhCERhSdEYLKUv1hrB0T71KofUu+/HDWYtSGxPmZB3EGGGLftEo02YSbdl h8p7Jp+RRLT7VFiWxIgfoREys/mGGbGbcfNKdWI1YCLYDx7UNxFe9oA/PiS6zRgHpF3E peCxuwwtRKxUgubT9jI01c/NpahPSsQ+3/R0VYx3ZfRVyirx9kOS2mQmrhzBKLg7ohYd Z7jtr5TVEMAiMbDzuZAd6b0RuirzWXqzZ1h+hBoW/6s+mopLjB7XXLjH8DwdxrIyuDkX 0A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dya47a7ya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Feb 2022 20:37:59 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 211KJe7J010622; Tue, 1 Feb 2022 20:37:59 GMT Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 3dya47a7xs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Feb 2022 20:37:58 +0000 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 211KX0DV024004; Tue, 1 Feb 2022 20:37:57 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma04wdc.us.ibm.com with ESMTP id 3dvw7ah5f1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Feb 2022 20:37:57 +0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 211KborB25035032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Feb 2022 20:37:50 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C4D1BB2068; Tue, 1 Feb 2022 20:37:50 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8929B205F; Tue, 1 Feb 2022 20:37:50 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 1 Feb 2022 20:37:50 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org Cc: zohar@linux.ibm.com, serge@hallyn.com, christian.brauner@ubuntu.com, containers@lists.linux.dev, dmitry.kasatkin@gmail.com, ebiederm@xmission.com, krzysztof.struczynski@huawei.com, roberto.sassu@huawei.com, mpeters@redhat.com, lhinds@redhat.com, lsturman@redhat.com, puiterwi@redhat.com, jejb@linux.ibm.com, jamjoom@us.ibm.com, linux-kernel@vger.kernel.org, paul@paul-moore.com, rgb@redhat.com, linux-security-module@vger.kernel.org, jmorris@namei.org, Stefan Berger , Denis Semakin Subject: [PATCH v10 12/27] ima: Define mac_admin_ns_capable() as a wrapper for ns_capable() Date: Tue, 1 Feb 2022 15:37:20 -0500 Message-Id: <20220201203735.164593-13-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220201203735.164593-1-stefanb@linux.ibm.com> References: <20220201203735.164593-1-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: ED0MaFJl-9pwdN1GxjdWG79u0F6Ummf6 X-Proofpoint-ORIG-GUID: EM3_S7S7j9uea-lVtrMYwQ1E083gr7Gd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-01_09,2022-02-01_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 impostorscore=0 clxscore=1011 mlxscore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202010114 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Define mac_admin_ns_capable() as a wrapper for the combined ns_capable() checks on CAP_MAC_ADMIN and CAP_SYS_ADMIN in a user namespace. Return true on the check if either capability or both are available. Use mac_admin_ns_capable() in place of capable(SYS_ADMIN). This will allow an IMA namespace to read the policy with only CAP_MAC_ADMIN, which has less privileges than CAP_SYS_ADMIN. Signed-off-by: Denis Semakin Signed-off-by: Stefan Berger --- include/linux/capability.h | 6 ++++++ security/integrity/ima/ima.h | 6 ++++++ security/integrity/ima/ima_fs.c | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/linux/capability.h b/include/linux/capability.h index 65efb74c3585..991579178f32 100644 --- a/include/linux/capability.h +++ b/include/linux/capability.h @@ -270,6 +270,12 @@ static inline bool checkpoint_restore_ns_capable(struct user_namespace *ns) ns_capable(ns, CAP_SYS_ADMIN); } +static inline bool mac_admin_ns_capable(struct user_namespace *ns) +{ + return ns_capable(ns, CAP_MAC_ADMIN) || + ns_capable(ns, CAP_SYS_ADMIN); +} + /* audit system wants to get cap info from files as well */ int get_vfs_caps_from_disk(struct user_namespace *mnt_userns, const struct dentry *dentry, diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index fb6bd054d899..0057b1fd6c18 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -487,4 +487,10 @@ static inline int ima_filter_rule_match(u32 secid, u32 field, u32 op, #define POLICY_FILE_FLAGS S_IWUSR #endif /* CONFIG_IMA_READ_POLICY */ +static inline +struct user_namespace *ima_user_ns_from_file(const struct file *filp) +{ + return file_inode(filp)->i_sb->s_user_ns; +} + #endif /* __LINUX_IMA_H */ diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c index 89d3113ceda1..c41aa61b7393 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c @@ -377,6 +377,9 @@ static const struct seq_operations ima_policy_seqops = { */ static int ima_open_policy(struct inode *inode, struct file *filp) { +#ifdef CONFIG_IMA_READ_POLICY + struct user_namespace *user_ns = ima_user_ns_from_file(filp); +#endif struct ima_namespace *ns = &init_ima_ns; if (!(filp->f_flags & O_WRONLY)) { @@ -385,7 +388,7 @@ static int ima_open_policy(struct inode *inode, struct file *filp) #else if ((filp->f_flags & O_ACCMODE) != O_RDONLY) return -EACCES; - if (!capable(CAP_SYS_ADMIN)) + if (!mac_admin_ns_capable(user_ns)) return -EPERM; return seq_open(filp, &ima_policy_seqops); #endif -- 2.31.1