Skip to content

Commit d6ef227

Browse files
idoschgregkh
authored andcommitted
bridge: netfilter: Fix forwarding of fragmented packets
[ Upstream commit 91b6dbc ] When netfilter defrag hooks are loaded (due to the presence of conntrack rules, for example), fragmented packets entering the bridge will be defragged by the bridge's pre-routing hook (br_nf_pre_routing() -> ipv4_conntrack_defrag()). Later on, in the bridge's post-routing hook, the defragged packet will be fragmented again. If the size of the largest fragment is larger than what the kernel has determined as the destination MTU (using ip_skb_dst_mtu()), the defragged packet will be dropped. Before commit ac6627a ("net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward"), ip_skb_dst_mtu() would return dst_mtu() as the destination MTU. Assuming the dst entry attached to the packet is the bridge's fake rtable one, this would simply be the bridge's MTU (see fake_mtu()). However, after above mentioned commit, ip_skb_dst_mtu() ends up returning the route's MTU stored in the dst entry's metrics. Ideally, in case the dst entry is the bridge's fake rtable one, this should be the bridge's MTU as the bridge takes care of updating this metric when its MTU changes (see br_change_mtu()). Unfortunately, the last operation is a no-op given the metrics attached to the fake rtable entry are marked as read-only. Therefore, ip_skb_dst_mtu() ends up returning 1500 (the initial MTU value) and defragged packets are dropped during fragmentation when dealing with large fragments and high MTU (e.g., 9k). Fix by moving the fake rtable entry's metrics to be per-bridge (in a similar fashion to the fake rtable entry itself) and marking them as writable, thereby allowing MTU changes to be reflected. Fixes: 62fa8a8 ("net: Implement read-only protection and COW'ing of metrics.") Fixes: 33eb987 ("bridge: initialize fake_rtable metrics") Reported-by: Venkat Venkatsubra <[email protected]> Closes: https://lore.kernel.org/netdev/PH0PR10MB4504888284FF4CBA648197D0ACB82@PH0PR10MB4504.namprd10.prod.outlook.com/ Tested-by: Venkat Venkatsubra <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Acked-by: Nikolay Aleksandrov <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent fcad74f commit d6ef227

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

net/bridge/br_nf_core.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,14 @@ static struct dst_ops fake_dst_ops = {
6565
* ipt_REJECT needs it. Future netfilter modules might
6666
* require us to fill additional fields.
6767
*/
68-
static const u32 br_dst_default_metrics[RTAX_MAX] = {
69-
[RTAX_MTU - 1] = 1500,
70-
};
71-
7268
void br_netfilter_rtable_init(struct net_bridge *br)
7369
{
7470
struct rtable *rt = &br->fake_rtable;
7571

7672
rcuref_init(&rt->dst.__rcuref, 1);
7773
rt->dst.dev = br->dev;
78-
dst_init_metrics(&rt->dst, br_dst_default_metrics, true);
74+
dst_init_metrics(&rt->dst, br->metrics, false);
75+
dst_metric_set(&rt->dst, RTAX_MTU, br->dev->mtu);
7976
rt->dst.flags = DST_NOXFRM | DST_FAKE_RTABLE;
8077
rt->dst.ops = &fake_dst_ops;
8178
}

net/bridge/br_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ struct net_bridge {
505505
struct rtable fake_rtable;
506506
struct rt6_info fake_rt6_info;
507507
};
508+
u32 metrics[RTAX_MAX];
508509
#endif
509510
u16 group_fwd_mask;
510511
u16 group_fwd_mask_required;

0 commit comments

Comments
 (0)