From: Andrew Morton <akpm@linux-foundation.org>
To: Manfred Spraul <manfred@colorfullife.com>
Cc: Andrey Ryabinin <a.ryabinin@samsung.com>,
Dmitry Vyukov <dvyukov@google.com>,
David Rientjes <rientjes@google.com>,
Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
Luiz Capitulino <lcapitulino@redhat.com>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
Nadia.Derbey@bull.net, aquini@redhat.com, davidlohr@hp.com,
Joe Perches <joe@perches.com>,
avagin@openvz.org, LKML <linux-kernel@vger.kernel.org>,
Kostya Serebryany <kcc@google.com>,
Dmitry Chernenkov <dmitryc@google.com>,
Andrey Konovalov <andreyknvl@google.com>,
Konstantin Khlebnikov <koct9i@gmail.com>,
kasan-dev <kasan-dev@googlegroups.com>
Subject: Re: [PATCH] kernel: sysctl: use 'unsigned long' type for 'zero' variable
Date: Fri, 5 Dec 2014 14:50:14 -0800 [thread overview]
Message-ID: <20141205145014.2f8a076eb5ba15bd2f97dd36@linux-foundation.org> (raw)
In-Reply-To: <547FFB5D.8000503@colorfullife.com>
On Thu, 04 Dec 2014 07:12:45 +0100 Manfred Spraul <manfred@colorfullife.com> wrote:
> Hi Andrew,
>
> On 12/04/2014 12:25 AM, Andrew Morton wrote:
> > On Wed, 03 Dec 2014 15:41:21 +0300 Andrey Ryabinin <a.ryabinin@samsung.com> wrote:
> >
> >> Use the 'unsigned long' type for 'zero' variable to fix this.
> >> Changing type to 'unsigned long' shouldn't affect any other users
> >> of this variable.
> >>
> >> Reported-by: Dmitry Vyukov <dvyukov@google.com>
> >> Fixes: ed4d4902ebdd ("mm, hugetlb: remove hugetlb_zero and hugetlb_infinity")
> >> Signed-off-by: Andrey Ryabinin <a.ryabinin@samsung.com>
> >> ---
> >> kernel/sysctl.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> >> index 15f2511..45c45c9 100644
> >> --- a/kernel/sysctl.c
> >> +++ b/kernel/sysctl.c
> >> @@ -120,7 +120,7 @@ static int sixty = 60;
> >>
> >> static int __maybe_unused neg_one = -1;
> >>
> >> -static int zero;
> >> +static unsigned long zero;
> >> static int __maybe_unused one = 1;
> >> static int __maybe_unused two = 2;
> >> static int __maybe_unused four = 4;
> > Yeah, this is ghastly.
> >
> > Look at
> >
> > {
> > .procname = "numa_balancing",
> > .data = NULL, /* filled in by handler */
> > .maxlen = sizeof(unsigned int),
> > .mode = 0644,
> > .proc_handler = sysctl_numa_balancing,
> > .extra1 = &zero,
> > .extra2 = &one,
> > },
> >
> > Now extra1 points at a long and extra2 points at an int.
> > sysctl_numa_balancing() calls proc_dointvec_minmax() and I think your
> > patch just broke big-endian 64-bit machines. "sched_autogroup_enabled"
> > breaks as well.
> What about getting rid of "extra1" and "extra2" as well and replace it
> with "min" and "max"?
>
> I've attached an idea
Looks sane.
> > and change proc_dointvec_minmax() and a million other functions to take
> > `union sysctl_payload *' arguments. But I haven't thought about it much.
> Another idea: why do we pass "int *" instead of "int"?
>
> With "int", we could use
> .int_min = 0;
> .int_max = 1;
Presumably they were originally made void* so they could point at any
thing at all. But I don't recall seeing extra1 and extra2 used for
anything other than bounds checking on a scalar.
Problem is, these things aren't always compile-time constants. For
example, pid_max_min and pid_max_max are altered at runtime.
I doubt if we need to support both ints and longs in extra1/2 - longs
should be OK for range-checking int values. The signed/unsigned issue
needs thinking about - there's a "neg_one" in there. If we make
everything "long" then we might run into signedness/range issues for
sysctls which can have large unsigned values with the top bit set:
0x8000000-0xffffffff and 0x8000000000000000 - ...
next prev parent reply other threads:[~2014-12-05 22:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-03 9:04 Out-of-bounds access in __do_proc_doulongvec_minmax Dmitry Vyukov
2014-12-03 12:39 ` Andrey Ryabinin
2014-12-03 12:41 ` [PATCH] kernel: sysctl: use 'unsigned long' type for 'zero' variable Andrey Ryabinin
2014-12-03 13:04 ` Rafael Aquini
2014-12-03 21:12 ` David Rientjes
2014-12-03 23:25 ` Andrew Morton
2014-12-04 0:19 ` Andrew Morton
2014-12-04 11:35 ` Andrey Ryabinin
2014-12-04 6:12 ` Manfred Spraul
2014-12-05 22:50 ` Andrew Morton [this message]
2014-12-13 20:51 ` Manfred Spraul
2014-12-15 6:41 ` Andrey Ryabinin
2014-12-17 14:30 ` [PATCH 1/2] hugetlb, sysctl: pass '.extra1 = NULL' rather then '.extra1 = &zero' Andrey Ryabinin
2014-12-17 14:30 ` [PATCH 2/2] mm: hugetlb: fix type of hugetlb_treat_as_movable variable Andrey Ryabinin
2014-12-18 0:39 ` David Rientjes
2014-12-18 0:38 ` [PATCH 1/2] hugetlb, sysctl: pass '.extra1 = NULL' rather then '.extra1 = &zero' David Rientjes
2014-12-03 13:27 ` Out-of-bounds access in __do_proc_doulongvec_minmax Dmitry Vyukov
2014-12-03 13:37 ` Andrey Ryabinin
2014-12-03 13:39 ` Dmitry Vyukov
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=20141205145014.2f8a076eb5ba15bd2f97dd36@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=Nadia.Derbey@bull.net \
--cc=a.ryabinin@samsung.com \
--cc=andreyknvl@google.com \
--cc=aquini@redhat.com \
--cc=avagin@openvz.org \
--cc=davidlohr@hp.com \
--cc=dmitryc@google.com \
--cc=dvyukov@google.com \
--cc=joe@perches.com \
--cc=kasan-dev@googlegroups.com \
--cc=kcc@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=koct9i@gmail.com \
--cc=lcapitulino@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=rientjes@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