From patchwork Tue May 2 22:13:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13229318 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 75F527491 for ; Tue, 2 May 2023 22:13:25 +0000 (UTC) Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C53E41FEE for ; Tue, 2 May 2023 15:13:19 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-3ef64d8b2b4so20708181cf.2 for ; Tue, 02 May 2023 15:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683065598; x=1685657598; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BQTKNZUjF1tZVGzsl9hQectj2Dnc9g2sG5AnMqu9CLU=; b=OWbTSLdBEIonx0WubXyoi68LxibN9qqiIEq18zR0SPzGf2GpXzGG0ioTvwRGXyOI4j 9OnN8CvG8lJNmsuvRrUOGcXDdrbWz3Cu9Ra1eEKgDXQoOBmzpLsIo4wxU9m9fde1dHud 3/cn/uwGw7uSb6XMjKVikXPDe4guIZj2M1mS9++QwM/9/5RKJN6tKRrr05gZPsRST4cJ baUuSYN2p2RrP8uSva73CPahgmNOGjQX9LJWnyDMPrHk+xvliaKe1X2LTFGZIqZDKSX4 YNcdh/5Kap20KdMs2uaDWYORDqN77uSGBO5enEo0yzbzojzRVQ8e9ln/hoBoh+qXuJA0 RSeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683065598; x=1685657598; 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:message-id:reply-to; bh=BQTKNZUjF1tZVGzsl9hQectj2Dnc9g2sG5AnMqu9CLU=; b=M39G1HxQPW0ygGqSOU4lYMD3AbnSjWOfGqYJ+dhGFUYT91ksXLM31I6U0+4MmgHL3u TrY5+2YMH+oKkjme2T5fOqagBFLvcHYrDGx0OX81+mEJ1aT0n+5rlmNLIe8y/IXxG9Us dZa47QUiU8zMRQZM+h0F84j5cETuinj5Hb1q4zDqJD0uf1ICgwctePra1VqjrrasDEjW RLyzVedNpJYVkKEI6obC9IYtVY6sPP+j4USFtP8St6IPeCIyclJxyEl33AShRcsJ9Tas GW3F8LLhSpxxeh0Z1rDKYO0R0rhnQacdpZOk7JPJzTxsfUPiwn6OJTmd2FkJ2HLxzkog NDkA== X-Gm-Message-State: AC+VfDwq2doMH2X0LE+yfrbHs03vU+miDRxMKCDSzRUi4X2TM64+6aHT KlsmA61gmZHY86iD3NtXr3TflfQPbNKz8w== X-Google-Smtp-Source: ACHHUZ63BGMHjXiAVrHuMCc/6e/tbSB08gjIepr2ta3bWxOPFfmtg7lmb9Pgh+bQz+w9NyidI9l+mg== X-Received: by 2002:ac8:7f0c:0:b0:3ef:5221:5710 with SMTP id f12-20020ac87f0c000000b003ef52215710mr29353666qtk.47.1683065598281; Tue, 02 May 2023 15:13:18 -0700 (PDT) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id cf23-20020a05622a401700b003ef58044a4bsm10362636qtb.34.2023.05.02.15.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 15:13:17 -0700 (PDT) From: Xin Long To: network dev , tipc-discussion@lists.sourceforge.net Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , Jon Maloy , Tung Nguyen Subject: [PATCHv2 net 1/3] tipc: add tipc_bearer_min_mtu to calculate min mtu Date: Tue, 2 May 2023 18:13:13 -0400 Message-Id: <8e3827ffaf71c0636541c01f76ff3a65868433ea.1683065352.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org As different media may requires different min mtu, and even the same media with different net family requires different min mtu, add tipc_bearer_min_mtu() to calculate min mtu accordingly. This API will be used to check the new mtu when doing the link mtu negotiation in the next patch. v1->v2: - use bearer_get() to avoid the open code. Signed-off-by: Xin Long --- net/tipc/bearer.c | 13 +++++++++++++ net/tipc/bearer.h | 3 +++ net/tipc/udp_media.c | 5 +++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 35cac7733fd3..0e9a29e1536b 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -541,6 +541,19 @@ int tipc_bearer_mtu(struct net *net, u32 bearer_id) return mtu; } +int tipc_bearer_min_mtu(struct net *net, u32 bearer_id) +{ + int mtu = TIPC_MIN_BEARER_MTU; + struct tipc_bearer *b; + + rcu_read_lock(); + b = bearer_get(net, bearer_id); + if (b) + mtu += b->encap_hlen; + rcu_read_unlock(); + return mtu; +} + /* tipc_bearer_xmit_skb - sends buffer to destination over bearer */ void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id, diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 490ad6e5f7a3..bd0cc5c287ef 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h @@ -146,6 +146,7 @@ struct tipc_media { * @identity: array index of this bearer within TIPC bearer array * @disc: ptr to link setup request * @net_plane: network plane ('A' through 'H') currently associated with bearer + * @encap_hlen: encap headers length * @up: bearer up flag (bit 0) * @refcnt: tipc_bearer reference counter * @@ -170,6 +171,7 @@ struct tipc_bearer { u32 identity; struct tipc_discoverer *disc; char net_plane; + u16 encap_hlen; unsigned long up; refcount_t refcnt; }; @@ -232,6 +234,7 @@ int tipc_bearer_setup(void); void tipc_bearer_cleanup(void); void tipc_bearer_stop(struct net *net); int tipc_bearer_mtu(struct net *net, u32 bearer_id); +int tipc_bearer_min_mtu(struct net *net, u32 bearer_id); bool tipc_bearer_bcast_support(struct net *net, u32 bearer_id); void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id, struct sk_buff *skb, diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c index c2bb818704c8..0a85244fd618 100644 --- a/net/tipc/udp_media.c +++ b/net/tipc/udp_media.c @@ -738,8 +738,8 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, udp_conf.local_ip.s_addr = local.ipv4.s_addr; udp_conf.use_udp_checksums = false; ub->ifindex = dev->ifindex; - if (tipc_mtu_bad(dev, sizeof(struct iphdr) + - sizeof(struct udphdr))) { + b->encap_hlen = sizeof(struct iphdr) + sizeof(struct udphdr); + if (tipc_mtu_bad(dev, b->encap_hlen)) { err = -EINVAL; goto err; } @@ -760,6 +760,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, else udp_conf.local_ip6 = local.ipv6; ub->ifindex = dev->ifindex; + b->encap_hlen = sizeof(struct ipv6hdr) + sizeof(struct udphdr); b->mtu = 1280; #endif } else { From patchwork Tue May 2 22:13:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13229317 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 7A4B9AD56 for ; Tue, 2 May 2023 22:13:25 +0000 (UTC) Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49B501FFB for ; Tue, 2 May 2023 15:13:20 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-3ef5bea20caso19692011cf.3 for ; Tue, 02 May 2023 15:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683065599; x=1685657599; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HgFZPI4XjlizNmEB1pNa+C6jlIbIG0Qwtes7V4DeJ2k=; b=fxbEPf0U9JIqmd0bDtIGFlLPrhzfk4EtTO/2G9wX+F4JZAqfG/nhGluYxEC8bhrPy9 /hCOu8HiL/UDATIUXoyVpq3J+54JEKdjat2zFxdkUDe4FPb6OpbwO69uLUEbyVz8wUkQ oBF9RtpXGbSVez2cQ/YRT1hVxk2G2BsGfytyL15maaKdnrDap5Jhet4HnO94FeGA7DyG mqQsVVrJC/eZC8k4GCN2FCEvAU03EuK717nU0MMxnzOAtA3yTe8v62NyxIOk5qgcZEUZ 98sb/4x7em5IJXHFboL/0+tY9ywf5jDQZHIKhJLAjiPZjyuyqKVx1r3URGfrCn7U8laN tE1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683065599; x=1685657599; 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:message-id:reply-to; bh=HgFZPI4XjlizNmEB1pNa+C6jlIbIG0Qwtes7V4DeJ2k=; b=FS3j6ZVieovgYD1+U2XwxLoRzVZweYjPapyFgRNlXaB1cMSLxd3t66aywjm63GZgTt XltTjmTRVnh+Atd0OSB/mVFC8sl2qfR/yWzV3Z+UUj1dLKyxsDaO2NfArioHjBZatMCz KCmfx6gmudi0TA3bauH4FkseX1Y3UAuVE7N47AWuDouSoyb6T1cyKQWSUop93wZlGbl9 G/mGBJ7259+wesNMcwzrxF7wi6c1vtBztjXSVOtHMj/iftliO5PHiNdp+6IuG4ETmOm7 xNx4Jc033mLLndCSYe02vZanCKhcsY5b4RUJZI4a5u0Tz8yWZh3H6wmPLCEPckQA65M/ yuGA== X-Gm-Message-State: AC+VfDw296J9GvqWL6OjoNPcgxjpDUOZRQEUu+PUSdSkrIyXBwd2IF72 SZ7NbHnkp2IvNvFnm6/FpZLY/WkBnSkVGA== X-Google-Smtp-Source: ACHHUZ5en8ZtWE5b5jRUXI9QV+ICEN3FE4wpo186FfCIdPPjUU6aXleBJL3FkDU5IogICs8zOZGxXw== X-Received: by 2002:ac8:5a54:0:b0:3ef:380a:d7bc with SMTP id o20-20020ac85a54000000b003ef380ad7bcmr29053674qta.54.1683065599209; Tue, 02 May 2023 15:13:19 -0700 (PDT) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id cf23-20020a05622a401700b003ef58044a4bsm10362636qtb.34.2023.05.02.15.13.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 15:13:18 -0700 (PDT) From: Xin Long To: network dev , tipc-discussion@lists.sourceforge.net Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , Jon Maloy , Tung Nguyen Subject: [PATCHv2 net 2/3] tipc: do not update mtu if msg_max is too small in mtu negotiation Date: Tue, 2 May 2023 18:13:14 -0400 Message-Id: <0d328807d5087d0b6d03c3d2e5f355cd44ed576a.1683065352.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org When doing link mtu negotiation, a malicious peer may send Activate msg with a very small mtu, e.g. 4 in Shuang's testing, without checking for the minimum mtu, l->mtu will be set to 4 in tipc_link_proto_rcv(), then n->links[bearer_id].mtu is set to 4294967228, which is a overflow of '4 - INT_H_SIZE - EMSG_OVERHEAD' in tipc_link_mss(). With tipc_link.mtu = 4, tipc_link_xmit() kept printing the warning: tipc: Too large msg, purging xmit list 1 5 0 40 4! tipc: Too large msg, purging xmit list 1 15 0 60 4! And with tipc_link_entry.mtu 4294967228, a huge skb was allocated in named_distribute(), and when purging it in tipc_link_xmit(), a crash was even caused: general protection fault, probably for non-canonical address 0x2100001011000dd: 0000 [#1] PREEMPT SMP PTI CPU: 0 PID: 0 Comm: swapper/0 Kdump: loaded Not tainted 6.3.0.neta #19 RIP: 0010:kfree_skb_list_reason+0x7e/0x1f0 Call Trace: skb_release_data+0xf9/0x1d0 kfree_skb_reason+0x40/0x100 tipc_link_xmit+0x57a/0x740 [tipc] tipc_node_xmit+0x16c/0x5c0 [tipc] tipc_named_node_up+0x27f/0x2c0 [tipc] tipc_node_write_unlock+0x149/0x170 [tipc] tipc_rcv+0x608/0x740 [tipc] tipc_udp_recv+0xdc/0x1f0 [tipc] udp_queue_rcv_one_skb+0x33e/0x620 udp_unicast_rcv_skb.isra.72+0x75/0x90 __udp4_lib_rcv+0x56d/0xc20 ip_protocol_deliver_rcu+0x100/0x2d0 This patch fixes it by checking the new mtu against tipc_bearer_min_mtu(), and not updating mtu if it is too small. v1->v2: - do the msg_max check against the min MTU early, as Tung suggested. Fixes: ed193ece2649 ("tipc: simplify link mtu negotiation") Reported-by: Shuang Li Signed-off-by: Xin Long --- net/tipc/link.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/tipc/link.c b/net/tipc/link.c index b3ce24823f50..2eff1c7949cb 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c @@ -2200,7 +2200,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, struct tipc_msg *hdr = buf_msg(skb); struct tipc_gap_ack_blks *ga = NULL; bool reply = msg_probe(hdr), retransmitted = false; - u32 dlen = msg_data_sz(hdr), glen = 0; + u32 dlen = msg_data_sz(hdr), glen = 0, msg_max; u16 peers_snd_nxt = msg_next_sent(hdr); u16 peers_tol = msg_link_tolerance(hdr); u16 peers_prio = msg_linkprio(hdr); @@ -2239,6 +2239,9 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, switch (mtyp) { case RESET_MSG: case ACTIVATE_MSG: + msg_max = msg_max_pkt(hdr); + if (msg_max < tipc_bearer_min_mtu(l->net, l->bearer_id)) + break; /* Complete own link name with peer's interface name */ if_name = strrchr(l->name, ':') + 1; if (sizeof(l->name) - (if_name - l->name) <= TIPC_MAX_IF_NAME) @@ -2283,8 +2286,8 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, l->peer_session = msg_session(hdr); l->in_session = true; l->peer_bearer_id = msg_bearer_id(hdr); - if (l->mtu > msg_max_pkt(hdr)) - l->mtu = msg_max_pkt(hdr); + if (l->mtu > msg_max) + l->mtu = msg_max; break; case STATE_MSG: From patchwork Tue May 2 22:13:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 13229319 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 BDBDABA2B for ; Tue, 2 May 2023 22:13:25 +0000 (UTC) Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 095E21FFF for ; Tue, 2 May 2023 15:13:21 -0700 (PDT) Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-75131c2997bso27122385a.1 for ; Tue, 02 May 2023 15:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683065600; x=1685657600; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=13KxgOJcr7gVZ8an57+aultClqJTer559gf4P+MeESk=; b=QQ/dHUjVwfaIetW2niX6G2tMyGPOV/RB7Qf1YTojUht72nMIs9k16ZxT1vvJpfBjy+ 0XT6dIB1rjjDYg2aj64LsZTyJAG3kj1SEPNN16fhkjLHfijzzls5cL1Jg+PwaVZ1Ojtt j2gtj+n1vfrumZ3dyDbUKG6gm9KP/9MuXbpCO5GjN01kBPi4abANY3rkQFMAsJEQXBhd 3M0bwyVJc/NABoJzIfd97VyfaiFRUx47FNfVg0b7WiaIhqXcJhnIWXKegAZ8UZHdXyep ri4Ao3CCbmFfpGaakrnfii/2TZGFoKtypjrC4BncKk6g+J86VUhY5aZdeIDI7nyMoVoU yP/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683065600; x=1685657600; 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:message-id:reply-to; bh=13KxgOJcr7gVZ8an57+aultClqJTer559gf4P+MeESk=; b=hUPE8XZeX9b2GikGpdWuIaTCBxXv0Xy4BzROItC+DXABJJAx2V37lAK/qUA7FJ1yE1 Dq7gK9kpcQxPJFhbb5zt+p0pvm5fu7LOx1vecBo0Vv1l/s6Rid8lpTI/u3cjqk7U99Mt Jx93hxo+D2P19bNn9KUfupjA4+CYqQbcUIAxzye3CMi9xelPd85pPykrP9CSWFyCkINR CaE2E9k4m6pvRHf3naB4yFQjLjawUFzsdL3+inqAP2mDvZAfv8RvWWgK4oTbSjtKkhpb LjGaXTw9uTMjZInd50C+GzGaLpr+XYkcKZWokvJLJrpA38h10WUijOrhAxIO8ZlYkAn9 pQHw== X-Gm-Message-State: AC+VfDyheH4cvyZtaKKyONyH4ZAL8YrXx5H/okltz12TBAXqa3RuiOyy KJcwxn0Pu8yp5WnrYstnL04wSGjm+D5Ttw== X-Google-Smtp-Source: ACHHUZ7XyuwUpeuXxLxeC+nX1/WQjqdrgU6QbBdfyffj1IifPnPzZt45bIwiX9H/vaQSGtWT21I80A== X-Received: by 2002:ac8:7f48:0:b0:3e3:9185:cb15 with SMTP id g8-20020ac87f48000000b003e39185cb15mr186278qtk.7.1683065600032; Tue, 02 May 2023 15:13:20 -0700 (PDT) Received: from wsfd-netdev15.ntdv.lab.eng.bos.redhat.com (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id cf23-20020a05622a401700b003ef58044a4bsm10362636qtb.34.2023.05.02.15.13.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 15:13:19 -0700 (PDT) From: Xin Long To: network dev , tipc-discussion@lists.sourceforge.net Cc: davem@davemloft.net, kuba@kernel.org, Eric Dumazet , Paolo Abeni , Jon Maloy , Tung Nguyen Subject: [PATCHv2 net 3/3] tipc: check the bearer min mtu properly when setting it by netlink Date: Tue, 2 May 2023 18:13:15 -0400 Message-Id: <1a6d4021e30266c8ff11a2eb25390ccd32766cf4.1683065352.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Checking the bearer min mtu with tipc_udp_mtu_bad() only works for IPv4 UDP bearer, and IPv6 UDP bearer has a different value for the min mtu. This patch checks with encap_hlen + TIPC_MIN_BEARER_MTU for min mtu, which works for both IPv4 and IPv6 UDP bearer. Note that tipc_udp_mtu_bad() is still used to check media min mtu in __tipc_nl_media_set(), as m->mtu currently is only used by the IPv4 UDP bearer as its default mtu value. Fixes: 682cd3cf946b ("tipc: confgiure and apply UDP bearer MTU on running links") Signed-off-by: Xin Long --- net/tipc/bearer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 0e9a29e1536b..53881406e200 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -1151,8 +1151,8 @@ int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info) return -EINVAL; } #ifdef CONFIG_TIPC_MEDIA_UDP - if (tipc_udp_mtu_bad(nla_get_u32 - (props[TIPC_NLA_PROP_MTU]))) { + if (nla_get_u32(props[TIPC_NLA_PROP_MTU]) < + b->encap_hlen + TIPC_MIN_BEARER_MTU) { NL_SET_ERR_MSG(info->extack, "MTU value is out-of-range"); return -EINVAL;