BPF List
 help / color / mirror / Atom feed
From: Mengchi Cheng <mengcc@amazon.com>
To: <roberto.sassu@huaweicloud.com>
Cc: <bpf@vger.kernel.org>, <casey@schaufler-ca.com>,
	<dmitry.kasatkin@gmail.com>, <eparis@parisplace.org>,
	<jmorris@namei.org>, <kamatam@amazon.com>,
	<keescook@chromium.org>, <kpsingh@kernel.org>,
	<linux-integrity@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-security-module@vger.kernel.org>,
	<linux-unionfs@vger.kernel.org>, <mengcc@amazon.com>,
	<miklos@szeredi.hu>, <nicolas.bouchinet@clip-os.org>,
	<paul@paul-moore.com>, <roberto.sassu@huawei.com>,
	<selinux@vger.kernel.org>, <serge@hallyn.com>,
	<stephen.smalley.work@gmail.com>, <yoonjaeh@amazon.com>,
	<zohar@linux.ibm.com>
Subject: Re: [PATCH v11 2/4] smack: Set the SMACK64TRANSMUTE xattr in smack_inode_init_security()
Date: Fri, 23 Jun 2023 12:32:22 -0700	[thread overview]
Message-ID: <20230623193222.2326429-1-mengcc@amazon.com> (raw)
In-Reply-To: <9f4b7bef5d090da9de50ed1aa1e103abc19b125f.camel@huaweicloud.com>

On Mon, 2023-06-05 08:38:29 +0000, Roberto Sassu wrote:
>
> On Sat, 2023-06-03 at 21:15 +0200, Roberto Sassu wrote:
> > From: Roberto Sassu <roberto.sassu@huawei.com>
> > 
> > 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.
> 
> Hi Mengchi
> 
> could you please redo your tests with this patch set applied?
> 
> https://lore.kernel.org/linux-integrity/20230603191518.1397490-1-roberto.sassu@huaweicloud.com/
> 
> You need:
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm.git/log/?h=next
> 
> https://github.com/cschaufler/smack-next/commits/next
> 
> Thanks
> 
> Roberto

Sorry for the later reply. It turned out lsm.git repo needs your previous
two overlay fs fixes before applying these four patches.
With v12 I did not see the issue I reported anymore.

Best,
Mengchi

> 
> > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> > ---
> >  security/smack/smack.h     |  2 +-
> >  security/smack/smack_lsm.c | 43 +++++++++++++++++++++++---------------
> >  2 files changed, 27 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 a1c30275692..b67d901ee74 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,16 @@ 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 == NULL)
> > +					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 +3535,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;
> >  		}
> 
> 

  parent reply	other threads:[~2023-06-23 19:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-03 19:15 [PATCH v11 0/4] evm: Do HMAC of multiple per LSM xattrs for new inodes Roberto Sassu
2023-06-03 19:15 ` [PATCH v11 1/4] security: Allow all LSMs to provide xattrs for inode_init_security hook Roberto Sassu
2023-06-09 20:02   ` Paul Moore
2023-06-03 19:15 ` [PATCH v11 2/4] smack: Set the SMACK64TRANSMUTE xattr in smack_inode_init_security() Roberto Sassu
2023-06-05  8:38   ` Roberto Sassu
2023-06-09  7:26     ` Jarkko Sakkinen
2023-06-10  7:01       ` Roberto Sassu
2023-06-23 19:32     ` Mengchi Cheng [this message]
2023-06-09 19:35   ` Mimi Zohar
2023-06-10  7:09     ` Roberto Sassu
2023-06-03 19:15 ` [PATCH v11 3/4] evm: Align evm_inode_init_security() definition with LSM infrastructure Roberto Sassu
2023-06-09 19:48   ` Mimi Zohar
2023-06-03 19:15 ` [PATCH v11 4/4] evm: Support multiple LSMs providing an xattr Roberto Sassu
2023-06-06 16:09 ` [PATCH v11 0/4] evm: Do HMAC of multiple per LSM xattrs for new inodes Mimi Zohar
2023-06-06 16:16   ` Roberto Sassu
2023-06-09 20:05 ` Paul Moore
2023-06-10  8:00   ` Roberto Sassu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230623193222.2326429-1-mengcc@amazon.com \
    --to=mengcc@amazon.com \
    --cc=bpf@vger.kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=dmitry.kasatkin@gmail.com \
    --cc=eparis@parisplace.org \
    --cc=jmorris@namei.org \
    --cc=kamatam@amazon.com \
    --cc=keescook@chromium.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=nicolas.bouchinet@clip-os.org \
    --cc=paul@paul-moore.com \
    --cc=roberto.sassu@huawei.com \
    --cc=roberto.sassu@huaweicloud.com \
    --cc=selinux@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=stephen.smalley.work@gmail.com \
    --cc=yoonjaeh@amazon.com \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox