Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp892233ybl; Wed, 29 Jan 2020 11:28:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwsIoLJrnrTW9rUVaYEX831S+lwxRIkE458AdU6KA9LmxIy5K/3jUR22C93eykivv/a99KK X-Received: by 2002:a9d:4c14:: with SMTP id l20mr641465otf.125.1580326090444; Wed, 29 Jan 2020 11:28:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580326090; cv=none; d=google.com; s=arc-20160816; b=LyVdYCz26c4kiMKtJCG0/dUjJFNiP9vQHkTeShDn5NhK2tokDt7XXFFlz88agOXRff 985MFAp4aQXLlnJ2NqlV61ie2b4YAg0I2TjnXUhY4nOo431TMU4H8cwhtUeBCAf+YRDQ eN5/yZkKloBhUN6U4bQSnmgJV9qWSbIszG45veVnJGLf/LXODMNqZBZmbaGiOyH6Z/D4 l0Qo9vLoRTJj0EL/ATEimtv+jbOdS3MzT0LMrpcY3S7IHSXyYxicT6os/2eWptI84W1e tLQDAo7TAjOCJdtZZhH38Vmin1P8reB9Eq/xKvIYYyskdPJG/njffHp5w3nVfNY1wlWp Vz/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=0eOPfy4DrkPraPiOe/HVjWqrk7rNFafSm7glsZ1rliQ=; b=zo4vdU7pSkB7eUxr/QUAgmsX+yC/tI1gJiippf8T2uf4oo1v4yFlbqqRklcoMP3ZQH TFjJwilNX/Rvh6ZNo7r5EXWObfsc7jj0ZzWoxRA2nerbgd7c/RluHP6avS7KUzfZCJgT hNKKsjCB4ZeQ2o90ROYMnup3UqoU/1Qx3OP8a8xia5SKW8fR8n/LigdWf0LvZSor7G/E bZAcb72qG72tjqu0XRaRvVPxU8T34tjDI7irlwj3T7zENi5/7k3IzVVKvf9dIRuYBKEi DOSsPYzn6CTil772Doyrm+h+f0A4UUWLX+Uew5O6jVMQovgrNGuzGf4zpxDjUiCAYcRc Jg0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0zQWbA7V; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si1682487otq.250.2020.01.29.11.27.58; Wed, 29 Jan 2020 11:28:10 -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=@kernel.org header.s=default header.b=0zQWbA7V; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727088AbgA2TNt (ORCPT + 99 others); Wed, 29 Jan 2020 14:13:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:33754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726183AbgA2TNs (ORCPT ); Wed, 29 Jan 2020 14:13:48 -0500 Received: from paulmck-ThinkPad-P72.home (unknown [199.201.64.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C476B205F4; Wed, 29 Jan 2020 19:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1580325227; bh=92ff4QxUOJxWhCCK6LSimpjMkzXTi+lzOK+GW8Ovhh8=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=0zQWbA7VpvkVjjcsooqJF/p4CoSQfkGAT8SsS1x9SUtpQJses139aJ6Q6F9W4Se0W y3CsJMxfjtFbiVognmRpXHnJ3QN6m9lLtApZnbI/4Fj2ko8q8GVZpJ/HJJtOXQwMai bXHRejPpx48jD36ovimq2JBngR/lM5Lvh34EfSaU= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 668C53521AEF; Wed, 29 Jan 2020 11:13:47 -0800 (PST) Date: Wed, 29 Jan 2020 11:13:47 -0800 From: "Paul E. McKenney" To: Dmitry Vyukov Cc: Marco Elver , Andrey Konovalov , Alexander Potapenko , kasan-dev , LKML , Mark Rutland , Will Deacon , Peter Zijlstra , Boqun Feng , Arnd Bergmann , Al Viro , Daniel Axtens , Christophe Leroy , Michael Ellerman , Masami Hiramatsu , Steven Rostedt , Ingo Molnar , Christian Brauner , Daniel Borkmann , Kees Cook , cyphar@cyphar.com, linux-arch Subject: Re: [PATCH v2 1/5] include/linux: Add instrumented.h infrastructure Message-ID: <20200129191347.GA21972@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200121160512.70887-1-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 24, 2020 at 12:22:56PM +0100, Dmitry Vyukov wrote: > On Tue, Jan 21, 2020 at 5:05 PM 'Marco Elver' via kasan-dev > wrote: > > > > This adds instrumented.h, which provides generic wrappers for memory > > access instrumentation that the compiler cannot emit for various > > sanitizers. Currently this unifies KASAN and KCSAN instrumentation. In > > future this will also include KMSAN instrumentation. > > > > Note that, copy_{to,from}_user should use special instrumentation, since > > we should be able to instrument both source and destination memory > > accesses if both are kernel memory. > > > > The current patch only instruments the memory access where the address > > is always in kernel space, however, both may in fact be kernel addresses > > when a compat syscall passes an argument allocated in the kernel to a > > real syscall. In a future change, both KASAN and KCSAN should check both > > addresses in such cases, as well as KMSAN will make use of both > > addresses. [It made more sense to provide the completed function > > signature, rather than updating it and changing all locations again at a > > later time.] > > Reviewed-by: Dmitry Vyukov I have applied this and the other four with Dmitry's Reviewed-by. Thank you all! Thanx, Paul > > Suggested-by: Arnd Bergmann > > Signed-off-by: Marco Elver > > Acked-by: Alexander Potapenko > > --- > > v2: > > * Simplify header, since we currently do not need pre/post user-copy > > distinction. > > * Make instrument_copy_{to,from}_user function arguments match > > copy_{to,from}_user and update rationale in commit message. > > --- > > include/linux/instrumented.h | 109 +++++++++++++++++++++++++++++++++++ > > 1 file changed, 109 insertions(+) > > create mode 100644 include/linux/instrumented.h > > > > diff --git a/include/linux/instrumented.h b/include/linux/instrumented.h > > new file mode 100644 > > index 000000000000..43e6ea591975 > > --- /dev/null > > +++ b/include/linux/instrumented.h > > @@ -0,0 +1,109 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > + > > +/* > > + * This header provides generic wrappers for memory access instrumentation that > > + * the compiler cannot emit for: KASAN, KCSAN. > > + */ > > +#ifndef _LINUX_INSTRUMENTED_H > > +#define _LINUX_INSTRUMENTED_H > > + > > +#include > > +#include > > +#include > > +#include > > + > > +/** > > + * instrument_read - instrument regular read access > > + * > > + * Instrument a regular read access. The instrumentation should be inserted > > + * before the actual read happens. > > + * > > + * @ptr address of access > > + * @size size of access > > + */ > > +static __always_inline void instrument_read(const volatile void *v, size_t size) > > +{ > > + kasan_check_read(v, size); > > + kcsan_check_read(v, size); > > +} > > + > > +/** > > + * instrument_write - instrument regular write access > > + * > > + * Instrument a regular write access. The instrumentation should be inserted > > + * before the actual write happens. > > + * > > + * @ptr address of access > > + * @size size of access > > + */ > > +static __always_inline void instrument_write(const volatile void *v, size_t size) > > +{ > > + kasan_check_write(v, size); > > + kcsan_check_write(v, size); > > +} > > + > > +/** > > + * instrument_atomic_read - instrument atomic read access > > + * > > + * Instrument an atomic read access. The instrumentation should be inserted > > + * before the actual read happens. > > + * > > + * @ptr address of access > > + * @size size of access > > + */ > > +static __always_inline void instrument_atomic_read(const volatile void *v, size_t size) > > +{ > > + kasan_check_read(v, size); > > + kcsan_check_atomic_read(v, size); > > +} > > + > > +/** > > + * instrument_atomic_write - instrument atomic write access > > + * > > + * Instrument an atomic write access. The instrumentation should be inserted > > + * before the actual write happens. > > + * > > + * @ptr address of access > > + * @size size of access > > + */ > > +static __always_inline void instrument_atomic_write(const volatile void *v, size_t size) > > +{ > > + kasan_check_write(v, size); > > + kcsan_check_atomic_write(v, size); > > +} > > + > > +/** > > + * instrument_copy_to_user - instrument reads of copy_to_user > > + * > > + * Instrument reads from kernel memory, that are due to copy_to_user (and > > + * variants). The instrumentation must be inserted before the accesses. > > + * > > + * @to destination address > > + * @from source address > > + * @n number of bytes to copy > > + */ > > +static __always_inline void > > +instrument_copy_to_user(void __user *to, const void *from, unsigned long n) > > +{ > > + kasan_check_read(from, n); > > + kcsan_check_read(from, n); > > +} > > + > > +/** > > + * instrument_copy_from_user - instrument writes of copy_from_user > > + * > > + * Instrument writes to kernel memory, that are due to copy_from_user (and > > + * variants). The instrumentation should be inserted before the accesses. > > + * > > + * @to destination address > > + * @from source address > > + * @n number of bytes to copy > > + */ > > +static __always_inline void > > +instrument_copy_from_user(const void *to, const void __user *from, unsigned long n) > > +{ > > + kasan_check_write(to, n); > > + kcsan_check_write(to, n); > > +} > > + > > +#endif /* _LINUX_INSTRUMENTED_H */ > > -- > > 2.25.0.341.g760bfbb309-goog > > > > -- > > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20200121160512.70887-1-elver%40google.com.