Received: by 10.223.176.46 with SMTP id f43csp1868870wra; Thu, 25 Jan 2018 01:09:15 -0800 (PST) X-Google-Smtp-Source: AH8x227aMuXZYQ0nQt1TxNilmh/qo7x9lOMloBsEFoUFeUfi/0vlYMOj6HuwBB/MIralqobr61gr X-Received: by 10.98.204.144 with SMTP id j16mr15656348pfk.101.1516871355891; Thu, 25 Jan 2018 01:09:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516871355; cv=none; d=google.com; s=arc-20160816; b=ZojAN+py6hff3t6sL6uACrnN7TyPte8pFO2DFjkLyocBhSDnNd4mUyrcHfQQ5J1RUr Sg0+Pcpq4fXXvJgoj6iYpOO7HvWN3akYHON2QhFcX59NUBUthXcKrDKb3IUFKzlCdZ+M Let5wJ/4wLFLWbvCibjyz3I/FOz81BPh/W0LNVXyaVX7spi8AexDA2Q/FwtUZ43LvDUZ YfzKxIFqpTRoZ7ViGpV+eWfYTqokBFA8xmYQrNKZ+ClLR/uMp+bJaUyDCq5wFU0aTkua zGckey3/BxcUIRK9cgWnTfIMg5pKOANRFtdNy0NhCezo2MkOY9gkWdHIxrL5Szaar+2a lpkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=m7+jQCvnhBblPkvyxrpPo0i//zoht20+oaCdwerWw1I=; b=ePnxx4h2kJ1S0XRk1w41RhE8zGyRjJXHZPe6RRWT+QaruwWjdFbYRYREu/L0OsYXoL S+yC/BDIgilj7HE5ThSCT4IBItMsKcC/iSLuugYnSCLLo9OsHaFlV9Oqp28uDj69MJTg hUgbNpfZro5SETa1xg+8Zwllix8uhJ580K/+YgWZxF04vHNLcFr2kBnrhKsKbcJNPxS9 ZI7nyjOVv53bo8HYR7/VW3iWJlGbVgLLPov3tgGp4HKmJgFXX+S2avukid3nydZwLZb+ KOS9WxTwfq4wmwlAuR8EuenHWmMj0dicmlg9FPEvQLtmdamm7tJ3dQv6p/lKIrVJzQ7Z gQ+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OXY9WP12; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x10-v6si1693970pln.30.2018.01.25.01.09.01; Thu, 25 Jan 2018 01:09:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OXY9WP12; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751434AbeAYJIi (ORCPT + 99 others); Thu, 25 Jan 2018 04:08:38 -0500 Received: from mail-pf0-f173.google.com ([209.85.192.173]:34617 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751390AbeAYJIe (ORCPT ); Thu, 25 Jan 2018 04:08:34 -0500 Received: by mail-pf0-f173.google.com with SMTP id e76so5340584pfk.1 for ; Thu, 25 Jan 2018 01:08:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=m7+jQCvnhBblPkvyxrpPo0i//zoht20+oaCdwerWw1I=; b=OXY9WP12tWyto2kdD5E7j3SzoIaP4WEvLpkY3G+lldIaL7ht+8Iq5I6IoLeAYHaxTI ZcBiUYRU58CSlXhiNQ27Kb3w69IJM6UqSTuVhTDLwTl5lPrM3aAf15/ZiqfaeW6wHWzq RDsSzqXUwy6yzR6tzdCaZMn/qSGIXLt0aggr7seToVMufpOkF9gw8NL0mjdiVzSunnly pKgRS6ihhbNEt1IrlgU07d1LEwxH+KH1FZuwoJ+T+l41V81ynESc/5Gesc4S3vBpwpya Js8GWi9RbJd8c5IckC97KkgMQuBCNQAiZGNKN6OyADuswzhGAQwhaPhwlbNDuqDYqb2q UB9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=m7+jQCvnhBblPkvyxrpPo0i//zoht20+oaCdwerWw1I=; b=A6fM4fT4/FOfsGFtkObB6kHvoLfo8afGjOp3XgRZSR0Y7+ut1Ld7Shg7Cx8WInknn7 5JjW0Ie5/1usnfKCLwM6CP5/i4/aga3ESHS1l2q8AigzccvjHilq/UIbYqmXyvVqamw2 TPJAJhMcqelxFHZDxhhqDWy4bHEXrS7CmOB4XgD6HZEasLQ2vvgsjZKuWZHqP+GQH/cE CvGnTKiz4MIePx/PRBWlK6I/CLKFMixht8bJ+hnxaGwSRzBebEn2tzKhsej3o4/nqEs6 K4413NKh5rC+7Yqv4BAyLUVcm1f3ZFsPObPCgF1KHlHd2sBLSx4fxsAKXm6DkTZotHaG sL+g== X-Gm-Message-State: AKwxyte2QjH+ioWtswzKwtsgSSnzdAeMjPs3otP0EYwpn5YrFHDrGXw+ 82YkdODugSmggEPlsQoBGonMdnSZbwlmz5lA2/F1hw== X-Received: by 2002:a17:902:76cc:: with SMTP id j12-v6mr8732567plt.120.1516871313641; Thu, 25 Jan 2018 01:08:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.140.151 with HTTP; Thu, 25 Jan 2018 01:08:13 -0800 (PST) In-Reply-To: <60d69abd8279434f997b0766736ba727@AcuMS.aculab.com> References: <20180109163745.3692-1-aryabinin@virtuozzo.com> <50fcfba8-fc16-b4a1-d117-24ebbe959c0c@virtuozzo.com> <60d69abd8279434f997b0766736ba727@AcuMS.aculab.com> From: Dmitry Vyukov Date: Thu, 25 Jan 2018 10:08:13 +0100 Message-ID: Subject: Re: [PATCH] lib/strscpy: remove word-at-a-time optimization. To: David Laight Cc: Linus Torvalds , Rasmus Villemoes , Andrey Ryabinin , Andrew Morton , Linux Kernel Mailing List , Kees Cook , Eryu Guan , Alexander Potapenko , Chris Metcalf , stable , kasan-dev Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 25, 2018 at 9:42 AM, David Laight wrote: > From: Dmitry Vyukov [mailto:dvyukov@google.com] >> Sent: 25 January 2018 08:33 >> >> On Wed, Jan 24, 2018 at 6:52 PM, Linus Torvalds >> wrote: >> > On Wed, Jan 24, 2018 at 12:54 AM, Rasmus Villemoes >> > 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. Was the first byte at least kmalloc-ed? That's what KASAN checks, it does not care about "written". KMSAN can detect uses of uninit data, but that's another story.