From patchwork Wed Dec 8 04:48:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 12695277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5FC8AC433EF for ; Wed, 8 Dec 2021 04:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=A4a4y8MNPxv5EkIOgVQtksBG2ZXHlgamAK37hLmmlmU=; b=OPcKk3HvhbNE9Jz+334y7nGW9M Xkrheiy0euZLGBuxwCBOO3SCLYp4rjcu7ydd1S7smqdElNJ6uXrxj47gbGpMA25AVgr1FJ1OmlTFg W9X31BJomeQSyi2TVzWn8VRCiOxtYvL6c7rVFR9iTkaQ12qxQhsgLo1AvGnjsjE7F/QW7MwJgpP7J 5Jp1VNJRz5VlhyffL+n6BRMeCK+TjwBQMrMIRAEwsugjOFAV9fqbxa1YJ1tWf9uuj/nks0Lr+7JbD FctAXhUyU62utG/MRyDGQDGCHysIuWiQH1rRC87dqrR/3r5APs5s1/UG4FGERmEFTVC9oeOoZ91AC mwktlqFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1muose-00BESM-TF; Wed, 08 Dec 2021 04:48:37 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1muosO-00BEMK-Pp for linux-arm-kernel@lists.infradead.org; Wed, 08 Dec 2021 04:48:22 +0000 Received: by mail-yb1-xb49.google.com with SMTP id q198-20020a25d9cf000000b005f7a6a84f9fso2519066ybg.6 for ; Tue, 07 Dec 2021 20:48:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=JtdRIroDVgccFwCdTVc0TsbiO+v4ycYN9fgE1zvbpew=; b=qioJGvHxCaUMYDmDWwlYCm4ZZ+I/yyWW6plwpkL0qqIm/yxh00rgj3Cj9bQulgK6dV pmNSUoGFXODYeH8/AgHcaNy+56yvC/IfqkIsGJ2nU1DCs5dHklqn6zvO6+6uL5zi4PKG ZsYV5JdtzeqjScR6HVpQcTk1Zdxk5Zt/JTHtOJosP2eq3+nm2bdTkOk0HeYqAZbCCFrX sFuguIvussQ80ecbny4Y7opDWo13Kh7hLHxb8cyc6GuZnOnbeHMnNqEnlCQk4VhFFW6w TTMezquVS9UurUhV30C0m6yfeHkoxhkcu3ii4CHmqPRmzh7gAQk06VS4aaXzSbUrk2CR gt8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=JtdRIroDVgccFwCdTVc0TsbiO+v4ycYN9fgE1zvbpew=; b=ujYwuxsdzW9bLBK0xR0moyobhtohrSJ9cA//RtUZzZEup5rMGtxX1MH7GXcdI2fHmp 1qeB3gw6SdWuHTNLECVylyCLT7Ms9j3tE+RvaBbdWf/4koGmamf7V2XdfLQiR+c/52g5 QbNC5KTW80SD+FKjTZBRpeNOqf4nFFw+iXoUN+mER1m8xmNxrBr1NPymGkKPFaKAjJgZ zjeD4BWhWK4/rLfEpKxh3GAI1OahGDNgni/7VE3yLexGmQF4CC+lRuYIzsP0WJkBINZ5 4SugQGUeMc39w98Iojaxzt8yYJAoFSbcXvVhrTckGf78GBtbgxyfb4EGokXHqUXxlusz mRnQ== X-Gm-Message-State: AOAM531q+xnIMgSMFUQCKjipLA3o+xXcZxyFSc1BdWkXaZKv0codVm+V VwjJecUo8gslAQMzEAEWX9V3bEo= X-Google-Smtp-Source: ABdhPJxsCHqUib2mOPudZ77H+uVFoQunSny/sJrZzgoUbaBQQJhAf9CMq9HP1U+BRyz4zwhjxAoOygw= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:be2d:924d:844b:d2fa]) (user=pcc job=sendgmr) by 2002:a25:d196:: with SMTP id i144mr54279180ybg.595.1638938899130; Tue, 07 Dec 2021 20:48:19 -0800 (PST) Date: Tue, 7 Dec 2021 20:48:03 -0800 In-Reply-To: <20211208044808.872554-1-pcc@google.com> Message-Id: <20211208044808.872554-2-pcc@google.com> Mime-Version: 1.0 References: <20211208044808.872554-1-pcc@google.com> X-Mailer: git-send-email 2.34.1.173.g76aa8bc2d0-goog Subject: [PATCH v3 1/6] include: split out uaccess instrumentation into a separate header From: Peter Collingbourne To: Catalin Marinas , Will Deacon , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Thomas Gleixner , Andy Lutomirski , Kees Cook , Andrew Morton , Masahiro Yamada , Sami Tolvanen , YiFei Zhu , Mark Rutland , Frederic Weisbecker , Viresh Kumar , Andrey Konovalov , Peter Collingbourne , Gabriel Krisman Bertazi , Chris Hyser , Daniel Vetter , Chris Wilson , Arnd Bergmann , Dmitry Vyukov , Christian Brauner , "Eric W. Biederman" , Alexey Gladkov , Ran Xiaokai , David Hildenbrand , Xiaofeng Cao , Cyrill Gorcunov , Thomas Cedeno , Marco Elver , Alexander Potapenko Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Evgenii Stepanov X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211207_204820_866452_987A924E X-CRM114-Status: GOOD ( 21.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In an upcoming change we are going to add uaccess instrumentation that uses inline access to struct task_struct from the instrumentation routines. Because instrumentation.h is included from many places including (recursively) from sched.h this would otherwise lead to a circular dependency. Break the dependency by moving uaccess instrumentation routines into a separate header, instrumentation-uaccess.h. Link: https://linux-review.googlesource.com/id/I625728db0c8db374e13e4ebc54985ac5c79ace7d Signed-off-by: Peter Collingbourne Acked-by: Dmitry Vyukov --- include/linux/instrumented-uaccess.h | 49 ++++++++++++++++++++++++++++ include/linux/instrumented.h | 34 ------------------- include/linux/uaccess.h | 2 +- lib/iov_iter.c | 2 +- lib/usercopy.c | 2 +- 5 files changed, 52 insertions(+), 37 deletions(-) create mode 100644 include/linux/instrumented-uaccess.h diff --git a/include/linux/instrumented-uaccess.h b/include/linux/instrumented-uaccess.h new file mode 100644 index 000000000000..ece549088e50 --- /dev/null +++ b/include/linux/instrumented-uaccess.h @@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * This header provides generic wrappers for memory access instrumentation for + * uaccess routines that the compiler cannot emit for: KASAN, KCSAN. + */ +#ifndef _LINUX_INSTRUMENTED_UACCESS_H +#define _LINUX_INSTRUMENTED_UACCESS_H + +#include +#include +#include +#include + +/** + * 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_UACCESS_H */ diff --git a/include/linux/instrumented.h b/include/linux/instrumented.h index 42faebbaa202..b68f415510c7 100644 --- a/include/linux/instrumented.h +++ b/include/linux/instrumented.h @@ -102,38 +102,4 @@ static __always_inline void instrument_atomic_read_write(const volatile void *v, kcsan_check_atomic_read_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 */ diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h index ac0394087f7d..c0c467e39657 100644 --- a/include/linux/uaccess.h +++ b/include/linux/uaccess.h @@ -3,7 +3,7 @@ #define __LINUX_UACCESS_H__ #include -#include +#include #include #include #include diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 66a740e6e153..3f9dc6df7102 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #define PIPE_PARANOIA /* for now */ diff --git a/lib/usercopy.c b/lib/usercopy.c index 7413dd300516..1cd188e62d06 100644 --- a/lib/usercopy.c +++ b/lib/usercopy.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include -#include +#include #include /* out-of-line parts */