Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1317918iob; Fri, 29 Apr 2022 02:45:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyD8N518PxJiowRcm5xGNtpYievUBxMGX4Ft4d7p0SatubAZaqlKYfj1zmXTCGzD3M0z5h X-Received: by 2002:a05:6512:158c:b0:472:2860:2dc6 with SMTP id bp12-20020a056512158c00b0047228602dc6mr9475223lfb.183.1651225545729; Fri, 29 Apr 2022 02:45:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651225545; cv=none; d=google.com; s=arc-20160816; b=M8ltblmqEd6dQ1PSMECPMNeyhDUTTm30gN57nJAxkh9PppOvMOn00e1VFZdebmCJoC RHFnfSz5W90v6b8SI1wq9TKC2/oGI5ItjEfbwRyFSqWPaxcvhrIt1JkI/GGR7MXKV0Oc O/LnD+BzSzu+uI7D7MYxPH6HZrQ1Wdkcw0TpgZmDFB3c5jLx7E35Rm7A5oYD6U4iso9O 6H1D4vxu2udqIY2f9KgyWF/PgJxAy+ehllxvynYlt/VxC7tp+onmyIUKmgZ2A+scSFr/ lLsaJMy6NYEb9tqhhnpbNmmKS/hJazdeGYbFlonZrt/XlwMfyJI+w4hkmUZbNW29XrYz oa/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RIN8gOawCXDxnuKuymLvtjAI0BjsxNFPgbemmO0+RTI=; b=T2PGhQ09uc8S0et66jF6Spf/e1jSvsmXUn+C2VFZTsiw7pUEnOo1CWcHrgUmj5BZCC 3jR88x8WT4ZIN3Ykz5jrDVSULAtt4wgf+weF+//SQRHmNn8JzFD8xq+P4V535KGslpvQ Az1DhuFsUX8GYZCJNc7+j2qr3xybX1IQjhPjJhPhNrgFwJ49avySxg2am+oLWJPB1llk Ah4YxPF0Od8o4DINRNKvbHQ8Mp2yILpEVqEGapfWv3WYU7bN7roc9bvo91uOMABVyCA7 JzhILsMSa7+dXX12bKF5UNf86ixu+N2FrSReJEf0mWW40rrOYjVKlpdPo8DFDHNyNZKH uaOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=k9qd4rs+; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l12-20020a2e700c000000b0024dd563281csi6226953ljc.89.2022.04.29.02.45.19; Fri, 29 Apr 2022 02:45:45 -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=@gmail.com header.s=20210112 header.b=k9qd4rs+; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348609AbiD1OzB (ORCPT + 99 others); Thu, 28 Apr 2022 10:55:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231589AbiD1Oys (ORCPT ); Thu, 28 Apr 2022 10:54:48 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C7485C746; Thu, 28 Apr 2022 07:51:33 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id i27so10056501ejd.9; Thu, 28 Apr 2022 07:51:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RIN8gOawCXDxnuKuymLvtjAI0BjsxNFPgbemmO0+RTI=; b=k9qd4rs+kos4p9fuFrcrhEaTVurYbQu5JAB5TlvpM1zhEvKT+R76kG9wVl/juFq0Wp vPSw7lsWKQ82Gv71hZte+YG+/2NSk9LIqPmLLSUlVrcfWH/8tFSC5k4s/yFeIDCVknbC vnvZFmxHdNKCL9GoyPA3RLovjT5SQAXbXbJpfOgcPRkQZR1KYa0aWlV/2inf89s2PDuX 7ZQDQxZuKSQ/KktfUMAfrrLbpai6I1p9t02jwzIElprS1pYAPW2thVQPdZWuUYtoNq4X R+c967GpLQXEEXrNZzuxgoeVwIW4cCm+cpYZWcAfD1bmfoNcesP8CJH2zATQlL86n6Rz 8mbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RIN8gOawCXDxnuKuymLvtjAI0BjsxNFPgbemmO0+RTI=; b=7ngw+/wo1dMatLPSN+GNlPVepD6PVGEXNoa8XhNQO2G1yFZbVbJQgMTiZURWpEgAu1 fW5PIXuFOA/2kpW2hg5mf2EgDlew+uD0OdhICAIXP710KolySjO9Y38W+4nQf5qFix2S yE+3xZUhf1JWllqYzH5ReyRzY3p2DtSysqiH+DkxcbZub64xuhlWGtPQT37eVs7+Zakm beveIKVNdCnVSumGQVXZDlXzegVae6vOm27J5/WVjBBItqKXbV7NtHuSX3vXQ+FIHSey 8goimv8Ob3n4CWiW6FCCu7o21tge6fhH4RsgSvXo8gzydlSOpY2V9Nlv9eAYyyF0MghN enbg== X-Gm-Message-State: AOAM532DHpbbo/zu+sV6XbWw5LC/sDxd8SiUQFfRFIfgiFweCl7iaFA0 ehZWPZWPDSccHIlJ9wjYHSE= X-Received: by 2002:a17:907:3e1e:b0:6ef:ebf8:4059 with SMTP id hp30-20020a1709073e1e00b006efebf84059mr32126466ejc.657.1651157492013; Thu, 28 Apr 2022 07:51:32 -0700 (PDT) Received: from anparri.mshome.net (host-79-49-65-106.retail.telecomitalia.it. [79.49.65.106]) by smtp.gmail.com with ESMTPSA id x18-20020a170906b09200b006e8baac3a09sm61616ejy.157.2022.04.28.07.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 07:51:31 -0700 (PDT) From: "Andrea Parri (Microsoft)" To: KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Michael Kelley , Stefano Garzarella , David Miller , Jakub Kicinski , Paolo Abeni Cc: linux-hyperv@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Andrea Parri (Microsoft)" Subject: [PATCH hyperv-next v2 3/5] hv_sock: Add validation for untrusted Hyper-V values Date: Thu, 28 Apr 2022 16:51:05 +0200 Message-Id: <20220428145107.7878-4-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220428145107.7878-1-parri.andrea@gmail.com> References: <20220428145107.7878-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 For additional robustness in the face of Hyper-V errors or malicious behavior, validate all values that originate from packets that Hyper-V has sent to the guest in the host-to-guest ring buffer. Ensure that invalid values cannot cause data being copied out of the bounds of the source buffer in hvs_stream_dequeue(). Signed-off-by: Andrea Parri (Microsoft) Reviewed-by: Michael Kelley Reviewed-by: Stefano Garzarella --- include/linux/hyperv.h | 5 +++++ net/vmw_vsock/hyperv_transport.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 460a716f47486..a01c9fd0a3348 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1696,6 +1696,11 @@ static inline u32 hv_pkt_datalen(const struct vmpacket_descriptor *desc) return (desc->len8 << 3) - (desc->offset8 << 3); } +/* Get packet length associated with descriptor */ +static inline u32 hv_pkt_len(const struct vmpacket_descriptor *desc) +{ + return desc->len8 << 3; +} struct vmpacket_descriptor * hv_pkt_iter_first_raw(struct vmbus_channel *channel); diff --git a/net/vmw_vsock/hyperv_transport.c b/net/vmw_vsock/hyperv_transport.c index 8c37d07017fc4..fd98229e3db30 100644 --- a/net/vmw_vsock/hyperv_transport.c +++ b/net/vmw_vsock/hyperv_transport.c @@ -577,12 +577,18 @@ static bool hvs_dgram_allow(u32 cid, u32 port) static int hvs_update_recv_data(struct hvsock *hvs) { struct hvs_recv_buf *recv_buf; - u32 payload_len; + u32 pkt_len, payload_len; + + pkt_len = hv_pkt_len(hvs->recv_desc); + + if (pkt_len < HVS_HEADER_LEN) + return -EIO; recv_buf = (struct hvs_recv_buf *)(hvs->recv_desc + 1); payload_len = recv_buf->hdr.data_size; - if (payload_len > HVS_MTU_SIZE) + if (payload_len > pkt_len - HVS_HEADER_LEN || + payload_len > HVS_MTU_SIZE) return -EIO; if (payload_len == 0) -- 2.25.1