From patchwork Fri Oct 28 20:56:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dexuan Cui X-Patchwork-Id: 12556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1040562wru; Fri, 28 Oct 2022 14:01:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59twFLf2vR9DcrwGhvXRIek4xlwSWKB2wt1AA0Q9DWLlm/ESk9UJCQutx5ihhgF7tGUQXL X-Received: by 2002:a05:6402:26c6:b0:45d:374b:fb73 with SMTP id x6-20020a05640226c600b0045d374bfb73mr1272679edd.424.1666990909931; Fri, 28 Oct 2022 14:01:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1666990909; cv=pass; d=google.com; s=arc-20160816; b=mhk42vRDsrolWNmMuPF+TGRjcy0tzl8O8Xo3mVhsIG6O/O+/N4x157GV2566cY1mDg AhRMcQAYkFGhFXoE56oaohRYJiu22FZ+/jdGYjkxfkKX/Y5yrXqPVzPsj3x3tb3udTc+ rLNZJies5CLdvn3LTGt6Cup5NoMnRvl8i6lFKOhwhxWVDjYArGY5LKyyjiCddJEc/vkz DXPWz3qDz+ygoOdAtvD3SfwD26vRuYvrNYLYhlV646xeqw48SgJHwru00CYzPJFxPSZa dEqpN/OTmH90DMT2aKBTBKqJN6JPyZzmrxlwo2YGQGwLU9yttgbkrDdaBC7YBaXy52OC TCOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=XIvsfBoUlx8X8o2tPgZOm7bAnD0kMXnofYnq8hjc5O8=; b=cBIaOwiERMg8q4tBEMQItEJKk+7Xijf2o3fZefkYb0T0JUhA9vV9mvsdwkttZ0Z0iH 21zTTKedZYKEHWqBEdOpd7ET1mV6QOosnkSeC4tPx5QLz7ASIreqyP1H4G5yuHa34btu x13fAhevNamUbdKF1rhDfsBp6IZFdUNpOlKfKGme6g2iYVECzPdSpceyzf01zQSxeZXG GwLdVfDGl+ERgBBxWXqUkaaB1aFWwdn0I5NsABR5nyQZ2d9Ux/L/KtWLjrdHaxxJEtfo LDUamlad4er43BDH05/jJgAajiiqjMqkQUMIx+ugmC4iDQzwANe1G6lRCFbWN2rZiM1q 9ePQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=K57ipt7v; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id tj5-20020a170907c24500b007acdb4016e0si4958569ejc.224.2022.10.28.14.01.14; Fri, 28 Oct 2022 14:01:49 -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=@microsoft.com header.s=selector2 header.b=K57ipt7v; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230127AbiJ1U6L (ORCPT + 99 others); Fri, 28 Oct 2022 16:58:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbiJ1U5n (ORCPT ); Fri, 28 Oct 2022 16:57:43 -0400 Received: from na01-obe.outbound.protection.outlook.com (mail-eastusazon11021025.outbound.protection.outlook.com [52.101.52.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E384522658C; Fri, 28 Oct 2022 13:57:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KnPJuftSLpFq39ySG1DYAxDLK/HBLVPY/OBI72c+UJ3SIIOuw0HcRvgnIWmLGN9av3+dmbWNCFo1ArLMBz3W9lVSxSsxsDgkps5501npMMP/evBB3buEPDsu9ebnjTi1CF14HO6qJf60tZkdLmK19PzZXuVfa6+q+oYANd3a0ZCmfcUA+KWHjvobz4rEeBD7znhg93ujqmYriyVFDgBV1l+ALZZXlxWOmneDxOhrvWSAfJekiQFZV/lHhmk+L/MKBZ+zLhkhKEK2xWEBM9BoDEt73ZaAsF/iuI2cAKRHuYWSgTlCHeIcGx/Xtznw9dtnoef/XiNqiXU2/6EFzX18Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XIvsfBoUlx8X8o2tPgZOm7bAnD0kMXnofYnq8hjc5O8=; b=AfSxUCK07EGvKUf76IztI5DvNUg+7NHxrrIuUFXUJJlS4MUmoVSlmnMdcXqcw/BIiAGb1IF8RNup/sF5J0h2eUng3yMi6VQPwuf9PW/9L3DHVUkvyGyr4OyhOP9h5U9WB5JUtE3e55Y65pCKDGhfIt8LCuyW8pdeod7Bt+sQi5ditI77ONLwITITKjRLTESmRxNfYUq5yjmiUEiqwHaKp6fhJxz9E3CtpuVP0En80xHmNwZo/co2r4qr7nUx44MwFknPx3yzWA8tEaZqi1QPt9gjuJcn1Ry0fq2gg7vFU4mDtiOr1ufZ7YjFfbgrYSxSdkOCQCuEPomNvrQndLo9yg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XIvsfBoUlx8X8o2tPgZOm7bAnD0kMXnofYnq8hjc5O8=; b=K57ipt7vTp5EXIUiuCp4NEBYk20MXVFHdNnXTpwazGuNeNL1zcMJeFL7aeMWNT0BIUYtr4v4MXtZJkyMsKaiS6eI9I125dd3c4JRsUmPCdYHs7wFfjVs0KaS4Uh7um8u6ppV51vhMlPSGqZpkHoWp/f+S5RDZllHLsAkF0PoKMg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) by PH0PR21MB1912.namprd21.prod.outlook.com (2603:10b6:510:d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.9; Fri, 28 Oct 2022 20:57:33 +0000 Received: from BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::a746:e3bf:9f88:152f]) by BL0PR2101MB1092.namprd21.prod.outlook.com ([fe80::a746:e3bf:9f88:152f%8]) with mapi id 15.20.5791.010; Fri, 28 Oct 2022 20:57:32 +0000 From: Dexuan Cui To: sgarzare@redhat.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, arseny.krasnov@kaspersky.com, netdev@vger.kernel.org Cc: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, kys@microsoft.com, haiyangz@microsoft.com, stephen@networkplumber.org, wei.liu@kernel.org, linux-hyperv@vger.kernel.org, Dexuan Cui Subject: [PATCH 2/2] vsock: fix possible infinite sleep in vsock_connectible_wait_data() Date: Fri, 28 Oct 2022 13:56:46 -0700 Message-Id: <20221028205646.28084-3-decui@microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221028205646.28084-1-decui@microsoft.com> References: <20221028205646.28084-1-decui@microsoft.com> Reply-To: decui@microsoft.com X-ClientProxiedBy: MW4P223CA0022.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::27) To BL0PR2101MB1092.namprd21.prod.outlook.com (2603:10b6:207:30::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL0PR2101MB1092:EE_|PH0PR21MB1912:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f44e39b-cbcf-4d0c-1443-08dab927089e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: j3kkpxTvHY/6v82qAvRaPkv5+G8SguZqPQ9fuPnFhe8mu7l+SIDzxdMd7W5Fie1PUF4K5irDFqiiXpXET5NsydHwxblgtIRQoS2Qk3um2UfcjLPXqThh1OTCjBK+ANiDQ0+qVUtZipHYepUMfmBgQdfxxo9c5jzZopTpX+ofMSmn/45p+EAf5617cVSQM/DPaSjUGGqa5QdXYK+z0CGCfXy9H74dr3FznqOW5gIhzSQWN14jVb9uaovViUOPCLXztzDhsKIMPVjGDQT1OwZLj9H9RO96+uJ4GEt6CtKOHebZBrdxBFMgQ3cUNMgiETui+ZbRSgXpTm0367Dy0JYoP8kcpWrznnDepGTAbsXmOIfSyBgsVLVv0yFwXj/1FyeHul1EAFQKYXijQCfOrDK++rxGyYf7WyQORzYPCdqPHxZKimGTjWHj/SEp13T67AZIAfmAdlhtbggC7Q7T6Mnkx1mVaunlOwvLsaKeo+RVN8AKu7BOadRmhbKruSZM/DBSka4lIKVpLo++BlBKgnOqluJnzyFs0tBODpRstKBh+bcAde7YumQ3sg8iXGzXPU16hESGV7uXE2f3v0CnUOLkbKVLd/kn0rMnu/vKlzCPj4EEjJ7tk0BcZXvw+tYnasocgBJ3/O4iz5Ca/V98QtxngLdRXv59Jm976ofx3nQeP4EZ6TDnEUz0RpVhqWkUFwx1bVB7tLJqMM5vRwThpl4sPvi9iXsSlLslw03/az+1xwCxqACARruxs7iQUJQfoMAI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL0PR2101MB1092.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(396003)(136003)(39860400002)(376002)(346002)(366004)(451199015)(6666004)(107886003)(52116002)(6506007)(82950400001)(8676002)(4326008)(7416002)(2906002)(3450700001)(66556008)(5660300002)(82960400001)(38100700002)(1076003)(41300700001)(86362001)(6512007)(66476007)(66946007)(316002)(36756003)(2616005)(186003)(83380400001)(6486002)(10290500003)(478600001)(8936002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QccOEw7B8D5KEOfi6PYCZoFhupOzIjLAx8lu0W/wLYQAGRY0kw2Wc7jOwBIAUI66JJmNHNE7gCUg2Jb4dnQgoOSw7c0nhh8HaJzfZCkE7p3/RSFIqVXyBnvAq7SDK0NNBSxUjNqXvCF4M1dq5bsLlitcSKLkJAH0qoOShZA2st7MPCSIsmFh81ApLOAKRH/BYV6PMpAodYpAPBDa2OpGNCr7rl4xX1PtSU5XH/bwMX5Sq7H2891Es8OsH/aO8JISno/Bo910zw3ZYinutbGguNAWA8A6mQ1JF/MmfXAl/+hMewifc6w35sTuF5YyfS7CV+UD6F1X9v0p+gOoKp1rQIYcYh3LWAYh5Wy5Osvr11dfc1h7xQ6G1m+nnaminM/1LfO3mgCJJbxQRM3vtSd+sPahU6H7W00/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1ytWhDxPbqZwa1hNyMkjN3YwbDtSUQnCdO9qBaKwWd7TLbLgKZkjuck5bFl2ToXI0ZdM/ntKMY6eo1PSNqdmzZAlp5MmfactRVQFCeAi/Xl6PlqcDz3ARWVpp/ndJtaN9V/mjO48X/RhVsGi0zC6ydT4CSw+rh78veofePeha+JIR3nQ+yp X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f44e39b-cbcf-4d0c-1443-08dab927089e X-MS-Exchange-CrossTenant-AuthSource: BL0PR2101MB1092.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2022 20:57:32.8298 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KXIh7+vDvT/H76kuCOuyg6ff0witgokUW8+10Xx14pntpux3bhrLwLbv4M8duJaXyGXeCeYEuxw/aeVKjCU4Qw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR21MB1912 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_NONE autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747966660378334866?= X-GMAIL-MSGID: =?utf-8?q?1747966660378334866?= Currently vsock_connectible_has_data() may miss a wakeup operation between vsock_connectible_has_data() == 0 and the prepare_to_wait(). Fix the race by adding the process to the wait qeuue before checking vsock_connectible_has_data(). Fixes: b3f7fd54881b ("af_vsock: separate wait data loop") Signed-off-by: Dexuan Cui --- net/vmw_vsock/af_vsock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index d258fd43092e..03a6b5bc6ba7 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1905,8 +1905,11 @@ static int vsock_connectible_wait_data(struct sock *sk, err = 0; transport = vsk->transport; - while ((data = vsock_connectible_has_data(vsk)) == 0) { + while (1) { prepare_to_wait(sk_sleep(sk), wait, TASK_INTERRUPTIBLE); + data = vsock_connectible_has_data(vsk); + if (data != 0) + break; if (sk->sk_err != 0 || (sk->sk_shutdown & RCV_SHUTDOWN) || @@ -1937,6 +1940,8 @@ static int vsock_connectible_wait_data(struct sock *sk, err = -EAGAIN; break; } + + finish_wait(sk_sleep(sk), wait); } finish_wait(sk_sleep(sk), wait);