From patchwork Sun Nov 5 20:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13446143 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B456F18B18 for ; Sun, 5 Nov 2023 20:57:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="u8Wy9jAN" Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C3B0EE for ; Sun, 5 Nov 2023 12:57:32 -0800 (PST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-507a29c7eefso4804733e87.1 for ; Sun, 05 Nov 2023 12:57:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699217850; x=1699822650; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hHGg7IgOG8aP3eorgAYgy9MJBjBd5UgvuR9R9eWvihw=; b=u8Wy9jANe9JmWn3rXVAJj1iNV1dQIxXllohcGldOr4GrLo2+dAwpct5BXSIncZGY/V IynXdgJUzzzrO6bQQ/QBdlwqCjGYq4JuQ7IMEHNfQOIfthAw9fOjYgqi3u9/j0y8Nkmu Zerox7yAGlML/hU/LfOzJ0DxroanMhajcMYIUqHDJEP7ksfV3FaYXjMVCTgaU4KEjJbT PPx3a1ceGdTx9ei7i8YcUT61pxDiWXcM3X8l5t8I6QHnMdyxS82iT7nwfMD6pHhQKnsZ 9gCXzh5QWjOcbvhR/Ma/YmRtbGeHrJ8akaujvYhe0E2oJUO3OTejjOLiNR0senP2x+IV ZUrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699217850; x=1699822650; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hHGg7IgOG8aP3eorgAYgy9MJBjBd5UgvuR9R9eWvihw=; b=sCTzOKquZ045y25hGX5uB8Ii50f0JkVIxXV4mnykMT1uNHobC/axVWaaf6i+mGo8nN /cMRwezWMMOUlstY22zddlUvW8wNx/7EtyysKQ295fgTwIOy4UTFX8TeNs03MjXS6ghD V7WW9G8VBZFbbXkyPw9YIR/4Xq+8uwX8cvVkx+3rc0Yrvvpa787xb/Sa8/EKskiVCL0x 1pRWnu6WF/gzRN1GSzN0e7BGU5h8A5Hrs2AxBDfPcFewfdZWza9U5AxPv12KmKvi5PHa oNSS7lcxbxxZG51bk2l5wY6KqGm8SiNoKK7DKPuNKIxtsFVowQEUFeWtO5wMKEIJILe9 c3fA== X-Gm-Message-State: AOJu0Yz+Afgn3A8LWT9nzjvbaAvDb6lakF5KLAIildt3oQX+bP2vEnNt OvyQVzzE16Lm9X0iHNQPRY96pw== X-Google-Smtp-Source: AGHT+IF7W3TbvSvzphWkJ38I4V5LXCkTCcll16Xd2nGcrFIOQF+dFaXj5XAglJ+flcNEhVosFX81xQ== X-Received: by 2002:a05:6512:368f:b0:506:8d2a:5654 with SMTP id d15-20020a056512368f00b005068d2a5654mr17718911lfs.28.1699217850484; Sun, 05 Nov 2023 12:57:30 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id d12-20020ac24c8c000000b00507c72697d0sm931873lfl.303.2023.11.05.12.57.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 12:57:30 -0800 (PST) From: Linus Walleij Date: Sun, 05 Nov 2023 21:57:25 +0100 Subject: [PATCH net v2 3/4] net: ethernet: cortina: Protect against oversized frames Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20231105-gemini-largeframe-fix-v2-3-cd3a5aa6c496@linaro.org> References: <20231105-gemini-largeframe-fix-v2-0-cd3a5aa6c496@linaro.org> In-Reply-To: <20231105-gemini-largeframe-fix-v2-0-cd3a5aa6c496@linaro.org> To: Hans Ulli Kroll , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Vladimir Oltean , Andrew Lunn Cc: linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-Patchwork-Delegate: kuba@kernel.org The max size of a transfer no matter the MTU is 64KB-1 so immediately bail out if the skb exceeds that. The calling site tries to linearize the skbuff on error so return a special error code -E2BIG to indicate that this will not work in any way and bail out immediately if this happens. Fixes: 4d5ae32f5e1e ("net: ethernet: Add a driver for Gemini gigabit ethernet") Signed-off-by: Linus Walleij --- drivers/net/ethernet/cortina/gemini.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cortina/gemini.c b/drivers/net/ethernet/cortina/gemini.c index b21a94b4ab5c..576174a862a9 100644 --- a/drivers/net/ethernet/cortina/gemini.c +++ b/drivers/net/ethernet/cortina/gemini.c @@ -1151,6 +1151,12 @@ static int gmac_map_tx_bufs(struct net_device *netdev, struct sk_buff *skb, if (skb->protocol == htons(ETH_P_8021Q)) mtu += VLAN_HLEN; + if (skb->len > 65535) { + /* The field for length is only 16 bits */ + netdev_err(netdev, "%s: frame too big, max size 65535 bytes\n", __func__); + return -E2BIG; + } + word1 = skb->len; word3 = SOF_BIT; @@ -1232,6 +1238,7 @@ static netdev_tx_t gmac_start_xmit(struct sk_buff *skb, struct gmac_txq *txq; int txq_num, nfrags; union dma_rwptr rw; + int ret; if (skb->len >= 0x10000) goto out_drop_free; @@ -1269,7 +1276,11 @@ static netdev_tx_t gmac_start_xmit(struct sk_buff *skb, } } - if (gmac_map_tx_bufs(netdev, skb, txq, &w)) { + ret = gmac_map_tx_bufs(netdev, skb, txq, &w); + if (ret == -E2BIG) + goto out_drop; + if (ret) { + /* Linearize and retry */ if (skb_linearize(skb)) goto out_drop;