From patchwork Fri Oct 18 09:43:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 11198009 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 7005514ED for ; Fri, 18 Oct 2019 09:44:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3C80020820 for ; Fri, 18 Oct 2019 09:44:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pnKWNJ3d" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C80020820 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 BD86F8E0031; Fri, 18 Oct 2019 05:44:19 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B881A8E0003; Fri, 18 Oct 2019 05:44:19 -0400 (EDT) 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 AC6B28E0031; Fri, 18 Oct 2019 05:44:19 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id 8629C8E0003 for ; Fri, 18 Oct 2019 05:44:19 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 4190262D9 for ; Fri, 18 Oct 2019 09:44:19 +0000 (UTC) X-FDA: 76056419838.25.dolls05_7cfbeedced532 X-Spam-Summary: 2,0,0,b3a78136f3aba4f0,d41d8cd98f00b204,3compxqykcb8bgd89mbjjbg9.7jhgdips-hhfq57f.jmb@flex--glider.bounces.google.com,:glider@google.com:vegard.nossum@oracle.com:dvyukov@google.com:,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2895:3138:3139:3140:3141:3142:3152:3354:3867:3868:3870:3871:3874:4321:4605:5007:6120:6261:6653:7901:8603:8660:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12296:12297:12438:12555:12895:12986:13148:13230:13846:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21611:21627:30054:30064,0,RBL:209.85.222.202:@flex--glider.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: dolls05_7cfbeedced532 X-Filterd-Recvd-Size: 5951 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Fri, 18 Oct 2019 09:44:18 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id h4so4917255qkd.18 for ; Fri, 18 Oct 2019 02:44:18 -0700 (PDT) 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=hyA1E6SUTuWEQF/SPoSfzqG9ZYu3T7j/J3xG2j/bseI=; b=pnKWNJ3dwof7ofHR3oQwcUok48WGHh1u5DakSH9E870/M9S6Re7Z8zwkUsXlAVG75g vs5HaHw1sq+KsPQ7/ETLatpHEYtfYSMb4XM0H4cCpakO5CLUy36Fnzu4Fqpfuy7VFqQQ ctJq0P93dISH0FxSN7puv5rJ1iK74fwDvPCfBZAIbfmSxCifRn8xwlfikMqt5OlPlLgQ rTrhisPa7QHp5ej5qjUBEW9KdRqSU/7hH4g9rPjJSb24srM3GutgDQ5sZ+2ZKi8VRr8z fibgd4qniGn3A8sqVY26nREN+nd9+h8UmsLOUAR1DKy3vThOI0wNpaRpnw/lfuqzQt6i GeUw== 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=hyA1E6SUTuWEQF/SPoSfzqG9ZYu3T7j/J3xG2j/bseI=; b=SWeE+K1NayZo0HHoPH12Fc1MAudmW5wScx7MV3NjpadY0pLL2kLNEQwbNu4GAjG5BO cokaDu/2wwJ4JiBOZz7wQTSU2nJS3WqIT1d1/3Ye82H6E+61S9vPsp1SHLxvBQPl0hZZ ov7vlcuKufsqqHh9DDDdClYWYc1vRJM5eCwBijimFuoRuzx63FmydbbWrhkiPLvvyEuy DPOOQ7LDO8Hw76D+eyu698Kdok1/lgBSTE7wy3FK/l53chW+ZU+HAg72ZhpMujpm0vW0 H7YWPAkB9ji7h/JdNXZLCvrdfghlZQYnERZosulwjsXQEOjfCBLPM5IRQiZaVpXCdFeX n+zQ== X-Gm-Message-State: APjAAAWymJrP1QR/1CtQWC50rvo74EGULmxFf8JB0z0HBthDukTVyl8U n/xHBYccPXN+hvlQOZIC1WKyS8LSeH8= X-Google-Smtp-Source: APXvYqwbP4TmedWPMkBEEDVbv2lCtzpE424w910Ig7UFcJFsrnTZroMp4G1Qf3g6EyHuhAsabaNC1tlG9Fs= X-Received: by 2002:a0c:fa8a:: with SMTP id o10mr8417746qvn.7.1571391858216; Fri, 18 Oct 2019 02:44:18 -0700 (PDT) Date: Fri, 18 Oct 2019 11:43:00 +0200 In-Reply-To: <20191018094304.37056-1-glider@google.com> Message-Id: <20191018094304.37056-23-glider@google.com> Mime-Version: 1.0 References: <20191018094304.37056-1-glider@google.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog Subject: [PATCH RFC v1 22/26] kmsan: use __msan_memcpy() where possible. From: glider@google.com To: Alexander Potapenko Cc: Vegard Nossum , Dmitry Vyukov , linux-mm@kvack.org 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. Signed-off-by: Alexander Potapenko To: Alexander Potapenko Cc: Vegard Nossum Cc: Dmitry Vyukov Cc: linux-mm@kvack.org --- Change-Id: Ib2512ce5aa8d457453dd38caa12f58f002166813 --- arch/x86/include/asm/string_64.h | 9 ++++++++- include/linux/compiler.h | 9 ++++++++- include/linux/string.h | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) 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 4a594bd1bc47..40b1ab13fec7 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) {