Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Chris Mason <clm@fb.com>, Qu Wenruo <wqu@suse.com>,
	Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] btrfs: qgroup: delete unnecessary check in btrfs_qgroup_check_inherit()
Date: Tue, 26 Mar 2024 16:26:43 +0100	[thread overview]
Message-ID: <20240326152643.GT14596@twin.jikos.cz> (raw)
In-Reply-To: <cb21ce67-e9d8-4844-8c70-eb42f6ac4aee@moroto.mountain>

On Thu, Mar 07, 2024 at 05:53:47PM +0300, Dan Carpenter wrote:
> This check "if (inherit->num_qgroups > PAGE_SIZE)" is confusing and
> unnecessary.
> 
> The problem with the check is that static checkers flag it as a
> potential mixup of between units of bytes vs number of elements.
> Fortunately, the check can safely be deleted because the next check is
> correct and applies an even stricter limit:
> 
> 	if (size != struct_size(inherit, qgroups, inherit->num_qgroups))
> 		return -EINVAL;
> 
> The "inherit" struct ends in a variable array of __u64 and
> "inherit->num_qgroups" is the number of elements in the array.  At the
> start of the function we check that:
> 
> 	if (size < sizeof(*inherit) || size > PAGE_SIZE)
> 		return -EINVAL;
> 
> Thus, since we verify that the whole struct fits within one page, that
> means that the number of elements in the inherit->qgroups[] array must
> be less than PAGE_SIZE.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Added to for-next, thanks.

      parent reply	other threads:[~2024-03-26 15:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-07 14:53 [PATCH] btrfs: qgroup: delete unnecessary check in btrfs_qgroup_check_inherit() Dan Carpenter
2024-03-07 19:37 ` Qu Wenruo
2024-03-26 15:26 ` David Sterba [this message]

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=20240326152643.GT14596@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=clm@fb.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wqu@suse.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox