mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Randy Dunlap' <rdunlap@infradead.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Alexander Viro <viro@zeniv.linux.org.uk>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Peter Zijlstra" <peterz@infradead.org>
Subject: RE: [PATCH] mm/uaccess: Use 'unsigned long' to placate UBSAN warnings, again
Date: Thu, 7 Jan 2021 10:06:43 +0000	[thread overview]
Message-ID: <c2f2f302c7e24ceb976f71232de6bdbc@AcuMS.aculab.com> (raw)
In-Reply-To: <6823854f-019f-f9db-7fd8-da8e7a0016d1@infradead.org>

From: Randy Dunlap
> Sent: 23 December 2020 07:19
> 
> On 12/22/20 9:04 PM, Josh Poimboeuf wrote:
> > GCC 7 has a known bug where UBSAN ignores '-fwrapv' and generates false
> > signed-overflow-UB warnings.  The type mismatch between 'i' and
> > 'nr_segs' in copy_compat_iovec_from_user() is causing such a warning,
> > which also happens to violate uaccess rules:
> >
> >   lib/iov_iter.o: warning: objtool: iovec_from_user()+0x22d: call to __ubsan_handle_add_overflow()
> with UACCESS enabled
> >
> > Fix it by making the variable types match.
> >
> > This is similar to a previous commit:
> >
> >   29da93fea3ea ("mm/uaccess: Use 'unsigned long' to placate UBSAN warnings on older GCC versions")
> >
> > Reported-by: Randy Dunlap <rdunlap@infradead.org>
> > Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
> 
> All good. Thanks.
> 
> Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested

FWIW I've tested the equivalent change locally.
It generates rather better code on amd64.
(You don't want to index arrays with 'int' unless you really have to.)
So probably:

Acked-by: David Laight <david.laight@aculab.com>

	David

> 
> 
> > ---
> >  lib/iov_iter.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/lib/iov_iter.c b/lib/iov_iter.c
> > index 1635111c5bd2..2e6a42f5d1df 100644
> > --- a/lib/iov_iter.c
> > +++ b/lib/iov_iter.c
> > @@ -1656,7 +1656,8 @@ static int copy_compat_iovec_from_user(struct iovec *iov,
> >  {
> >  	const struct compat_iovec __user *uiov =
> >  		(const struct compat_iovec __user *)uvec;
> > -	int ret = -EFAULT, i;
> > +	int ret = -EFAULT;
> > +	unsigned long i;
> >
> >  	if (!user_access_begin(uvec, nr_segs * sizeof(*uvec)))
> >  		return -EFAULT;
> >
> 
> 
> --
> ~Randy

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2021-01-07 10:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-23  5:04 Josh Poimboeuf
2020-12-23  7:18 ` Randy Dunlap
2021-01-07 10:06   ` David Laight [this message]
2021-01-04 15:13 ` Peter Zijlstra
2021-01-06 23:37   ` Kees Cook
2021-01-07  0:06     ` Randy Dunlap
2021-01-07 21:07       ` Kees Cook
2021-01-13 23:27         ` Josh Poimboeuf
2021-01-07 10:51     ` Dmitry Vyukov
2021-01-14 10:59   ` [PATCH] ubsan: Require GCC-8+ or Clang to use UBSAN Peter Zijlstra
2021-01-14 11:09     ` Andrey Ryabinin
2021-01-18 17:53       ` Josh Poimboeuf
2021-02-09 18:24         ` Josh Poimboeuf
2021-02-09 23:17           ` Andrey Rybainin
2021-02-10  0:21             ` Kees Cook

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=c2f2f302c7e24ceb976f71232de6bdbc@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®