netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Kees Cook <keescook@chromium.org>
Cc: "Richard Weinberger" <richard@nod.at>,
	linux-hardening@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Sergey Senozhatsky" <senozhatsky@chromium.org>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Rasmus Villemoes" <linux@rasmusvillemoes.dk>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"John Fastabend" <john.fastabend@gmail.com>
Subject: Re: [RFC PATCH 0/1] Integer overflows while scanning for integers
Date: Thu, 8 Jun 2023 17:27:40 +0200	[thread overview]
Message-ID: <ZIHzbBXlxEz6As9N@alley> (raw)
In-Reply-To: <202306071634.51BBAFD14@keescook>

On Wed 2023-06-07 16:36:12, Kees Cook wrote:
> On Thu, Jun 08, 2023 at 12:37:54AM +0200, Richard Weinberger wrote:
> > Hi!
> > 
> > Lately I wondered whether users of integer scanning functions check
> > for overflows.
> > To detect such overflows around scanf I came up with the following
> > patch. It simply triggers a WARN_ON_ONCE() upon an overflow.
> > 
> > After digging into various scanf users I found that the network device
> > naming code can trigger an overflow.
> > 
> > e.g:
> > $ ip link add 1 type veth peer name 9999999999
> > $ ip link set name "%d" dev 1
> > 
> > It will trigger the following WARN_ON_ONCE():
> > ------------[ cut here ]------------
> > WARNING: CPU: 2 PID: 433 at lib/vsprintf.c:3701 vsscanf+0x6ce/0x990
> 
> Hm, it's considered a bug if a WARN or BUG can be reached from
> userspace,

Good point. WARN() does not look like the right way in this case.

Another problem is that some users use panic_on_warn. In this case,
the above "ip" command calls would trigger panic(). And it does not
look like an optimal behavior.

I know there already are some WARN_ONs for similar situations, e.g.
set_field_width() or set_precision(). But these do not get random
values. And it would actually be nice to introduce something like
INFO() that would be usable for these less serious problems where
the backtrace is useful but they should never trigger panic().

> so this probably needs to be rearranged (or callers fixed).
> Do we need to change the scanf API for sane use inside the kernel?

It seems that userspace implementation of sscanf() and vsscanf()
returns -ERANGE in this case. It might be a reasonable solution.

Well, there is a risk of introducing security problems. The error
value might cause an underflow/overflow when the caller does not expect
a negative value.

Alternative solution would be to update the "ip" code so that it
reads the number separately and treat zero return value as
-EINVAL.

Best Regards,
Petr

  reply	other threads:[~2023-06-08 15:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07 22:37 [RFC PATCH 0/1] Integer overflows while scanning for integers Richard Weinberger
2023-06-07 22:37 ` [RFC PATCH 1/1] vsprintf: Warn on integer scanning overflows Richard Weinberger
2023-06-08 14:27   ` Andy Shevchenko
2023-06-08 16:14     ` Richard Weinberger
2023-06-08 16:23       ` Andy Shevchenko
2023-06-12  6:16   ` kernel test robot
2023-06-07 23:36 ` [RFC PATCH 0/1] Integer overflows while scanning for integers Kees Cook
2023-06-08 15:27   ` Petr Mladek [this message]
2023-06-08 16:12     ` Richard Weinberger
2023-06-08 16:19     ` Greg KH
2023-06-08 16:23       ` Richard Weinberger
2023-06-09 10:10     ` Rasmus Villemoes
2023-06-09 17:02       ` Petr Mladek
2023-06-09 17:46         ` Linus Torvalds
2023-06-10 19:31       ` David Laight

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=ZIHzbBXlxEz6As9N@alley \
    --to=pmladek@suse.com \
    --cc=alex.gaynor@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ast@kernel.org \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gary@garyguo.net \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=keescook@chromium.org \
    --cc=kuba@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=netdev@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richard@nod.at \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=wedsonaf@gmail.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).