summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-03-04 19:59:14 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-03-05 16:28:05 +0100
commit4378835b3730d778bbc5bb7916bb076accddbb03 (patch)
tree66bbf01563babb4ead00404bb08f0d1cc98ff112
parent582d3b8bd764a043a05377481db7afa0f9589b54 (diff)
downloadbarebox-4378835b3730.tar.gz
barebox-4378835b3730.tar.xz
fs: opendir: reference mount point until closedir is called
We currently don't keep the path used for opendir alive beyond the function, because all files are read and added into a linked list at once. If an unmount happens before closedir though, the file names will become invalidated, which shouldn't happen. Keep the path alive for longer to block unmount until directory iteration is over. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-30-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--fs/fs.c4
-rw-r--r--include/dirent.h2
2 files changed, 4 insertions, 2 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 7d9bee539d..a31343e2e2 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2757,6 +2757,7 @@ DIR *opendir(const char *pathname)
file.f_op = dir->d_inode->i_fop;
d = xzalloc(sizeof(*d));
+ d->path = path;
INIT_LIST_HEAD(&d->entries);
rd.dir = d;
@@ -2765,8 +2766,6 @@ DIR *opendir(const char *pathname)
if (ret)
goto out_release;
- path_put(&path);
-
return d;
out_release:
@@ -2785,6 +2784,7 @@ int closedir(DIR *dir)
if (!dir)
return errno_set(-EBADF);
+ path_put(&dir->path);
release_dir(dir);
return 0;
diff --git a/include/dirent.h b/include/dirent.h
index 75627730f8..6e77058d29 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -3,6 +3,7 @@
#define __DIRENT_H
#include <linux/list.h>
+#include <linux/path.h>
struct dirent {
char d_name[256];
@@ -13,6 +14,7 @@ typedef struct dir {
struct fs_driver *fsdrv;
struct dirent d;
void *priv; /* private data for the fs driver */
+ struct path path;
struct list_head entries;
} DIR;