Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4584398rwd; Sun, 11 Jun 2023 10:21:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ79IurnVjbFz/vWAR2vqJijo3bDHyv4WI6B7a7FH+v3qQ0JzmDNDr0PQbeBaYCo0g27B/Ad X-Received: by 2002:aa7:d9d2:0:b0:516:b12a:30b9 with SMTP id v18-20020aa7d9d2000000b00516b12a30b9mr3238101eds.25.1686504064174; Sun, 11 Jun 2023 10:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686504064; cv=none; d=google.com; s=arc-20160816; b=PisQJCV3MX7DCi4CLsthNHNxug4DsQ1/hMTp0ueF8M5oPhn9eClN1Ze3FJ/tF61osg lpl8e0L3VWZBiJzlMwIQUEWY7vNG833SQOv2V3sgUKHr2Nr4x8GtgZsifRlnHLbPpluw k7lutK9MqzCn323feKBNMVQlTGqZAHaZwTmaBbxb+4ipnLrSD19Z3tD/cchAQgG6bC62 f1pwLQJ3ULva6wPsv8pgWY+xCfVYBZh69z3oFZp3zikilDDLYLu25mkWZazMXfl78mQg PWgqTXuUsXDIct3IHDd5FJRz3JDBopQBiYqTyDWiy5XqAH5PjCVVj665vtAFhb0KRUVw Y/lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=7DgmiJ22fK35rNDSjxBWlZUyMsVle3zhBPTayVRxagg=; b=xuUnZnnaVG0Vfg0jbnFXVqUFw9DEu208wlhjPvv8b9tBHWlZol4eZ9BDSXIp+/f0Zx iX20wHZ5Hea4vAxCXkVvIamBLIqmnt1FmU4qVvVK9dfAYVVK2NrFMOumxERTEVJH6z+k Ac+CqEGA6kSBNZsbwI6nFhzJirXOX6d8cECfOcGCbaz/to9U5FgS2wxJpHfhdYN87ohD c3/CGKaB58bFsiiP+ra91MWhVDeMqpMd+mF84QllSdbMzWqqko0Zgaxy6me2m1u0vZyJ JnVGF/KugtJvrbqKWnRQQfkRdf2CePo7I+twmWmWpqk6UKNo9AXuucpNkd/rjOi3nUuv knyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=WlZvjTDl; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f7-20020a056402160700b005163b43284bsi4914878edv.158.2023.06.11.10.20.39; Sun, 11 Jun 2023 10:21:04 -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=@yahoo.com header.s=s2048 header.b=WlZvjTDl; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232041AbjFKQ7Y (ORCPT + 99 others); Sun, 11 Jun 2023 12:59:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231786AbjFKQ7W (ORCPT ); Sun, 11 Jun 2023 12:59:22 -0400 Received: from sonic311-30.consmr.mail.ne1.yahoo.com (sonic311-30.consmr.mail.ne1.yahoo.com [66.163.188.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52285E5F for ; Sun, 11 Jun 2023 09:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1686502758; bh=7DgmiJ22fK35rNDSjxBWlZUyMsVle3zhBPTayVRxagg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From:Subject:Reply-To; b=WlZvjTDlFW8Dge+gd1tlpy2eF6YGB8TV+StzVBR2hJE/BRtRxfyBmqKc3NKdxVPLKPyraFh73Y2lj7lUvActlXW4TCpUvpN/lJW2eQXM+eEn5zDzwFz+8YLBfpIwp07/SKJwsGJW/6j9q5jex6YhnQW7mpiCFFbbqecgV+pX/P0l4KoGUmOtkoMGXnJrNu8B6ktjwGpPu28V7W4PHKkSI98QhYOoyTywvvTLdPr3VqRbRXDKgfXOz1Pp/W9KBPFuF6YHkQWJW5ZCz4eDXGOZsaX01WbtQg0ZbW+eyD0wPaDDk0z+ou3xQgU5Kkmb+PTe2RrGIaxDejdEGhK3BWqifQ== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1686502758; bh=Bw/LP1AfuaenQ0zxwdibPZAH47OgxOVjpM6yDDmmHlq=; h=X-Sonic-MF:Date:Subject:To:From:From:Subject; b=kTuxdssiPuuJVLxUsysBhWHXN741iK7E6F/z6tAU0gbyw1PSQNP9NzU8vfUcpMalhyOKJnYxmoS5UEE2nLOsxVphsIWCfF7UsAJdGEgV/kV6Z47mw95tihV88imwQTPWXddRid3c0cUK6E6ZXf23i/XOKTVtxLdQmtxylRKiZXQaZWdZ0AYlIcS7yCuE5SplkvtJ9OLJPM/P6agxIDt6e+iKg+PtBPOou27TqCR1mZFXnCcP5Y344flZPXqylvQMH6KbtnLydXFU1gMAmwT7kniHHCfxmSHxniTdw5eVxnhw6Z9penxfUzAf3qZbKnY51avh7pHBF1mqFG4vfrieHQ== X-YMail-OSG: L.q6DH0VM1msMV_aMf1IXTl60njTH76ZX6CVdR2rTZWI.fi02qwrRdqY7t4QlR1 ybQ2_iK3wO4D7UWTz.N5phjZ1HItKaFA6hQxTQd5vdxSBpNG5FROpV3WHLRlTKqtfMabF_39zYTP QgINTZG2KsTjYcimAEHM7sdYT1LkXPIFH9uYOIN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qjl0GuSTtkQ3uLTSRdVvklNK3yFbNf_L9l9BU O2zuT.3LXlq2.sw-- X-Sonic-MF: X-Sonic-ID: 3d22b0d8-f4f9-4c6a-a046-6dd8537797e8 Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.ne1.yahoo.com with HTTP; Sun, 11 Jun 2023 16:59:18 +0000 Received: by hermes--production-ne1-574d4b7954-xz2cn (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 73c567dd6e3213e09855c459a66d5812; Sun, 11 Jun 2023 16:59:16 +0000 (UTC) Message-ID: Date: Sun, 11 Jun 2023 09:59:14 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH v12 2/4] smack: Set the SMACK64TRANSMUTE xattr in smack_inode_init_security() Content-Language: en-US To: Roberto Sassu , zohar@linux.ibm.com, dmitry.kasatkin@gmail.com, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, stephen.smalley.work@gmail.com, eparis@parisplace.org Cc: linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, bpf@vger.kernel.org, kpsingh@kernel.org, keescook@chromium.org, nicolas.bouchinet@clip-os.org, Roberto Sassu , Casey Schaufler References: <20230610075738.3273764-1-roberto.sassu@huaweicloud.com> <20230610075738.3273764-3-roberto.sassu@huaweicloud.com> From: Casey Schaufler In-Reply-To: <20230610075738.3273764-3-roberto.sassu@huaweicloud.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Mailer: WebService/1.1.21516 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On 6/10/2023 12:57 AM, Roberto Sassu wrote: > From: Roberto Sassu > > With the newly added ability of LSMs to supply multiple xattrs, set > SMACK64TRASMUTE in smack_inode_init_security(), instead of d_instantiate(). > Do it by incrementing SMACK_INODE_INIT_XATTRS to 2 and by calling > lsm_get_xattr_slot() a second time, if the transmuting conditions are met. > > The LSM infrastructure passes all xattrs provided by LSMs to the > filesystems through the initxattrs() callback, so that filesystems can > store xattrs in the disk. > > After the change, the SMK_INODE_TRANSMUTE inode flag is always set by > d_instantiate() after fetching SMACK64TRANSMUTE from the disk. Before it > was done by smack_inode_post_setxattr() as result of the __vfs_setxattr() > call. > > Removing __vfs_setxattr() also prevents invalidating the EVM HMAC, by > adding a new xattr without checking and updating the existing HMAC. > > Signed-off-by: Roberto Sassu Reviewed-by: Casey Schaufler > --- > security/smack/smack.h | 2 +- > security/smack/smack_lsm.c | 45 ++++++++++++++++++++++++-------------- > 2 files changed, 29 insertions(+), 18 deletions(-) > > diff --git a/security/smack/smack.h b/security/smack/smack.h > index aa15ff56ed6..041688e5a77 100644 > --- a/security/smack/smack.h > +++ b/security/smack/smack.h > @@ -128,7 +128,7 @@ struct task_smack { > > #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */ > #define SMK_INODE_TRANSMUTE 0x02 /* directory is transmuting */ > -#define SMK_INODE_CHANGED 0x04 /* smack was transmuted */ > +#define SMK_INODE_CHANGED 0x04 /* smack was transmuted (unused) */ > #define SMK_INODE_IMPURE 0x08 /* involved in an impure transaction */ > > /* > diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c > index 25ade3819af..679156601a1 100644 > --- a/security/smack/smack_lsm.c > +++ b/security/smack/smack_lsm.c > @@ -52,7 +52,14 @@ > #define SMK_RECEIVING 1 > #define SMK_SENDING 2 > > -#define SMACK_INODE_INIT_XATTRS 1 > +/* > + * Smack uses multiple xattrs. > + * SMACK64 - for access control, > + * SMACK64TRANSMUTE - label initialization, > + * Not saved on files - SMACK64IPIN and SMACK64IPOUT, > + * Must be set explicitly - SMACK64EXEC and SMACK64MMAP > + */ > +#define SMACK_INODE_INIT_XATTRS 2 > > #ifdef SMACK_IPV6_PORT_LABELING > static DEFINE_MUTEX(smack_ipv6_lock); > @@ -935,7 +942,6 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir, > struct xattr *xattrs, int *xattr_count) > { > struct task_smack *tsp = smack_cred(current_cred()); > - struct inode_smack *issp = smack_inode(inode); > struct smack_known *skp = smk_of_task(tsp); > struct smack_known *isp = smk_of_inode(inode); > struct smack_known *dsp = smk_of_inode(dir); > @@ -963,6 +969,8 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir, > if ((tsp->smk_task == tsp->smk_transmuted) || > (may > 0 && ((may & MAY_TRANSMUTE) != 0) && > smk_inode_transmutable(dir))) { > + struct xattr *xattr_transmute; > + > /* > * The caller of smack_dentry_create_files_as() > * should have overridden the current cred, so the > @@ -971,7 +979,18 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir, > */ > if (tsp->smk_task != tsp->smk_transmuted) > isp = dsp; > - issp->smk_flags |= SMK_INODE_CHANGED; > + xattr_transmute = lsm_get_xattr_slot(xattrs, > + xattr_count); > + if (xattr_transmute) { > + xattr_transmute->value = kmemdup(TRANS_TRUE, > + TRANS_TRUE_SIZE, > + GFP_NOFS); > + if (!xattr_transmute->value) > + return -ENOMEM; > + > + xattr_transmute->value_len = TRANS_TRUE_SIZE; > + xattr_transmute->name = XATTR_SMACK_TRANSMUTE; > + } > } > > xattr->value = kstrdup(isp->smk_known, GFP_NOFS); > @@ -3518,20 +3537,12 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode) > * If there is a transmute attribute on the > * directory mark the inode. > */ > - if (isp->smk_flags & SMK_INODE_CHANGED) { > - isp->smk_flags &= ~SMK_INODE_CHANGED; > - rc = __vfs_setxattr(&nop_mnt_idmap, dp, inode, > - XATTR_NAME_SMACKTRANSMUTE, > - TRANS_TRUE, TRANS_TRUE_SIZE, > - 0); > - } else { > - rc = __vfs_getxattr(dp, inode, > - XATTR_NAME_SMACKTRANSMUTE, trattr, > - TRANS_TRUE_SIZE); > - if (rc >= 0 && strncmp(trattr, TRANS_TRUE, > - TRANS_TRUE_SIZE) != 0) > - rc = -EINVAL; > - } > + rc = __vfs_getxattr(dp, inode, > + XATTR_NAME_SMACKTRANSMUTE, trattr, > + TRANS_TRUE_SIZE); > + if (rc >= 0 && strncmp(trattr, TRANS_TRUE, > + TRANS_TRUE_SIZE) != 0) > + rc = -EINVAL; > if (rc >= 0) > transflag = SMK_INODE_TRANSMUTE; > }