From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3E81641D8D for ; Mon, 27 Feb 2023 08:10:30 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 39635410D3; Mon, 27 Feb 2023 08:10:30 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2068.outbound.protection.outlook.com [40.107.93.68]) by mails.dpdk.org (Postfix) with ESMTP id E95DC40A7D for ; Mon, 27 Feb 2023 08:10:28 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PFZsXEdry8DIYVFEfwjf7C9drB31disnNfpIDZ8RgN6DvhuP1JqUreFeLQCVbinzx3sty9aGnxz9bbBI2YqoED3o+PRFlzTauSD3lUscYHPZDXIU0lV73A5ZkMbeBQ9N8b7k94MhpL902ehj3/4TxWTDIfUAiAiqjMMrgDamrtGqUj4AF++f/GB71Zhj/WiQaRp3lnTHJQivnwtnBm+MtUEoiyc5SY/X3uFXCH+Oi0qcq2VNP/HvJu5gbvnZJ4whFWuwqD9px2ssicL2AqlWIl73yIWMda2znWaF2HhhXqh205oLxtWChhr3yK4KIkoDhnFdm0+ezJhh8OUE3HXGXg== 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=d3cufpkpZ80TcPTv+UdZ+2AsVl/4Kkz8D7fURQibRXA=; b=B79ofYqR7keI2kgGPz6j4j3apbGXU5kVkQDtrgEd1OldROeOes9LbVSj1RlyuvHYp07rtotbgX6Fsj7fK5byQpA/ARaPb8eJVz9/Y6/k9rYasADEta/PcF/gJxi/pgvoAQ+k5bZu8c9I/5b4SUqFFb0/xe9Wgu79sesnTNjs9dRrCk1GMozBnZEBKeLf4JylELG2ZDpiPuA6X66jseCpxO0ncJMJBbIWtEHLXh4IpAtt0dk/EJTlvXTMKZ70KcuaJGKHKnQTkf//VjNw+rjRcGTGiS6N395KYdpVf3pu40taW/2triWY9mP8brKqvWBjg2Hjy6dA2CuY90Uunh7OAA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d3cufpkpZ80TcPTv+UdZ+2AsVl/4Kkz8D7fURQibRXA=; b=dKzNKZ4Nw4DYAdGRsLMgGjDltBKa9/QJIvvTyk6aaMO4o93Z8DAJIewpyaSc3A4WHQW1StERvWM2wEAUGpFHa65/pAJU0LUx8YvCqup7YL9esI2wpmu7pD4liHB1w9Wgvt/PY8bk3FEvJ+XGmrrAMd2l77w4DfYYc9O4TQLLiyH5aH/0Ccw4Q7fbvPaMMSXw2oJf5xlBnUNnsKrdy6T9W+xJRRj8lHi22aCD31YCP5DlwsdbPxQU4Rnx+8djNo8zCnKeSDaIIKqVxL2jA9RUDRO82xMunqBkU8Wk4lu7EG+P4YSsCcrx9nm4jfb5iLDOHLYgu6/w+XQ15bqyoxHEwQ== Received: from BN9P222CA0007.NAMP222.PROD.OUTLOOK.COM (2603:10b6:408:10c::12) by MW4PR12MB6803.namprd12.prod.outlook.com (2603:10b6:303:20e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.27; Mon, 27 Feb 2023 07:10:26 +0000 Received: from BL02EPF00010208.namprd05.prod.outlook.com (2603:10b6:408:10c:cafe::a2) by BN9P222CA0007.outlook.office365.com (2603:10b6:408:10c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.29 via Frontend Transport; Mon, 27 Feb 2023 07:10:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL02EPF00010208.mail.protection.outlook.com (10.167.241.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.12 via Frontend Transport; Mon, 27 Feb 2023 07:10:25 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Sun, 26 Feb 2023 23:10:08 -0800 Received: from nvidia.com (10.126.230.37) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 26 Feb 2023 23:10:05 -0800 From: Xueming Li To: Maxime Coquelin CC: David Marchand , Chenbo Xia , dpdk stable Subject: patch 'vhost: fix possible FD leaks' has been queued to stable release 22.11.2 Date: Mon, 27 Feb 2023 14:59:53 +0800 Message-ID: <20230227070107.15664-85-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230227070107.15664-1-xuemingl@nvidia.com> References: <20230227062349.13764-1-xuemingl@nvidia.com> <20230227070107.15664-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF00010208:EE_|MW4PR12MB6803:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e22f660-d0a0-4e90-80d1-08db1891b359 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X8XQnDZTiIWY09lbPTf4dgQWukb3QCIa1kTcuWWs7k6u8+oHitbz+gnI8BC2nimX8QR9gVqDnGg3A5i8MTti/MNu7COFhfUaZbcFGpuSdfQf1xV4x1OqkIWi/H3nkdGXphZVgCdB1/5CcFsHvBQ74DW6fd9HA2KDBK7E1PhkyvbISnR8ZcloZIOdeYbopvGCBtnWbrOm1Td6zoXgrhukKizeyBFwXSRQdrVlyPBXO3vDnHgfU6QW+SdBXlyJ8D4IbXf9ziRSzFn10zjcVbnJXV0fFgFvm4opFYD0hhfXy1w7DFHuFEguoZlH9Z67UvM/98+7DXsffYa4EtaazK+alwFYK+oJhqC88uE1nB14sr8HaWM7uDaeo9odviMRwuthY5skymki7Jn/8QNxDINx/bPcabAvYMxNdWOi1/wKH7cRyWTPjI6fcGTyfDL0Ohgj52gKinCCxi2gD/LS42iG5mA3YqhjZt6DzqFtig4/kVfLEMPc/bhKMh6cFd9KXk1f4KP6iue3Q1KGqTveik55BWYk0uxbGn6JOElgFfa3PXVJNj4Usc/U5wjzcsCDhUxPCkrkQA/GLCGaXWa4NfP8mRhspP2Tjunpq6GMvzUsNYQ7SP5DgnNDo/kQS4FfVeh4ZaVniPC5kg+W3mqFXUB6xtOsrSkIzVjieYl9VDvS5JTlyz5bw8X1C+AlJEdd/SiNQJPehm/ZJY6K0/Dv2yt0MPTxqjoj1iZGLFHdtQWUrHfyhRPhz8jL5ckkGIk8j+sNkXv+0yzERo94EZy9GSf1bYoVpblndDdaPGb6DP4UHnI= X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230025)(4636009)(136003)(396003)(39860400002)(376002)(346002)(451199018)(40470700004)(46966006)(36840700001)(6286002)(186003)(16526019)(40460700003)(82740400003)(7636003)(83380400001)(316002)(356005)(8936002)(6916009)(8676002)(4326008)(41300700001)(70206006)(336012)(2906002)(5660300002)(70586007)(36860700001)(6666004)(7696005)(55016003)(40480700001)(478600001)(1076003)(426003)(26005)(53546011)(47076005)(966005)(2616005)(36756003)(82310400005)(86362001)(54906003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2023 07:10:25.9338 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7e22f660-d0a0-4e90-80d1-08db1891b359 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF00010208.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6803 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi, FYI, your patch has been queued to stable release 22.11.2 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 03/01/23. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging This queued commit can be viewed at: https://git.dpdk.org/dpdk-stable/commit/?h=22.11-staging&id=eab1940f972ccb8b4abc045254693e268b5a0fcf Thanks. Xueming Li --- >From eab1940f972ccb8b4abc045254693e268b5a0fcf Mon Sep 17 00:00:00 2001 From: Maxime Coquelin Date: Tue, 7 Feb 2023 17:22:39 +0100 Subject: [PATCH] vhost: fix possible FD leaks Cc: Xueming Li [ upstream commit 585283f9a703fcd994dbf9aca07dea9445319862 ] On failure, read_vhost_message() only closed the message FDs if the header size was unexpected, but there are other cases where it is required. For example in the case the payload size read from the header is greater than the expected maximum payload size. This patch fixes this by closing all messages FDs in all error cases. It also improve error logging by displaying the request name when failure happens if possible. Fixes: bf472259dde6 ("vhost: fix possible denial of service by leaking FDs") Signed-off-by: Maxime Coquelin Signed-off-by: David Marchand Reviewed-by: Chenbo Xia --- lib/vhost/vhost_user.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 76058c3ee5..8df66e68b3 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -2817,29 +2817,36 @@ read_vhost_message(struct virtio_net *dev, int sockfd, struct vhu_msg_context * ret = read_fd_message(dev->ifname, sockfd, (char *)&ctx->msg, VHOST_USER_HDR_SIZE, ctx->fds, VHOST_MEMORY_MAX_NREGIONS, &ctx->fd_num); - if (ret <= 0) { - return ret; - } else if (ret != VHOST_USER_HDR_SIZE) { + if (ret <= 0) + goto out; + + if (ret != VHOST_USER_HDR_SIZE) { VHOST_LOG_CONFIG(dev->ifname, ERR, "Unexpected header size read\n"); - close_msg_fds(ctx); - return -1; + ret = -1; + goto out; } if (ctx->msg.size) { if (ctx->msg.size > sizeof(ctx->msg.payload)) { VHOST_LOG_CONFIG(dev->ifname, ERR, "invalid msg size: %d\n", ctx->msg.size); - return -1; + ret = -1; + goto out; } ret = read(sockfd, &ctx->msg.payload, ctx->msg.size); if (ret <= 0) - return ret; + goto out; if (ret != (int)ctx->msg.size) { VHOST_LOG_CONFIG(dev->ifname, ERR, "read control message failed\n"); - return -1; + ret = -1; + goto out; } } +out: + if (ret <= 0) + close_msg_fds(ctx); + return ret; } @@ -2987,13 +2994,10 @@ vhost_user_msg_handler(int vid, int fd) } } + ctx.msg.request.master = VHOST_USER_NONE; ret = read_vhost_message(dev, fd, &ctx); - if (ret <= 0) { - if (ret < 0) - VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost read message failed\n"); - else - VHOST_LOG_CONFIG(dev->ifname, INFO, "vhost peer closed\n"); - + if (ret == 0) { + VHOST_LOG_CONFIG(dev->ifname, INFO, "vhost peer closed\n"); return -1; } @@ -3003,6 +3007,14 @@ vhost_user_msg_handler(int vid, int fd) else msg_handler = NULL; + if (ret < 0) { + VHOST_LOG_CONFIG(dev->ifname, ERR, "vhost read message %s%s%sfailed\n", + msg_handler != NULL ? "for " : "", + msg_handler != NULL ? msg_handler->description : "", + msg_handler != NULL ? " " : ""); + return -1; + } + if (msg_handler != NULL && msg_handler->description != NULL) { if (request != VHOST_USER_IOTLB_MSG) VHOST_LOG_CONFIG(dev->ifname, INFO, -- 2.25.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2023-02-27 14:08:43.654922800 +0800 +++ 0086-vhost-fix-possible-FD-leaks.patch 2023-02-27 14:08:40.809237000 +0800 @@ -1 +1 @@ -From 585283f9a703fcd994dbf9aca07dea9445319862 Mon Sep 17 00:00:00 2001 +From eab1940f972ccb8b4abc045254693e268b5a0fcf Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit 585283f9a703fcd994dbf9aca07dea9445319862 ] @@ -17 +19,0 @@ -Cc: stable@dpdk.org @@ -27 +29 @@ -index b4236820a2..d702d082dd 100644 +index 76058c3ee5..8df66e68b3 100644 @@ -30 +32 @@ -@@ -2831,29 +2831,36 @@ read_vhost_message(struct virtio_net *dev, int sockfd, struct vhu_msg_context * +@@ -2817,29 +2817,36 @@ read_vhost_message(struct virtio_net *dev, int sockfd, struct vhu_msg_context * @@ -75 +77 @@ -@@ -3031,13 +3038,10 @@ vhost_user_msg_handler(int vid, int fd) +@@ -2987,13 +2994,10 @@ vhost_user_msg_handler(int vid, int fd) @@ -92 +94 @@ -@@ -3047,6 +3051,14 @@ vhost_user_msg_handler(int vid, int fd) +@@ -3003,6 +3007,14 @@ vhost_user_msg_handler(int vid, int fd)