linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Len Baker <len.baker@gmx.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
	Kees Cook <keescook@chromium.org>,
	Iurii Zaikin <yzaikin@google.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-hardening@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sysctl: Avoid open coded arithmetic in memory allocator functions
Date: Sat, 16 Oct 2021 17:18:24 +0100	[thread overview]
Message-ID: <YWr7UN1+RkayVWy2@casper.infradead.org> (raw)
In-Reply-To: <20211016152829.9836-1-len.baker@gmx.com>

On Sat, Oct 16, 2021 at 05:28:28PM +0200, Len Baker wrote:
> +static size_t new_dir_size(size_t namelen)
> +{
> +	size_t bytes;
> +
> +	if (check_add_overflow(sizeof(struct ctl_dir), sizeof(struct ctl_node),
> +			       &bytes))
> +		return SIZE_MAX;
> +	if (check_add_overflow(bytes, array_size(sizeof(struct ctl_table), 2),
> +			       &bytes))
> +		return SIZE_MAX;
> +	if (check_add_overflow(bytes, namelen, &bytes))
> +		return SIZE_MAX;
> +	if (check_add_overflow(bytes, (size_t)1, &bytes))
> +		return SIZE_MAX;
> +
> +	return bytes;
> +}

I think this is overkill.  All these structs are small and namelen is
supplied by the kernel, not specified by userspace.  It really complicates
the code, and I don't see the advantage.


  reply	other threads:[~2021-10-16 16:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-16 15:28 [PATCH] sysctl: Avoid open coded arithmetic in memory allocator functions Len Baker
2021-10-16 16:18 ` Matthew Wilcox [this message]
2021-10-23 10:31   ` Len Baker

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=YWr7UN1+RkayVWy2@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=gustavoars@kernel.org \
    --cc=keescook@chromium.org \
    --cc=len.baker@gmx.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=yzaikin@google.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;
as well as URLs for NNTP newsgroup(s).