From patchwork Sat Feb 24 06:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 13570249 Return-Path: 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 D4D43C48BF6 for ; Sat, 24 Feb 2024 06:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10CA76B0071; Sat, 24 Feb 2024 01:28:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BCF06B0074; Sat, 24 Feb 2024 01:28:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EA99E6B0075; Sat, 24 Feb 2024 01:28:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D97346B0071 for ; Sat, 24 Feb 2024 01:28:36 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8560881254 for ; Sat, 24 Feb 2024 06:28:36 +0000 (UTC) X-FDA: 81825718632.02.4BBE89C Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) by imf18.hostedemail.com (Postfix) with ESMTP id 998A01C0007 for ; Sat, 24 Feb 2024 06:28:33 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708756114; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M9Fg4KJqLbBGP8r0njyeZzZvmuNITeV0o6CVYVXKe3g=; b=aB3cgV3h3msDh0F9MyIojLkQ8YCHyYba9KqxRGfbisRgPS5tI1xBj6nDgxdXPgsPMqZByb LNq8056Lea+w7YiuIhKJz07Hmov+mdpBPvzZZCj0Q3v4InJMCUdsiBBr4kAuCZNK1i2kLx oEnzzrk1vNYkMdL5VePGDvk8Y4YkUKE= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf18.hostedemail.com: domain of penguin-kernel@I-love.SAKURA.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@I-love.SAKURA.ne.jp ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708756114; a=rsa-sha256; cv=none; b=HxgJXB201rGKpJx5InktVtFN+0+wN5D3L68POPwAacWm4sfrT4AIXQ4V6LCoHtqBxZ5K8a XkpHaeM7yZ3KdX8bMub7w3dPHaw9hYT+Zv+fOJ3T2uR9Yv7+RaL9MeIWBJPATXunDvXRis vTamoJFMXSeY1gpP8RSaB8Vev0lc72A= Received: from fsav314.sakura.ne.jp (fsav314.sakura.ne.jp [153.120.85.145]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 41O6Rwxi089466; Sat, 24 Feb 2024 15:27:58 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav314.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav314.sakura.ne.jp); Sat, 24 Feb 2024 15:27:58 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav314.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 41O6Rw5x089462 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sat, 24 Feb 2024 15:27:58 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <7f322fe9-34ba-43be-bb50-539577d1c183@I-love.SAKURA.ne.jp> Date: Sat, 24 Feb 2024 15:27:57 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2] x86: disable non-instrumented version of copy_page when KMSAN is enabled Content-Language: en-US From: Tetsuo Handa To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , the arch/x86 maintainers , "H. Peter Anvin" Cc: Johannes Weiner , Yosry Ahmed , Nhat Pham , Minchan Kim , linux-mm , kasan-dev , Mark-PK Tsai , Sergey Senozhatsky , Alexander Potapenko References: <20240223044356.GJ11472@google.com> <6dd78966-1459-465d-a80a-39b17ecc38a6@I-love.SAKURA.ne.jp> <678f31f8-5890-47fa-972e-df966aeb783d@I-love.SAKURA.ne.jp> In-Reply-To: <678f31f8-5890-47fa-972e-df966aeb783d@I-love.SAKURA.ne.jp> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 998A01C0007 X-Stat-Signature: gg3ndazo6c6n7b5znjp7ci6twxegpuzu X-HE-Tag: 1708756113-959286 X-HE-Meta: U2FsdGVkX1/nrMw2L12gwSPBwIiUstTu0WimkVKVcsLdqCD85EWF1ehX+iVSKOeIN+K96zqIzdEQJ4dvfcGKxLo5qasyXAXxMdAe10GgFOj8u2d6UNZFqyWThvPgXlX9f4c9l8iGN1qTSx4CHuCmN7L3wuf1wSuo8r4oTv0i2AgDWnkbQOMQdeDa9MhCsv+KdscpUGTYqC0EaFw9WvMdUcdvmOWKNZ07aRDGQ6wTwqFBTBM5TKOj5Km6nQ/kaJ6YL/0KJ75SpSOOURu6x1jW3pX0TsuATkBVnMUTbnUFVdgp175H4N/Z62rkXfOVZ9AwrU8+xkcygwLAXQQsl6IqJ6GELNWB1EVhadSheEkuXYa/wO49f1wxIfo21Mtp7OHxwqAfLa2oVeTwjK2ExU85Y9EzHTnvxsn9RUq/L2C+b4OlpDlGd5oGJenKm3BuXSG7b5uCGbVkOszsRR2veyWUva1ihmodEZqAz+4kAedPJs2DpvCv898JNxBKGvbvcGNYCCxTe6Mbp594e/UoLAwGqvpXwoC31Kf5vB3mtA12JBIr5R5B6ITqWwdrXlUSuWY8B9a0Z4HiaUrRp9cMg53hhlFpnXLLqxzlFSDaZ9hbEcYjJhwMCT9TYYbAukpc+GlHxzvpd1VF9guFohTMJwsV1prm2sLPyAyOq1MUq2ZBRVfnKJgmrZ/38JEqvC++YhO2LPxdE28LrrekDqmy8anBVliDZFFQqvlV3cvIp5IciR9S203DMFfQeIrc4daMPQPApS70NqzsZxnx1WF7ym/LjY80wZQqdm0xXtyUOdrE2JjALsCOWi44q7AQCQo4TVEgo/loMfJy67ehNZ6DQqd6p6ACy0/bycxQj9A6Y01AVEkic4uOU5jTUywwAmrbK3u7z3DU30JqlefjeIev0iVTLaDyRUCftB/7n/QlEgNuwiAfGdSiinkETFptR19+ThIdKoR9y3xsnNk/ApEPcPK 5CO0z8zh zYCWmlHxZ55ziKtUEejwkHK6Z7JzlGdMpKFlE+2rUwD8LIkAJJssdsQK84QBUcMWnnK+rq8RB0K9/7Cd5SfrcjCUGz8uh8EvuME8uZNALVY76QvOV4RLz5woJbfMFCvG91Ps7SoCTDS2IU8MNjcPKmlVWg3GrynZff3/r79lBmFS9I26WUmj/Usmm78ckC0hErew4KdyXmHc5lVZniSWzzXTlW77vqLd2Nbq6vAuvrcxwroo56/9BJ4pM9nssXaFNcrO9YFGmWfRCth3CWFkANTlsIyt9OIJCSYu8nSyI3MG24eU= 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: List-Subscribe: List-Unsubscribe: I found that commit afb2d666d025 ("zsmalloc: use copy_page for full page copy") caused a false-positive KMSAN warning. [ 50.030627][ T2974] BUG: KMSAN: use-after-free in obj_malloc+0x6cc/0x7b0 [ 50.165956][ T2974] Uninit was stored to memory at: [ 50.170819][ T2974] obj_malloc+0x70a/0x7b0 [ 50.328931][ T2974] Uninit was created at: [ 50.341845][ T2974] free_unref_page_prepare+0x130/0xfc0 We need to use instrumented version when KMSAN is enabled. Let arch/x86/include/asm/page_64.h implement copy_page() using memcpy() like arch/x86/include/asm/page_32.h does. Signed-off-by: Tetsuo Handa --- arch/x86/include/asm/page_64.h | 9 +++++++++ 1 file changed, 9 insertions(+) Changes in v2: Update explanation, for I misinterpreted source/destination direction. diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index cc6b8e087192..f13bba3a9dab 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -58,7 +58,16 @@ static inline void clear_page(void *page) : "cc", "memory", "rax", "rcx"); } +#ifdef CONFIG_KMSAN +/* Use of non-instrumented assembly version confuses KMSAN. */ +void *memcpy(void *to, const void *from, __kernel_size_t len); +static inline void copy_page(void *to, void *from) +{ + memcpy(to, from, PAGE_SIZE); +} +#else void copy_page(void *to, void *from); +#endif #ifdef CONFIG_X86_5LEVEL /*