From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752613AbdGRWEo (ORCPT ); Tue, 18 Jul 2017 18:04:44 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48110 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751969AbdGRWEm (ORCPT ); Tue, 18 Jul 2017 18:04:42 -0400 Date: Tue, 18 Jul 2017 15:04:41 -0700 From: Andrew Morton To: Andrey Ryabinin Cc: Linus Torvalds , Dave Jones , Alexander Potapenko , Dmitry Vyukov , kasan-dev@googlegroups.com, Linux Kernel Mailing List , Chris Metcalf Subject: Re: [PATCH] lib/strscpy: avoid KASAN false positive Message-Id: <20170718150441.fe789a065bd97d7dd67e8b36@linux-foundation.org> In-Reply-To: <96a21da7-1258-0ada-298f-e0388849402a@virtuozzo.com> References: <20170718171523.32208-1-aryabinin@virtuozzo.com> <96a21da7-1258-0ada-298f-e0388849402a@virtuozzo.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 19 Jul 2017 00:31:36 +0300 Andrey Ryabinin wrote: > On 07/18/2017 11:26 PM, Linus Torvalds wrote: > > On Tue, Jul 18, 2017 at 1:15 PM, Andrey Ryabinin > > wrote: > >> > >> No, it does warn about valid users. The report that Dave posted wasn't about wrong strscpy() usage > >> it was about reading 8-bytes from 5-bytes source string. It wasn't about buggy 'count' at all. > >> So KASAN will warn for perfectly valid code like this: > >> char dest[16]; > >> strscpy(dest, "12345", sizeof(dest)): > > > > Ugh, ok, yes. > > > >> For strscpy() that would mean making the *whole* read from 'src' buffer unchecked by KASAN. > > > > So we do have that READ_ONCE_NOCHECK(), but could we perhaps have > > something that doesn't do a NOCHECK but a partial check and is simply > > ok with "this is an optimistc longer access" > > > > This can be dont, I think. > > Something like this: > static inline unsigned long read_partial_nocheck(unsigned long *x) > { > unsigned long ret = READ_ONCE_NOCHECK(x); > kasan_check_partial(x, sizeof(unsigned long)); > return ret; > } > (Cc Chris) We could just remove all that word-at-a-time logic. Do we have any evidence that this would harm anything?