linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Brauner <christian@brauner.io>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: keescook@chromium.org, linux-kernel@vger.kernel.org,
	ebiederm@xmission.com, mcgrof@kernel.org,
	akpm@linux-foundation.org, joe.lawrence@redhat.com,
	longman@redhat.com
Subject: Re: [PATCH 1/2] sysctl: add overflow detection to proc_get_long()
Date: Mon, 15 Oct 2018 06:47:44 +0200	[thread overview]
Message-ID: <81C57381-F8F8-467B-84DF-8948F44B242F@brauner.io> (raw)
In-Reply-To: <20181015000310.GX32577@ZenIV.linux.org.uk>

On October 15, 2018 2:03:10 AM GMT+02:00, Al Viro <viro@ZenIV.linux.org.uk> wrote:
>On Sun, Oct 14, 2018 at 08:53:46PM +0200, Christian Brauner wrote:
>
>> > Yecchh...  First of all, the cast back to unsigned long long is
>completely
>> > pointless.  What's more,
>> 
>> Sorry, seriously asking: why? This was meant to handle the case where
>> sizeof(unsigned long long) != sizeof(unsigned long) and I just looked
>at
>> _kstrtoul() which does the same:
>> 
>> int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
>> {
>> 	unsigned long long tmp;
>> 	int rv;
>> 
>> 	rv = kstrtoull(s, base, &tmp);
>> 	if (rv < 0)
>> 		return rv;
>> 	if (tmp != (unsigned long long)(unsigned long)tmp)
>> 		return -ERANGE;
>> 	*res = tmp;
>> 	return 0;
>> }
>> 
>> Sorry, if I'm being dense here.
>
>C quiz:
>	given that type of e1 is unsigned long long and type of e2 -
>unsigned long, what conversions are going to happen in e1 == e2?

Yeah, I know that.
As I said in my reply to Alexey before: I 
thought you were saying the whole right 
side of the disjunction was not needed.

I also do like the explicit recast and
followed what all of the other kstr*()
functions are doing.
Alexey sent a fix for all of them just
a few hours ago [1] which - imho - is 
really not necessary. There's no harm 
done by this and it's a fairly widely used
pattern.

That being said, happy to remove the
second explicit cast.

[1]: https://lkml.org/lkml/2018/10/15/22

>
>[relevant part of C standard: 6.5.9 (Equality operators),
>6.3.1.8 (Usual arithmetic conversions)]


  reply	other threads:[~2018-10-15  4:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-14 13:25 [PATCH 0/2] sysctl: cap file-max value at ULONG_MAX Christian Brauner
2018-10-14 13:25 ` [PATCH 1/2] sysctl: add overflow detection to proc_get_long() Christian Brauner
2018-10-14 17:18   ` Al Viro
2018-10-14 18:53     ` Christian Brauner
2018-10-15  0:03       ` Al Viro
2018-10-15  4:47         ` Christian Brauner [this message]
2018-10-14 13:25 ` [PATCH 2/2] sysctl: handle overflow for file-max Christian Brauner
2018-10-14 22:13 [PATCH 1/2] sysctl: add overflow detection to proc_get_long() Alexey Dobriyan
2018-10-14 22:43 ` Christian Brauner

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=81C57381-F8F8-467B-84DF-8948F44B242F@brauner.io \
    --to=christian@brauner.io \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=joe.lawrence@redhat.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mcgrof@kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    --subject='Re: [PATCH 1/2] sysctl: add overflow detection to proc_get_long()' \
    /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

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).