From: David Laight <David.Laight@ACULAB.COM>
To: 'Rasmus Villemoes' <linux@rasmusvillemoes.dk>,
Al Viro <viro@zeniv.linux.org.uk>,
Andy Lutomirski <luto@kernel.org>
Cc: syzbot <syzbot+ea3a78a71705faf41d77@syzkaller.appspotmail.com>,
"Aleksa Sarai" <cyphar@cyphar.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
LKML <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"syzkaller-bugs@googlegroups.com"
<syzkaller-bugs@googlegroups.com>,
Thomas Gleixner <tglx@linutronix.de>, "X86 ML" <x86@kernel.org>
Subject: RE: WARNING in ex_handler_uaccess
Date: Mon, 21 Sep 2020 10:33:19 +0000 [thread overview]
Message-ID: <8bef09fd4d644f48a7c83aa18b653f76@AcuMS.aculab.com> (raw)
In-Reply-To: <bc5d889c-17f0-dcb8-d174-f21b321cf85b@rasmusvillemoes.dk>
From: Rasmus Villemoes
> Sent: 21 September 2020 11:22
> On 19/09/2020 02.17, Al Viro wrote:
> > On Fri, Sep 18, 2020 at 05:07:43PM -0700, Andy Lutomirski wrote:
> >> On Fri, Sep 18, 2020 at 4:55 PM Al Viro <viro@zeniv.linux.org.uk> wrote:
> >>>
> >>> On Fri, Sep 18, 2020 at 04:31:33PM -0700, Andy Lutomirski wrote:
> >>>
> >>>> check_zeroed_user() looks buggy. It does:
> >>>>
> >>>> if (!user_access_begin(from, size))
> >>>> return -EFAULT;
> >>>>
> >>>> unsafe_get_user(val, (unsigned long __user *) from, err_fault);
> >>>>
> >>>> This is wrong if size < sizeof(unsigned long) -- you read outside the
> >>>> area you verified using user_access_begin().
> >>>
> >>> Read the code immediately prior to that. from will be word-aligned,
> >>> and size will be extended accordingly. If the area acceptable for
> >>> user_access_begin() ends *NOT* on a word boundary, you have a problem
> >>> and I would strongly recommend to seek professional help.
> >>>
> >>> All reads in that thing are word-aligned and word-sized. So I very
> >>> much doubt that your analysis is correct.
> >>
> >> Maybe -ETOOTIRED, but I seriously question the math in here. Suppose
> >> from == (unsigned long *)1 and size == 1. Then align is 1, and we do:
> >>
> >> from -= align;
> >> size += align;
> >>
> >> So now from = 0 and size = 2. Now we do user_access_begin(0, 2) and
> >> then immediately read 4 or 8 bytes. No good.
> >
> > Could you explain what kind of insane hardware manages to do #PF-related
> > checks (including SMAP, whatever) with *sub*WORD* granularity?
> >
> > If it's OK with 16bit read from word-aligned address, but barfs on 64bit
> > one... I want to know what the hell had its authors been smoking.
> >
>
> So, not sure how the above got triggered, but I notice there might be an
> edge case in check_zeroed_user():
>
> from -= align;
> size += align;
>
> if (!user_read_access_begin(from, size))
> return -EFAULT;
>
> unsafe_get_user(val, (unsigned long __user *) from, err_fault);
>
>
> Suppose size is (size_t)-3 and align is 3. What's the convention for
> access_ok(whatever, 0)? Is that equivalent to access_ok(whatever, 1), or
> is it always true (or $ARCH-dependent)?
Doesn't matter, it will be doing access_ok(xxx, 8) regardless of
the user-supplied transfer length.
> But, AFAICT, no current caller of check_zeroed_user can end up passing
> in a size that can overflow to 0. E.g. for the case at hand, size cannot
> be more than SIZE_MAX-24.
Basically KASAN doesn't like you reading full words and masking
off the unused bytes.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2020-09-21 10:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-18 21:01 syzbot
2020-09-18 23:31 ` Andy Lutomirski
2020-09-18 23:55 ` Al Viro
2020-09-19 0:07 ` Andy Lutomirski
2020-09-19 0:17 ` Al Viro
2020-09-19 15:37 ` David Laight
2020-09-21 10:22 ` Rasmus Villemoes
2020-09-21 10:33 ` David Laight [this message]
2020-09-23 4:26 ` Al Viro
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=8bef09fd4d644f48a7c83aa18b653f76@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=bp@alien8.de \
--cc=cyphar@cyphar.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=syzbot+ea3a78a71705faf41d77@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tglx@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
--cc=x86@kernel.org \
/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
Powered by JetHome