Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp1136240rdf; Wed, 22 Nov 2023 06:35:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEvjSjl4KIDgMLqf65oi0VVg4ZORI4KeUgppatmciYaLPETeUlj+BAvjGQHvdFCcsLZNzcP X-Received: by 2002:a05:6a20:d48d:b0:187:a4df:4e57 with SMTP id im13-20020a056a20d48d00b00187a4df4e57mr2655797pzb.20.1700663746273; Wed, 22 Nov 2023 06:35:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700663746; cv=none; d=google.com; s=arc-20160816; b=CUCvWxhhWZWpyAAa5hwnZaWI8oGeQlg6BsveMojEIyZaKFOoRKk00+kS/WmbebHK/6 OH8DcVO6LeoALJOYcALcPtqI/nkPrO4faMqSfbhpUBi23GG4smWC2PpLnVvgT36KLlwQ pjTpkp10uVhpQ3ggAkhAAw45lpHznWtOlyPr1hSdiSQCmi3kDGwQ0ebaJGaY4eQlnNom MiP9fUhxFsxsZQAlmbf9h1HQYCTKkj4KTDleqjcQ9o8Hun3I4DBT5sFkeJIdRRj5EJ4v ZT4ofAeb6+CCSJjSaac7byeyKv0FEelFQLTq4QTzOiGEQOFmJaPikkD6cv5J4KHpD0Ed R+Lw== 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=/qAUay4ymRETrhjBOfJAyaJJFwV2ox1PgnG/cMAHyKw=; fh=a+V2/MhRBAVNrfWuKbg2u5A3a9Ucl8Skda0qKJds0KM=; b=RASaz7a0RypxgzNC5AT90a9FBLMR7k7UEcYMJ2PMmj3VBnVReZ6/2pdFTKfZTdH0eM lnkAfxKesTyIEaax+fUDTlPxjOZkdElx5a6628DcMv9c5iByymeQEQ99LBUu4E3L7F/F wbieDIThAf+hfe1zcy9a7pWKib523a8hzOOKNM2DvNTPU20wt9NL1n20ZGjVfxIS8Jwd 7Mj9GFYanpb5xGevoPiBy9ETwTQNhPEehLG/SgXp+MGcBQkmYibc3qIk78WEnptlQozr q6BV4Z0REW65ZIW32BLdUV3ky2Dt3CGI6DXcXztkWAG1tJqLc+IMVZgaqnIMusLudTRr grEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q+pnI5g2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 15-20020a63104f000000b005c1e78daf17si12906378pgq.485.2023.11.22.06.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 06:35:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q+pnI5g2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2B621807C755; Wed, 22 Nov 2023 06:35:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343864AbjKVOfG (ORCPT + 99 others); Wed, 22 Nov 2023 09:35:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231720AbjKVOfE (ORCPT ); Wed, 22 Nov 2023 09:35:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24BECD47 for ; Wed, 22 Nov 2023 06:35:01 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61D35C433C7; Wed, 22 Nov 2023 14:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1700663700; bh=Mqs5y4yUtAnpQhNl5oklydm8euubbQ9EWewbjA5KJdM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q+pnI5g2v4NCiN+ggQWfkNW5IApj8lCKgkLMmndCPepkimS6e3iLnfR1QEthtdtwg l23Oz6lCStNFbzNZkjzT0C9kEkvuLbbmD4v1X+1z56sBlHG1L6tj4coPef4+j0jXlF /jSDoBW1J4yDfR7Li9htL3/zxd5oHaQ8hq6ej6lw= Date: Wed, 22 Nov 2023 14:34:55 +0000 From: Greg Kroah-Hartman To: Yewon Choi 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: <2023112257-polymer-banknote-4869@gregkh> References: <20231122122005.GA4661@libra05> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231122122005.GA4661@libra05> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 22 Nov 2023 06:35:12 -0800 (PST) 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? thanks, greg k-h