Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp588286lqg; Fri, 1 Mar 2024 14:41:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVR0Ohe0Z3diaN8dpUEEsj6Lhfuyaom8rC6Yf+t+UI5EmBKd2X25mYwVhMCEf/9sFTITEM8Vae6UYfyfu7iTCidY0TJgcE0LeCzOIH5PQ== X-Google-Smtp-Source: AGHT+IHSV+yQdAtl8VIOHhyvvvNm3mkMKz33bGVMfRl3mqRArZ1BzkfVRtc+/BGamf2ueaVc0FSU X-Received: by 2002:a05:6402:2267:b0:565:6bbc:39d1 with SMTP id du7-20020a056402226700b005656bbc39d1mr2199059edb.5.1709332913912; Fri, 01 Mar 2024 14:41:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709332913; cv=pass; d=google.com; s=arc-20160816; b=hcrsmm7Uv2q1zTDAq/f9e1XojzCt5uJMqG/NCNvIql+BkmvGtpxHQhuMCMXcPQ4jOP kAQ5bNJxkhoFtQC1FvYY3wZUWlv8Swxt8PXUsEQSd/1mKhajvYEz4GClGWHS/dP0tD9+ j3t18mCzhY6GwRhG3/BknFx5GvyNCC3CWGlaWnQnBNJ/DN528GBsuGx23jkdpr5Hu/m/ G+WIdHzob9HOiaYTUTFuW7wreyp4jFJRxuUFQzznvLaNwsv538MrYxz7GXCnJZMaurbw 6Hu/sTYKYmh8K0rm1TPQZH9O3QujnX+Tb86rzAHYlojvnGVpD6jSPDLBFR1DmR5CCiyw AHtA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:subject:from:cc:to:content-language :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=kGsroOKd8qwFc2D8F/6xThqNMtidRFLHoIRZwpqUoHg=; fh=jeB3HxN2GrPyfbhpvZPZn4LpRZCyFUenHn11qXUQvms=; b=yrW1eIwS/aMu5J4sq1nT+V+l0K0txEtCwGhibnafCzNw/fz9iHOPoMSVIYJwMsbB9K ZZ1XBSq8D0iGI0Cr4aFheyuzseEkyUbg/H63eIF8Cu/GfdQoCLiwRxpoarJ1Ilfhw3/K +c4Zo0gd/zG2lyN1608qEWA5cq8WfYSCw25wka8oQIoerNjWb1LrpHP1w/U/rinoKqYy wN4qUAvqsIthGlryEkqI/U/FEu5CjNA+TIwdi6JNK/SL0Z1cWi0vJmJQ6eAVuKWi3ksg Wo/0H31rK9QwcAQSMXanhbRUXooQEWra2786XO+6nafTLEFdkG/rr6lzu0JFchHjdTJb v+Jw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=i-love.sakura.ne.jp); spf=pass (google.com: domain of linux-kernel+bounces-89206-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89206-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e16-20020a50d4d0000000b00565aec519f8si1839780edj.191.2024.03.01.14.41.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 14:41:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89206-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=i-love.sakura.ne.jp); spf=pass (google.com: domain of linux-kernel+bounces-89206-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89206-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A17511F2641C for ; Fri, 1 Mar 2024 22:41:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 218025EE6A; Fri, 1 Mar 2024 22:41:47 +0000 (UTC) Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24C9059B6F for ; Fri, 1 Mar 2024 22:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.181.97.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709332906; cv=none; b=LPgS1UWtKoxCHQPPLm9y1/Z2MIHsEb2RU2sVwXUyDrE4ziUENN5VEeXhsw0n/qGqSqhTGVwjbls1g2DikWoK73DnephC5naXO1sGCk4Wj/GS7HNZ/3x8gqtECAimPlIaxCFSWV2VkRtCtSWuPdgH8s8FFiSLdXKfRk7Ka5Bcbvg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709332906; c=relaxed/simple; bh=y05OlHIzADcP3OrGVS6Hx+8JB8tEpPHFBEbcYJFqEzA=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=V09dFfV6SaJrU1MYEnkPnaxc83kDO63csBrWa2NgovKg5ELHoIiBe8tSidHYOanzsd8YQfIJk0ErYrDBQ4eFb1iiPXxMez3EGIl4WVmEJmgVcpQ9yFvx6RRfwIyBUYJsIUqCDLOApg7PWvYNIlPp2pZ8xP0jiZY0lJpq/+VcuB0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp; arc=none smtp.client-ip=202.181.97.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp Received: from fsav313.sakura.ne.jp (fsav313.sakura.ne.jp [153.120.85.144]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 421Mf9oZ091718; Sat, 2 Mar 2024 07:41:09 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav313.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav313.sakura.ne.jp); Sat, 02 Mar 2024 07:41:09 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav313.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 421Mf8l1091714 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sat, 2 Mar 2024 07:41:08 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <1a817eb5-7cd8-44d6-b409-b3bc3f377cb9@I-love.SAKURA.ne.jp> Date: Sat, 2 Mar 2024 07:41:09 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: LKML , the arch/x86 maintainers Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" From: Tetsuo Handa Subject: [PATCH v3] x86: disable non-instrumented version of copy_page when KMSAN is enabled Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Commit afb2d666d025 ("zsmalloc: use copy_page for full page copy") caused a false-positive KMSAN warning. Implement copy_page() using memcpy() when KMSAN is enabled. BUG: KMSAN: use-after-free in obj_malloc+0x6cc/0x7b0 Uninit was stored to memory at: obj_malloc+0x70a/0x7b0 Uninit was created at: free_unref_page_prepare+0x130/0xfc0 Signed-off-by: Tetsuo Handa --- Changes in v3: Update description/comment and use include file, suggested by Thomas Gleixner. arch/x86/include/asm/page_64.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index cc6b8e087192..98a71727dbac 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -9,6 +9,7 @@ #include #include +#include /* duplicated to the one in bootmem.h */ extern unsigned long max_pfn; @@ -58,7 +59,18 @@ static inline void clear_page(void *page) : "cc", "memory", "rax", "rcx"); } +#ifdef CONFIG_KMSAN +/* + * The assembly version of copy_page() is not instrumented and + * therefore breaks KMSAN. Fall back to memcpy. + */ +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 /* -- 2.34.1