Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp650458rbb; Sat, 24 Feb 2024 18:43:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUIROjf//lesToYJTS0M6oXl8quLC3SNxEAyjTIXnkvfEURW5VVHE2YEAHeGU6FF0YynwXy7B8PnqqUyYu7Mw4++d0w6Skr4Xyaq+5jiw== X-Google-Smtp-Source: AGHT+IFmcZUOSP4+92rA5n69Ye/8p056G+oTaXqS5lDiV8m+x0ZZ2R/6WPCPLxJsPT4r+m6deuby X-Received: by 2002:a17:90a:f009:b0:29a:90ef:66f4 with SMTP id bt9-20020a17090af00900b0029a90ef66f4mr4649457pjb.17.1708829025840; Sat, 24 Feb 2024 18:43:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708829025; cv=pass; d=google.com; s=arc-20160816; b=OepvsxcqvdQPwkS0MmR/1keArDRj75nJ6giyUdZSIdZGYDnKxx/7zhicFISrfTUyKr ahX/YWpx/Kztd4FGqmiNtECVgbxxUCSqJsXvhOH4w923eEL4iQY8ciNg472GQv+Lkwog 5pNxMbNVeAniRSndubUspccdyBtBRkxObcL4FN6XYJ5AYZrPtG3cQXl5DQsMsJcKaUD8 91Yy1jXXz0RXgjSjWslSYuGKxBqQ3RaAhTA0VGxQLEmCtcagUOHhO6UjQlFvCSSOOmh4 uajfrzahshG96flLe3I5VDucXAPdo9lQnpijVdiBNjkQGrR1YHRY22wZY1eSGprgw+0+ VQ4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:message-id:in-reply-to:date:mime-version :list-unsubscribe:list-subscribe:list-id:precedence; bh=8qmbVFqRc1bT7FEfHid+/HYK9f07F0/h1BWUmErVMx8=; fh=V9AeBafJgTW96HdC48wsxGAfd7Fe9P2uAL8tLCjpUN4=; b=qYwgnZBkmM4v0vUMr69SW8Tnz/GZytT2YAiZasKxKDJ2yukRDXht5oN8X/C2HVD5LL lEzl4W4CxS/rFAt+MZWyvioVw+Yjv1+nPlqYyCL4Vde9CLZ/TJs45tIMsxYKN1xSam+N aIF86bFjTr/cl6NfPpa5+rO4cSmu1RcxEeVBLc1OYtWPJmN0s8dCFTdYDxu43XgX+nEX 3Q1P2LPm5woaXGLBclp6ZNOO+eSu+Lz+ozhx1Lz7npYL/eUbh01ArC9LyvEwqntPzZkn D7mTvCIHgeK01LU6Cr1ssMGwqEE5Kc9WhUGybmbQJszx8ft4i7gM8+HvOe38/Ux6WEtb UWJg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=m3kw2wvrgufz5godrsrytgd7.apphosting.bounces.google.com); spf=pass (google.com: domain of linux-kernel+bounces-79951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=appspotmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k2-20020a17090a590200b00298c3b85759si3499255pji.146.2024.02.24.18.43.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 18:43:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=m3kw2wvrgufz5godrsrytgd7.apphosting.bounces.google.com); spf=pass (google.com: domain of linux-kernel+bounces-79951-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79951-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=appspotmail.com 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 86EC4281E6A for ; Sun, 25 Feb 2024 02:43:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB733BA29; Sun, 25 Feb 2024 02:42:46 +0000 (UTC) Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8232D944C for ; Sun, 25 Feb 2024 02:42:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828966; cv=none; b=r9mHk7n4hNUVCV76EYy9sDsmKMSUiS/UR0igOyD377Ecr7Xz/DJv9V1k6Fybo7CFHXfhYUTpRS5VLk4h112LbsbauOmRzK3eUaukzpoPs3c1j5YX/IscvvFuMTRRlOt+LDQcSYxhlu8h8RVK3P2ryeDVC3ToeL5/BxqF2LlQw/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708828966; c=relaxed/simple; bh=AdOTLa6n8/xEXoBnyPxUclExl4y+f+HtJRkRlIgmNDw=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=OLAI1rGTfmRJJqOsDuhXiXQK6vVgkCCadpKz+Se5e2tvUkwd/beK2o9cBZpLP+D44Veil1m359jTqYwwKkJfFTL8LtZmydW8AJ9PFZxEtMY400GpsfGnolLfMLri2Ji3Far38IIgqQAiuSAi3lcJZTrRw1HaWxpeDelSTB1IQYE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.166.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-7c79b0aaa86so180045639f.2 for ; Sat, 24 Feb 2024 18:42:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708828963; x=1709433763; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8qmbVFqRc1bT7FEfHid+/HYK9f07F0/h1BWUmErVMx8=; b=CDZrRW8/RJ/18hKZ1nwQX/uYpyDZUdRmlX5beiSeKTTIsTuNwuajz9gjdKTqi5RuA5 kEdmmUjRbX/IysFn2yNov0vvz3ktvQLJJ8IyYwGlH+u8mRwr7SCIKoH//fAgpAKnGyWv mykO6IUzDkVvp43v70ua3wscz4XPeC0FruOPJBWZ9FHh8sEVESdQa1y52acPgcN9uWmO w2/g07q7Bp1j0JbtTus5K0qnRN70x3XPLotqHXIbI8Az4kw5JsOBmuysMge+V8ggUGof qXwR3nAgeDjrouSFS8nrne3G1zCe8RcYbzk7EjmOwCRTNc2ZbWKlOl0lbf/T2JZ4hOez +EpA== X-Gm-Message-State: AOJu0YxHuj9NT2y1x7ED4D5O41pM7xgTEQive9qiOB4n5Sq0kkBdF+V5 zFrZpUbc45LUpipTeP5v5+gEkMTNTeDcbDSd24cH3QrG/uOKlNOoh+5EECiqfCijBBhBH5nvwPC /ZCvazhgHRy62D8T6W7SDJ5w2qKoYhGAbhIRn21VvlFzT/iqjPVnfUbnBQQ== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6e02:1808:b0:365:7607:3f6d with SMTP id a8-20020a056e02180800b0036576073f6dmr331211ilv.1.1708828963821; Sat, 24 Feb 2024 18:42:43 -0800 (PST) Date: Sat, 24 Feb 2024 18:42:43 -0800 In-Reply-To: <000000000000fd588e060de27ef4@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <0000000000005ee46906122bbf6d@google.com> Subject: Re: [syzbot] Re: [syzbot] [virtualization?] KMSAN: uninit-value in virtqueue_add (4) From: syzbot To: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org. *** Subject: Re: [syzbot] [virtualization?] KMSAN: uninit-value in virtqueue_add (4) Author: penguin-kernel@i-love.sakura.ne.jp #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/arch/x86/lib/copy_mc.c b/arch/x86/lib/copy_mc.c index 6e8b7e600def..bc701dcbb133 100644 --- a/arch/x86/lib/copy_mc.c +++ b/arch/x86/lib/copy_mc.c @@ -61,9 +61,9 @@ unsigned long copy_mc_enhanced_fast_string(void *dst, const void *src, unsigned */ unsigned long __must_check copy_mc_to_kernel(void *dst, const void *src, unsigned len) { - if (copy_mc_fragile_enabled) + if (0 && copy_mc_fragile_enabled) return copy_mc_fragile(dst, src, len); - if (static_cpu_has(X86_FEATURE_ERMS)) + if (0 && static_cpu_has(X86_FEATURE_ERMS)) return copy_mc_enhanced_fast_string(dst, src, len); memcpy(dst, src, len); return 0; @@ -74,14 +74,14 @@ unsigned long __must_check copy_mc_to_user(void __user *dst, const void *src, un { unsigned long ret; - if (copy_mc_fragile_enabled) { + if (0 && copy_mc_fragile_enabled) { __uaccess_begin(); ret = copy_mc_fragile((__force void *)dst, src, len); __uaccess_end(); return ret; } - if (static_cpu_has(X86_FEATURE_ERMS)) { + if (0 && static_cpu_has(X86_FEATURE_ERMS)) { __uaccess_begin(); ret = copy_mc_enhanced_fast_string((__force void *)dst, src, len); __uaccess_end(); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index e0aa6b440ca5..039ffa49f324 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -253,11 +253,16 @@ size_t memcpy_from_iter_mc(void *iter_from, size_t progress, static size_t __copy_from_iter_mc(void *addr, size_t bytes, struct iov_iter *i) { + size_t ret; + if (unlikely(i->count < bytes)) bytes = i->count; if (unlikely(!bytes)) return 0; - return iterate_bvec(i, bytes, addr, NULL, memcpy_from_iter_mc); + ret = iterate_bvec(i, bytes, addr, NULL, memcpy_from_iter_mc); + if (bytes != ret) + printk("addr=%px bytes=%d ret=%d\n", addr, bytes, ret); + return ret; } static __always_inline 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)