* [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums()
@ 2023-07-26 6:59 Dan Carpenter
2023-08-01 9:05 ` Marek Behún
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Dan Carpenter @ 2023-07-26 6:59 UTC (permalink / raw)
To: Marek Behún; +Cc: Qu Wenruo, u-boot
If btrfs_read_fs_root() fails with -ENOENT, then we go to the next
entry. Fine. But if it fails for a different reason then we need
to clean up and return an error code. In the current code it
doesn't clean up but instead dereferences "root" and crashes.
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
I didn't CC the btrfs mailing list. Perhaps, I should have?
fs/btrfs/subvolume.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
index d446e7a2c418..68ca7e48e48e 100644
--- a/fs/btrfs/subvolume.c
+++ b/fs/btrfs/subvolume.c
@@ -199,6 +199,7 @@ static int list_subvolums(struct btrfs_fs_info *fs_info)
ret = PTR_ERR(root);
if (ret == -ENOENT)
goto next;
+ goto out;
}
ret = list_one_subvol(root, result);
if (ret < 0)
--
2.39.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums()
2023-07-26 6:59 [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums() Dan Carpenter
@ 2023-08-01 9:05 ` Marek Behún
2023-08-01 11:13 ` Dan Carpenter
2023-08-01 9:06 ` Qu Wenruo
2023-08-09 1:40 ` Tom Rini
2 siblings, 1 reply; 5+ messages in thread
From: Marek Behún @ 2023-08-01 9:05 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Qu Wenruo, u-boot
On Wed, 26 Jul 2023 09:59:04 +0300
Dan Carpenter <dan.carpenter@linaro.org> wrote:
> If btrfs_read_fs_root() fails with -ENOENT, then we go to the next
> entry. Fine. But if it fails for a different reason then we need
> to clean up and return an error code. In the current code it
> doesn't clean up but instead dereferences "root" and crashes.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> I didn't CC the btrfs mailing list. Perhaps, I should have?
>
> fs/btrfs/subvolume.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
> index d446e7a2c418..68ca7e48e48e 100644
> --- a/fs/btrfs/subvolume.c
> +++ b/fs/btrfs/subvolume.c
> @@ -199,6 +199,7 @@ static int list_subvolums(struct btrfs_fs_info *fs_info)
> ret = PTR_ERR(root);
> if (ret == -ENOENT)
> goto next;
> + goto out;
> }
> ret = list_one_subvol(root, result);
> if (ret < 0)
Reviewed-by: Marek Behún <kabel@kernel.org>
nice catch :) Dan, I always wanted to ask, since I've seen many such
"nice catches" over different subsystems from you. Do you write some
tools to find these? Or do you use coccinelle, or something?
Marek
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums()
2023-07-26 6:59 [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums() Dan Carpenter
2023-08-01 9:05 ` Marek Behún
@ 2023-08-01 9:06 ` Qu Wenruo
2023-08-09 1:40 ` Tom Rini
2 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2023-08-01 9:06 UTC (permalink / raw)
To: Dan Carpenter, Marek Behún; +Cc: u-boot
On 2023/7/26 14:59, Dan Carpenter wrote:
> If btrfs_read_fs_root() fails with -ENOENT, then we go to the next
> entry. Fine. But if it fails for a different reason then we need
> to clean up and return an error code. In the current code it
> doesn't clean up but instead dereferences "root" and crashes.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Qu Wenruo <wqu@suse.com>
> ---
> I didn't CC the btrfs mailing list. Perhaps, I should have?
This patch is fine. The function is specific to U-boot, and not utilized
by kernel/btrfs-progs.
Thanks,
Qu
>
> fs/btrfs/subvolume.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/btrfs/subvolume.c b/fs/btrfs/subvolume.c
> index d446e7a2c418..68ca7e48e48e 100644
> --- a/fs/btrfs/subvolume.c
> +++ b/fs/btrfs/subvolume.c
> @@ -199,6 +199,7 @@ static int list_subvolums(struct btrfs_fs_info *fs_info)
> ret = PTR_ERR(root);
> if (ret == -ENOENT)
> goto next;
> + goto out;
> }
> ret = list_one_subvol(root, result);
> if (ret < 0)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums()
2023-08-01 9:05 ` Marek Behún
@ 2023-08-01 11:13 ` Dan Carpenter
0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2023-08-01 11:13 UTC (permalink / raw)
To: Marek Behún; +Cc: Qu Wenruo, u-boot
On Tue, Aug 01, 2023 at 11:05:11AM +0200, Marek Behún wrote:
> nice catch :) Dan, I always wanted to ask, since I've seen many such
> "nice catches" over different subsystems from you. Do you write some
> tools to find these? Or do you use coccinelle, or something?
>
Thanks! I'm using Smatch.
https://github.com/error27/smatch/
It's handy for me that u-boot and the Linux kernel have so much in
common and I can re-use a the kernel checks. I had to make some changes
to Smatch to make it work but those are pushed now.
U-boot is something that Linaro cares about so if you have static
checker ideas then feel free to email the smatch mailing list.
smatch@vger.kernel.org
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums()
2023-07-26 6:59 [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums() Dan Carpenter
2023-08-01 9:05 ` Marek Behún
2023-08-01 9:06 ` Qu Wenruo
@ 2023-08-09 1:40 ` Tom Rini
2 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2023-08-09 1:40 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Marek Behún, Qu Wenruo, u-boot
[-- Attachment #1: Type: text/plain, Size: 534 bytes --]
On Wed, Jul 26, 2023 at 09:59:04AM +0300, Dan Carpenter wrote:
> If btrfs_read_fs_root() fails with -ENOENT, then we go to the next
> entry. Fine. But if it fails for a different reason then we need
> to clean up and return an error code. In the current code it
> doesn't clean up but instead dereferences "root" and crashes.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> Reviewed-by: Marek Behún <kabel@kernel.org>
> Reviewed-by: Qu Wenruo <wqu@suse.com>
Applied to u-boot/next, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-09 1:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-26 6:59 [PATCH] fs: btrfs: Prevent error pointer dereference in list_subvolums() Dan Carpenter
2023-08-01 9:05 ` Marek Behún
2023-08-01 11:13 ` Dan Carpenter
2023-08-01 9:06 ` Qu Wenruo
2023-08-09 1:40 ` Tom Rini
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.