From patchwork Fri Nov 22 11:26:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11257909 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 11E1014DB for ; Fri, 22 Nov 2019 11:27:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C4F1020672 for ; Fri, 22 Nov 2019 11:27:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="A9iNrjXY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4F1020672 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 A38EE6B04F1; Fri, 22 Nov 2019 06:27:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9EA686B04F3; Fri, 22 Nov 2019 06:27: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 8FF4B6B04F4; Fri, 22 Nov 2019 06:27:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id 7A9A76B04F1 for ; Fri, 22 Nov 2019 06:27:49 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 3F1C86115 for ; Fri, 22 Nov 2019 11:27:49 +0000 (UTC) X-FDA: 76183688658.23.space83_9ff948fa0b3b X-Spam-Summary: 2,0,0,aed5490170e83118,d41d8cd98f00b204,3m8bxxqykcbq052xyb08805y.w86527eh-664fuw4.8b0@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: space83_9ff948fa0b3b X-Filterd-Recvd-Size: 7442 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Nov 2019 11:27:48 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id j12so3724951wrw.15 for ; Fri, 22 Nov 2019 03:27: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=WMdcaBgqN9BSTZ5Lijleqz/AUu/3qgAHylSjnwfZOt4=; b=A9iNrjXYfTYvB2prDa3NQFgOV1mjB0BGWet1i6Hd8AS9H2kizzk6Zx+L+Dhvlsspjr 6/K5I3sZKYFEpIB/Oh/GwK/XfN/FdMmlYmiJ+pLWJQ/YhcOJvoPylFZkVGTqcu5EeMUs qEgpdmwOM01jat0IaDlt/Gzfd2pY583GYaFLIkXXgORGfeP+SLARl4datDu1jnxYhwRB cPaZBOzYYSllLHzReCBYr7lJx19II9eaCTDuka7FukQBSvoXUElTpEtvuVrHkT35VLYk bAMauA6rV5DFvxm1bIcZJBT28ykgqyJGPBFvOetf5wb7OjMC7yQcJi+KqtITToRI4IB4 a58A== 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=WMdcaBgqN9BSTZ5Lijleqz/AUu/3qgAHylSjnwfZOt4=; b=WP6L+NC3ssXzLTwWg6XYnrXUBpvhPDre+xwcr5eFQ0zb7Wy81vCDLu1TVOQILSdV78 rllVNIuMyPVQM1qrWG/iKt1tpbeQEw7z6AEZNXxobxXQbmAFBqMEUeB0NbV/Ibxljn9O RDg/iSnP+NlyKcSGzPYCHtfcW6UCje/u9oiDIbtF84SIrJFg+jr3IgSPdmTFmWQQhXyY cFdXoJMOw0YZ+hZ5e+RLIqIF31MdSdao1mj2gvIBK1hv1A1D0lXBAIy2FHHSLkGV1oCo uNICEtGECH1safT4mXEwPQQVbbIBlVwKFbyaJB6b/py2bNzetDIVDdErjYcThemBLpzz U63w== X-Gm-Message-State: APjAAAUwF4cNzUeZOKYdMgSAipiY4bRTX0Npu68zz9wDJQWU3Qw4/jVf VbPPahlqZygE1x5Ek9YAd6P9RQND4bM= X-Google-Smtp-Source: APXvYqyHFjBDOdKdyXu0XqV5X8RTxFKhpF6B6CTHJZWBcz70iIJC5FnAscK/hFBNnRL0bCd/KJOSj68Clng= X-Received: by 2002:adf:9d88:: with SMTP id p8mr17496045wre.286.1574422067290; Fri, 22 Nov 2019 03:27:47 -0800 (PST) Date: Fri, 22 Nov 2019 12:26:11 +0100 In-Reply-To: <20191122112621.204798-1-glider@google.com> Message-Id: <20191122112621.204798-27-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 26/36] kmsan: use __msan_memcpy() where possible. 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: Unless stated otherwise (by explicitly calling __memcpy()) we want all memcpy() calls to call __msan_memcpy() so that shadow and origin values are updated accordingly. Bootloader must still the default string functions to avoid crashes. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: linux-mm@kvack.org --- v3: - use default string functions in the bootloader Change-Id: Ib2512ce5aa8d457453dd38caa12f58f002166813 --- arch/x86/boot/compressed/misc.h | 1 + arch/x86/include/asm/string_64.h | 9 ++++++++- include/linux/compiler.h | 9 ++++++++- include/linux/string.h | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index c8181392f70d..dd4bd8c5d97a 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -12,6 +12,7 @@ #undef CONFIG_PARAVIRT_XXL #undef CONFIG_PARAVIRT_SPINLOCKS #undef CONFIG_KASAN +#undef CONFIG_KMSAN /* cpu_feature_enabled() cannot be used this early */ #define USE_EARLY_PGTABLE_L5 diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h index 75314c3dbe47..d3c76d910c23 100644 --- a/arch/x86/include/asm/string_64.h +++ b/arch/x86/include/asm/string_64.h @@ -11,7 +11,13 @@ function. */ #define __HAVE_ARCH_MEMCPY 1 +#if defined(CONFIG_KMSAN) +#undef memcpy +/* __msan_memcpy() is defined in compiler.h */ +#define memcpy(dst, src, len) __msan_memcpy(dst, src, len) +#else extern void *memcpy(void *to, const void *from, size_t len); +#endif extern void *__memcpy(void *to, const void *from, size_t len); #define __HAVE_ARCH_MEMSET @@ -64,7 +70,8 @@ char *strcpy(char *dest, const char *src); char *strcat(char *dest, const char *src); int strcmp(const char *cs, const char *ct); -#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) +#if (defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__)) || \ + (defined(CONFIG_KMSAN) && !defined(__SANITIZE_MEMORY__)) /* * For files that not instrumented (e.g. mm/slub.c) we diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 99d40f31a2c3..9ce11f4f4cb2 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -179,6 +179,13 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, #include +#ifdef CONFIG_KMSAN +void *__msan_memcpy(void *dst, const void *src, u64 size); +#define __DO_MEMCPY(res, p, size) __msan_memcpy(res, p, size) +#else +#define __DO_MEMCPY(res, p, size) __builtin_memcpy(res, p, size) +#endif + #define __READ_ONCE_SIZE \ ({ \ switch (size) { \ @@ -188,7 +195,7 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \ default: \ barrier(); \ - __builtin_memcpy((void *)res, (const void *)p, size); \ + __DO_MEMCPY((void *)res, (const void *)p, size); \ barrier(); \ } \ }) diff --git a/include/linux/string.h b/include/linux/string.h index b6ccdc2c7f02..5d8ce09cba2e 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -363,6 +363,7 @@ __FORTIFY_INLINE void *memset(void *p, int c, __kernel_size_t size) return __builtin_memset(p, c, size); } +#ifndef CONFIG_KMSAN __FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size) { size_t p_size = __builtin_object_size(p, 0); @@ -377,6 +378,7 @@ __FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size) fortify_panic(__func__); return __builtin_memcpy(p, q, size); } +#endif __FORTIFY_INLINE void *memmove(void *p, const void *q, __kernel_size_t size) {