mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Dmitry Vyukov' <dvyukov@google.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	Kees Cook <keescook@chromium.org>, Eryu Guan <eguan@redhat.com>,
	Alexander Potapenko <glider@google.com>,
	Chris Metcalf <metcalf@alum.mit.edu>,
	stable <stable@vger.kernel.org>,
	kasan-dev <kasan-dev@googlegroups.com>
Subject: RE: [PATCH] lib/strscpy: remove word-at-a-time optimization.
Date: Thu, 25 Jan 2018 08:42:43 +0000	[thread overview]
Message-ID: <60d69abd8279434f997b0766736ba727@AcuMS.aculab.com> (raw)
In-Reply-To: <CACT4Y+Y=NKgSLQqy0zrOuSOWOd2H2P0DcN09CnV+XnXuAgRF8Q@mail.gmail.com>

From: Dmitry Vyukov [mailto:dvyukov@google.com]
> Sent: 25 January 2018 08:33
> 
> On Wed, Jan 24, 2018 at 6:52 PM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> > On Wed, Jan 24, 2018 at 12:54 AM, Rasmus Villemoes
> > <rasmus.villemoes@prevas.dk> wrote:
> >>
> >> I see something similar, but at the 30->31 transition, and the
> >> branch-misses remain at 1-3% for higher values, until 42 where it drops
> >> back to 0%. Anyway, I highly doubt we do a lot of string copies of
> >> strings longer then 32.
> >
> > So I really dislike that microbenchmark, because it just has the same
> > length all the time. Which is very wrong, and makes the benchmark
> > pointless. A big part of this all is branch mispredicts, you shouldn't
> > just hand it the pattern on a plate.
> >
> > Anyway, the reason I really dislike the patch is not because I think
> > strscpy() is all that important, but I *do* think that the
> > word-at-a-time thing is conceptually something we do care about, and I
> > hate removing it just because of KASAN not understanding it.
> >
> > So I'd *much* rather have some way to tell KASAN that word-at-a-time
> > is going on. Because that approach definitely makes a difference in
> > other places.
> 
> 
> The other option was to use READ_ONCE_NOCHECK(). Not sure if the "read
> once" part will affect codegen here, though.
> But if word-at-a-time thing is conceptually something we do care
> about, we could also introduce something like READ_PARTIALLY_VALID(),
> which would check that at least first byte of the read is valid and
> that it does not cross heap block boundary (but outside of KASAN is a
> normal read).

The first byte might not have been written either.
For example, doing a strlen() on a misaligned string you might read
the aligned word containing the first byte and adjust the value so
that the initial byte(s) are not zero.
After scanning for a zero byte the length would be corrected.

	David

  reply	other threads:[~2018-01-25  8:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-09 16:37 Andrey Ryabinin
2018-01-09 16:47 ` Andrey Ryabinin
2018-01-24  8:54   ` Rasmus Villemoes
2018-01-24 17:52     ` Linus Torvalds
2018-01-25  8:32       ` Dmitry Vyukov
2018-01-25  8:42         ` David Laight [this message]
2018-01-25  9:08           ` Dmitry Vyukov
2018-01-25 17:55         ` Linus Torvalds
2018-01-25 19:13           ` Andrey Ryabinin
2018-01-30  9:12             ` Dmitry Vyukov
2018-01-24  8:47 ` Rasmus Villemoes
2018-01-24 15:53 ` Andy Shevchenko

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=60d69abd8279434f997b0766736ba727@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=dvyukov@google.com \
    --cc=eguan@redhat.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=metcalf@alum.mit.edu \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®