Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp610470rbb; Sat, 24 Feb 2024 16:01:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWNgoIoxPfQzDsVvA88tabrAX6YcBxISlAu2OC3u/kEWiu1cf1NiNhBe3nZDsYZKuEX5YvgGQTgSOozcXUhrqQ2k7Z8J4x57cf0ARMp7w== X-Google-Smtp-Source: AGHT+IE4ufmhMJc8/Gx3zIxrbJryQeFMqhod3WUJKXknnUFdKQRM1VmWeOtVemCiwVMIQbK1U0HW X-Received: by 2002:a05:6a20:c702:b0:1a0:a06e:41cf with SMTP id hi2-20020a056a20c70200b001a0a06e41cfmr3529544pzb.32.1708819301418; Sat, 24 Feb 2024 16:01:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708819301; cv=pass; d=google.com; s=arc-20160816; b=gXWOO15VbgtjmwSfzJnRs4hpV+o2tfDE5g2vHRRUSwk6pLm6/Tstn/YqRrU82o0uXU 8o0QyGEoi3Sv7IHUlQIdCtSI9yi9CpNT1j4mbF/raTlKWf7dpZVM06VCYrNPm/OoUg0A jhLYxqZx40CSEnQPRuB9QyQ8YNdNYtWm6erLzMYCaiCwt7l+wSfBUCgQU5zAGz2oALO7 qzTrMbzHW3KcLR2LV1kXl+K5FB+PFzQCKGDyyw5RcBkhlF5fHVM5dFajgdALafB/OFgB fGii48X7wc0xdEVD9cCjZ4pAGah4iyRb63phzQ60Gb9u4NnvYHXTX/8BBNrob9NOl5M0 7k/Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=7b7Co+R0ZRxXy/MPTeKGsZMSW1lxqYdWUUhoNj0o9as=; fh=XtnChCGTA7i8TGRIfzbKtEnVweQvxQA2iZ1Ims3W+AE=; b=E+GjsptRQpm8Irc+86TzLe/0a4I3yFnpAOMo3m9FTcb0cRjS7E95SNIYxC9LuaaOwc iDMkrLwKBCRWR8TaqJPx6z4ASovmNcAM/KjmeKEy0ajOw8HKfbSx3cvztT+auDoVmAxM tJf0vHm42U/HwkMlWyFonQmGh4OTCHDBH5ThSzdxYu/3GniwbgQ063FwArdDALUgSJrx jcdIq4xM1Wxyy4yBo9t1x9XA+Xeg1EHppLNpyqKYGB1kFW57xLI9RBTaU8RvndssTHDJ yk+91d0DwvsEhoifxgMu/JGmXdkCmRrlyPv+8BqDiFai8cAN3EGbsg0IiSQuBYDO9zwG OeEA==; 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-79907-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79907-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p3-20020a634f43000000b005dc4b84b38asi1454381pgl.72.2024.02.24.16.01.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 16:01:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79907-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; 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-79907-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79907-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0B952282394 for ; Sun, 25 Feb 2024 00:01:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2AFC4817; Sun, 25 Feb 2024 00:01:35 +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 F0B34624 for ; Sun, 25 Feb 2024 00:01:31 +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=1708819294; cv=none; b=Me3naggRI0LcxeBCFvMr+zF2NcDNRD7iUuocBOSMUGVxru4OXfiINCH7PGJ1Cz9kIC/K4K328Jm+ba+kZhaO+5FNWlMlYiuHFCthrQ2D0wqnoE8Aytkg4xjOMGtp3mYoS5TMIQ1/mrbTou804fZS7T5MUoBua7eCRnoBSzRPKQM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708819294; c=relaxed/simple; bh=PA3f8p9PSQOP+huvK5/WKeQuDFz8b1e9dTDMnaE8xqs=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=gzW1vEMTuWbJt7uhU0/SITnhuWPIr8U+Um41W43qkq+xjwebHP2DgvUyAlIbYML8QOCh3xtMwg7i+yeKADN5gNZxzEv2FQ2oiwuRUXiFlLmoy/cHPhuj13cpLU7JOV9eCqZ2NEAIU8NXQVEtAwMb9YnaF0OlamIbMuAJw65m7X8= 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 fsav311.sakura.ne.jp (fsav311.sakura.ne.jp [153.120.85.142]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 41P01JUB022406; Sun, 25 Feb 2024 09:01:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav311.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav311.sakura.ne.jp); Sun, 25 Feb 2024 09:01:19 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav311.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 41P01IsN022399 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Sun, 25 Feb 2024 09:01:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Sun, 25 Feb 2024 09:01:19 +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 Subject: Re: [syzbot] [virtualization?] KMSAN: uninit-value in virtqueue_add (4) Content-Language: en-US From: Tetsuo Handa To: syzbot , syzkaller-bugs@googlegroups.com Cc: linux-kernel@vger.kernel.org References: <000000000000fd588e060de27ef4@google.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git v6.7 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 /* diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c index 5d6e2dee5692..0b09daa188ef 100644 --- a/mm/kmsan/hooks.c +++ b/mm/kmsan/hooks.c @@ -359,6 +359,12 @@ void kmsan_handle_dma_sg(struct scatterlist *sg, int nents, } /* Functions from kmsan-checks.h follow. */ + +/* + * To create an origin, kmsan_poison_memory() unwinds the stacks and stores it + * into the stack depot. This may cause deadlocks if done from within KMSAN + * runtime, therefore we bail out if kmsan_in_runtime(). + */ void kmsan_poison_memory(const void *address, size_t size, gfp_t flags) { if (!kmsan_enabled || kmsan_in_runtime()) @@ -371,47 +377,31 @@ void kmsan_poison_memory(const void *address, size_t size, gfp_t flags) } EXPORT_SYMBOL(kmsan_poison_memory); +/* + * Unlike kmsan_poison_memory(), this function can be used from within KMSAN + * runtime, because it does not trigger allocations or call instrumented code. + */ void kmsan_unpoison_memory(const void *address, size_t size) { unsigned long ua_flags; - if (!kmsan_enabled || kmsan_in_runtime()) + if (!kmsan_enabled) return; ua_flags = user_access_save(); - kmsan_enter_runtime(); /* The users may want to poison/unpoison random memory. */ kmsan_internal_unpoison_memory((void *)address, size, KMSAN_POISON_NOCHECK); - kmsan_leave_runtime(); user_access_restore(ua_flags); } EXPORT_SYMBOL(kmsan_unpoison_memory); /* - * Version of kmsan_unpoison_memory() that can be called from within the KMSAN - * runtime. - * - * Non-instrumented IRQ entry functions receive struct pt_regs from assembly - * code. Those regs need to be unpoisoned, otherwise using them will result in - * false positives. - * Using kmsan_unpoison_memory() is not an option in entry code, because the - * return value of in_task() is inconsistent - as a result, certain calls to - * kmsan_unpoison_memory() are ignored. kmsan_unpoison_entry_regs() ensures that - * the registers are unpoisoned even if kmsan_in_runtime() is true in the early - * entry code. + * Version of kmsan_unpoison_memory() called from IRQ entry functions. */ void kmsan_unpoison_entry_regs(const struct pt_regs *regs) { - unsigned long ua_flags; - - if (!kmsan_enabled) - return; - - ua_flags = user_access_save(); - kmsan_internal_unpoison_memory((void *)regs, sizeof(*regs), - KMSAN_POISON_NOCHECK); - user_access_restore(ua_flags); + kmsan_unpoison_memory((void *)regs, sizeof(*regs)); } void kmsan_check_memory(const void *addr, size_t size)