mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master] fs: fix file creation by not pointing file dentry at parent dir
@ 2025-06-24 15:21 Ahmad Fatoum
  0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2025-06-24 15:21 UTC (permalink / raw)
  To: barebox; +Cc: sha, Ahmad Fatoum

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




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-06-24 19:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-24 15:21 [PATCH master] fs: fix file creation by not pointing file dentry at parent dir Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox