Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp382070rwl; Wed, 29 Mar 2023 03:21:31 -0700 (PDT) X-Google-Smtp-Source: AKy350aduYKRJ+nl4pTyeLJvBLpOXQE7OzpQZa8HyyRu08lMmEkXC3zr0s3kLaWi2j7QTa7+sJWF X-Received: by 2002:a17:906:738a:b0:92f:bef6:7843 with SMTP id f10-20020a170906738a00b0092fbef67843mr17565882ejl.22.1680085291261; Wed, 29 Mar 2023 03:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680085291; cv=none; d=google.com; s=arc-20160816; b=n9rU0/zPJ4zNoUGlxDPgW+amhohvGAWepQMgW1B38wH1Ys0cPHIFbhb/bbM16X5K0H C1DBPpuCCBnB52es54x7YLXUULz/WKkjahb47fIyXX1TsLa5RDcYF/5qYdZ/E40paC+E +UpTcjSzWFVEy+Qrpl6TeUi9nKu98S8+30kbJjKinenj/Gt0M5WTZ5IeHxbfSTJST1ps 1tJVgUTnNh6D6cuveJX85Zw/A5vHAAilb5vuDNtEyHU/U3+jqI815/eWVdQRnb67WVKP bGfCxdzdv5B/lSzkSI4XFKWuYEC2aznQjpfbu6iouMhgWjmkOeasUEdR7F3XMGwatqC7 PEfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8KE21p/4rHvIIb3Hr9Wpwb2jk+KRZpBrqUJOxWv9CkA=; b=Zm6YuLNVBPACfN5X/ZA3ByOY19h7P+ijmPnII1VqUgDVngEhgxtEUtokR97ZHWaQYI g9SWY6E04K93/VsPUUiM4CptNrAQW1SB5Gj8hjwU5c261wz16eisowLyrEwmkUghEVZ3 V4AcBpqQeILlsgUKC9XQcMC/A+W4CB6nuZIUkT/cByC3k2BfFGJuH+JtJ8x7R1IV9Efn 1LfS0teqVeaD2GDrnFLuh/TXxD2W5Jot4vtW2xVPojbqSX7v52mP+pheiaf/T8XIw0zS KA/gE6j479NuHk8C0rXlH2KfTqplIxxf5k1RFke2rkhEdGZVQNlqkbrVVJGCCqFmLnwc Jneg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nRiRfoV+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lh17-20020a170906f8d100b0093048a8bd2esi30986176ejb.43.2023.03.29.03.21.07; Wed, 29 Mar 2023 03:21:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nRiRfoV+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231492AbjC2KPc (ORCPT + 99 others); Wed, 29 Mar 2023 06:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231504AbjC2KP3 (ORCPT ); Wed, 29 Mar 2023 06:15:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B6D94480 for ; Wed, 29 Mar 2023 03:15:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A074361C35 for ; Wed, 29 Mar 2023 10:15:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF22EC433D2; Wed, 29 Mar 2023 10:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1680084924; bh=oLJgHbDdDrr+s5ptyAuzO1SNbf0Oju6Msn0laatr/hU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nRiRfoV+Y3qfPNtePaFUCd89Q6F/P5BbYjgbOpVjX5XjDR8v3SmWnmPSnHCl5x7s0 zDgmF9IibZbr30Helxq56C0B5W5EVDGopvaAP284u1sxcJBDblxb8nYsMXFXOfWW2Q P9FdJ5gEtBkr/RZDDVDrU/eblnBYeDmJ+OeH0Bxg= Date: Wed, 29 Mar 2023 12:15:21 +0200 From: Greg KH To: "Dae R. Jeong" Cc: bryantan@vmware.com, vdasa@vmware.com, pv-drivers@vmware.com, arnd@arndb.de, linux-kernel@vger.kernel.org Subject: Re: [PATCH] vmci_host: fix a race condition in vmci_host_poll() causing GPF Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 27, 2023 at 09:01:53PM +0900, Dae R. Jeong wrote: > During fuzzing, a general protection fault is observed in > vmci_host_poll(). > > general protection fault, probably for non-canonical address 0xdffffc0000000019: 0000 [#1] PREEMPT SMP KASAN > KASAN: null-ptr-deref in range [0x00000000000000c8-0x00000000000000cf] > RIP: 0010:__lock_acquire+0xf3/0x5e00 kernel/locking/lockdep.c:4926 > <- omitting registers -> > Call Trace: > > lock_acquire+0x1a4/0x4a0 kernel/locking/lockdep.c:5672 > __raw_spin_lock_irqsave include/linux/spinlock_api_smp.h:110 [inline] > _raw_spin_lock_irqsave+0xb3/0x100 kernel/locking/spinlock.c:162 > add_wait_queue+0x3d/0x260 kernel/sched/wait.c:22 > poll_wait include/linux/poll.h:49 [inline] > vmci_host_poll+0xf8/0x2b0 drivers/misc/vmw_vmci/vmci_host.c:174 > vfs_poll include/linux/poll.h:88 [inline] > do_pollfd fs/select.c:873 [inline] > do_poll fs/select.c:921 [inline] > do_sys_poll+0xc7c/0x1aa0 fs/select.c:1015 > __do_sys_ppoll fs/select.c:1121 [inline] > __se_sys_ppoll+0x2cc/0x330 fs/select.c:1101 > do_syscall_x64 arch/x86/entry/common.c:51 [inline] > do_syscall_64+0x4e/0xa0 arch/x86/entry/common.c:82 > entry_SYSCALL_64_after_hwframe+0x46/0xb0 > > Example thread interleaving that causes the general protection fault > is as follows: > > CPU1 (vmci_host_poll) CPU2 (vmci_host_do_init_context) > ----- ----- > // Read uninitialized context > context = vmci_host_dev->context; > // Initialize context > vmci_host_dev->context = vmci_ctx_create(); > vmci_host_dev->ct_type = VMCIOBJ_CONTEXT; > > if (vmci_host_dev->ct_type == VMCIOBJ_CONTEXT) { > // Dereferencing the wrong pointer > poll_wait(..., &context->host_context); > } > > In this scenario, vmci_host_poll() reads vmci_host_dev->context first, > and then reads vmci_host_dev->ct_type to check that > vmci_host_dev->context is initialized. However, since these two reads > are not atomically executed, there is a chance of a race condition as > described above. > > To fix this race condition, read vmci_host_dev->context after checking > the value of vmci_host_dev->ct_type so that vmci_host_poll() always > reads an initialized context. > > Reported-by: Dae R. Jeong > Fixes: 8bf503991f87 ("VMCI: host side driver implementation.") > Signed-off-by: Dae R. Jeong If you author and sign-off on the patch, no need for a Reported-by: as that is obvious :) And how did you test this change? thanks, greg k-h