* [PATCH 01/13] fs: ramfs: zero the rest of a chunk when truncating
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:51 ` [PATCH 02/13] fs: fat: zero-fill files grown by truncate Sascha Hauer
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
Shrinking a file only frees the chunks entirely beyond the new size. The
chunk the new end falls into keeps its old contents past it, and as
growing the file again doesn't allocate anything as long as the chunks
are big enough, it brings them back:
write 10000 bytes, ftruncate(3000), ftruncate(6000)
-> bytes 3000..5999 hold the old data instead of zeroes
Newly allocated chunks are zeroed, so clear the remainder of the chunk
when shrinking to keep everything beyond the end of a file zero.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/ramfs.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/ramfs.c b/fs/ramfs.c
index d86bf6144e..0df4af5294 100644
--- a/fs/ramfs.c
+++ b/fs/ramfs.c
@@ -311,6 +311,14 @@ static void ramfs_truncate_down(struct ramfs_inode *node, unsigned long size)
list_del(&data->list);
node->alloc_size -= data->size;
ramfs_put_chunk(data);
+ } else if (data->ofs + data->size > size) {
+ /*
+ * Growing the file again reuses the rest of this
+ * chunk, which must read back as zeroes then, like
+ * newly allocated chunks do.
+ */
+ memset(data->data + size - data->ofs, 0,
+ data->ofs + data->size - size);
}
}
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 02/13] fs: fat: zero-fill files grown by truncate
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
2026-11-18 14:51 ` [PATCH 01/13] fs: ramfs: zero the rest of a chunk when truncating Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:51 ` [PATCH 03/13] fs: keep the file size when O_TRUNC fails Sascha Hauer
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
fat_truncate() grows a file by seeking beyond its end, which makes FatFs
extend the cluster chain without clearing anything. Whatever the newly
allocated clusters held before, e.g. the contents of deleted files, and
whatever followed the old end in its last cluster, e.g. data cut off by
an earlier truncate, becomes part of the file:
write 10000 bytes, ftruncate(3000), ftruncate(6000)
-> bytes 3000..5999 hold the old data instead of zeroes
Grow files by writing zeroes from the old end instead. The VFS extends a
file by truncating it before writing beyond its end, so this also fills
the hole such a write leaves with zeroes.
Fixes: 17e91068b1 ("fs: add fat filesystem support")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fat/fat.c | 46 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 40 insertions(+), 6 deletions(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index b6f9fd8fe5..1c5aa257b4 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -159,6 +159,34 @@ static int fat_write(struct file *f, const void *buf, size_t insize)
return outsize;
}
+/*
+ * Grow @f_file to @size bytes. Seeking past the end would extend the file as
+ * well, but leave whatever the newly allocated clusters and the rest of the
+ * last one held before, so write zeroes instead.
+ */
+static int fat_extend(FIL *f_file, loff_t size)
+{
+ static const u8 zeroes[SZ_4K];
+ UINT now, written;
+ int ret;
+
+ ret = f_lseek(f_file, f_file->fsize);
+ if (ret)
+ return ret;
+
+ while (f_file->fsize < size) {
+ now = min_t(loff_t, size - f_file->fsize, sizeof(zeroes));
+
+ ret = f_write(f_file, zeroes, now, &written);
+ if (ret)
+ return ret;
+ if (written != now)
+ return -ENOSPC;
+ }
+
+ return 0;
+}
+
static int fat_truncate(struct file *f, loff_t size)
{
FIL *f_file = f->private_data;
@@ -171,13 +199,19 @@ static int fat_truncate(struct file *f, loff_t size)
lastofs = f_file->fptr;
- ret = f_lseek(f_file, size);
- if (ret)
- return ret;
+ if (size > f_file->fsize) {
+ ret = fat_extend(f_file, size);
+ if (ret)
+ return ret;
+ } else {
+ ret = f_lseek(f_file, size);
+ if (ret)
+ return ret;
- ret = f_truncate(f_file);
- if (ret)
- return ret;
+ ret = f_truncate(f_file);
+ if (ret)
+ return ret;
+ }
/* don't extend the file again in case it was shrunk */
ret = f_lseek(f_file, min_t(loff_t, lastofs, size));
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 03/13] fs: keep the file size when O_TRUNC fails
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
2026-11-18 14:51 ` [PATCH 01/13] fs: ramfs: zero the rest of a chunk when truncating Sascha Hauer
2026-11-18 14:51 ` [PATCH 02/13] fs: fat: zero-fill files grown by truncate Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:51 ` [PATCH 04/13] fs: legacy: return -EPERM when a driver can't create symlinks Sascha Hauer
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
do_dentry_open() sets the file size to zero for O_TRUNC before checking
whether truncating the file worked. f_size is the size of the inode, so
when it fails, e.g. on a read-only file system, the file stays intact
on the medium, but appears empty until it's evicted from the cache:
open("file", O_WRONLY | O_TRUNC) -> -EROFS
stat("file") -> st_size 0
read() -> 0
Only set the size once truncating succeeded.
Fixes: 7d91d56436 ("fs: replace FILE.size by f_inode.i_size")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/fs.c b/fs/fs.c
index e05d3b7a4a..88969fc287 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2736,9 +2736,9 @@ static int do_dentry_open(struct file *f)
if (f->f_flags & O_TRUNC) {
error = fsdev_truncate(f, 0);
- f->f_size = 0;
if (error)
goto err_release;
+ f->f_size = 0;
}
if (f->f_flags & O_APPEND)
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 04/13] fs: legacy: return -EPERM when a driver can't create symlinks
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (2 preceding siblings ...)
2026-11-18 14:51 ` [PATCH 03/13] fs: keep the file size when O_TRUNC fails Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:51 ` [PATCH 05/13] fs: uimagefs: allow opening a file more than once Sascha Hauer
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
The VFS returns -EPERM from symlink() when a file system has no symlink
operation, like Linux. The legacy layer has one for all file systems
using it and returns -ENOSYS from it instead when the driver can't
create symlinks, so the error depends on which API a file system
happens to use. Return -EPERM there as well.
Fixes: b3fbfad7ae ("fs: dentry cache implementation")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/legacy.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/legacy.c b/fs/legacy.c
index 5344737fa6..d90232623e 100644
--- a/fs/legacy.c
+++ b/fs/legacy.c
@@ -257,8 +257,9 @@ static int legacy_symlink(struct inode *dir, struct dentry *dentry,
char *pathname;
int ret;
+ /* like the VFS does when a file system can't create symlinks */
if (!legacy_ops->symlink)
- return -ENOSYS;
+ return -EPERM;
pathname = dpath(dentry, fsdev->vfsmount.mnt_root);
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 05/13] fs: uimagefs: allow opening a file more than once
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (3 preceding siblings ...)
2026-11-18 14:51 ` [PATCH 04/13] fs: legacy: return -EPERM when a driver can't create symlinks Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:51 ` [PATCH 06/13] fs: nfs: drop the write and truncate stubs Sascha Hauer
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
uimagefs keeps the descriptor of the uImage a data file is read from in
the uimagefs_handle_data of that file, which all opens of the file
share. Opening it a second time overwrites the descriptor of the first,
which is leaked, and closing either closes the one the other reads
from:
fd1 = open("data0"); fd2 = open("data0");
close(fd1);
read(fd2) -> -EBADF
Keep the descriptor in a structure of its own for each open file.
Fixes: 12158a28d4 ("fs: add uimagefs")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/uimagefs.c | 36 ++++++++++++++++++++++++++++--------
include/uimagefs.h | 1 -
2 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/fs/uimagefs.c b/fs/uimagefs.c
index b805b357ac..52dc7182ef 100644
--- a/fs/uimagefs.c
+++ b/fs/uimagefs.c
@@ -68,10 +68,18 @@ static struct uimagefs_handle_data *uimagefs_get_by_name(
return NULL;
}
+/* an open file, the same one can be open more than once */
+struct uimagefs_file {
+ struct uimagefs_handle_data *d;
+ /* the uImage for data files, -1 otherwise */
+ int fd;
+};
+
static int uimagefs_open(struct device *dev, struct file *file, const char *filename)
{
struct uimagefs_handle *priv = dev->priv;
struct uimagefs_handle_data *d;
+ struct uimagefs_file *uf;
if (filename[0] == '/')
filename++;
@@ -80,36 +88,48 @@ static int uimagefs_open(struct device *dev, struct file *file, const char *file
if (!d)
return -EINVAL;
+ uf = xzalloc(sizeof(*uf));
+ uf->d = d;
+ uf->fd = -1;
+
if (uimagefs_is_data_file(d)) {
- d->fd = open(priv->filename, O_RDONLY);
- if (d->fd < 0)
- return d->fd;
+ uf->fd = open(priv->filename, O_RDONLY);
+ if (uf->fd < 0) {
+ int ret = uf->fd;
+
+ free(uf);
+ return ret;
+ }
}
file->f_size = d->size;
- file->private_data = d;
+ file->private_data = uf;
return 0;
}
static int uimagefs_close(struct device *dev, struct file *file)
{
- struct uimagefs_handle_data *d = file->private_data;
+ struct uimagefs_file *uf = file->private_data;
+
+ if (uf->fd >= 0)
+ close(uf->fd);
- close(d->fd);
+ free(uf);
return 0;
}
static int uimagefs_read(struct file *file, void *buf, size_t insize)
{
- struct uimagefs_handle_data *d = file->private_data;
+ struct uimagefs_file *uf = file->private_data;
+ struct uimagefs_handle_data *d = uf->d;
if (!uimagefs_is_data_file(d)) {
memcpy(buf, &d->data[file->f_pos], insize);
return insize;
} else {
- return pread(d->fd, buf, insize, d->offset + file->f_pos);
+ return pread(uf->fd, buf, insize, d->offset + file->f_pos);
}
}
diff --git a/include/uimagefs.h b/include/uimagefs.h
index 6b34982e4e..88cc84b634 100644
--- a/include/uimagefs.h
+++ b/include/uimagefs.h
@@ -31,7 +31,6 @@ struct uimagefs_handle_data {
enum uimagefs_type type;
uint64_t size;
- int fd;
size_t offset; /* offset in the image */
size_t pos; /* pos in the data */
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 06/13] fs: nfs: drop the write and truncate stubs
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (4 preceding siblings ...)
2026-11-18 14:51 ` [PATCH 05/13] fs: uimagefs: allow opening a file more than once Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:51 ` [PATCH 07/13] fs: fat: fix building without CONFIG_FS_FAT_LFN Sascha Hauer
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
The NFS client can't write, but has write and truncate operations that
only return -ENOSYS. That makes it the only read-only file system that
fails to truncate a file with -ENOSYS rather than with -EROFS, which the
VFS returns when there is no truncate operation, e.g. when opening a file
with O_TRUNC:
open("/mnt/nfs/file", O_WRONLY | O_TRUNC) -> -ENOSYS
Drop both stubs. The VFS then fails writes with -EBADF and truncating
with -EROFS, like for other file systems that can't write.
Fixes: 9ede56ad24 ("fs: Add NFS support")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/nfs.c | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/fs/nfs.c b/fs/nfs.c
index 7a859a718b..496dd742ae 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -1245,11 +1245,6 @@ static void nfs_handler(void *ctx, char *p, unsigned len)
list_add_tail(&packet->list, &npriv->packets);
}
-static int nfs_truncate(struct file *f, loff_t size)
-{
- return -ENOSYS;
-}
-
static void nfs_do_close(struct file_priv *priv)
{
if (priv->fifo)
@@ -1386,11 +1381,6 @@ static int nfs_close(struct inode *inode, struct file *file)
return 0;
}
-static int nfs_write(struct file *file, const void *inbuf, size_t insize)
-{
- return -ENOSYS;
-}
-
static int nfs_read(struct file *file, void *buf, size_t insize)
{
struct file_priv *priv = file->private_data;
@@ -1543,8 +1533,6 @@ static const struct file_operations nfs_file_operations = {
.release = nfs_close,
.read = nfs_read,
.lseek = nfs_lseek,
- .write = nfs_write,
- .truncate = nfs_truncate,
};
static const struct inode_operations nfs_symlink_inode_operations = {
.get_link = nfs_get_link,
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 07/13] fs: fat: fix building without CONFIG_FS_FAT_LFN
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (5 preceding siblings ...)
2026-11-18 14:51 ` [PATCH 06/13] fs: nfs: drop the write and truncate stubs Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:51 ` [PATCH 08/13] fs: bpkfs: skip the data of ignored duplicates Sascha Hauer
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
FILINFO only has the lfname and lfsize fields with long file name
support, so the FAT fuzz test, which sets them depending on
IS_ENABLED(CONFIG_FS_FAT_LFN), breaks building FAT without it:
fs/fat/fat.c: error: 'FILINFO' has no member named 'lfname'
Use #ifdef like the rest of the driver does.
Fixes: f585092b1737 ("fs: fat: add fuzz test for FAT filesystem")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/fat/fat.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 1c5aa257b4..f413c1cd8f 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -454,7 +454,9 @@ static int fuzz_fat(struct block_device *ramdisk)
BYTE buf[512];
UINT br;
int ret, i;
+#ifdef CONFIG_FS_FAT_LFN
char lfname[256];
+#endif
priv.cdev = &ramdisk->cdev;
fat.userdata = &priv;
@@ -475,10 +477,11 @@ static int fuzz_fat(struct block_device *ramdisk)
for (i = 0; i < 64; i++) {
memset(&finfo, 0, sizeof(finfo));
- if (IS_ENABLED(CONFIG_FS_FAT_LFN)) {
- finfo.lfname = lfname;
- finfo.lfsize = sizeof(lfname);
- }
+#ifdef CONFIG_FS_FAT_LFN
+ /* FILINFO only has the fields for long names with LFN */
+ finfo.lfname = lfname;
+ finfo.lfsize = sizeof(lfname);
+#endif
ret = f_readdir(&dir, &finfo);
if (ret || finfo.fname[0] == '\0')
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 08/13] fs: bpkfs: skip the data of ignored duplicates
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (6 preceding siblings ...)
2026-11-18 14:51 ` [PATCH 07/13] fs: fat: fix building without CONFIG_FS_FAT_LFN Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:51 ` [PATCH 09/13] fs: bpkfs: allow opening a file more than once Sascha Hauer
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
When a package holds the same type of image for the same hardware ID
more than once, bpkfs ignores all but the first. It forgets to seek
past the data of the ignored one though, so it reads the next data
header from that data instead, and mounting the package fails:
bpkfs bpkfs0: ignore data 3 type kernel already present, ignored
ERROR: bpkfs bpkfs0: could not seek: Invalid argument
Seek past the data before checking for duplicates, and free the name
of an ignored one, which leaked.
Fixes: 2f677b9b1ed5 ("fs: add BPKFS support")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/bpkfs.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/fs/bpkfs.c b/fs/bpkfs.c
index 7908b13175..62d0229f8e 100644
--- a/fs/bpkfs.c
+++ b/fs/bpkfs.c
@@ -438,9 +438,19 @@ static int bpkfs_probe(struct device *dev)
offset += d->size;
size -= d->size;
+ /* to the next data header, also behind data that is ignored */
+ if (lseek(fd, d->size, SEEK_CUR) < 0) {
+ dev_err(dev, "could not seek: %m\n");
+ ret = -errno;
+ free(d->name);
+ free(d);
+ goto err;
+ }
+
if (bpkfs_get_by_type(priv, d->hw_id, d->type)) {
dev_info(dev, "ignore data %d type %s already present, ignored\n",
i, type);
+ free(d->name);
free(d);
continue;
}
@@ -448,12 +458,6 @@ static int bpkfs_probe(struct device *dev)
list_add_tail(&d->list, &h->list_data);
priv->nb_data_entries++;
- if (lseek(fd, d->size, SEEK_CUR) < 0) {
- dev_err(dev, "could not seek: %m\n");
- ret = -errno;
- goto err;
- }
-
type = d->name;
d = xzalloc(sizeof(*d));
d->type = be32_to_cpu(data_header.type);
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 09/13] fs: bpkfs: allow opening a file more than once
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (7 preceding siblings ...)
2026-11-18 14:51 ` [PATCH 08/13] fs: bpkfs: skip the data of ignored duplicates Sascha Hauer
@ 2026-11-18 14:51 ` Sascha Hauer
2026-11-18 14:52 ` [PATCH 10/13] fs: bpkfs: make room for the NUL after the checksum string Sascha Hauer
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:51 UTC (permalink / raw)
To: BAREBOX
bpkfs keeps the descriptor of the package a data file is read from in
the bpkfs_handle_data of that file, which all opens of the file share.
Opening it a second time overwrites the descriptor of the first, which
is leaked, and closing either closes the one the other reads from:
fd1 = open("hw_id_1/kernel"); fd2 = open("hw_id_1/kernel");
close(fd1);
read(fd2) -> -EBADF
Keep the descriptor in a structure of its own for each open file, as
uimagefs does.
Fixes: 2f677b9b1ed5 ("fs: add BPKFS support")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/bpkfs.c | 33 +++++++++++++++++++++++++--------
include/bpkfs.h | 1 -
2 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/fs/bpkfs.c b/fs/bpkfs.c
index 62d0229f8e..eabba22cce 100644
--- a/fs/bpkfs.c
+++ b/fs/bpkfs.c
@@ -127,11 +127,19 @@ static struct bpkfs_handle_data *bpkfs_get_by_type(
return NULL;
}
+/* an open file, the same one can be open more than once */
+struct bpkfs_file {
+ struct bpkfs_handle_data *d;
+ /* the package for data files, -1 otherwise */
+ int fd;
+};
+
static int bpkfs_open(struct device *dev, struct file *f, const char *filename)
{
struct bpkfs_handle *priv = dev->priv;
struct bpkfs_handle_data *d;
struct bpkfs_handle_hw *h;
+ struct bpkfs_file *bf;
const char *dir, *file;
int ret = -EINVAL;
char *tmp = xstrdup(filename);
@@ -151,16 +159,21 @@ static int bpkfs_open(struct device *dev, struct file *f, const char *filename)
if (!d)
goto out;
+ bf = xzalloc(sizeof(*bf));
+ bf->d = d;
+ bf->fd = -1;
+
if (!bpkfs_is_crc_file(d)) {
- d->fd = open(priv->filename, O_RDONLY);
- if (d->fd < 0) {
- ret = d->fd;
+ bf->fd = open(priv->filename, O_RDONLY);
+ if (bf->fd < 0) {
+ ret = bf->fd;
+ free(bf);
goto out;
}
}
f->f_size = d->size;
- f->private_data = d;
+ f->private_data = bf;
ret = 0;
out:
@@ -171,9 +184,12 @@ static int bpkfs_open(struct device *dev, struct file *f, const char *filename)
static int bpkfs_close(struct device *dev, struct file *file)
{
- struct bpkfs_handle_data *d = file->private_data;
+ struct bpkfs_file *bf = file->private_data;
+
+ if (bf->fd >= 0)
+ close(bf->fd);
- close(d->fd);
+ free(bf);
return 0;
}
@@ -181,13 +197,14 @@ static int bpkfs_close(struct device *dev, struct file *file)
static int bpkfs_read(struct file *file, void *buf,
size_t insize)
{
- struct bpkfs_handle_data *d = file->private_data;
+ struct bpkfs_file *bf = file->private_data;
+ struct bpkfs_handle_data *d = bf->d;
if (bpkfs_is_crc_file(d)) {
memcpy(buf, &d->data[file->f_pos], insize);
return insize;
} else {
- return pread(d->fd, buf, insize, d->offset + file->f_pos);
+ return pread(bf->fd, buf, insize, d->offset + file->f_pos);
}
}
diff --git a/include/bpkfs.h b/include/bpkfs.h
index c80dc211c6..252cee90a6 100644
--- a/include/bpkfs.h
+++ b/include/bpkfs.h
@@ -46,7 +46,6 @@ struct bpkfs_handle_data {
uint32_t hw_id;
uint64_t size;
- int fd;
size_t offset; /* offset in the image */
size_t pos; /* pos in the data */
uint32_t crc;
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 10/13] fs: bpkfs: make room for the NUL after the checksum string
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (8 preceding siblings ...)
2026-11-18 14:51 ` [PATCH 09/13] fs: bpkfs: allow opening a file more than once Sascha Hauer
@ 2026-11-18 14:52 ` Sascha Hauer
2026-11-18 14:52 ` [PATCH 11/13] fs: pstore: read from the file position Sascha Hauer
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:52 UTC (permalink / raw)
To: BAREBOX
The .crc file of each image holds its checksum as 8 hex digits, which
bpkfs prints into an 8-byte array with sprintf(), so the terminating
NUL is written behind it, into the list head following it in struct
bpkfs_handle_data. It's overwritten right after by adding the entry to
the list, so this went unnoticed.
Make the array 9 bytes. The file still is the 8 digits without the NUL.
Fixes: 2f677b9b1ed5 ("fs: add BPKFS support")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/bpkfs.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/bpkfs.h b/include/bpkfs.h
index 252cee90a6..9a12f5a1ba 100644
--- a/include/bpkfs.h
+++ b/include/bpkfs.h
@@ -50,7 +50,8 @@ struct bpkfs_handle_data {
size_t pos; /* pos in the data */
uint32_t crc;
- char data[8];
+ /* the checksum of the data as 8 hex digits for .crc files */
+ char data[9];
struct list_head list;
};
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 11/13] fs: pstore: read from the file position
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (9 preceding siblings ...)
2026-11-18 14:52 ` [PATCH 10/13] fs: bpkfs: make room for the NUL after the checksum string Sascha Hauer
@ 2026-11-18 14:52 ` Sascha Hauer
2026-11-18 14:52 ` [PATCH 12/13] fs: pstore: don't free the records when unmounting Sascha Hauer
2026-11-18 14:52 ` [PATCH 13/13] fs: efivarfs: zero-fill variables grown by truncate Sascha Hauer
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:52 UTC (permalink / raw)
To: BAREBOX
pstore reads at a position of its own, which it keeps in the
pstore_private of the file and resets on open. Reads at another
position, like pread(), get data from the wrong place, and so does
any read when the same file is open more than once.
Read from the file position like other file systems do. That makes the
lseek() operation and the position of its own unnecessary.
Fixes: 160d2ed0ba18 ("fs: Add pstore filesystem")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/pstore/fs.c | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/fs/pstore/fs.c b/fs/pstore/fs.c
index 49ea5edf74..1a0eba4fa4 100644
--- a/fs/pstore/fs.c
+++ b/fs/pstore/fs.c
@@ -41,7 +41,6 @@ struct pstore_private {
struct list_head list;
struct pstore_record *record;
ssize_t size;
- ssize_t pos;
};
static void free_pstore_private(struct pstore_private *private)
@@ -118,7 +117,6 @@ static int pstore_open(struct device *dev, struct file *file, const char *filena
file->f_size = d->size;
file->private_data = d;
- d->pos = 0;
return 0;
}
@@ -133,21 +131,11 @@ static int pstore_read(struct file *file, void *buf,
{
struct pstore_private *d = file->private_data;
- memcpy(buf, &d->record->buf[d->pos], insize);
- d->pos += insize;
+ memcpy(buf, &d->record->buf[file->f_pos], insize);
return insize;
}
-static int pstore_lseek(struct file *file, loff_t pos)
-{
- struct pstore_private *d = file->private_data;
-
- d->pos = pos;
-
- return 0;
-}
-
static int pstore_unlink(struct device *dev, const char *filename)
{
struct list_head *head = dev->priv;
@@ -249,7 +237,6 @@ static const struct fs_legacy_ops pstore_ops = {
.closedir = pstore_closedir,
.stat = pstore_stat,
.read = pstore_read,
- .lseek = pstore_lseek,
};
static struct fs_driver pstore_driver = {
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 12/13] fs: pstore: don't free the records when unmounting
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (10 preceding siblings ...)
2026-11-18 14:52 ` [PATCH 11/13] fs: pstore: read from the file position Sascha Hauer
@ 2026-11-18 14:52 ` Sascha Hauer
2026-11-18 14:52 ` [PATCH 13/13] fs: efivarfs: zero-fill variables grown by truncate Sascha Hauer
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:52 UTC (permalink / raw)
To: BAREBOX
The records belong to pstore rather than to a mount of it: they are
read from the backend once, and every mount of pstore shows the same
list of them. Unmounting pstore frees all of them nevertheless, without
removing them from the list. pstore is mounted on /pstore at startup,
so unmounting another mount of it leaves /pstore with a list of freed
records, and so does unmounting /pstore and mounting it again:
mount -t pstore none /mnt; umount /mnt; ls /pstore -> use after free
Leave the records alone when unmounting. They are still freed when
removing them with unlink().
Fixes: 160d2ed0ba18 ("fs: Add pstore filesystem")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/pstore/fs.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/fs/pstore/fs.c b/fs/pstore/fs.c
index 1a0eba4fa4..a5b48a04c0 100644
--- a/fs/pstore/fs.c
+++ b/fs/pstore/fs.c
@@ -208,15 +208,6 @@ static int pstore_stat(struct device *dev, const char *filename,
return 0;
}
-static void pstore_remove(struct device *dev)
-{
- struct pstore_private *d, *tmp;
-
- list_for_each_entry_safe(d, tmp, &allpstore, list) {
- free_pstore_private(d);
- }
-}
-
static int pstore_probe(struct device *dev)
{
struct list_head *priv = &allpstore;
@@ -243,7 +234,6 @@ static struct fs_driver pstore_driver = {
.legacy_ops = &pstore_ops,
.drv = {
.probe = pstore_probe,
- .remove = pstore_remove,
.name = "pstore",
}
};
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 13/13] fs: efivarfs: zero-fill variables grown by truncate
2026-11-18 14:51 [PATCH 00/13] fs: fixes found by file system conformance tests Sascha Hauer
` (11 preceding siblings ...)
2026-11-18 14:52 ` [PATCH 12/13] fs: pstore: don't free the records when unmounting Sascha Hauer
@ 2026-11-18 14:52 ` Sascha Hauer
12 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2026-11-18 14:52 UTC (permalink / raw)
To: BAREBOX
efivarfs_truncate() grows the buffer of a variable with realloc(), which
leaves the new bytes uninitialized, and stores the variable with them:
write 1000 bytes, ftruncate(300), ftruncate(600)
-> bytes 300..599 hold whatever was in memory
Clear what the variable grows by.
Fixes: 46b5a6d6527f ("fs: efivars: implement write support")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/efivarfs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index da826234b9..efc6d9a12b 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -232,8 +232,11 @@ static int efivarfs_truncate(struct file *f, loff_t size)
struct efi_runtime_services *rt = efile->priv->rt;
efi_status_t efiret;
+ efile->buf = realloc(efile->buf, size + sizeof(uint32_t));
+ /* what a variable grows by reads back as zeroes */
+ if (size > efile->size)
+ memset(efile->buf + efile->size, 0, size - efile->size);
efile->size = size;
- efile->buf = realloc(efile->buf, efile->size + sizeof(uint32_t));
efiret = rt->set_variable(efile->name, &efile->vendor,
efile->attributes,
--
2.47.3
^ permalink raw reply [flat|nested] 14+ messages in thread