diff mbox series

[RFC,1/2] smack: Retrieve transmuting information in smack_inode_getsecurity()

Message ID 20230508170234.3595105-1-roberto.sassu@huaweicloud.com (mailing list archive)
State Handled Elsewhere
Headers show
Series [RFC,1/2] smack: Retrieve transmuting information in smack_inode_getsecurity() | expand

Commit Message

Roberto Sassu May 8, 2023, 5:02 p.m. UTC
From: Roberto Sassu <roberto.sassu@huawei.com>

Enhance smack_inode_getsecurity() to retrieve the value for
SMACK64TRANSMUTE from the inode security blob, similarly to SMACK64.

This helps to display accurate values in the situation where the security
labels come from mount options and not from xattrs.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 security/smack/smack_lsm.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Comments

Casey Schaufler May 8, 2023, 5:24 p.m. UTC | #1
On 5/8/2023 10:02 AM, Roberto Sassu wrote:
> From: Roberto Sassu <roberto.sassu@huawei.com>
>
> Enhance smack_inode_getsecurity() to retrieve the value for
> SMACK64TRANSMUTE from the inode security blob, similarly to SMACK64.
>
> This helps to display accurate values in the situation where the security
> labels come from mount options and not from xattrs.

I will kick the tires on these patches. They look good at first glance.

>
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> ---
>  security/smack/smack_lsm.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index 7a3e9ab137d..c7e37ed2799 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -1463,10 +1463,19 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,
>  	struct super_block *sbp;
>  	struct inode *ip = inode;
>  	struct smack_known *isp;
> +	struct inode_smack *ispp;
> +	size_t label_len;
> +	char *label = NULL;
>  
> -	if (strcmp(name, XATTR_SMACK_SUFFIX) == 0)
> +	if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
>  		isp = smk_of_inode(inode);
> -	else {
> +	} else if (strcmp(name, XATTR_SMACK_TRANSMUTE) == 0) {
> +		ispp = smack_inode(inode);
> +		if (ispp->smk_flags & SMK_INODE_TRANSMUTE)
> +			label = TRANS_TRUE;
> +		else
> +			label = "";
> +	} else {
>  		/*
>  		 * The rest of the Smack xattrs are only on sockets.
>  		 */
> @@ -1488,13 +1497,18 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,
>  			return -EOPNOTSUPP;
>  	}
>  
> +	if (!label)
> +		label = isp->smk_known;
> +
> +	label_len = strlen(label);
> +
>  	if (alloc) {
> -		*buffer = kstrdup(isp->smk_known, GFP_KERNEL);
> +		*buffer = kstrdup(label, GFP_KERNEL);
>  		if (*buffer == NULL)
>  			return -ENOMEM;
>  	}
>  
> -	return strlen(isp->smk_known);
> +	return label_len;
>  }
>  
>
Casey Schaufler May 11, 2023, 5:12 p.m. UTC | #2
On 5/8/2023 10:02 AM, Roberto Sassu wrote:
> From: Roberto Sassu <roberto.sassu@huawei.com>
>
> Enhance smack_inode_getsecurity() to retrieve the value for
> SMACK64TRANSMUTE from the inode security blob, similarly to SMACK64.
>
> This helps to display accurate values in the situation where the security
> labels come from mount options and not from xattrs.
>
> Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>

Looks good. I have added to smack next.

> ---
>  security/smack/smack_lsm.c | 22 ++++++++++++++++++----
>  1 file changed, 18 insertions(+), 4 deletions(-)
>
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index 7a3e9ab137d..c7e37ed2799 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -1463,10 +1463,19 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,
>  	struct super_block *sbp;
>  	struct inode *ip = inode;
>  	struct smack_known *isp;
> +	struct inode_smack *ispp;
> +	size_t label_len;
> +	char *label = NULL;
>  
> -	if (strcmp(name, XATTR_SMACK_SUFFIX) == 0)
> +	if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
>  		isp = smk_of_inode(inode);
> -	else {
> +	} else if (strcmp(name, XATTR_SMACK_TRANSMUTE) == 0) {
> +		ispp = smack_inode(inode);
> +		if (ispp->smk_flags & SMK_INODE_TRANSMUTE)
> +			label = TRANS_TRUE;
> +		else
> +			label = "";
> +	} else {
>  		/*
>  		 * The rest of the Smack xattrs are only on sockets.
>  		 */
> @@ -1488,13 +1497,18 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,
>  			return -EOPNOTSUPP;
>  	}
>  
> +	if (!label)
> +		label = isp->smk_known;
> +
> +	label_len = strlen(label);
> +
>  	if (alloc) {
> -		*buffer = kstrdup(isp->smk_known, GFP_KERNEL);
> +		*buffer = kstrdup(label, GFP_KERNEL);
>  		if (*buffer == NULL)
>  			return -ENOMEM;
>  	}
>  
> -	return strlen(isp->smk_known);
> +	return label_len;
>  }
>  
>
Munehisa Kamata Aug. 21, 2023, 7:55 a.m. UTC | #3
Hi Casey, Roberto

On Thu, 2023-05-11 17:12:50 +0000, Casey Schaufler wrote:
>
> On 5/8/2023 10:02 AM, Roberto Sassu wrote:
> > From: Roberto Sassu <roberto.sassu@huawei.com>
> >
> > Enhance smack_inode_getsecurity() to retrieve the value for
> > SMACK64TRANSMUTE from the inode security blob, similarly to SMACK64.
> >
> > This helps to display accurate values in the situation where the security
> > labels come from mount options and not from xattrs.
> >
> > Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
> 
> Looks good. I have added to smack next.

Do you have any objections to backporting these patches to -stable? If not,
I'll ask it in the stable list along with another overlayfs-related fix
387ef964460f ("Smack:- Use overlay inode label in smack_inode_copy_up()").


Thanks,
Munehisa

> 
> > ---
> >  security/smack/smack_lsm.c | 22 ++++++++++++++++++----
> >  1 file changed, 18 insertions(+), 4 deletions(-)
> >
> > diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> > index 7a3e9ab137d..c7e37ed2799 100644
> > --- a/security/smack/smack_lsm.c
> > +++ b/security/smack/smack_lsm.c
> > @@ -1463,10 +1463,19 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,
> >  	struct super_block *sbp;
> >  	struct inode *ip = inode;
> >  	struct smack_known *isp;
> > +	struct inode_smack *ispp;
> > +	size_t label_len;
> > +	char *label = NULL;
> >  
> > -	if (strcmp(name, XATTR_SMACK_SUFFIX) == 0)
> > +	if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
> >  		isp = smk_of_inode(inode);
> > -	else {
> > +	} else if (strcmp(name, XATTR_SMACK_TRANSMUTE) == 0) {
> > +		ispp = smack_inode(inode);
> > +		if (ispp->smk_flags & SMK_INODE_TRANSMUTE)
> > +			label = TRANS_TRUE;
> > +		else
> > +			label = "";
> > +	} else {
> >  		/*
> >  		 * The rest of the Smack xattrs are only on sockets.
> >  		 */
> > @@ -1488,13 +1497,18 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,
> >  			return -EOPNOTSUPP;
> >  	}
> >  
> > +	if (!label)
> > +		label = isp->smk_known;
> > +
> > +	label_len = strlen(label);
> > +
> >  	if (alloc) {
> > -		*buffer = kstrdup(isp->smk_known, GFP_KERNEL);
> > +		*buffer = kstrdup(label, GFP_KERNEL);
> >  		if (*buffer == NULL)
> >  			return -ENOMEM;
> >  	}
> >  
> > -	return strlen(isp->smk_known);
> > +	return label_len;
> >  }
> >  
> >  
>
diff mbox series

Patch

diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 7a3e9ab137d..c7e37ed2799 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1463,10 +1463,19 @@  static int smack_inode_getsecurity(struct mnt_idmap *idmap,
 	struct super_block *sbp;
 	struct inode *ip = inode;
 	struct smack_known *isp;
+	struct inode_smack *ispp;
+	size_t label_len;
+	char *label = NULL;
 
-	if (strcmp(name, XATTR_SMACK_SUFFIX) == 0)
+	if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
 		isp = smk_of_inode(inode);
-	else {
+	} else if (strcmp(name, XATTR_SMACK_TRANSMUTE) == 0) {
+		ispp = smack_inode(inode);
+		if (ispp->smk_flags & SMK_INODE_TRANSMUTE)
+			label = TRANS_TRUE;
+		else
+			label = "";
+	} else {
 		/*
 		 * The rest of the Smack xattrs are only on sockets.
 		 */
@@ -1488,13 +1497,18 @@  static int smack_inode_getsecurity(struct mnt_idmap *idmap,
 			return -EOPNOTSUPP;
 	}
 
+	if (!label)
+		label = isp->smk_known;
+
+	label_len = strlen(label);
+
 	if (alloc) {
-		*buffer = kstrdup(isp->smk_known, GFP_KERNEL);
+		*buffer = kstrdup(label, GFP_KERNEL);
 		if (*buffer == NULL)
 			return -ENOMEM;
 	}
 
-	return strlen(isp->smk_known);
+	return label_len;
 }