Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp336499pxb; Fri, 22 Apr 2022 01:50:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyS+2WW+CYwB19Q5tE4eQo+2yDhKG17H3F6LaE/FbIPXaQ6Rw0oHYZ4BB6Z1zsaJ5u4+qaD X-Received: by 2002:a50:e78d:0:b0:41d:c8ec:81b0 with SMTP id b13-20020a50e78d000000b0041dc8ec81b0mr3637885edn.56.1650617401802; Fri, 22 Apr 2022 01:50:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650617401; cv=none; d=google.com; s=arc-20160816; b=wrt1VmIxDfVlnfiVzTpX4IpRlt+ZYQg5pXy1NJjlRUfbRc1/69gjn2yV4zZ/+cOK+K pir4rfDtAh2PQNXJMeZhqpVRlbh8YkJW89Y2ahUofTMVxi/20+Wx6XrJ4LOhGhezzO05 XX2eJIi+WPQ+SEixvTv3JZCWkusLPShE//8WrmAqehZJcbW+yftk3apsOKZ9VYrVzsBe /kIX6AO9yKsxZK67FE416sgOf0Ha/47p1M7iyrOSPEYXKCMBf7fosBPwo2f0ZGeVwbSY RcJJsXuAcK7tGeXoSCNvXwk5QF04+sRurIJq0usKTv+zVcxG+wvV0tTuOSDhcWfzuz1j 8mdw== 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=aRRoCyAInH2cMZr2R6NPtnpNruFbKMds2YxsIkCHkNE=; b=kNvxFg+9pb6Icj1WPfdnAFl248Y7PaqhLh3IMW7+4rTQZeMFea6gyLHdyPk7AAw2Wr 7ahLeR3u35oaChYEaJvM9lqXjlFaRa/V0nyX9oldFu8fPcdRWOEhb8KOU2wA9JHeh7Qe zTdkoyj1BzWOJ0IlvT0pAc657E1v+lEzXItWY62DrcAmeedskXyhsxmq/IKga8xuEnCE kI8PTPLeFh0CEGi0zXZVXHk9M2YfXZkpPJuT7BIf1GJsDVKt0yrHHpZCOL6jh9uyiAwG aA1ER/dF5bg5WDJf7QAgfjerKrtM9aWJpj28cQOnLvyUCMixzMdhJQnhWSV2NRW/IsPg 2G6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=jaTEdbKf; 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 w7-20020a1709062f8700b006e8d2490511si6006754eji.34.2022.04.22.01.49.38; Fri, 22 Apr 2022 01:50:01 -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=@ibm.com header.s=pp1 header.b=jaTEdbKf; 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 S1379483AbiDTOLX (ORCPT + 99 others); Wed, 20 Apr 2022 10:11:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379372AbiDTOKM (ORCPT ); Wed, 20 Apr 2022 10:10:12 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EE04443C8; Wed, 20 Apr 2022 07:07:17 -0700 (PDT) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23KDlVag019539; Wed, 20 Apr 2022 14:06:46 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=aRRoCyAInH2cMZr2R6NPtnpNruFbKMds2YxsIkCHkNE=; b=jaTEdbKflV/hBT7tmWw/M2zWiGLDMnE9i8DPljA4OfQ1jLYGnO1VIatyn+0hjnncCyHj T03g3MHu0d+QJyqv2yIOEnA+eUjpmXOD0DwLOLzMm/90kTVEC7RTz+3b91z8aEX0M4Us eyEPwZ8IxRNBt6yoTJzgOnQhZBTXbrpVvNmJMJC+6cunJx3yuR5Za55s64MSfZoa+cMz ZLmEsxd+7wK7TmGI6kxW14bMO22c+Fyucnlqf8oGGJHYAJeIb6V7EBa9GmXBq3zqQRTx se/GGCN4UTp2bYHx/bjgOZvLL3WouwJ0Y9S+VVn3S2cFMxykDB0flk4Q59SLNHRrlN05 CA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fg7vpqyvk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Apr 2022 14:06:45 +0000 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23KDnG9Y024647; Wed, 20 Apr 2022 14:06:45 GMT Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fg7vpqyup-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Apr 2022 14:06:45 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23KE1xs3023574; Wed, 20 Apr 2022 14:06:43 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma01wdc.us.ibm.com with ESMTP id 3ffneacskx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Apr 2022 14:06:43 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23KE6gpH16187796 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Apr 2022 14:06:42 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7322DAE060; Wed, 20 Apr 2022 14:06:42 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 530B2AE064; Wed, 20 Apr 2022 14:06:42 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 20 Apr 2022 14:06:42 +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, jpenumak@redhat.com, Stefan Berger , Denis Semakin Subject: [PATCH v12 11/26] ima: Define mac_admin_ns_capable() as a wrapper for ns_capable() Date: Wed, 20 Apr 2022 10:06:18 -0400 Message-Id: <20220420140633.753772-12-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420140633.753772-1-stefanb@linux.ibm.com> References: <20220420140633.753772-1-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 6w5YkAjoHgt0BAywrMOL-tc6s0AWxiZR X-Proofpoint-GUID: erxzDSYmAVF0FmvobUNjinenuGSX2Mxw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-20_04,2022-04-20_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204200081 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 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. Since CAP_MAC_ADMIN is an additional capability added to an existing gate avoid auditing in case it is not set. Signed-off-by: Denis Semakin Signed-off-by: Stefan Berger --- v11: - use ns_capable_noaudit for CAP_MAC_ADMIN to avoid auditing in this case --- 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..dc3e1230b365 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_noaudit(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 5bf7f080c2be..626a6ce2453c 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -491,4 +491,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.34.1