From: Qu Wenruo <wqu@suse.com>
To: "Dilip Mallavarapu" <dilipchowdary21@gmail.com>,
"Marek Behún" <kabel@kernel.org>
Cc: Tom Rini <trini@konsulko.com>, u-boot@lists.u-boot-project.org
Subject: Re: [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing
Date: Tue, 17 Nov 2026 07:43:31 +1030 [thread overview]
Message-ID: <767dd299-5aa0-4e4f-a84f-a55395214a30@suse.com> (raw)
In-Reply-To: <20261116205502.14884-1-dilipchowdary21@gmail.com>
在 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);
next prev parent reply other threads:[~2026-11-16 21:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 20:55 [PATCH] fs/btrfs: fix path buffer overflow in subvolume listing Dilip Mallavarapu
2026-11-16 21:13 ` Qu Wenruo [this message]
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
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=767dd299-5aa0-4e4f-a84f-a55395214a30@suse.com \
--to=wqu@suse.com \
--cc=dilipchowdary21@gmail.com \
--cc=kabel@kernel.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/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 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.