All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH] smack: preserve low-integrity labels across file copy via whitelist
Date: Wed, 30 Sep 2026 03:14:24 +0000	[thread overview]
Message-ID: <20260930031424.73B181F000FF@smtp.kernel.org> (raw)
In-Reply-To: <9EAFC73B591799F5+20260930030425.496501-1-tangpengke@yhkylin.cn>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] security/smack: TOCTOU race in smack_inode_init_security() causes NULL deref
- [High] security/smack: lockless mutation of shared cred in smack_file_open()
- [High] security/smack: caching file labels on task creds mislabels unrelated files
- [Medium] security/smack: smk_preserve state leaks during label transmutation
--

commit 6dde1ac3f8846672b424ea2f203f58b7b5b2f900
Author: Tang Pengke <tangpengke@yhkylin.cn>
smack: preserve low-integrity labels across file copy via whitelist

This commit introduces a mechanism to preserve low-integrity Smack labels
across file copies by temporarily storing a whitelisted label in the
task's Smack credential during file open. This label is then inherited by
the next inode created by the task.

> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c

[ ... ]

> @@ -1066,6 +1073,19 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
>  		}
>  	}
>  
> +#ifdef CONFIG_SECURITY_SMACK_COPYWHITELIST
> +	/*
> +	 * If a whitelisted label was recorded on file open and no
> +	 * transmutation applies, inherit it so the new file keeps the
> +	 * source's (low-integrity) label across the copy.
> +	 */
> +	if (!trans_cred && tsp->smk_preserve != NULL &&
> +	    !(trans_rule && smk_inode_transmutable(dir))) {

[Severity: Medium]
If transmutation applies, the condition checking smk_inode_transmutable(dir)
evaluates to false and this block is skipped.

Because tsp->smk_preserve is not cleared in that path, will the untrusted
label leak and inadvertently taint the next unrelated file created in a
non-transmutable directory?

> +		issp->smk_inode = tsp->smk_preserve;
> +		tsp->smk_preserve = NULL;

[Severity: Critical]
Could a time-of-check to time-of-use race occur here if the task credential
is shared among multiple threads?

If thread A and thread B both enter smack_inode_init_security() concurrently,
could thread B clear tsp->smk_preserve right after thread A checks it for
non-null, causing thread A to assign a null pointer to issp->smk_inode? 

This appears to lead to a kernel panic when issp->smk_inode->smk_known is
subsequently passed to strlen() a few lines below.

> +	}
> +#endif
> +

[ ... ]

> @@ -2068,6 +2088,39 @@ static int smack_file_open(struct file *file)
>  	smk_ad_setfield_u_fs_path(&ad, file->f_path);
>  	rc = smk_tskacc(tsp, smk_of_inode(inode), MAY_READ, &ad);
>  	rc = smk_bu_credfile(file->f_cred, file, MAY_READ, rc);
> +	if (rc)
> +		return rc;
> +
> +#ifdef CONFIG_SECURITY_SMACK_COPYWHITELIST

[ ... ]

> +	if (!list_empty(&smk_preserve_wl) &&
> +	    (file->f_flags & O_ACCMODE) == O_RDONLY &&
> +	    S_ISREG(inode->i_mode)) {
> +		struct smack_known *skp = smk_of_inode(inode);
> +
> +		if (smk_preserve_allowed(skp))
> +			tsp->smk_preserve = skp;

[Severity: High]
Is it safe to locklessly mutate a live, committed, and potentially shared
cred structure here? 

Since credentials can be shared between threads via clone flags, mutating
tsp->smk_preserve without synchronization might result in data races. Standard
kernel patterns generally treat cred structures as immutable after
commit_creds() is called.

[Severity: High]
Does latching the file's label onto the task simply because a file was read
risk mislabeling unrelated files during subsequent creations? 

For example, if a program reads a whitelisted file and subsequently creates
a completely unrelated temporary file, it seems the unrelated file will
erroneously inherit the whitelisted label in smack_inode_init_security().

> +	}
> +#endif
>  
>  	return rc;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/9EAFC73B591799F5+20260930030425.496501-1-tangpengke@yhkylin.cn?part=1

      reply	other threads:[~2026-09-30  3:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30  3:04 [PATCH] smack: preserve low-integrity labels across file copy via whitelist Tang Pengke
2026-09-30  3:14 ` sashiko-bot [this message]

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=20260930031424.73B181F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.