From: sashiko-bot@kernel.org
To: "Cai Xinchen" <caixinchen1@huawei.com>
Cc: selinux@vger.kernel.org, bpf@vger.kernel.org
Subject: Re: [PATCH v2 stable/linux-6.18.y 1/2] lsm: add backing_file LSM hooks
Date: Fri, 26 Jun 2026 07:33:36 +0000 [thread overview]
Message-ID: <20260626073336.EFD191F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260626075035.143419-2-caixinchen1@huawei.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The error path in alloc_empty_backing_file() triggers a double execution of the backing_file_free LSM hooks with a NULL security blob, violating the LSM API contract.
--
commit 5c2fdae294837ef2192abffb715e055fefb686b4
Author: Paul Moore <paul@paul-moore.com>
lsm: add backing_file LSM hooks
This commit adds a security blob to the backing_file struct and new LSM hooks
(security_backing_file_alloc, security_backing_file_free, and
security_mmap_backing_file). This provides the necessary mechanisms for LSMs
to enforce access controls on the mmap() and mprotect() operations in stacked
filesystems.
> diff --git a/fs/file_table.c b/fs/file_table.c
> index 762f03dcbcd77..987e01da99389 100644
> --- a/fs/file_table.c
> +++ b/fs/file_table.c
[ ... ]
> @@ -318,7 +337,7 @@ struct file *alloc_empty_backing_file(int flags, const struct cred *cred)
>
> /* The f_mode flags must be set before fput(). */
> ff->file.f_mode |= FMODE_BACKING | FMODE_NOACCOUNT;
> - error = init_backing_file(ff);
> + error = init_backing_file(ff, user_file);
> if (unlikely(error)) {
> fput(&ff->file);
> return ERR_PTR(error);
> }
[ ... ]
> diff --git a/security/security.c b/security/security.c
> index 603c3c6d5635d..9285909908ab8 100644
> --- a/security/security.c
> +++ b/security/security.c
[ ... ]
> @@ -2965,6 +2997,57 @@ void security_file_free(struct file *file)
> }
> }
>
> +/**
> + * security_backing_file_alloc() - Allocate and setup a backing file blob
> + * @backing_file: the backing file
> + * @user_file: the associated user visible file
> + *
> + * Allocate a backing file LSM blob and perform any necessary initialization of
> + * the LSM blob. There will be some operations where the LSM will not have
> + * access to @user_file after this point, so any important state associated
> + * with @user_file that is important to the LSM should be captured in the
> + * backing file's LSM blob.
> + *
> + * LSM's should avoid taking a reference to @user_file in this hook as it will
> + * result in problems later when the system attempts to drop/put the file
> + * references due to a circular dependency.
> + *
> + * Return: Return 0 if the hook is successful, negative values otherwise.
> + */
> +int security_backing_file_alloc(struct file *backing_file,
> + const struct file *user_file)
> +{
> + int rc;
> +
> + rc = lsm_backing_file_alloc(backing_file);
> + if (rc)
> + return rc;
> + rc = call_int_hook(backing_file_alloc, backing_file, user_file);
> + if (unlikely(rc))
> + security_backing_file_free(backing_file);
[Severity: Medium]
Does this error path lead to a double execution of the free hooks?
If call_int_hook() fails, security_backing_file_alloc() cleans up by calling
security_backing_file_free().
The error then propagates back to init_backing_file(), and then to
alloc_empty_backing_file(), which calls fput() on the error path.
The fput() call initiates the VFS teardown path, which eventually calls
backing_file_free() and executes security_backing_file_free() for a second
time.
Similarly, if lsm_backing_file_alloc() fails with -ENOMEM, it returns an error
without calling any hooks, but the subsequent fput() will still execute the
free hook without the alloc hook ever running.
> +
> + return rc;
> +}
> +
> +/**
> + * security_backing_file_free() - Free a backing file blob
> + * @backing_file: the backing file
> + *
> + * Free any LSM state associate with a backing file's LSM blob, including the
> + * blob itself.
> + */
> +void security_backing_file_free(struct file *backing_file)
> +{
> + void *blob = backing_file_security(backing_file);
> +
> + call_void_hook(backing_file_free, backing_file);
Because call_void_hook() is executed unconditionally even if blob is NULL,
could this cause state corruption for BPF LSM programs tracking file lifecycles,
or a NULL pointer dereference in future LSMs implementing the free hook?
> +
> + if (blob) {
> + backing_file_set_security(backing_file, NULL);
> + kmem_cache_free(lsm_backing_file_cache, blob);
> + }
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260626075035.143419-1-caixinchen1@huawei.com?part=1
next prev parent reply other threads:[~2026-06-26 7:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-26 7:50 [PATCH v2 stable/linux-6.18.y 0/2] Backport Fix incorrect overlayfs mmap() and mprotect() LSM access controls Cai Xinchen
2026-06-26 7:50 ` [PATCH v2 stable/linux-6.18.y 1/2] lsm: add backing_file LSM hooks Cai Xinchen
2026-06-26 7:33 ` sashiko-bot [this message]
2026-06-26 7:50 ` [PATCH v2 stable/linux-6.18.y 2/2] selinux: fix overlayfs mmap() and mprotect() access checks Cai Xinchen
2026-06-26 7:31 ` sashiko-bot
2026-06-26 17:54 ` [PATCH v2 stable/linux-6.18.y 0/2] Backport Fix incorrect overlayfs mmap() and mprotect() LSM access controls Sasha Levin
-- strict thread matches above, loose matches on Subject: below --
2026-06-26 2:40 Cai Xinchen
2026-06-26 2:40 ` [PATCH v2 stable/linux-6.18.y 1/2] lsm: add backing_file LSM hooks Cai Xinchen
2026-06-26 2:27 ` sashiko-bot
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=20260626073336.EFD191F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=caixinchen1@huawei.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=selinux@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