linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huaweicloud.com>
To: Konstantin Andreev <andreev@swemel.ru>,
	Casey Schaufler <casey@schaufler-ca.com>
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH 2/5] smack: fix bug: SMACK64TRANSMUTE set on non-directory
Date: Mon, 16 Jun 2025 10:42:16 +0200	[thread overview]
Message-ID: <c9d0b5e758a3dcf7e5aed7ca597ecec02c72dc52.camel@huaweicloud.com> (raw)
In-Reply-To: <20250616010745.800386-3-andreev@swemel.ru>

On Mon, 2025-06-16 at 04:07 +0300, Konstantin Andreev wrote:
> When a new file system object is created
> and the conditions for label transmutation are met,
> the SMACK64TRANSMUTE extended attribute is set
> on the object regardless of its type:
> file, pipe, socket, symlink, or directory.
> 
> However,
> SMACK64TRANSMUTE may only be set on directories.
> 
> This bug is a combined effect of the commits [1] and [2]
> which both transfer functionality
> from smack_d_instantiate() to smack_inode_init_security(),
> but only in part.
> 
> Commit [1] set blank  SMACK64TRANSMUTE on improper object types.

Hi Konstantin

I didn't see where, can you point where it is done?

> Commit [2] set "TRUE" SMACK64TRANSMUTE on improper object types.
> 
> [1] 2023-06-10,
> Fixes: baed456a6a2f ("smack: Set the SMACK64TRANSMUTE xattr in smack_inode_init_security()")
> Link: https://lore.kernel.org/linux-security-module/20230610075738.3273764-3-roberto.sassu@huaweicloud.com/
> 
> [2] 2023-11-16,
> Fixes: e63d86b8b764 ("smack: Initialize the in-memory inode in smack_inode_init_security()")
> Link: https://lore.kernel.org/linux-security-module/20231116090125.187209-5-roberto.sassu@huaweicloud.com/
> 
> Signed-off-by: Konstantin Andreev <andreev@swemel.ru>
> ---
>  security/smack/smack_lsm.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index a7292d286f7c..2d3186e50c62 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -1028,18 +1028,20 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
>  		if (!trans_cred)
>  			issp->smk_inode = dsp;
>  
> -		issp->smk_flags |= SMK_INODE_TRANSMUTE;
> -		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;

To avoid having another indentation, you could also set xattr_transmute
to NULL initially, and call lsm_get_xattr_slot() only for directories.
Setting SMK_INODE_TRANSMUTE in issp->smk_flags should be done of course
if xattr_transmute != NULL.

Either way is fine for me.

Roberto

> +		if (S_ISDIR(inode->i_mode)) {
> +			issp->smk_flags |= SMK_INODE_TRANSMUTE;
> +			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_transmute->value_len = TRANS_TRUE_SIZE;
> +				xattr_transmute->name = XATTR_SMACK_TRANSMUTE;
> +			}
>  		}
>  	}
>  


  reply	other threads:[~2025-06-16  8:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16  1:07 [PATCH 0/5] smack: fix bugs: invalid unix socket label, invalid transmute attr Konstantin Andreev
2025-06-16  1:07 ` [PATCH 1/5] smack: deduplicate "does access rule request transmutation" Konstantin Andreev
2025-06-16  1:07 ` [PATCH 2/5] smack: fix bug: SMACK64TRANSMUTE set on non-directory Konstantin Andreev
2025-06-16  8:42   ` Roberto Sassu [this message]
2025-06-16 11:25     ` Re[2]: " Konstantin Andreev
2025-06-16  1:07 ` [PATCH 3/5] smack: deduplicate xattr setting in smack_inode_init_security() Konstantin Andreev
2025-06-16  8:47   ` Roberto Sassu
2025-06-16  1:07 ` [PATCH 4/5] smack: always "instantiate" inode " Konstantin Andreev
2025-06-16  1:07 ` [PATCH 5/5] smack: fix bug: invalid label of unix socket file Konstantin Andreev
2025-06-16  9:05   ` Roberto Sassu
2025-06-16 11:46     ` Re[2]: " Konstantin Andreev
2025-06-16 17:11       ` Casey Schaufler
2025-06-16 17:53         ` Re[4]: " Konstantin Andreev
2025-06-16 18:36           ` Casey Schaufler
2025-06-23 17:09 ` [PATCH 0/5] smack: fix bugs: invalid unix socket label, invalid transmute attr Casey Schaufler

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=c9d0b5e758a3dcf7e5aed7ca597ecec02c72dc52.camel@huaweicloud.com \
    --to=roberto.sassu@huaweicloud.com \
    --cc=andreev@swemel.ru \
    --cc=casey@schaufler-ca.com \
    --cc=linux-security-module@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).