From patchwork Fri Nov 22 11:25:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11257873 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 839361593 for ; Fri, 22 Nov 2019 11:26:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 45EA620674 for ; Fri, 22 Nov 2019 11:26:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jeQwCpjJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45EA620674 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 B72BD6B04CE; Fri, 22 Nov 2019 06:26:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AFD8F6B04D0; Fri, 22 Nov 2019 06:26:49 -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 9C3AE6B04CF; Fri, 22 Nov 2019 06:26:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0118.hostedemail.com [216.40.44.118]) by kanga.kvack.org (Postfix) with ESMTP id 7E5936B04CD for ; Fri, 22 Nov 2019 06:26:49 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 57C4A2478 for ; Fri, 22 Nov 2019 11:26:49 +0000 (UTC) X-FDA: 76183686138.14.hair72_14cefdb50c1c X-Spam-Summary: 2,0,0,664964cee50a35a6,d41d8cd98f00b204,3-mxxxqykcnc9eb67k9hh9e7.5hfebgnq-ffdo35d.hk9@flex--glider.bounces.google.com,:vegard.nossum@oracle.com:dvyukov@google.com::glider@google.com:viro@zeniv.linux.org.uk:adilger.kernel@dilger.ca:akpm@linux-foundation.org:andreyknvl@google.com: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:elver@google.com:mark.rutland@arm.com:martin.petersen@oracle.com:schwidefsky@de.ibm.com:willy@infradead.org:mst@redhat.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@li X-HE-Tag: hair72_14cefdb50c1c X-Filterd-Recvd-Size: 5485 Received: from mail-vk1-f202.google.com (mail-vk1-f202.google.com [209.85.221.202]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Nov 2019 11:26:48 +0000 (UTC) Received: by mail-vk1-f202.google.com with SMTP id m72so330687vka.20 for ; Fri, 22 Nov 2019 03:26:48 -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=AJbL8t2LoDc0S3aM1fYFs6IMw4ptpvXN/jZoxp9SH5I=; b=jeQwCpjJk7/mJ7+/MpT96zZ3E0uRtLwt3HdAM3D833Zv9KHBUvpN1/hOfIEisAjUIi kX3r0Shmw8Pffx0q8S8GDYoVHpnCv2tcj0yNmmNRq+TI04OlyK4GpHR/IoqO8ylNwwx5 6BtEIGnDEhsR4qOq0bE+k9APiNN6mgnPWF9bI9I5zFUVnqYgtmyhsI978bFnja59lQIV iSe2NFFUOaVrcZdy7tclicMalmyrenYqAuEPDfClLXmU+WKc1Zy6wD9rkRw/31LpS6VB xquY5lNVFlp4Lvokm/GejQk6znkb/4k9XKs7AKESaiydkvzvhxWKnJpUL9UmVv0pqvie vZ2A== 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=AJbL8t2LoDc0S3aM1fYFs6IMw4ptpvXN/jZoxp9SH5I=; b=ANNYtJQT74Zqi6qXak7fp0Rnowl2aQkXrGt4fpnnRhWXm/ifHBMdOaeZOBGiKv/bhA SAYRAWDGsMIHpY8ELV/uorvbI8HprgtVeMXm+U4W4mznwBFBU6gwSX1XG3nzu9OqgI+v FNE2iZMI36JW1QXNUkVRX3ghf+XHBezgMTxAxWlo/hKBT7i5v2h3dylano08SnEGeNrj EsUz6n6PEeR4ZFrDSdWXAtUBsrilyhUy1s2idI00N7nQ8Gz47SvKkeGFnewc3V9QXfQK wcMyqImlE15BlQ/TcoOkvY0TtwzBz4miM38xiIujNJYIaveE2FhYmyeOfg3xSS4vVkv6 OdBg== X-Gm-Message-State: APjAAAW0YbRlucs7PmT7eXVCZ5mOCVnptErmbPS4Y/wc3l1Bsxv91rDN WDEWXZ1utCfNowHnNgpjUxxBlQWqUM4= X-Google-Smtp-Source: APXvYqx0Clb2fEqOuADQ4gPd7A4WTpu7vpaR4MxAgiia+LoStEVK14w8Q25QY2+lJR6EgBfFcRp7G9D7V9U= X-Received: by 2002:a67:c881:: with SMTP id v1mr10115116vsk.59.1574422008168; Fri, 22 Nov 2019 03:26:48 -0800 (PST) Date: Fri, 22 Nov 2019 12:25:52 +0100 In-Reply-To: <20191122112621.204798-1-glider@google.com> Message-Id: <20191122112621.204798-8-glider@google.com> Mime-Version: 1.0 References: <20191122112621.204798-1-glider@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog Subject: [PATCH RFC v3 07/36] kmsan: introduce __no_sanitize_memory and __SANITIZE_MEMORY__ From: glider@google.com To: Vegard Nossum , Dmitry Vyukov , linux-mm@kvack.org Cc: glider@google.com, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, akpm@linux-foundation.org, andreyknvl@google.com, 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, elver@google.com, mark.rutland@arm.com, martin.petersen@oracle.com, schwidefsky@de.ibm.com, willy@infradead.org, mst@redhat.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: linux-mm@kvack.org Acked-by: Marco Elver --- Change-Id: I1f1672652c8392f15f7ca8ac26cd4e71f9cc1e4b --- include/linux/compiler-clang.h | 8 ++++++++ include/linux/compiler-gcc.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index 333a6695a918..edba13a069a6 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -24,6 +24,14 @@ #define __no_sanitize_address #endif +/* KMSAN is a Clang-only tool, thus putting the defines here */ +#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