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: 161783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2301720vqu; Sun, 5 Nov 2023 12:58:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfGFs7W3Rat4ZhcemiBnBYVMicm3/jdKjXxmE5rXBCljMkPHpiRJyj8Yk0Js88LXxmq85+ X-Received: by 2002:a17:90a:7563:b0:27d:853:9109 with SMTP id q90-20020a17090a756300b0027d08539109mr25348790pjk.20.1699217889841; Sun, 05 Nov 2023 12:58:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699217889; cv=none; d=google.com; s=arc-20160816; b=JAj32+y7pJdd9Tf4qk738maSx7IQWWf4twWmekdGVEsAyCTQuNwcSOrM4WstnBSdbQ eNuY9JSHfIW1XwNHg9cfIkFMGSv4Ld4VV3pGV0vDki9hUBKKDW/s36F89U1pypSm25Cs CVXf4BLwFz5zB0x8fttJaAN8fGZbmcZ0YtN4lICrPYda7XHJiHdhvqkLR65nz2miDwHy /85IXb2Br3MLzioLvALChH3jPVpcUJtS2deoKJEABn/sp+NzfGIEwcl5LVR/jbaXiKQB XZlrJPH071/123LMgIQlt0b4KGG9mCHm/yPVyKPyaOvCrewiiACUaDhqhxJlvspoVgNI BHkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=hHGg7IgOG8aP3eorgAYgy9MJBjBd5UgvuR9R9eWvihw=; fh=G3jVr66/sTBxblB4VkyKBP17P5NL/3UjRtmVOzWFD40=; b=F6MsH8ZM1CGhTz1SpkRRln0mVDGKtTnkNPp/300SqAl7+wOUN55uocELrjgECmR5bE wJ5YZDLGtY+A00VtYPuhjiOoa4H+ERjsPskodsNXMpHrLASI3vHz9YWsQ4VgICYcOTkb hSMobo6l1kiAJjBxzwNaMMXfnW6GXmkKfC9G+jtm7jydqd33Oh4AO59dLaDeQl/6Ruv1 bcqVSBfwfQBsMqQWbKrL6bhEq7ijGITvn15iF3ym2cbhSS1Y/8jylfowdErTIUuM6X9k y15Ne8psvDMiKVcNRn9JWZ7HG1Rh2nOKXdic+EALRbLtj6O5FdgmJATgJZ2stZs+m+uU 1hvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u8Wy9jAN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id w4-20020a17090abc0400b0027ffe28ed7asi6526897pjr.66.2023.11.05.12.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 12:58:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u8Wy9jAN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C9DA18053612; Sun, 5 Nov 2023 12:58:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229872AbjKEU5l (ORCPT + 34 others); Sun, 5 Nov 2023 15:57:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229655AbjKEU5f (ORCPT ); Sun, 5 Nov 2023 15:57:35 -0500 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D268F2 for ; Sun, 5 Nov 2023 12:57:32 -0800 (PST) Received: by mail-lj1-x22e.google.com with SMTP id 38308e7fff4ca-2c514cbbe7eso54279311fa.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=Ezixc6WFM2FuR+NEcIeZCj2dzV6oMP9F7y9Zhyt9ayzhpnNMgwsz9MiihJimRhdA/5 RopiLpcqinjMh1Z34Kp3h4sTRBJ3ABymISVqDB2rAkvU6mLDvryl2mDBTiDxXPv5BAA4 yoZMzSBBPrp/vE48MCiY3P7nYfY93wl6HNPhzcBWulNshCfAqQUVYDMgmW+Hx4URp8rQ wMuiaoQaOKoFUqC/9J88NS0Xt4WItH13sF5/hKKkLXaKlgHkfmh4+qM5gcxL80GHZ1zM +jzOkFsNYfbrqvX0hDaLtM+R7lm37HOX9D6stOuAfasHE0C9qqDou02Ov5s+cdaREIOI ANKA== X-Gm-Message-State: AOJu0Yyd+SKImRMfFZRUg9XaPpXVSo53v9DwoV+xwfFtLEI8VbNYBgxB S4pSbjqtCuFa1syJ0hJ8I1VLAA== 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 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-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Sun, 05 Nov 2023 12:58:04 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781759098188992568 X-GMAIL-MSGID: 1781759098188992568 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;