kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix array index in qgroup_auto_inherit()
@ 2024-05-04 11:38 Dan Carpenter
  2024-05-04 22:41 ` Qu Wenruo
  2024-05-06 17:38 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-05-04 11:38 UTC (permalink / raw)
  To: Boris Burkov
  Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs,
	linux-kernel, kernel-janitors

The "i++" was accidentally left out so it just sets qgids[0] over and
over.

Fixes: 5343cd9364ea ("btrfs: qgroup: simple quota auto hierarchy for nested subvolumes")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
From static analysis.  Untested.

 fs/btrfs/qgroup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 2ca6bbc1bcc9..1284e78fffce 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -3121,7 +3121,7 @@ static int qgroup_auto_inherit(struct btrfs_fs_info *fs_info,
 	qgids = res->qgroups;
 
 	list_for_each_entry(qg_list, &inode_qg->groups, next_group)
-		qgids[i] = qg_list->group->qgroupid;
+		qgids[i++] = qg_list->group->qgroupid;
 
 	*inherit = res;
 	return 0;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: fix array index in qgroup_auto_inherit()
  2024-05-04 11:38 [PATCH] btrfs: fix array index in qgroup_auto_inherit() Dan Carpenter
@ 2024-05-04 22:41 ` Qu Wenruo
  2024-05-06 17:38 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2024-05-04 22:41 UTC (permalink / raw)
  To: Dan Carpenter, Boris Burkov
  Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs,
	linux-kernel, kernel-janitors



在 2024/5/4 21:08, Dan Carpenter 写道:
> The "i++" was accidentally left out so it just sets qgids[0] over and
> over.
>
> Fixes: 5343cd9364ea ("btrfs: qgroup: simple quota auto hierarchy for nested subvolumes")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

It is indeed the case, btrfs_qgroup_inherit::groups[] should be the
parent qgroupis the subvolume would be added to.

In fact this can lead to unexpected problems, as the groups[1:] would be
all 0, leading to later find_qgroup_rb() unable to find a qgroup and
cause snapshot creation failure.

IMHO you can also craft a fstest case, where the parent subvolume is
assgined to multiple qgroups, and creating a new subvolume inside that
one, which should lead to subvolume creation failure.

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
>  From static analysis.  Untested.
>
>   fs/btrfs/qgroup.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
> index 2ca6bbc1bcc9..1284e78fffce 100644
> --- a/fs/btrfs/qgroup.c
> +++ b/fs/btrfs/qgroup.c
> @@ -3121,7 +3121,7 @@ static int qgroup_auto_inherit(struct btrfs_fs_info *fs_info,
>   	qgids = res->qgroups;
>
>   	list_for_each_entry(qg_list, &inode_qg->groups, next_group)
> -		qgids[i] = qg_list->group->qgroupid;
> +		qgids[i++] = qg_list->group->qgroupid;
>
>   	*inherit = res;
>   	return 0;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: fix array index in qgroup_auto_inherit()
  2024-05-04 11:38 [PATCH] btrfs: fix array index in qgroup_auto_inherit() Dan Carpenter
  2024-05-04 22:41 ` Qu Wenruo
@ 2024-05-06 17:38 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2024-05-06 17:38 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Boris Burkov, Chris Mason, Josef Bacik, David Sterba,
	linux-btrfs, linux-kernel, kernel-janitors

On Sat, May 04, 2024 at 02:38:41PM +0300, Dan Carpenter wrote:
> The "i++" was accidentally left out so it just sets qgids[0] over and
> over.
> 
> Fixes: 5343cd9364ea ("btrfs: qgroup: simple quota auto hierarchy for nested subvolumes")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> >From static analysis.  Untested.

A real bug, thanks. Patch added to for-next.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-06 17:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-04 11:38 [PATCH] btrfs: fix array index in qgroup_auto_inherit() Dan Carpenter
2024-05-04 22:41 ` Qu Wenruo
2024-05-06 17:38 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).