From: Mark Rutland <mark.rutland@arm.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, agordeev@linux.ibm.com,
aou@eecs.berkeley.edu, bp@alien8.de, catalin.marinas@arm.com,
dave.hansen@linux.intel.com, davem@davemloft.net,
gor@linux.ibm.com, hca@linux.ibm.com, linux-arch@vger.kernel.org,
linux@armlinux.org.uk, mingo@redhat.com, palmer@dabbelt.com,
paul.walmsley@sifive.com, robin.murphy@arm.com,
tglx@linutronix.de, viro@zeniv.linux.org.uk, will@kernel.org
Subject: Re: [PATCH v2 1/4] lib: test copy_{to,from}_user()
Date: Wed, 22 Mar 2023 13:55:08 +0000 [thread overview]
Message-ID: <ZBsIvLUBNwYAjNUK@FVFF77S0Q05N> (raw)
In-Reply-To: <CAHk-=wgknoR11b+mX=AP8TcHP+gsFGdhPk7sJPROaQBBsqdubw@mail.gmail.com>
On Tue, Mar 21, 2023 at 11:04:26AM -0700, Linus Torvalds wrote:
> On Tue, Mar 21, 2023 at 5:25 AM Mark Rutland <mark.rutland@arm.com> wrote:
> >
> > * arm64's copy_to_user() under-reports the number of bytes copied in
> > some cases, e.g.
>
> So I think this is the ok case.
>
> > * arm's copy_to_user() under-reports the number of bytes copied in some
> > cases, and both copy_to_user() and copy_from_user() don't guarantee
> > that at least a single byte is copied when a partial copy is possible,
>
> Again, this is ok historically.
>
> > * i386's copy_from_user does not guarantee that at least a single byte
> > is copied when a partial copit is possible, e.g.
> >
> > | too few bytes consumed (offset=4093, size=8, ret=8)
>
> And here's the real example of "we've always done this optimization".
> The exact details have differed, but the i386 case is the really
> really traditional one: it does word-at-a-time copies, and does *not*
> try to fall back to byte-wise copies. Never has.
Sure; I understand that. The reason for pointing this out is that Al was very
specific that implementations *must* guarantee this back in:
https://lore.kernel.org/all/YNSyZaZtPTmTa5P8@zeniv-ca.linux.org.uk/
... and that this could be done by having the fixup handler try to copy a byte.
I had assumed that *something* depended upon that, but I don't know what that
something actually is.
I'm not wedded to the semantic either way; if that's not required I can drop it
from the tests.
> > * s390 passes all tests
> >
> > * sparc's copy_from_user() over-reports the number of bbytes copied in
> > some caes, e.g.
>
> So this case I think this is wrong, and an outright bug. That can
> cause people to think that uninitialized data is initialized, and leak
> sensitive information.
Agreed.
> > * x86_64 passes all tests
>
> I suspect your testing is flawed due to being too limited, and x86-64
> having multiple different copying routines.
Sorry; I should've called that out explicitly. I'm aware I'm not testing all
the variants (I'd be happy to); I just wanted to check that I wasn't going off
into the weeds with the semantics first.
I probably should've sent this as an RFC...
> Yes, at some point we made everything be quite careful with
> "handle_tail" etc, but we end up still having things that fail early,
> and fail hard.
>
> At a minimum, at least unsafe_copy_to_user() will fault and not do the
> "fill to the very last byte" case. Of course, that doesn't return a
> partial length (it only has a "fail" case), but it's an example of
> this whole thing where we haven't really been byte-exact when doing
> copies.
Sure; that does seem to be different structurally too, so it'd need to be
plumbed into the harness differently.
I'll note that's more like {get,put}_user() which similarly just have a fail
case (and a put_user() could do a parital write then fault).
> So again, I get the feeling that these rules may make sense from a
> validation standpoint, but I'm not 100% sure we should generally have
> to be this careful.
I'm more than happy to relax the tests (and the docs); I just need to know
where the boundary is between what we must guarantee and what's a nice-to-have.
Thanks,
Mark.
next prev parent reply other threads:[~2023-03-22 13:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 12:25 [PATCH v2 0/4] usercopy: generic tests + arm64 fixes Mark Rutland
2023-03-21 12:25 ` [PATCH v2 1/4] lib: test copy_{to,from}_user() Mark Rutland
2023-03-21 17:09 ` Catalin Marinas
2023-03-22 14:05 ` Mark Rutland
2023-03-23 22:16 ` David Laight
2023-03-27 10:11 ` Catalin Marinas
2023-03-21 18:04 ` Linus Torvalds
2023-03-22 13:55 ` Mark Rutland [this message]
2023-03-21 12:25 ` [PATCH v2 2/4] lib: test clear_user() Mark Rutland
2023-03-21 17:13 ` Catalin Marinas
2023-03-21 12:25 ` [PATCH v2 3/4] arm64: fix __raw_copy_to_user semantics Mark Rutland
2023-03-21 17:50 ` Linus Torvalds
2023-03-22 14:16 ` Mark Rutland
2023-03-22 14:48 ` Catalin Marinas
2023-03-22 15:30 ` Mark Rutland
2023-03-22 16:39 ` Linus Torvalds
2023-03-21 12:25 ` [PATCH v2 4/4] arm64: fix clear_user() semantics Mark Rutland
2023-11-15 22:30 ` [PATCH v2 0/4] usercopy: generic tests + arm64 fixes 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=ZBsIvLUBNwYAjNUK@FVFF77S0Q05N \
--to=mark.rutland@arm.com \
--cc=agordeev@linux.ibm.com \
--cc=aou@eecs.berkeley.edu \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mingo@redhat.com \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robin.murphy@arm.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=will@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;
as well as URLs for NNTP newsgroup(s).