Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp168399rdh; Wed, 22 Nov 2023 23:49:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCIUGpBhPSIm5+em4X3VjgH+TDg0cYm4DYoYI024VXbfnaNHDryfsNvE4dodhXAl453Rfw X-Received: by 2002:a05:6830:2695:b0:6d7:ed0f:8824 with SMTP id l21-20020a056830269500b006d7ed0f8824mr6137487otu.5.1700725784565; Wed, 22 Nov 2023 23:49:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700725784; cv=none; d=google.com; s=arc-20160816; b=rAxAcZo00ClBLM8si0uqe7okW25sieFG+CbYfbxJ3Zf1TphoYo7g1pqPbhjodZCCrm bosM5gGNzXBjX18ftS9ZnnOB1L/wBLMTFtypWQtHY+Tu5M6+lKG9YCjarmfxYEsZX2y6 wqDz2iTyxgSFqND2sID55ZmfeXo82qAP5rRjk53zI5mfV5SpnvZI7czvGUQvQi5w9fre 5391ND3NP7dxk6+LhKZYtf5NW8cuGBneugXeQxm3EX3AZ59PColf7LXw/zyUkwuD5oxC HdCt4DdBVOueExDXVE8rPvpfMZMdH7BpnbBuzxpYVHZzykFtdiO6gGNDYo0VjTDLZsQi 9gcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=lRYYXREQnqSeaqPOY5OUyl6/qjVZptAOkwbxS4AIXhA=; fh=8Yl36FbB8ETGiyj19g5H4YzGN7U4Ot99EwCNWmMUkSY=; b=aqdQOm9Oz1J0gfz6ws9GSpEDF0r3dv7ACxigM1zZV6FdUDz0bNZXsDnwvww5aXod2W xuA0Jy+6mYtbLI2EDX/CKH68A4PYOcm5BvxF6fQYUX8QhCMJXrtlys+d8M9gaObaNizO UtTo2LSxYluH4cOCuWng8sLvWTkLfwEu1Jdch9fGRxShawfZYlBcY+YamThPctAyylbx X2VSfUAy/gX4gTf+LxYM39vbXDF4Y6yFJCfSvcYHT67p0p1sMtJstG8hdOA7euCfud15 Zz0CqWMfOOROQez9T/G1+xf8R6qALudtcwFNmdbTJy27fiNBoJyLmQfJw4ALxSSbS0oM cyXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=j69AsyHj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id ca17-20020a056a02069100b00565f0e91894si861326pgb.394.2023.11.22.23.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 23:49:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=j69AsyHj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 17E51807595E; Wed, 22 Nov 2023 23:49:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231744AbjKWHtW (ORCPT + 99 others); Thu, 23 Nov 2023 02:49:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjKWHtU (ORCPT ); Thu, 23 Nov 2023 02:49:20 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45F44E7 for ; Wed, 22 Nov 2023 23:49:27 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1cf74ad87e0so4897845ad.3 for ; Wed, 22 Nov 2023 23:49:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700725767; x=1701330567; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=lRYYXREQnqSeaqPOY5OUyl6/qjVZptAOkwbxS4AIXhA=; b=j69AsyHj8ICXm9hqiVbRRBXpFGZJ/DQceX87H/XbPpejVjnTLk4LqOwJANhyqNREFB ZWPF7KncYRcQ10+ZRpn3G7/xU8xBzaLz11QjS0OtESWPE+KwMwuW+OKZ4Hmh1aoqoI8+ O3Twu6AJb6yxAhfyNMjnTbGtwTUFU5yUwK02imz5pu35vPSmTe5FZB6RWnFcS/9Uj/PP lv3nx5z7TvVB7splfJ2xKUSx6ZZlgsK3uhB3aNNO5t9UtLV+JKMWeObGdK7k3n1zfmbA IqH9xJNHGbxpNOPfppUj2gQ6qe9xb2jbS90EAB3J4BSfA8nO0kV7g1/W2T5nke63ZzW6 YTww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700725767; x=1701330567; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lRYYXREQnqSeaqPOY5OUyl6/qjVZptAOkwbxS4AIXhA=; b=ZHXiSplI/YMtfMDhyM2kMuuChs6XlfrxLtmQeT2DlxKnulhscCJR3ENqWW9ppVCEWA MqZpfdrfy+u0n7cMmqh5RTHxSVuz9/mIoNExRM+PM0VWIl1uGGvynss+nIfanZ21SxIO 0FqA+Uh+9dTMvoY4tuYRFZAzEPlFaPBXODqn6j9IWrCrtLSyg/krGi83WJN9tgCY4sbe 40edLXDTzhB/l6TExuKjqx8Hp+SNqVVx0Qo4uUnPyOMXLb5QDADjqmCZ0rNSTuYLFGmt /OoKBEWNqyVz1N3n/uxcYW0BeAEgCSUNIwVqyS/ieZ730kwYd0SxgMSDTz9WmFo/fqad ujvw== X-Gm-Message-State: AOJu0Ywa4+s8E1t2hFRhIVerRDf4eAJd+kGBkLyDBU+M/TBaHyUpvI7S Ojou26vjUETu82zQy68IfrE= X-Received: by 2002:a17:903:244e:b0:1cc:4e81:36a4 with SMTP id l14-20020a170903244e00b001cc4e8136a4mr5727627pls.5.1700725766519; Wed, 22 Nov 2023 23:49:26 -0800 (PST) Received: from libra05 ([143.248.188.128]) by smtp.gmail.com with ESMTPSA id e4-20020a170902d38400b001cc1dff5b86sm679598pld.244.2023.11.22.23.49.24 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Nov 2023 23:49:26 -0800 (PST) Date: Thu, 23 Nov 2023 16:49:22 +0900 From: Yewon Choi To: Greg Kroah-Hartman Cc: Bryan Tan , Vishnu Dasa , VMware PV-Drivers Reviewers , Arnd Bergmann , linux-kernel@vger.kernel.org, threeearcat@gmail.com Subject: Re: [PATCH] vmci_host: use smp_load_acquire/smp_store_release when accessing vmci_host_dev->ct_type Message-ID: <20231123074920.GA10480@libra05> References: <20231122122005.GA4661@libra05> <2023112257-polymer-banknote-4869@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2023112257-polymer-banknote-4869@gregkh> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 22 Nov 2023 23:49:42 -0800 (PST) On Wed, Nov 22, 2023 at 02:34:55PM +0000, Greg Kroah-Hartman wrote: > On Wed, Nov 22, 2023 at 09:20:08PM +0900, Yewon Choi wrote: > > In vmci_host.c, missing memory barrier between vmci_host_dev->ct_type > > and vmci_host_dev->context may cause uninitialized data access. > > > > One of possible execution flows is as follows: > > > > CPU 1 (vmci_host_do_init_context) > > ===== > > vmci_host_dev->context = vmci_ctx_create(...) // 1 > > vmci_host_dev->ct_type = VMCIOBJ_CONTEXT; // 2 > > > > CPU 2 (vmci_host_poll) > > ===== > > if (vmci_host_dev->ct_type == VMCIOBJ_CONTEXT) { // 3 > > context = vmci_host_dev->context; // 4 > > poll_wait(..., &context->host_context.wait_queue, ...); > > > > While ct_type serves as a flag indicating that context is initialized, > > there is no memory barrier which prevents reordering between > > 1,2 and 3, 4. So it is possible that 4 reads uninitialized > > vmci_host_dev->context. > > In this case, the null dereference occurs in poll_wait(). > > > > In order to prevent this kind of reordering, we change plain accesses > > to ct_type into smp_load_acquire() and smp_store_release(). > > > > Signed-off-by: Yewon Choi > > --- > > drivers/misc/vmw_vmci/vmci_host.c | 40 ++++++++++++++++++------------- > > 1 file changed, 23 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/misc/vmw_vmci/vmci_host.c b/drivers/misc/vmw_vmci/vmci_host.c > > index abe79f6fd2a7..e83b6e0fe55b 100644 > > --- a/drivers/misc/vmw_vmci/vmci_host.c > > +++ b/drivers/misc/vmw_vmci/vmci_host.c > > @@ -139,7 +139,7 @@ static int vmci_host_close(struct inode *inode, struct file *filp) > > { > > struct vmci_host_dev *vmci_host_dev = filp->private_data; > > > > - if (vmci_host_dev->ct_type == VMCIOBJ_CONTEXT) { > > + if (smp_load_acquire(&vmci_host_dev->ct_type) == VMCIOBJ_CONTEXT) { > > This is getting tricky, why not use a normal lock to ensure that all is > safe? close isn't on a "fast path", so this shouldn't be a speed issue, > right? > I think using locks can be considered orthogonal to correcting memory ordering. As you pointed out, vmci_host_close is not a performance-critical function while other functions using vmci_host_dev->context are performance-critical. If the lock is needed, we will need to add locks in all of them. I cannot be sure which is better. Besides that, it seems to be a separate issue. On the other hand, the current implementation doesn't guarantee memory ordering which leads to wrong behavior. This patch fixes this issue by adding primitives. Thank you for your reply. Regards, Yewon Choi > thanks, > > greg k-h