From: Vasiliy Kulikov <segooon@gmail.com>
To: David Rientjes <rientjes@google.com>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
kernel-janitors@vger.kernel.org,
"André Goddard Rosa" <andre.goddard@gmail.com>,
"Joe Perches" <joe@perches.com>,
"Frederic Weisbecker" <fweisbec@gmail.com>,
"Bjorn Helgaas" <bjorn.helgaas@hp.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib: vsprintf: fix invalid arg check
Date: Thu, 11 Nov 2010 21:02:51 +0000 [thread overview]
Message-ID: <20101111210251.GA26283@albatros> (raw)
In-Reply-To: <alpine.DEB.2.00.1011111224161.25829@chino.kir.corp.google.com>
On Thu, Nov 11, 2010 at 12:38 -0800, David Rientjes wrote:
> On Thu, 11 Nov 2010, Vasiliy Kulikov wrote:
>
> > > > > "size" is size_t. If we want to check whether it was underflowed
> > > > > then we should cast it to ssize_t instead of int. When
> > > > > sizeof(size_t) > sizeof(int) the code sees UINT_MAX as underflow,
> > > > > but it is not.
> > > > >
> > > >
> > > > Does this patch fix any actual observed problem?
> >
> > I don't think so, this fix is more theoretical than practical.
> > However, maybe there is some crazy driver that fills array of 2GB with
> > s*printf().
> >
>
> All sizes passed to vsprintf() greater than INT_MAX are invalid; that's
> what the original code is testing, warning, and handling correctly.
Not always correctly:
(int)(0xFFFFFFFFL + 2) = 1 is positive.
> No, it shouldn't, these functions return int. INT_MAX is the largest
> value we can handle successfully and that's why it is the special case for
> sprintf() and vsprintf().
>
> The code as it stands is correct not because of the type of the size but
> rather the type of the return value.
OK, if the main reason here is return value type, then the correct
handling should be:
/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
- if (WARN_ON_ONCE((int) size < 0))
+ if (WARN_ON_ONCE(size > INT_MAX)
return 0;
This should catch all underflows and too big integers.
--
Vasiliy
WARNING: multiple messages have this Message-ID (diff)
From: Vasiliy Kulikov <segooon@gmail.com>
To: David Rientjes <rientjes@google.com>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
kernel-janitors@vger.kernel.org,
"André Goddard Rosa" <andre.goddard@gmail.com>,
"Joe Perches" <joe@perches.com>,
"Frederic Weisbecker" <fweisbec@gmail.com>,
"Bjorn Helgaas" <bjorn.helgaas@hp.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib: vsprintf: fix invalid arg check
Date: Fri, 12 Nov 2010 00:02:51 +0300 [thread overview]
Message-ID: <20101111210251.GA26283@albatros> (raw)
In-Reply-To: <alpine.DEB.2.00.1011111224161.25829@chino.kir.corp.google.com>
On Thu, Nov 11, 2010 at 12:38 -0800, David Rientjes wrote:
> On Thu, 11 Nov 2010, Vasiliy Kulikov wrote:
>
> > > > > "size" is size_t. If we want to check whether it was underflowed
> > > > > then we should cast it to ssize_t instead of int. When
> > > > > sizeof(size_t) > sizeof(int) the code sees UINT_MAX as underflow,
> > > > > but it is not.
> > > > >
> > > >
> > > > Does this patch fix any actual observed problem?
> >
> > I don't think so, this fix is more theoretical than practical.
> > However, maybe there is some crazy driver that fills array of 2GB with
> > s*printf().
> >
>
> All sizes passed to vsprintf() greater than INT_MAX are invalid; that's
> what the original code is testing, warning, and handling correctly.
Not always correctly:
(int)(0xFFFFFFFFL + 2) = 1 is positive.
> No, it shouldn't, these functions return int. INT_MAX is the largest
> value we can handle successfully and that's why it is the special case for
> sprintf() and vsprintf().
>
> The code as it stands is correct not because of the type of the size but
> rather the type of the return value.
OK, if the main reason here is return value type, then the correct
handling should be:
/* Reject out-of-range values early. Large positive sizes are
used for unknown buffer sizes. */
- if (WARN_ON_ONCE((int) size < 0))
+ if (WARN_ON_ONCE(size > INT_MAX)
return 0;
This should catch all underflows and too big integers.
--
Vasiliy
next prev parent reply other threads:[~2010-11-11 21:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-10 20:38 [PATCH] lib: vsprintf: fix invalid arg check Vasiliy Kulikov
2010-11-10 20:38 ` Vasiliy Kulikov
2010-11-10 21:08 ` Andrew Morton
2010-11-10 21:08 ` Andrew Morton
2010-11-10 21:38 ` David Rientjes
2010-11-10 21:38 ` David Rientjes
2010-11-11 8:34 ` Vasiliy Kulikov
2010-11-11 8:34 ` Vasiliy Kulikov
2010-11-11 20:38 ` David Rientjes
2010-11-11 20:38 ` David Rientjes
2010-11-11 21:02 ` Vasiliy Kulikov [this message]
2010-11-11 21:02 ` Vasiliy Kulikov
2010-11-11 21:34 ` David Rientjes
2010-11-11 21:34 ` David Rientjes
2010-11-12 17:42 ` Vasiliy Kulikov
2010-11-12 17:42 ` Vasiliy Kulikov
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=20101111210251.GA26283@albatros \
--to=segooon@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andre.goddard@gmail.com \
--cc=bjorn.helgaas@hp.com \
--cc=fweisbec@gmail.com \
--cc=joe@perches.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.