From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: sha@pengutronix.de, Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master] fs: fix file creation by not pointing file dentry at parent dir
Date: Tue, 24 Jun 2025 17:21:48 +0200 [thread overview]
Message-ID: <20250624152148.2230298-1-a.fatoum@pengutronix.de> (raw)
A last-minute regression fix to allow unmounting file systems in some
situations unfortunately introduced a regression of its own:
Creating new files with O_CREAT associated a file descriptor's struct
file with the dentry of the parent directory instead of the dentry
of the newly created file.
Opening already existing files worked fine though, leading to e.g.
problems when saving a fresh environment to a directory:
barebox@TI AM335x BeagleBone black:/ rm /mnt/mmc0.0/barebox.env
barebox@TI AM335x BeagleBone black:/ saveenv
saving environment to /mnt/mmc0.0/barebox.env
could not open /mnt/mmc0.0/barebox.env: Invalid argument
saveenv: Invalid argument
barebox@TI AM335x BeagleBone black:/ saveenv
saving environment to /mnt/mmc0.0/barebox.env
Opening existing files did not regress, because filename_lookup stores
the dentry of the actual file, unlike filename_create, which stores the
dentry of the parent directory.
Fixes: a3ef153fdf26 ("fs: unreference path on file close")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
I noticed this with saveenv to FAT, because FAT doesn't like opening /,
but I could imagine other subtle errors creeping up elsewhere.
I think a v2025.06.1 may be in order..
---
fs/fs.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index 8689e14e68ef..4a500bbdd9da 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2604,6 +2604,12 @@ int openat(int dirfd, const char *pathname, int flags)
error = create(path.dentry, dentry);
if (error)
goto out1;
+ /* repoint path.dentry from parent to newly created entry.
+ * path.mnt already points at the correct vfsmount, even
+ * for a dirfd of the root directory, so that's fine.
+ */
+ dput(path.dentry);
+ path.dentry = dentry;
} else {
dput(dentry);
error = -ENOENT;
--
2.39.5
reply other threads:[~2025-06-24 19:55 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20250624152148.2230298-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=sha@pengutronix.de \
/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