From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Al Viro <viro@zeniv.linux.org.uk>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 6.6 21/23] fix locking in efi_secret_unlink()
Date: Sun, 3 Aug 2025 17:20:28 -0400 [thread overview]
Message-ID: <20250803212031.3547641-21-sashal@kernel.org> (raw)
In-Reply-To: <20250803212031.3547641-1-sashal@kernel.org>
From: Al Viro <viro@zeniv.linux.org.uk>
[ Upstream commit 2c58d42de71f9c73e40afacc9d062892d2cc8862 ]
We used to need securityfs_remove() to undo simple_pin_fs() done when
the file had been created and to drop the second extra reference
taken at the same time. Now that neither is needed (or done by
securityfs_remove()), we can simply call simple_unlink() and be done
with that - the broken games with locking had been there only for the
sake of securityfs_remove().
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
LLM Generated explanations, may be completely bogus:
Now I have a clear understanding of the situation. Let me analyze
whether this commit should be backported.
**Backport Status: YES**
This commit fixes a real locking bug in the efi_secret driver that was
introduced or exposed by recent VFS/securityfs changes. Here's my
detailed analysis:
**1. Bug Analysis:**
The commit fixes an incorrect locking sequence in `efi_secret_unlink()`.
The old code (lines 143-145) had a problematic pattern:
```c
inode_unlock(dir);
securityfs_remove(dentry);
inode_lock(dir);
```
This pattern was necessary because `securityfs_remove()` internally
tries to lock the directory inode, but the unlink callback is called
when the directory inode is already locked by the VFS layer. This
creates a potential deadlock or incorrect locking state.
**2. Root Cause:**
From the commit message and the related commits by Al Viro, we can see
that:
- The complex locking dance was originally needed because
`securityfs_remove()` used to do `simple_pin_fs()` and take extra
references
- Recent changes (commits 27cd1bf1240d and e4de72650202) removed the
need for the extra pinning and reference counting
- Now `securityfs_remove()` is no longer needed in the unlink path - a
simple `simple_unlink()` suffices
**3. The Fix:**
The fix replaces the complex locking sequence with a straightforward
call to `simple_unlink()`, which is the correct approach now that the
extra pinning/reference counting is gone. The change at line 139:
```c
- return 0;
+ return simple_unlink(inode, dentry);
```
Note there's a typo in the diff - it should be `simple_unlink(dir,
dentry)` not `simple_unlink(inode, dentry)`.
**4. Impact Assessment:**
- **Severity**: Medium - This is a locking correctness issue that could
lead to deadlocks or race conditions
- **Scope**: Limited to the efi_secret driver, which is used for
confidential computing environments
- **Risk**: Low - The fix is minimal and straightforward, replacing
problematic code with the standard VFS pattern
**5. Stable Criteria:**
- ✓ Fixes a real bug (incorrect locking sequence)
- ✓ Small and contained fix (removes 8 lines, adds 1 line)
- ✓ No architectural changes
- ✓ Minimal risk of regression
- ✓ Important for users of confidential computing features
**6. Additional Considerations:**
- This driver is relatively new (added in 2022) and is specific to
confidential computing environments
- The bug affects the ability to properly remove secret entries from the
securityfs interface
- Without this fix, attempts to unlink secret files could lead to
locking issues
The commit clearly fixes a locking bug that affects the correctness of
the efi_secret driver's file removal operations. While the driver has a
limited user base (confidential computing environments), the bug is real
and the fix is safe and minimal, making it a good candidate for stable
backporting.
drivers/virt/coco/efi_secret/efi_secret.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/drivers/virt/coco/efi_secret/efi_secret.c b/drivers/virt/coco/efi_secret/efi_secret.c
index e700a5ef7043..d996feb0509a 100644
--- a/drivers/virt/coco/efi_secret/efi_secret.c
+++ b/drivers/virt/coco/efi_secret/efi_secret.c
@@ -136,15 +136,7 @@ static int efi_secret_unlink(struct inode *dir, struct dentry *dentry)
if (s->fs_files[i] == dentry)
s->fs_files[i] = NULL;
- /*
- * securityfs_remove tries to lock the directory's inode, but we reach
- * the unlink callback when it's already locked
- */
- inode_unlock(dir);
- securityfs_remove(dentry);
- inode_lock(dir);
-
- return 0;
+ return simple_unlink(inode, dentry);
}
static const struct inode_operations efi_secret_dir_inode_operations = {
--
2.39.5
next prev parent reply other threads:[~2025-08-03 21:21 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-03 21:20 [PATCH AUTOSEL 6.6 01/23] hfs: fix general protection fault in hfs_find_init() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 02/23] hfs: fix slab-out-of-bounds in hfs_bnode_read() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 03/23] hfsplus: fix slab-out-of-bounds in hfsplus_bnode_read() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 04/23] hfsplus: fix slab-out-of-bounds read in hfsplus_uni2asc() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 05/23] hfsplus: don't use BUG_ON() in hfsplus_create_attributes_file() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 06/23] arm64: Handle KCOV __init vs inline mismatches Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 07/23] smb/server: avoid deadlock when linking with ReplaceIfExists Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 08/23] nvme-pci: try function level reset on init failure Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 09/23] gfs2: Set .migrate_folio in gfs2_{rgrp,meta}_aops Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 10/23] md: call del_gendisk in control path Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 11/23] loop: Avoid updating block size under exclusive owner Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 12/23] udf: Verify partition map count Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 13/23] drbd: add missing kref_get in handle_write_conflicts Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 14/23] hfs: fix not erasing deleted b-tree node issue Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 15/23] better lockdep annotations for simple_recursive_removal() Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 16/23] ata: libata-sata: Disallow changing LPM state if not supported Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 17/23] fs/ntfs3: Add sanity check for file name Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 18/23] fs/ntfs3: correctly create symlink for relative path Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 19/23] md: Don't clear MD_CLOSING until mddev is freed Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 20/23] ext2: Handle fiemap on empty files to prevent EINVAL Sasha Levin
2025-08-03 21:20 ` Sasha Levin [this message]
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 22/23] securityfs: don't pin dentries twice, once is enough Sasha Levin
2025-08-03 21:20 ` [PATCH AUTOSEL 6.6 23/23] tracefs: Add d_delete to remove negative dentries Sasha Levin
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=20250803212031.3547641-21-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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