Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5048842pxb; Wed, 26 Jan 2022 03:46:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2ALzC+58T+lJhEQVsL4hCyslJzztN3V6Dm2HdUXgfzyf789Ix6LenzT45AU4KDT7mJ05M X-Received: by 2002:a17:902:ab09:b0:14b:2640:6432 with SMTP id ik9-20020a170902ab0900b0014b26406432mr20056485plb.45.1643197595165; Wed, 26 Jan 2022 03:46:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643197595; cv=none; d=google.com; s=arc-20160816; b=orzP/oIRdbjzkwO9ZyY5NCv4kB8XDh1ipGbj5CfHhY9sF/xzA1xmU2j23nQbUkHlWJ BwGOaOfObe799DpQb0yW0OjdvN8WllBupv4XJCy+AiUCP3GLxfWzztQRxBalFIXNI2OG w4H4Blmh2KI3Ni+ywsDxCqhzus9oqEgDxhyfqawE2d1U15l4QKoD7ACk27ol24ii3j2Q SMrP3AAwHOfzz6mjTEKvHl7G/EiXl5Gtj+Sijt17aBR70xsAtKA9/pc97AeXrIju2QN3 RlICY7qNOPYQ2JYa8PTBTCk4mJvKTjCObDxviItYHLbeFP5tFXseT/8GiEhXZGeA2Pdy N7Yg== 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=ADg8slEUxx1nyVrfNPf7q4g1mltMrxp4uCFeeo4DNRs=; b=QLidzBAs2YzmBYWCiATgVZ5Itcc4edn1dRj/n7EFSC/l6d7HnEVJ0NVqeLtxyvFlCj mVOOoVLjg6b4Ub04BRNYCK+bz9GUk5+aaa6Rwob6ZLUr4dPQQfZwlKEmzSR/OtZhNxXU QuYU+gWhbFARQ+kIE2c+5vJ9Pv8SNbiphMs04YvjhsBdpjXH1Rx8Gmv+lgmmqNjJw/y0 6WTHIYp9rxtQWbPg506P1IEBcpevco5w7teybucUcPvzXlYFavVzvu/kCd3KvV2IyY70 i17YYcU0kniCxBFK5pkDN0XZURLGFZLF7LZLQeJ/7c4gYi0l0fX/+ZL8XQKrapn6QzUV 53YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=EO9WqZp6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mq12si3355249pjb.18.2022.01.26.03.46.22; Wed, 26 Jan 2022 03:46:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=EO9WqZp6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S234413AbiAYWr4 (ORCPT + 99 others); Tue, 25 Jan 2022 17:47:56 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:18554 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234225AbiAYWr3 (ORCPT ); Tue, 25 Jan 2022 17:47:29 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20PLGeI3031514; Tue, 25 Jan 2022 22:47:01 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=ADg8slEUxx1nyVrfNPf7q4g1mltMrxp4uCFeeo4DNRs=; b=EO9WqZp6A2pdhIEyLbiiGhORYOJ7hvd2z9M0/3FbnEGvV7zrNn7ctfwo6lBI+8i0IHnU D2xpkCMfnq7KeQ7CPNxMS4Gu8fMPGsFKynmq/TZZ65O/CUhUlVElAkrn0E0GeMkQ6rX8 4H+/bI0n9wBD6x51SUDkJLGJmGhBL2xyc7ivmN4qmog5kOln3CYQlELTqJKzJSMiilf9 N7z/zpoNEINBTBLE6YyfXnA+I57Nq79G7olQlNUXsa0rWBiFdgi5kDv5Lk94w5qbAT2Q 42lJ87a9Q2kMdGx9p4cIiuEjbLAMcm8rnLQomTXrTUeQ6giJTFLfRutcNGgs8/HIeORh zA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3dtryvsftu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jan 2022 22:47:01 +0000 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 20PMgMCl011573; Tue, 25 Jan 2022 22:47:00 GMT Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0b-001b2d01.pphosted.com with ESMTP id 3dtryvsftq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jan 2022 22:47:00 +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 20PMhSdR005118; Tue, 25 Jan 2022 22:47:00 GMT Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by ppma04wdc.us.ibm.com with ESMTP id 3dr9jaq50h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jan 2022 22:47:00 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 20PMkwVN39256494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Jan 2022 22:46:58 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 261BCAC066; Tue, 25 Jan 2022 22:46:58 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 13524AC067; Tue, 25 Jan 2022 22:46:58 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Tue, 25 Jan 2022 22:46:58 +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 v9 12/23] ima: Define mac_admin_ns_capable() as a wrapper for ns_capable() Date: Tue, 25 Jan 2022 17:46:34 -0500 Message-Id: <20220125224645.79319-13-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220125224645.79319-1-stefanb@linux.vnet.ibm.com> References: <20220125224645.79319-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: PT1s5Lw4AZsJILgU7IuyW3lVtLfcIr4S X-Proofpoint-ORIG-GUID: wrTfO28z6fwkhfY98-nG2CheCI6twWvm 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-01-25_05,2022-01-25_02,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 impostorscore=0 adultscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2201250135 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Berger 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 3afb7a74d2cf..9162f06d182f 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