Linux-bcachefs Archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: Erick Archer <erick.archer@gmx.com>
Cc: Brian Foster <bfoster@redhat.com>,
	 "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	 linux-bcachefs@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] bcachefs: Prefer struct_size over open coded arithmetic
Date: Sun, 10 Mar 2024 15:41:58 -0400	[thread overview]
Message-ID: <rmna7gzrezwrhmrsgheswqsnc53nk6xiu5en6fg3ag44f3blps@otgd65u62umx> (raw)
In-Reply-To: <20240310110226.6366-1-erick.archer@gmx.com>

On Sun, Mar 10, 2024 at 12:02:26PM +0100, Erick Archer wrote:
> This is an effort to get rid of all multiplications from allocation
> functions in order to prevent integer overflows [1][2].
> 
> As the "op" variable is a pointer to "struct promote_op" and this
> structure ends in a flexible array:
> 
> struct promote_op {
> 	[...]
> 	struct bio_vec bi_inline_vecs[];
> };
> 
> and the "t" variable is a pointer to "struct journal_seq_blacklist_table"
> and this structure also ends in a flexible array:
> 
> struct journal_seq_blacklist_table {
> 	[...]
> 	struct journal_seq_blacklist_table_entry {
> 		u64		start;
> 		u64		end;
> 		bool		dirty;
> 	}			entries[];
> };
> 
> the preferred way in the kernel is to use the struct_size() helper to
> do the arithmetic instead of the argument "size + size * count" in the
> kzalloc() functions.
> 
> This way, the code is more readable and safer.
> 
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
> Link: https://github.com/KSPP/linux/issues/160 [2]
> Signed-off-by: Erick Archer <erick.archer@gmx.com>

applied

      reply	other threads:[~2024-03-10 19:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-10 11:02 [PATCH v2] bcachefs: Prefer struct_size over open coded arithmetic Erick Archer
2024-03-10 19:41 ` Kent Overstreet [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=rmna7gzrezwrhmrsgheswqsnc53nk6xiu5en6fg3ag44f3blps@otgd65u62umx \
    --to=kent.overstreet@linux.dev \
    --cc=bfoster@redhat.com \
    --cc=erick.archer@gmx.com \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-bcachefs@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).