Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52234C6FA82 for ; Fri, 23 Sep 2022 12:32:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DD4F184225; Fri, 23 Sep 2022 14:32:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=codasip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=codasip.com header.i=@codasip.com header.b="oK81xctI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 78663840AE; Fri, 23 Sep 2022 14:31:54 +0200 (CEST) Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5802383FB2 for ; Fri, 23 Sep 2022 14:31:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=codasip.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel.obuch@codasip.com Received: by mail-ej1-x62d.google.com with SMTP id sd10so390069ejc.2 for ; Fri, 23 Sep 2022 05:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=codasip.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=ebkqt/54vuWm0WG0VUUBy7PsjagLmnqZucovCqw/JXY=; b=oK81xctIa5WxFoXInpYROF1UfKvVllL2WvSd4YSQuy0kqigE3U5IXgOIaqhRPdNo2m Gd+UrYZyDhFwjYxhqOPKA0HUCRrlLq/LhKtj2DYHKAUoVT8WGIUf+aEk93hbIjrWY98V KcSyrvBSyJl5/IZn5vThHUDsLdNYlAp+04oO5IsibIT9UBgQENm1KSOlyiKnchxBnBlI aO5llXvgq4BKsokzM6+k9MC5Ecq7MZnPVSY0FxSwPdVqargDI5glWaY0Qb6s1VQXceNr q7b7LBNrMC8yiRlVmRVlblHiuZLAJ+tVgtkkawrrPKkbKRsBvv5TzRlNhy/EtjWTPrYm J8+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=ebkqt/54vuWm0WG0VUUBy7PsjagLmnqZucovCqw/JXY=; b=OiD/yTylgZ5Tl0SplrCH+rqR+YdH7U5sSxZ5kJTX/GjMtBMkwcakakl6AfsH3SXfT/ ujBP1VqmTlNNwT7P24iAyDH0qNfCwPlYhKX1OZmYZrAoSPzeJ1MoNbrDWYeIxYkevLU9 BgfRYKHCtQGJmQNATSlkW2uoJVmf2LART7zwmPwvNtOwhUDM713retlD/61iy/ZGv1WG gzJtbmX/6f2VsSnGEBhOXRRxFXlWIbtSYOrX8HiaSejF2YYseii4VaJ9a/L24tv55Flk IhWw6wWjA9oHc3aXcDuCS8XwMjYViV3agAzKW7i7dpDqzquPyFVBFc9d8Q8cVafceq8y GDwQ== X-Gm-Message-State: ACrzQf3EYUrG6ctyE8SZ7JXDbO9Vjq43lQud2sENFKT7K2/ekAYHq6xQ vIraE56duXAq8zPajYIJHC3uISUUrsND1bV7NYU= X-Google-Smtp-Source: AMsMyM6VOSO+BKwKR/Qz6TZMhjaOYTP2prLONhWWUNNzCiVvET+IflZNhld6VnP0DlOaUmQDrPrXbA== X-Received: by 2002:a17:907:e9e:b0:77f:9688:2714 with SMTP id ho30-20020a1709070e9e00b0077f96882714mr6749396ejc.208.1663936311650; Fri, 23 Sep 2022 05:31:51 -0700 (PDT) Received: from nb76.codasip.com ([193.85.186.210]) by smtp.gmail.com with ESMTPSA id f15-20020a50d54f000000b004527eb874ebsm5538207edj.40.2022.09.23.05.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 05:31:51 -0700 (PDT) From: samuel.obuch@codasip.com To: u-boot@lists.denx.de Cc: rfried.dev@gmail.com, michal.simek@amd.com, Samuel Obuch Subject: [PATCH v2 3/3] net: emaclite: fix handling for IP packets with specific lengths Date: Fri, 23 Sep 2022 14:31:21 +0200 Message-Id: <20220923123121.49411-3-samuel.obuch@codasip.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220923123121.49411-1-samuel.obuch@codasip.com> References: <20220923123121.49411-1-samuel.obuch@codasip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Samuel Obuch The maximum length is capped similarly to the emaclite_send function. Avoid integer underflow for values of ip->ip_len < 30, the minimum length of an IP packet is 21 bytes. Signed-off-by: Samuel Obuch --- drivers/net/xilinx_emaclite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c index c12736d0ee..52127a05e8 100644 --- a/drivers/net/xilinx_emaclite.c +++ b/drivers/net/xilinx_emaclite.c @@ -518,6 +518,8 @@ try_again: length = ntohs(ip->ip_len); length += ETHER_HDR_SIZE + ETH_FCS_LEN; debug("IP Packet %x\n", length); + if (length > PKTSIZE) + length = PKTSIZE; break; default: debug("Other Packet\n"); @@ -526,7 +528,7 @@ try_again: } /* Read the rest of the packet which is longer then first read */ - if (length != first_read) + if (length > first_read) xemaclite_alignedread(addr + first_read, etherrxbuff + first_read, length - first_read); -- 2.31.1