Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2898298rdh; Wed, 27 Sep 2023 17:01:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6E3W5XBmDhxCNaNWiNrjLBeu+5BAKMjX/9zhhdK+iysMEdw1Cmh/UCzL+QLf8tjXWo/J3 X-Received: by 2002:a05:6102:404:b0:452:d9d4:a056 with SMTP id d4-20020a056102040400b00452d9d4a056mr3500833vsq.26.1695859291939; Wed, 27 Sep 2023 17:01:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695859291; cv=none; d=google.com; s=arc-20160816; b=PnF4eOZb8OYACENlNUHvnG5Owa0SlClMUz3bXKcITPPYG3/ruVdvKgkttaADZqIjTD iNI/iUOzLgmDD+4z0/qFcApASPB8vLN4F/oeONBKr4YF6t5eiS31LhcopifknB0sR31g gXRckFTq9rQZzHu82+ffyKOXFnipI4I7qcL/O+dk8x17oOvffzAwEl2P8AMvRCi0PQTh Oexw1ax7VIDg61x9rAuXsdJt9IAOp+Rcmv2x0eAVDsPp2kYoXXZ6nNX3IpvqnwQsNXb6 AcPBYZymyXCnsvH8lUA9WS/9rJo9c4pXFmIMcx6Y1FrryF1OmWqznRJ563xUuOvdveen 7G9w== 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=zYLgfwVrqDBS5frwkU8WzeM8Y0joHuphXzHL6ORt8IQ=; fh=KEIRyY1ncna42F+oJiEJvuFTsA7qQFAh/VoL/oeushU=; b=cFc/6HiPWppUOYT43lOOutDonyvqb+jG/9ZtUI/YGxPi75yyBlkGiDcrdynZV8u/HL zYfAsGTM0Mu19qMM42iQy3NQ3+m43zpwO7ANrD1m6LZMGTBtPWs0F5GvOuZd5MNIbz9i b36dnQc0+AFm8Ai5416Qjg+r7H49jxCRFQwqyYQHr3VtmqyEIhrDiZvGnaCjpIQ/KKrj agth6urwywI1DhbmRjgsQxSuOS9OzzTuMvbIzmkbecqa4jfKW/Q0enOf9DHMlGbRdicN iNiAMGF1/CP8gs9R9BhRtOlVur/voCimoeAlm0RYmsBbegHxQhf3pvEco01U5wvHSct5 7EjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=r9RGtuVk; 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 x5-20020a654145000000b0057b55b52870si17192074pgp.170.2023.09.27.17.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 17:01:31 -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=r9RGtuVk; 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 9B00A801CBEE; Wed, 27 Sep 2023 14:19:30 -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 S229878AbjI0VTY (ORCPT + 99 others); Wed, 27 Sep 2023 17:19:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbjI0VTX (ORCPT ); Wed, 27 Sep 2023 17:19:23 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D119012A; Wed, 27 Sep 2023 14:19:20 -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 53CE120B74C0; Wed, 27 Sep 2023 14:19:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 53CE120B74C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1695849560; bh=zYLgfwVrqDBS5frwkU8WzeM8Y0joHuphXzHL6ORt8IQ=; h=From:To:Cc:Subject:Date:From; b=r9RGtuVkjU1msQKVhEeBLsmKxlWXSVP2EZq8TN2Sb7w0wdbOpbquGZzhVyne/SZTw w7mzMl985oAl20ftM4fLyW7g6uoUSPCToBkWmmSMXLIhkfhdn6Z0lVh+lscZ13UhhW zZJtOhcjGS4yfEOlvSx+ZDI66y+PX1Tc/CP5eSD8= From: Sonia Sharma To: linux-kernel@vger.kernel.org Cc: linux-hyperv@vger.kernel.org, netdev@vger.kernel.org, sosha@microsoft.com, kys@microsoft.com, mikelley@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, longli@microsoft.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Subject: [PATCH net-next v6] net: hv_netvsc: fix netvsc_send_completion to avoid multiple message length checks Date: Wed, 27 Sep 2023 14:19:16 -0700 Message-Id: <1695849556-20746-1-git-send-email-sosha@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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]); Wed, 27 Sep 2023 14:19:30 -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 --- 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