Message ID | 20220905122452.2258262-36-glider@google.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.org> X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E84D5ECAAD5 for <linux-mm@archiver.kernel.org>; Mon, 5 Sep 2022 12:26:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82B928D008A; Mon, 5 Sep 2022 08:26:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7DEFF8D0076; Mon, 5 Sep 2022 08:26:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 654E28D008A; Mon, 5 Sep 2022 08:26:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5772A8D0076 for <linux-mm@kvack.org>; Mon, 5 Sep 2022 08:26:35 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 37E4A160777 for <linux-mm@kvack.org>; Mon, 5 Sep 2022 12:26:35 +0000 (UTC) X-FDA: 79877955150.09.2A7F18D Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf16.hostedemail.com (Postfix) with ESMTP id E86BD18006C for <linux-mm@kvack.org>; Mon, 5 Sep 2022 12:26:34 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id ds17-20020a170907725100b007419bfb5fd4so2255020ejc.4 for <linux-mm@kvack.org>; Mon, 05 Sep 2022 05:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=yflFKH40jmwCCGQluWMEQ//gU/gWIMkmRe3xdXByGVQ=; b=fAxph5Y6U04CXZrajhFkL+LMhlfmAqX1mOptfFGFa+34F1+59OCoqL+hyS00yE9PU3 JiQF8Q7PP63alm8LFCcaO0ZZHzZ5WxGFto4GmMcgZr9o9k0lEZRIQVzzKRElWx4oA9Ez 7ZjbmW+o8zPS23NFbXCbrLPnQaO1lqjWBLYh2MePrjtDiEAPdC3lrLsuRUbPOH3mzVEQ PgdyG8vgJN4Qnre4Ot1waLJj7+TH2C6/GbnJwovqjOPhmu9jof0uYhctQHZkHtEoZesE L4Z7jgUgDUS3X3M2bfaQgTzxuHr1pPSXpKXdHYlPC0r3legvJZAdTPNLBXX4Lymsq/aN mAFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=yflFKH40jmwCCGQluWMEQ//gU/gWIMkmRe3xdXByGVQ=; b=P3oz7C+nXwNGufb9qa53Uo6WCB/jnQs5/x9/KmnjoCk/S+gzXWrRNGCXX5C3YEXWqt DM08AYxSC4O19yuriQ2cjUS6/5ilGoivzTR3j3f5dMN3KSta0/2Dl/MIhQnQe+GU1+vD Q+N7oxwH53ELCOWYMGCKdmY6JOV75pjQpcK5QiqyeLDSAQNlEEdsXqOpZ1NCRrGctbIk VbL/+7+wRdINdeD6j7L+8a2yADlj3EthtOzpDDWORlAOXcaW5UVKCg2/OmSJjECUL1tX SowS8aRT8R+A8lhssE2ucTVa+0hSWkNuJnHtQP9GxGkQvE0qEByDqovUf96z2N6iPHJA W6vg== X-Gm-Message-State: ACgBeo1gLt4ec7rDo9bKwKeuX5Z3XMOfkxLallGbGi6rPVU8D4Xnsg4A BmhzVEZdsK4y7QAt4B3BvGKHpgfRQkg= X-Google-Smtp-Source: AA6agR7p8f0oX7Qv/mGgEi+wXgphK2AAXJizc5KwHHFoVlbMDXfcad2dvQIIPWVBGG5QIQ/9evyI4QEPVGs= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:b808:8d07:ab4a:554c]) (user=glider job=sendgmr) by 2002:a17:907:2722:b0:731:2aeb:7942 with SMTP id d2-20020a170907272200b007312aeb7942mr35645383ejl.734.1662380793723; Mon, 05 Sep 2022 05:26:33 -0700 (PDT) Date: Mon, 5 Sep 2022 14:24:43 +0200 In-Reply-To: <20220905122452.2258262-1-glider@google.com> Mime-Version: 1.0 References: <20220905122452.2258262-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220905122452.2258262-36-glider@google.com> Subject: [PATCH v6 35/44] x86: kmsan: handle open-coded assembly in lib/iomem.c From: Alexander Potapenko <glider@google.com> To: glider@google.com Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Alexei Starovoitov <ast@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, Andrey Konovalov <andreyknvl@google.com>, Andy Lutomirski <luto@kernel.org>, Arnd Bergmann <arnd@arndb.de>, Borislav Petkov <bp@alien8.de>, Christoph Hellwig <hch@lst.de>, Christoph Lameter <cl@linux.com>, David Rientjes <rientjes@google.com>, Dmitry Vyukov <dvyukov@google.com>, Eric Dumazet <edumazet@google.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Herbert Xu <herbert@gondor.apana.org.au>, Ilya Leoshkevich <iii@linux.ibm.com>, Ingo Molnar <mingo@redhat.com>, Jens Axboe <axboe@kernel.dk>, Joonsoo Kim <iamjoonsoo.kim@lge.com>, Kees Cook <keescook@chromium.org>, Marco Elver <elver@google.com>, Mark Rutland <mark.rutland@arm.com>, Matthew Wilcox <willy@infradead.org>, "Michael S. Tsirkin" <mst@redhat.com>, Pekka Enberg <penberg@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Petr Mladek <pmladek@suse.com>, Steven Rostedt <rostedt@goodmis.org>, Thomas Gleixner <tglx@linutronix.de>, Vasily Gorbik <gor@linux.ibm.com>, Vegard Nossum <vegard.nossum@oracle.com>, Vlastimil Babka <vbabka@suse.cz>, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662380794; a=rsa-sha256; cv=none; b=0dWl0wN74QK4uPLXis6zHM0/hTQrJtC53wyTspcKiLB5qus+hmkjH8My71kh/QjVTn5RV4 QkaWpk5WRbNiBnqBWjHMCPIxeaOa5CDTkj8/B0PCKPIDu4sfU1hL+jSnorVAmq5ERMSXIb BqeRyDxUKobXxqUmkOhO08OxMRRLbSs= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=fAxph5Y6; spf=pass (imf16.hostedemail.com: domain of 3-eoVYwYKCEYotqlmzowwotm.kwutqv25-uus3iks.wzo@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3-eoVYwYKCEYotqlmzowwotm.kwutqv25-uus3iks.wzo@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662380794; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yflFKH40jmwCCGQluWMEQ//gU/gWIMkmRe3xdXByGVQ=; b=QaarBXO64o5yOvhSNTZCuQtgk0vczJ9eeGRezbLZXWXY1wykdhWzUKiofP4lxU3ssjpKmc 8sowgkg/JjObUT5ZhYe6lYQjK+ThSkKuLi2Ekh8nEa7zbDn4P3oBZfwf2D2SzTk8xTsNrO /KE5TNDizGeDTQi1dzp5p+jBpPNhTeg= X-Stat-Signature: yicgco61okamk7xjnr6wyg1f5qppbgwc X-Rspamd-Queue-Id: E86BD18006C Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=fAxph5Y6; spf=pass (imf16.hostedemail.com: domain of 3-eoVYwYKCEYotqlmzowwotm.kwutqv25-uus3iks.wzo@flex--glider.bounces.google.com designates 209.85.218.74 as permitted sender) smtp.mailfrom=3-eoVYwYKCEYotqlmzowwotm.kwutqv25-uus3iks.wzo@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1662380794-797359 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: <linux-mm.kvack.org> |
Series |
Add KernelMemorySanitizer infrastructure
|
expand
|
diff --git a/arch/x86/lib/iomem.c b/arch/x86/lib/iomem.c index 3e2f33fc33de2..e0411a3774d49 100644 --- a/arch/x86/lib/iomem.c +++ b/arch/x86/lib/iomem.c @@ -1,6 +1,7 @@ #include <linux/string.h> #include <linux/module.h> #include <linux/io.h> +#include <linux/kmsan-checks.h> #define movs(type,to,from) \ asm volatile("movs" type:"=&D" (to), "=&S" (from):"0" (to), "1" (from):"memory") @@ -37,6 +38,8 @@ static void string_memcpy_fromio(void *to, const volatile void __iomem *from, si n-=2; } rep_movs(to, (const void *)from, n); + /* KMSAN must treat values read from devices as initialized. */ + kmsan_unpoison_memory(to, n); } static void string_memcpy_toio(volatile void __iomem *to, const void *from, size_t n) @@ -44,6 +47,8 @@ static void string_memcpy_toio(volatile void __iomem *to, const void *from, size if (unlikely(!n)) return; + /* Make sure uninitialized memory isn't copied to devices. */ + kmsan_check_memory(from, n); /* Align any unaligned destination IO */ if (unlikely(1 & (unsigned long)to)) { movs("b", to, from);
KMSAN cannot intercept memory accesses within asm() statements. That's why we add kmsan_unpoison_memory() and kmsan_check_memory() to hint it how to handle memory copied from/to I/O memory. Signed-off-by: Alexander Potapenko <glider@google.com> --- Link: https://linux-review.googlesource.com/id/Icb16bf17269087e475debf07a7fe7d4bebc3df23 --- arch/x86/lib/iomem.c | 5 +++++ 1 file changed, 5 insertions(+)