Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1245403rwn; Thu, 15 Sep 2022 12:37:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM78LM/SRgS9VOppePnT0lHbRtWa4mMSbop98cWDb26PW3xcOMxBiTkEduDH6b4PDcVKecTG X-Received: by 2002:a17:906:6a14:b0:774:a998:d9a2 with SMTP id qw20-20020a1709066a1400b00774a998d9a2mr1006052ejc.496.1663270620240; Thu, 15 Sep 2022 12:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663270620; cv=none; d=google.com; s=arc-20160816; b=jngFHQp+KzE0lnTzbdaXOacZG/dknECXvJa9/rPKxkg+rok9PJ3DBAPM+yMfvUpJQI QHr/AnHHTO+zJtdo6v15iUEYfv9IZDSyN2SiON6up7OBURfZiAi2rNsZoAIjChaB7ymQ t5HVHQxq0lQ0SQTfMD8V/UYOqLL++79xu09PpW4xBqD2vGlY5ZgxzB9871XDxaYoTpgr nZybx32DW5qBAWYnibCb7dcTxdGMRhbneEv5WNY19y643DXf/4D6XRk0vV8HRt4wo+Eg Hhv9xTPMpFvKilSKVgl74SH+oZXLYWqcgqpy+1gZZqRmU9xKVMPBY+O2QTgeyoDThThm h6yA== 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=UJB4H84uCBmA/o5130mZ4RBzH8/Cx5kE0j0u6xHqKTw=; b=oh4/+QjZ7ZrrAZPdOc4aqPa1u0zAPo/M44zgAqUXxdwq/aHxxGDwg6D1u58dxdTIz9 vYuE/zm65e5p3BnimvOz2Dn3z0NkEFg6IBbluGJpl6BFkqNFnkiYG2dDyuhR41Xeb9/m JG3RNoWssyv6+qizxeISQ9oKPGv3uaQBVI3TG7EjCXD42lB0Q9Pkj3p77tOQTVQjVgGB L0yMqQ44wHNph4HSEkvtANGHBCXDiy+ZZveLdSgiHggOkh+JM7OdGckCn3hwJh5g2Z7T c2JJvyPfxMYs2ru8jn8JMAVpC5lj3Hb/uMcoOTO3B9ofV1i81xhsDRa0IKQLw8Hvj40m xchQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=E2aFhU8v; 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 cx1-20020a170906c80100b0073cd848ae8asi12801026ejb.321.2022.09.15.12.36.34; Thu, 15 Sep 2022 12:37:00 -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=E2aFhU8v; 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 S230024AbiIOTd6 (ORCPT + 99 others); Thu, 15 Sep 2022 15:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbiIOTdS (ORCPT ); Thu, 15 Sep 2022 15:33:18 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11B339D656; Thu, 15 Sep 2022 12:33:11 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28FI271S024376; Thu, 15 Sep 2022 19:32:40 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=UJB4H84uCBmA/o5130mZ4RBzH8/Cx5kE0j0u6xHqKTw=; b=E2aFhU8vIvt0JWsaVvLWFhvLUIJLR6ht94xVggHoEVZJDeNBUrtwB8H3NKuH6ucfpnIy A1ryus/oI/3SRDRfXsWbuS9q9dXQSV9d9a9xq5eTdfGi4XNkj3ei/h6o8HvdqeNBSZ+N KmmtJ9HphgKhgBhMaV/ootN8toCAz22b8fQY+kKnCfBD2pO+M4Z6nYLJ0Bd2TTGKPqG9 KhaQ2rIdjYWldXlt1PY9wFg/ilG9FTCViYbxArx1MF7/Mn774IyrTNCOwlx6/gKYnqxa QBYqFmnZ/gi5U+zg4SwWzObUcS5qZ2sSzfKVtF+E3IRxS/PWbkMAvkMMv8wvDjGjMunn wQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jm8yn2nyy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Sep 2022 19:32:40 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 28FI3Tce030364; Thu, 15 Sep 2022 19:32:39 GMT Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jm8yn2nx3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Sep 2022 19:32:39 +0000 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28FJKo42023987; Thu, 15 Sep 2022 19:32:37 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma05wdc.us.ibm.com with ESMTP id 3jm9160ddw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Sep 2022 19:32:37 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28FJWbiD17498768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Sep 2022 19:32:37 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F18A0AE05C; Thu, 15 Sep 2022 19:32:36 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D5081AE063; Thu, 15 Sep 2022 19:32:36 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 15 Sep 2022 19:32:36 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org Cc: zohar@linux.ibm.com, serge@hallyn.com, brauner@kernel.org, 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 Subject: [PATCH v14 13/26] userns: Add pointer to ima_namespace to user_namespace Date: Thu, 15 Sep 2022 15:32:08 -0400 Message-Id: <20220915193221.1728029-14-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915193221.1728029-1-stefanb@linux.ibm.com> References: <20220915193221.1728029-1-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: CeYHPy9YezLG-ZRXE4BaZfos4h2QhMfd X-Proofpoint-GUID: OhJO7DAcG5i195E2QynKa_xzMnyzCMe7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-15_10,2022-09-14_04,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 clxscore=1015 phishscore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209150119 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,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 Add a pointer to ima_namespace to the user_namespace and initialize the init_user_ns with a pointer to init_ima_ns. We need a pointer from the user namespace to its associated IMA namespace since IMA namespaces are piggybacking on user namespaces. Signed-off-by: Stefan Berger Acked-by: Christian Brauner Reviewed-by: Mimi Zohar --- v13: - Added comment to ima_namespace pointer in user_namespace structure following Serge's suggestion v11: - Added lost A-b from Christian back - Added sentence to patch description explaining why we need the pointer v9: - Deferred implementation of ima_ns_from_user_ns() to later patch --- include/linux/ima.h | 2 ++ include/linux/user_namespace.h | 9 +++++++++ kernel/user.c | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/include/linux/ima.h b/include/linux/ima.h index 81708ca0ebc7..e0a17fda456a 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -14,6 +14,8 @@ #include struct linux_binprm; +extern struct ima_namespace init_ima_ns; + #ifdef CONFIG_IMA extern enum hash_algo ima_get_current_hash_algo(void); extern int ima_bprm_check(struct linux_binprm *bprm); diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 33a4240e6a6f..8cb3489c988d 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -36,6 +36,7 @@ struct uid_gid_map { /* 64 bytes -- 1 cache line */ #define USERNS_INIT_FLAGS USERNS_SETGROUPS_ALLOWED struct ucounts; +struct ima_namespace; enum ucount_type { UCOUNT_USER_NAMESPACES, @@ -99,6 +100,14 @@ struct user_namespace { #endif struct ucounts *ucounts; long ucount_max[UCOUNT_COUNTS]; +#ifdef CONFIG_IMA_NS + /* Pointer to ima_ns which this user_ns created. Can be null. IMA's + * file access checks will walk the userns->parent chain and check + * against all active ima_ns's. Note that when the user_ns is + * freed, the ima_ns is guaranteed to be free-able. + */ + struct ima_namespace *ima_ns; +#endif } __randomize_layout; struct ucounts { diff --git a/kernel/user.c b/kernel/user.c index e2cf8c22b539..e5d1f4b9b8ba 100644 --- a/kernel/user.c +++ b/kernel/user.c @@ -19,6 +19,7 @@ #include #include #include +#include /* * userns count is 1 for root user, 1 for init_uts_ns, @@ -67,6 +68,9 @@ struct user_namespace init_user_ns = { .keyring_name_list = LIST_HEAD_INIT(init_user_ns.keyring_name_list), .keyring_sem = __RWSEM_INITIALIZER(init_user_ns.keyring_sem), #endif +#ifdef CONFIG_IMA_NS + .ima_ns = &init_ima_ns, +#endif }; EXPORT_SYMBOL_GPL(init_user_ns); -- 2.36.1