Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1742648rdb; Mon, 9 Oct 2023 01:00:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGc6I6UlUYq0aFd6rUpULwig2ZmN3vcX7ew6qjb9Cd2zuksTHpFheyzeYFMkkOrvtHz6dNa X-Received: by 2002:a05:6a00:1a43:b0:68a:582b:6b62 with SMTP id h3-20020a056a001a4300b0068a582b6b62mr16248841pfv.7.1696838404739; Mon, 09 Oct 2023 01:00:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696838404; cv=none; d=google.com; s=arc-20160816; b=VOsudI7dOaPWm9e1s5qAmXgQun6U4NYXL+G2EdIYMZW9pF9Q5gNTEuzIX8Ztd5stRq /kE8UO8mitmAoC7sUobeEqYXFgRlP9qfudA6dGiMAzCV5KnxumDc5WWdVK6yXabcib6w 8k6wZA6Ir21F7Gzs3JgRYomhHiiMKA2aCJG+Znjd0gvew/fWOipp0W56wCqkNm4hnvc8 UkedhAlAB4oEzC6HlRwJjPd3KweU8o6JsTrYpBto9ON1qO07MjIx0P5SkQ1UzQXICN4x XYhIk5JLN+P0lyN1pAMNN7OXzaMdmEa8HgXfZVUOwJR482ez+ppZRQTA7aNRtDhjScP2 wing== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=ciYxCapYU4oDZf85UphUOQ42M2gQNBx7cupu6nGUlqQ=; fh=g3UYIe03XDD9FdZt4aAumcnJ60MccAQRicUPsEzn/2Y=; b=vNMqdPbU7P80EduP3msYYQ+0fR0qc59KEMbjhriWWR7Qtj2aZh0evQQgO/0D166DTE 4eAsCOAG2XWg9jQ7WZ1zDBMXMiKi516PLZQTv9Jj9vkURmaiVxGcq/vRZG/Wr+zOz9Bw yk/0Yg+LOGKjjlQlEcUDXExlPIetN1k+fuA3EaU04WYYkgdWN7qe3J+o54XXZzEfy5LZ UXfgW9Z6ArfkOjDOZVN9Gp6SzwOuskxYh19tzAA8PDSF7lnpPijIekjQgxD5QeKu3RZy vay+60XZ374+X3EAmgCEYKcF6be8OePKquRxyOmVAsTexCKUDPvgeKnPpxUgXcBweeit C++w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=XjO8kt82; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id t64-20020a638143000000b00565eccbc52fsi9339913pgd.303.2023.10.09.01.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:00:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=XjO8kt82; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 4997C80218A8; Mon, 9 Oct 2023 01:00:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345455AbjJIH7y (ORCPT + 99 others); Mon, 9 Oct 2023 03:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345450AbjJIH7x (ORCPT ); Mon, 9 Oct 2023 03:59:53 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 90C4A94 for ; Mon, 9 Oct 2023 00:59:52 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 01D0820B74C0; Mon, 9 Oct 2023 00:59:51 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 01D0820B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1696838391; bh=ciYxCapYU4oDZf85UphUOQ42M2gQNBx7cupu6nGUlqQ=; h=From:To:Cc:Subject:Date:From; b=XjO8kt82vd/+moVA/ZunIs9QBrX85JGVRZXLWt765Mpy0H9dw2mrmOvcdk6cqB59/ 8yCsSf8JJyIPfJbtS6PvomW6dtwBZIOmSzx0qMyD9ue+/BsbE6gHhwbKeel/YMgUZp 9T2eeoL9uth5tztUduHnYlvwJybyVgFEmbJxA8YA= From: Sonia Sharma To: linux-kernel@vger.kernel.org Cc: sosha@microsoft.com Subject: [PATCH net-next v7] hv_netvsc: fix netvsc_send_completion to avoid multiple message length checks Date: Mon, 9 Oct 2023 00:59:46 -0700 Message-Id: <1696838386-8779-1-git-send-email-sosha@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 01:00:02 -0700 (PDT) From: Sonia Sharma The switch statement in netvsc_send_completion() is incorrectly validating the length of incoming network packets by falling through to the next case. Avoid the fallthrough. Instead break after a case match and then process the complete() call. The current code has not caused any known failures. But nonetheless, the code should be corrected as a different ordering of the switch cases might cause a length check to fail when it should not. Signed-off-by: Sonia Sharma --- Changes in v3: * added return statement in default case as pointed by Michael Kelley. Changes in v4: * added fixes tag * modified commit message to explain the issue fixed by patch. Changes in v5: * Dropped fixes tag as suggested by Simon Horman. * fixed indentation Changes in v7: * Dropped the prefix "net" from subject line. --- drivers/net/hyperv/netvsc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c index 82e9796c8f5e..0f7e4d377776 100644 --- a/drivers/net/hyperv/netvsc.c +++ b/drivers/net/hyperv/netvsc.c @@ -851,7 +851,7 @@ static void netvsc_send_completion(struct net_device *ndev, msglen); return; } - fallthrough; + break; case NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE: if (msglen < sizeof(struct nvsp_message_header) + @@ -860,7 +860,7 @@ static void netvsc_send_completion(struct net_device *ndev, msglen); return; } - fallthrough; + break; case NVSP_MSG1_TYPE_SEND_SEND_BUF_COMPLETE: if (msglen < sizeof(struct nvsp_message_header) + @@ -869,7 +869,7 @@ static void netvsc_send_completion(struct net_device *ndev, msglen); return; } - fallthrough; + break; case NVSP_MSG5_TYPE_SUBCHANNEL: if (msglen < sizeof(struct nvsp_message_header) + @@ -878,10 +878,6 @@ static void netvsc_send_completion(struct net_device *ndev, msglen); return; } - /* Copy the response back */ - memcpy(&net_device->channel_init_pkt, nvsp_packet, - sizeof(struct nvsp_message)); - complete(&net_device->channel_init_wait); break; case NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE: @@ -904,13 +900,19 @@ static void netvsc_send_completion(struct net_device *ndev, netvsc_send_tx_complete(ndev, net_device, incoming_channel, desc, budget); - break; + return; default: netdev_err(ndev, "Unknown send completion type %d received!!\n", nvsp_packet->hdr.msg_type); + return; } + + /* Copy the response back */ + memcpy(&net_device->channel_init_pkt, nvsp_packet, + sizeof(struct nvsp_message)); + complete(&net_device->channel_init_wait); } static u32 netvsc_get_next_send_section(struct netvsc_device *net_device) -- 2.25.1