* [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing
@ 2026-11-16 20:55 Dilip Mallavarapu
2026-11-16 21:13 ` Qu Wenruo
2026-11-16 21:43 ` [PATCH v2] " Dilip Mallavarapu
0 siblings, 2 replies; 6+ messages in thread
From: Dilip Mallavarapu @ 2026-11-16 20:55 UTC (permalink / raw)
To: Marek Behún, Qu Wenruo; +Cc: Tom Rini, u-boot, Dilip Mallavarapu
get_path_in_subvol() and list_one_subvol() accumulate a path across the
on-disk inode-ref / root-ref chain with strncat(path_ret, tmp, PATH_MAX).
strncat()'s bound limits the source copy, not the destination total, and
there is no depth/cycle limit, so a deep or cyclic ref chain overflows
the PATH_MAX path_ret buffer (CWE-787/120).
Use strlcat()/strlcpy(), which bound the total length, and reject the
path if it would be truncated (which also terminates a cyclic chain).
Reachable via the btrsubvol command on a crafted btrfs image.
Signed-off-by: Dilip Mallavarapu <dilipchowdary21@gmail.com>
---
fs/btrfs/subvolume.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
index 68ca7e48e48..bac9c1d1722 100644
--- a/fs/btrfs/subvolume.c
+++ b/fs/btrfs/subvolume.c
@@ -64,7 +64,16 @@ static int get_path_in_subvol(struct btrfs_root *root, u64 ino, char *path_ret)
(unsigned long)(iref + 1), name_len);
path_ret[name_len] = '/';
path_ret[name_len + 1] = '\0';
- strncat(path_ret, tmp, PATH_MAX);
+ /*
+ * strncat()'s bound limits the source copy, not the
+ * destination, so a deep/cyclic ref chain would overflow
+ * path_ret (PATH_MAX). strlcat() bounds the total; reject
+ * the path if it would be truncated.
+ */
+ if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
+ ret = -ENAMETOOLONG;
+ goto out;
+ }
btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
cur = key.offset;
@@ -128,7 +137,10 @@ static int list_one_subvol(struct btrfs_root *root, char *path_ret)
(unsigned long)(rr + 1), name_len);
path_ret[name_len] = '/';
path_ret[name_len + 1] = '\0';
- strncat(path_ret, tmp, PATH_MAX);
+ if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
+ ret = -ENAMETOOLONG;
+ goto out;
+ }
/* Get the path inside the parent subvolume */
btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
@@ -146,9 +158,12 @@ static int list_one_subvol(struct btrfs_root *root, char *path_ret)
cur = key.offset;
}
/* Add the leading '/' */
- strncpy(tmp, path_ret, PATH_MAX);
- strncpy(path_ret, "/", PATH_MAX);
- strncat(path_ret, tmp, PATH_MAX);
+ strlcpy(tmp, path_ret, PATH_MAX);
+ strlcpy(path_ret, "/", PATH_MAX);
+ if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
+ ret = -ENAMETOOLONG;
+ goto out;
+ }
out:
btrfs_release_path(&path);
free(tmp);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing
2026-11-16 20:55 [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing Dilip Mallavarapu
@ 2026-11-16 21:13 ` Qu Wenruo
2026-11-16 21:17 ` Tom Rini
2026-11-16 21:43 ` [PATCH v2] " Dilip Mallavarapu
1 sibling, 1 reply; 6+ messages in thread
From: Qu Wenruo @ 2026-11-16 21:13 UTC (permalink / raw)
To: Dilip Mallavarapu, Marek Behún; +Cc: Tom Rini, u-boot
在 2026/11/17 07:25, Dilip Mallavarapu 写道:
> get_path_in_subvol() and list_one_subvol() accumulate a path across the
> on-disk inode-ref / root-ref chain with strncat(path_ret, tmp, PATH_MAX).
> strncat()'s bound limits the source copy, not the destination total, and
> there is no depth/cycle limit, so a deep or cyclic ref chain overflows
> the PATH_MAX path_ret buffer (CWE-787/120).
>
> Use strlcat()/strlcpy(), which bound the total length, and reject the
> path if it would be truncated (which also terminates a cyclic chain).
>
> Reachable via the btrsubvol command on a crafted btrfs image.
>
> Signed-off-by: Dilip Mallavarapu <dilipchowdary21@gmail.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Just a nitpick on the comment.
> ---
> fs/btrfs/subvolume.c | 25 ++++++++++++++++++++-----
> 1 file changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
> index 68ca7e48e48..bac9c1d1722 100644
> --- a/fs/btrfs/subvolume.c
> +++ b/fs/btrfs/subvolume.c
> @@ -64,7 +64,16 @@ static int get_path_in_subvol(struct btrfs_root *root, u64 ino, char *path_ret)
> (unsigned long)(iref + 1), name_len);
> path_ret[name_len] = '/';
> path_ret[name_len + 1] = '\0';
> - strncat(path_ret, tmp, PATH_MAX);
> + /*
> + * strncat()'s bound limits the source copy, not the
> + * destination, so a deep/cyclic ref chain would overflow
> + * path_ret (PATH_MAX). strlcat() bounds the total; reject
> + * the path if it would be truncated.
> + */
This comment seems overkilled, and it only covers one call site.
To be honest, I don't think there is any comment needed for usage of
strlcat()/strlcpy().
Thanks,
Qu
> + if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
> + ret = -ENAMETOOLONG;
> + goto out;
> + }
>
> btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
> cur = key.offset;
> @@ -128,7 +137,10 @@ static int list_one_subvol(struct btrfs_root *root, char *path_ret)
> (unsigned long)(rr + 1), name_len);
> path_ret[name_len] = '/';
> path_ret[name_len + 1] = '\0';
> - strncat(path_ret, tmp, PATH_MAX);
> + if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
> + ret = -ENAMETOOLONG;
> + goto out;
> + }
>
> /* Get the path inside the parent subvolume */
> btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
> @@ -146,9 +158,12 @@ static int list_one_subvol(struct btrfs_root *root, char *path_ret)
> cur = key.offset;
> }
> /* Add the leading '/' */
> - strncpy(tmp, path_ret, PATH_MAX);
> - strncpy(path_ret, "/", PATH_MAX);
> - strncat(path_ret, tmp, PATH_MAX);
> + strlcpy(tmp, path_ret, PATH_MAX);
> + strlcpy(path_ret, "/", PATH_MAX);
> + if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
> + ret = -ENAMETOOLONG;
> + goto out;
> + }
> out:
> btrfs_release_path(&path);
> free(tmp);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing
2026-11-16 21:13 ` Qu Wenruo
@ 2026-11-16 21:17 ` Tom Rini
2026-11-16 21:26 ` Dilip
0 siblings, 1 reply; 6+ messages in thread
From: Tom Rini @ 2026-11-16 21:17 UTC (permalink / raw)
To: Qu Wenruo, Dilip Mallavarapu; +Cc: Marek Behún, u-boot
[-- Attachment #1: Type: text/plain, Size: 2052 bytes --]
On Tue, Nov 17, 2026 at 07:43:31AM +1030, Qu Wenruo wrote:
>
>
> 在 2026/11/17 07:25, Dilip Mallavarapu 写道:
> > get_path_in_subvol() and list_one_subvol() accumulate a path across the
> > on-disk inode-ref / root-ref chain with strncat(path_ret, tmp, PATH_MAX).
> > strncat()'s bound limits the source copy, not the destination total, and
> > there is no depth/cycle limit, so a deep or cyclic ref chain overflows
> > the PATH_MAX path_ret buffer (CWE-787/120).
> >
> > Use strlcat()/strlcpy(), which bound the total length, and reject the
> > path if it would be truncated (which also terminates a cyclic chain).
> >
> > Reachable via the btrsubvol command on a crafted btrfs image.
> >
> > Signed-off-by: Dilip Mallavarapu <dilipchowdary21@gmail.com>
>
> Reviewed-by: Qu Wenruo <wqu@suse.com>
>
> Just a nitpick on the comment.
>
> > ---
> > fs/btrfs/subvolume.c | 25 ++++++++++++++++++++-----
> > 1 file changed, 20 insertions(+), 5 deletions(-)
> >
> > diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
> > index 68ca7e48e48..bac9c1d1722 100644
> > --- a/fs/btrfs/subvolume.c
> > +++ b/fs/btrfs/subvolume.c
> > @@ -64,7 +64,16 @@ static int get_path_in_subvol(struct btrfs_root *root, u64 ino, char *path_ret)
> > (unsigned long)(iref + 1), name_len);
> > path_ret[name_len] = '/';
> > path_ret[name_len + 1] = '\0';
> > - strncat(path_ret, tmp, PATH_MAX);
> > + /*
> > + * strncat()'s bound limits the source copy, not the
> > + * destination, so a deep/cyclic ref chain would overflow
> > + * path_ret (PATH_MAX). strlcat() bounds the total; reject
> > + * the path if it would be truncated.
> > + */
>
> This comment seems overkilled, and it only covers one call site.
>
> To be honest, I don't think there is any comment needed for usage of
> strlcat()/strlcpy().
Yes, and it's the kind of thing which AI tends to do, and then expects
human reviewers to remark on. Please note that the AI policy for U-Boot
is "please don't".
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing
2026-11-16 21:17 ` Tom Rini
@ 2026-11-16 21:26 ` Dilip
2026-11-16 23:22 ` Tom Rini
0 siblings, 1 reply; 6+ messages in thread
From: Dilip @ 2026-11-16 21:26 UTC (permalink / raw)
To: Tom Rini; +Cc: Qu Wenruo, Marek Behún, u-boot
[-- Attachment #1: Type: text/plain, Size: 2748 bytes --]
Thanks Qu, I'll drop the comment in v2.
Tom, noted on the AI policy. To be upfront: I did use an LLM to help with
the analysis and drafting here. The bugs and the fixes I've gone through
and verified myself, but I should have said so when Quentin asked, and I'll
keep future submissions in my own words. Happy to continue only as far as
is useful to you, the findings stand on their own either way.
Dilip
On Mon, Nov 16, 2026 at 3:17 PM Tom Rini <trini@konsulko.com> wrote:
> On Tue, Nov 17, 2026 at 07:43:31AM +1030, Qu Wenruo wrote:
> >
> >
> > 在 2026/11/17 07:25, Dilip Mallavarapu 写道:
> > > get_path_in_subvol() and list_one_subvol() accumulate a path across the
> > > on-disk inode-ref / root-ref chain with strncat(path_ret, tmp,
> PATH_MAX).
> > > strncat()'s bound limits the source copy, not the destination total,
> and
> > > there is no depth/cycle limit, so a deep or cyclic ref chain overflows
> > > the PATH_MAX path_ret buffer (CWE-787/120).
> > >
> > > Use strlcat()/strlcpy(), which bound the total length, and reject the
> > > path if it would be truncated (which also terminates a cyclic chain).
> > >
> > > Reachable via the btrsubvol command on a crafted btrfs image.
> > >
> > > Signed-off-by: Dilip Mallavarapu <dilipchowdary21@gmail.com>
> >
> > Reviewed-by: Qu Wenruo <wqu@suse.com>
> >
> > Just a nitpick on the comment.
> >
> > > ---
> > > fs/btrfs/subvolume.c | 25 ++++++++++++++++++++-----
> > > 1 file changed, 20 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
> > > index 68ca7e48e48..bac9c1d1722 100644
> > > --- a/fs/btrfs/subvolume.c
> > > +++ b/fs/btrfs/subvolume.c
> > > @@ -64,7 +64,16 @@ static int get_path_in_subvol(struct btrfs_root
> *root, u64 ino, char *path_ret)
> > > (unsigned long)(iref + 1), name_len);
> > > path_ret[name_len] = '/';
> > > path_ret[name_len + 1] = '\0';
> > > - strncat(path_ret, tmp, PATH_MAX);
> > > + /*
> > > + * strncat()'s bound limits the source copy, not the
> > > + * destination, so a deep/cyclic ref chain would overflow
> > > + * path_ret (PATH_MAX). strlcat() bounds the total; reject
> > > + * the path if it would be truncated.
> > > + */
> >
> > This comment seems overkilled, and it only covers one call site.
> >
> > To be honest, I don't think there is any comment needed for usage of
> > strlcat()/strlcpy().
>
> Yes, and it's the kind of thing which AI tends to do, and then expects
> human reviewers to remark on. Please note that the AI policy for U-Boot
> is "please don't".
>
> --
> Tom
>
[-- Attachment #2: Type: text/html, Size: 3639 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] fs/btrfs: fix path buffer overflow in subvolume listing
2026-11-16 20:55 [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing Dilip Mallavarapu
2026-11-16 21:13 ` Qu Wenruo
@ 2026-11-16 21:43 ` Dilip Mallavarapu
1 sibling, 0 replies; 6+ messages in thread
From: Dilip Mallavarapu @ 2026-11-16 21:43 UTC (permalink / raw)
To: Marek Behún, Qu Wenruo; +Cc: Tom Rini, u-boot, Dilip Mallavarapu
get_path_in_subvol() and list_one_subvol() accumulate a path across the
on-disk inode-ref / root-ref chain with strncat(path_ret, tmp, PATH_MAX).
strncat()'s bound limits the source copy, not the destination total, and
there is no depth/cycle limit, so a deep or cyclic ref chain overflows
the PATH_MAX path_ret buffer (CWE-787/120).
Use strlcat()/strlcpy(), which bound the total length, and reject the
path if it would be truncated (which also terminates a cyclic chain).
Reachable via the btrsubvol command on a crafted btrfs image.
Signed-off-by: Dilip Mallavarapu <dilipchowdary21@gmail.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
---
Changes in v2:
- Drop the inline explanatory comment (Qu Wenruo, Tom Rini)
fs/btrfs/subvolume.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
index 68ca7e48e48..a62d547b3b7 100644
--- a/fs/btrfs/subvolume.c
+++ b/fs/btrfs/subvolume.c
@@ -64,7 +64,10 @@ static int get_path_in_subvol(struct btrfs_root *root, u64 ino, char *path_ret)
(unsigned long)(iref + 1), name_len);
path_ret[name_len] = '/';
path_ret[name_len + 1] = '\0';
- strncat(path_ret, tmp, PATH_MAX);
+ if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
+ ret = -ENAMETOOLONG;
+ goto out;
+ }
btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
cur = key.offset;
@@ -128,7 +131,10 @@ static int list_one_subvol(struct btrfs_root *root, char *path_ret)
(unsigned long)(rr + 1), name_len);
path_ret[name_len] = '/';
path_ret[name_len + 1] = '\0';
- strncat(path_ret, tmp, PATH_MAX);
+ if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
+ ret = -ENAMETOOLONG;
+ goto out;
+ }
/* Get the path inside the parent subvolume */
btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);
@@ -146,9 +152,12 @@ static int list_one_subvol(struct btrfs_root *root, char *path_ret)
cur = key.offset;
}
/* Add the leading '/' */
- strncpy(tmp, path_ret, PATH_MAX);
- strncpy(path_ret, "/", PATH_MAX);
- strncat(path_ret, tmp, PATH_MAX);
+ strlcpy(tmp, path_ret, PATH_MAX);
+ strlcpy(path_ret, "/", PATH_MAX);
+ if (strlcat(path_ret, tmp, PATH_MAX) >= PATH_MAX) {
+ ret = -ENAMETOOLONG;
+ goto out;
+ }
out:
btrfs_release_path(&path);
free(tmp);
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing
2026-11-16 21:26 ` Dilip
@ 2026-11-16 23:22 ` Tom Rini
0 siblings, 0 replies; 6+ messages in thread
From: Tom Rini @ 2026-11-16 23:22 UTC (permalink / raw)
To: Dilip; +Cc: Qu Wenruo, Marek Behún, u-boot
[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]
On Mon, Nov 16, 2026 at 03:26:01PM -0600, Dilip wrote:
> Thanks Qu, I'll drop the comment in v2.
>
> Tom, noted on the AI policy. To be upfront: I did use an LLM to help with
> the analysis and drafting here. The bugs and the fixes I've gone through
> and verified myself, but I should have said so when Quentin asked, and I'll
> keep future submissions in my own words. Happy to continue only as far as
> is useful to you, the findings stand on their own either way.
I want to address the general notion you're making here, that
LLM-discovered findings stand on their own.
They do not. Setting aside (because *largely* they're better today than
6 months ago) if they're technically true the question is, do they
architecturally matter? We're a bootloader, not a general purpose
operating system. We have real resource constraints. We (generally)
aren't sitting on the network. Someone has to have physical access to
the device. Often devices aren't going to be looking at removable
storage.
This is also not to say that correctness doesn't matter, it does. And
reasonable defense-in-depth programming techniques are useful too.
But they are things that require looking at the system as a whole, and
seeing what needs to be done. And what is even the threat model and so
is or is not relevant.
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-17 4:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 20:55 [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing Dilip Mallavarapu
2026-11-16 21:13 ` Qu Wenruo
2026-11-16 21:17 ` Tom Rini
2026-11-16 21:26 ` Dilip
2026-11-16 23:22 ` Tom Rini
2026-11-16 21:43 ` [PATCH v2] " Dilip Mallavarapu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.