From patchwork Fri Dec 20 18:49:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11306147 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D0676C1 for ; Fri, 20 Dec 2019 18:50:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4AA2C206DA for ; Fri, 20 Dec 2019 18:50:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="iDQMfzbj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4AA2C206DA Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 22ECC8E01AA; Fri, 20 Dec 2019 13:50:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 204F58E019D; Fri, 20 Dec 2019 13:50:25 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11BDB8E01AA; Fri, 20 Dec 2019 13:50:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id EDBDD8E019D for ; Fri, 20 Dec 2019 13:50:24 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id AD907180AD81A for ; Fri, 20 Dec 2019 18:50:24 +0000 (UTC) X-FDA: 76286410368.16.wheel29_77ed39aeb3f1d X-Spam-Summary: 2,0,0,ce3e8c03d5eea355,d41d8cd98f00b204,37hf9xqykcakpurmn0pxxpun.lxvurw36-vvt4jlt.x0p@flex--glider.bounces.google.com,:vegard.nossum@oracle.com:dvyukov@google.com:elver@google.com:andreyknvl@google.com::glider@google.com:viro@zeniv.linux.org.uk:adilger.kernel@dilger.ca:akpm@linux-foundation.org:aryabinin@virtuozzo.com:luto@kernel.org:ard.biesheuvel@linaro.org:arnd@arndb.de:hch@infradead.org:hch@lst.de:darrick.wong@oracle.com:davem@davemloft.net:dmitry.torokhov@gmail.com:ebiggers@google.com:edumazet@google.com:ericvh@gmail.com:gregkh@linuxfoundation.org:harry.wentland@amd.com:herbert@gondor.apana.org.au:iii@linux.ibm.com:mingo@elte.hu:jasowang@redhat.com:axboe@kernel.dk:m.szyprowski@samsung.com:mark.rutland@arm.com:martin.petersen@oracle.com:schwidefsky@de.ibm.com:willy@infradead.org:mst@redhat.com:mhocko@suse.com:monstr@monstr.eu:pmladek@suse.com:cai@lca.pw:rdunlap@infradead.org:robin.murphy@arm.com:sergey.senozhatsky@gmail.com:rostedt@goodmis.org:tiwai@suse.c om:tytso X-HE-Tag: wheel29_77ed39aeb3f1d X-Filterd-Recvd-Size: 5663 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Dec 2019 18:50:24 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id b131so2822952wmd.9 for ; Fri, 20 Dec 2019 10:50:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=oKQH6mh5cyqv8MpU4SEw2x/oB2+Oo1B9wy7RcgntgtY=; b=iDQMfzbj0UMx6SrFMQItnvxh9V3HQ5TSAQFmyO8nxIyYLMo/BcG3+VgIiHav+gkTQ9 sq3AgHrwjkMDEK7qHKrKMoNcFGaflOvZR5f86sUOHfSCI7LP/BKRwo8Tz5A5ZEJ98QDT yxKy5t6cLDDfMSx0+kNTwP686KqbvU4fBkX5nefRGyRVDXtKJKKD2cUNtasPpT798PBY gcNa82Du28Tk0KLtg2hbineTpbhpYvQTcugT5Odl1YyjD+YjZCBOg71CN0hR0UJOLUtq mUywwlXKSDjMGQNKGiNF/YPJf7aGLQjek6uByBkbw48YJ4FFLhIHu2YVQWQelMZaaAQk BVXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=oKQH6mh5cyqv8MpU4SEw2x/oB2+Oo1B9wy7RcgntgtY=; b=D8bmjf6J7kIYt2XIwk+aDWDAtI5ArV9uCMCnwv0xmek+AbOVMSZi2JAq5UUmCs0ayw inYrG7DbpgaVB2N/gb147N2dvG8SL16ez/6cr40zoP4g9/YDJ2txXSS+W2sWDHA5EJJN VTQGLB3kgJxwfymyK7BjSDZl5KbpjVCwL8QS9HFChDhVIXN2L9ds7uDU6W4713El50Lg 9EVL7btBvvyNc8nckVHc7BIupmmSTTLM1CRK9zWhQbrAVRaJvOOwMU7HCHITytfVoDvU 3LC2eazye2iU1ovisgkL3Ga5Ub8ZBjFXmdeMnSustCZFA1ut8t7p2KukTyW9NvJ6W+Fy VZ8g== X-Gm-Message-State: APjAAAUuyjoD0e5gO6pbRFZ6EImtljG5OCi+1LaRylzNMhLRAcS5QJAJ Cr3j6dmM9a5d1Inek1KZDYteLcCLg1o= X-Google-Smtp-Source: APXvYqyNZIOut+CLdfyzhxTBXJ0JguKrBMgwcMLrz9R2uOFWverv9WWLCkX38Kw3PXVovqCZ5aOXhYRDSXM= X-Received: by 2002:a5d:4481:: with SMTP id j1mr17403593wrq.348.1576867822499; Fri, 20 Dec 2019 10:50:22 -0800 (PST) Date: Fri, 20 Dec 2019 19:49:20 +0100 In-Reply-To: <20191220184955.223741-1-glider@google.com> Message-Id: <20191220184955.223741-8-glider@google.com> Mime-Version: 1.0 References: <20191220184955.223741-1-glider@google.com> X-Mailer: git-send-email 2.24.1.735.g03f4e72817-goog Subject: [PATCH RFC v4 07/42] kmsan: introduce __no_sanitize_memory and __SANITIZE_MEMORY__ From: glider@google.com To: Vegard Nossum , Dmitry Vyukov , Marco Elver , Andrey Konovalov , linux-mm@kvack.org Cc: glider@google.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, akpm@linux-foundation.org, aryabinin@virtuozzo.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, hch@infradead.org, hch@lst.de, darrick.wong@oracle.com, davem@davemloft.net, dmitry.torokhov@gmail.com, ebiggers@google.com, edumazet@google.com, ericvh@gmail.com, gregkh@linuxfoundation.org, harry.wentland@amd.com, herbert@gondor.apana.org.au, iii@linux.ibm.com, mingo@elte.hu, jasowang@redhat.com, axboe@kernel.dk, m.szyprowski@samsung.com, mark.rutland@arm.com, martin.petersen@oracle.com, schwidefsky@de.ibm.com, willy@infradead.org, mst@redhat.com, mhocko@suse.com, monstr@monstr.eu, pmladek@suse.com, cai@lca.pw, rdunlap@infradead.org, robin.murphy@arm.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org, tiwai@suse.com, tytso@mit.edu, tglx@linutronix.de, gor@linux.ibm.com, wsa@the-dreams.de X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: __no_sanitize_memory is a function attribute that makes KMSAN ignore the uninitialized values coming from the function's inputs, and initialize the function's outputs. Functions marked with this attribute can't be inlined into functions not marked with it, and vice versa. __SANITIZE_MEMORY__ is a macro that's defined iff the file is instrumented with KMSAN. This is not the same as CONFIG_KMSAN, which is defined for every file. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: Marco Elver Cc: Andrey Konovalov Cc: linux-mm@kvack.org Acked-by: Marco Elver --- v4: - dropped an unnecessary comment as requested by Marco Elver Change-Id: I1f1672652c8392f15f7ca8ac26cd4e71f9cc1e4b --- include/linux/compiler-clang.h | 7 +++++++ include/linux/compiler-gcc.h | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index 333a6695a918..01e1f754f6d3 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -24,6 +24,13 @@ #define __no_sanitize_address #endif +#if __has_feature(memory_sanitizer) +# define __SANITIZE_MEMORY__ +# define __no_sanitize_memory __attribute__((no_sanitize("kernel-memory"))) +#else +# define __no_sanitize_memory +#endif + /* * Not all versions of clang implement the the type-generic versions * of the builtin overflow checkers. Fortunately, clang implements diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index d7ee4c6bad48..e5ebc788dde4 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -145,6 +145,11 @@ #define __no_sanitize_address #endif +/* + * GCC doesn't support KMSAN. + */ +#define __no_sanitize_memory + #if GCC_VERSION >= 50100 #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1 #endif