Received: by 10.223.176.46 with SMTP id f43csp920294wra; Wed, 24 Jan 2018 07:54:19 -0800 (PST) X-Google-Smtp-Source: AH8x225ZLs8JoQyOQhoNWWfHToOg6X7nr2XKY3jimCu7MbgfUqGPRzceWqNoDybrZAhep3ABf1Mh X-Received: by 10.99.163.96 with SMTP id v32mr10905062pgn.432.1516809259824; Wed, 24 Jan 2018 07:54:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516809259; cv=none; d=google.com; s=arc-20160816; b=OhVT1pp9dNzxwTZda6N0sDrlWawFKPLSW5gLfFMGiFmK59DyH6f56SITZghjK+y3Bb LU3g7Pow6o6qpTfMz0j6zNoay0hCziELdnqvkb6VShVySbGKu7g10Sc003uqWMHJUsed rJg0pnX7UzPyT8wbmbeggNZAsKBlT8J6Ukzo+lWbgd3g1YGfBZQgKjY+IBdNddqvakqi ewj7tK75sj/GZE5GkcPiegf8sQdvuwxJ1kYp+rsAuPuloGfK2vtHAilsv1OKJbSCHuOM XbkjWdYOtnYEp42ScyXWXt1gtHfx1GFnRDGrBLwlMWTQqzYiDUuBczTB8IpghYrAeCrE nk7A== 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=WU1uRy7puBm1nqtgxUJp7zmzyRY5TdpcniDycFy98WA=; b=FCmk8dsdw8TdIYQ60d5sB3CGDlgp2asKqZNc3eyDrkaWh4hWBzeSAPEuP5b7QBl8VW NHBDdYz+icN4oQZ4oEuUZF/+0pEIAS741AqzKDGyLGsDGLwJOrHeYbj3VKXWN4bS71jV 3gvNBBgl9+AOiPuO7D5LQwf0pzlYKCqMFZZOPB6MFwFUCcIfQ3ze0W6W6QRcLucBFQGo Z1Yl0GUbWiS05BIjWUJn8ySj9LL5Nkob403SgZlwtmTfYzzpGhtlHtRf1XNbhkSnHSxk Qv4aLBbnaatu8zfyc4DOC63ooY/MDr3vK5xthWWVTkUrV4/TVcXWWCHgCVIBH5/6cnwV Y6pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dbucobC1; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c7-v6si365471pll.674.2018.01.24.07.54.05; Wed, 24 Jan 2018 07:54:19 -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=@gmail.com header.s=20161025 header.b=dbucobC1; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934244AbeAXPxY (ORCPT + 99 others); Wed, 24 Jan 2018 10:53:24 -0500 Received: from mail-qt0-f178.google.com ([209.85.216.178]:33775 "EHLO mail-qt0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933953AbeAXPxW (ORCPT ); Wed, 24 Jan 2018 10:53:22 -0500 Received: by mail-qt0-f178.google.com with SMTP id d8so11484836qtm.0; Wed, 24 Jan 2018 07:53:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=WU1uRy7puBm1nqtgxUJp7zmzyRY5TdpcniDycFy98WA=; b=dbucobC1QCuPnY4KG6F1/g+ITdCqH73ICsqG9SimnYQUumU07NS6RxtxaZ+APvcmSW F4IEVmyqRfK/CnvFYsIOAel1c1T+gGTCPoovDLpYhkJ6Xwssic7D7ZyEfmUI/m2GZmf5 TNm3EHbl7dE2LZkkrV4upNhnVPbSvYyxo5QX+ZkB+ZCb081mB6H6kiOJ1bkrqRovGMXe M4sdtStl6heL3mybs0EX8ohrcT3x60AniYMlTrvupjgy4SG8KfiFcj5mV30WQjMXR83H NMc2qXQU9Y1bL9WGpdRerNWQxcToZRz0RVf51G3xXvTxXwnLQd330tx7g7o9vbyRgv02 KPPQ== 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=WU1uRy7puBm1nqtgxUJp7zmzyRY5TdpcniDycFy98WA=; b=SDKpSsQg4gZ+w7SOuJ17hW/X5WaEs7S39aq4Do991M4oR53mLadvSrJ40MEFJ+/Fpn cpnhY/G2DExENVDqCsBRcGqdP1wjqaYVRofAcYUO12weUacgyOrbTHjhS5m+PgeuSoUP PGboq7NiOVds/zl7/8H4bzBXzsdOXLZUIBaue2E5No7LgLv3W2PIGsfoKNiANH3MnEaD hp1Lwfb0sU1HsjZEOBhVuHtSISM2RnYICXclM2UDIbybP9f/huJ+VKhZTJyCfhNwoIRX aoKCX1+85oKNR46sfQ5tGdANsIqrRf9YrBbL94zRE6NK/HI5qbhio6/KMt4tHG/D+/Qv GS1g== X-Gm-Message-State: AKwxytcZSZuy2B1PXm0mcfck4GsEYyiBrb213tf3y/d3bgXmZs1v7i9D TD93OEIIhvi498W4dEQkptzRPkEBLljJ8RyihdLZ1NQ/ X-Received: by 10.55.87.70 with SMTP id l67mr9960315qkb.319.1516809202218; Wed, 24 Jan 2018 07:53:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.175.35 with HTTP; Wed, 24 Jan 2018 07:53:21 -0800 (PST) In-Reply-To: <20180109163745.3692-1-aryabinin@virtuozzo.com> References: <20180109163745.3692-1-aryabinin@virtuozzo.com> From: Andy Shevchenko Date: Wed, 24 Jan 2018 17:53:21 +0200 Message-ID: Subject: Re: [PATCH] lib/strscpy: remove word-at-a-time optimization. To: Andrey Ryabinin Cc: Andrew Morton , Linus Torvalds , Linux Kernel Mailing List , Kees Cook , Eryu Guan , Alexander Potapenko , Chris Metcalf , David Laight , Dmitry Vyukov , stable@vger.kernel.org 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 Tue, Jan 9, 2018 at 6:37 PM, Andrey Ryabinin wrote: > strscpy() performs the word-at-a-time optimistic reads. So it may > may access the memory past the end of the object, which is perfectly fine > since strscpy() doesn't use that (past-the-end) data and makes sure the > optimistic read won't cross a page boundary. > > But KASAN doesn't know anything about that so it will complain. > There are several possible ways to address this issue, but none > are perfect. See https://lkml.kernel.org/r/9f0a9cf6-51f7-cd1f-5dc6-6d510a7b8ec4@virtuozzo.com > > It seems the best solution is to simply disable word-at-a-time > optimization. My trivial testing shows that byte-at-a-time > could be up to x4.3 times slower than word-at-a-time. > It may seems like a lot, but it's actually ~1.2e-10 sec per symbol vs > ~4.8e-10 sec per symbol on modern hardware. And we don't use strscpy() > in a performance critical paths to copy large amounts of data, > so it shouldn't matter anyway. What prevents you to revert the patch? After this one the all advantages of the function becomes useless AFAIU. -- With Best Regards, Andy Shevchenko