Skip to contentSkip to conversation

net: bridge: fix a bug on using a neighbour cache entry without checking its state

PATCH In review kchen 2 participants 3 messages Jan 6, 2019 – Jan 8, 2019

Subsystems (4)
lore
Share & tools
lore

kchen

author
#0 lore raw

PATCH 1/1 net: bridge: fix a bug on using a neighbour cache entry without checking its state

From: JianJhen Chen <[email protected]>

When handling DNAT'ed packets on a bridge device, the neighbour cache entry from lookup was used without checking its state. It means that a cache entry in the NUD_STALE state will be used directly instead of entering the NUD_DELAY state to confirm the reachability of the neighbor.

This problem becomes worse after commit 2724680bceee ("neigh: Keep neighbour cache entries if number of them is small enough."), since all neighbour cache entries in the NUD_STALE state will be kept in the neighbour table as long as the number of cache entries does not exceed the value specified in gc_thresh1.

This commit validates the state of a neighbour cache entry before using the entry.

---
 net/bridge/br_netfilter_hooks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_netfilter_hooks.c +1 -1
index b1b5e85..ed683e5 100644
@@ -278,7 +278,7 @@ int br_nf_pre_routing_finish_bridge(struct net *net, struct sock *sk, struct sk_
 		struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
 		int ret;
 
-		if (neigh->hh.hh_len) {
+		if ((neigh->nud_state & NUD_CONNECTED) && neigh->hh.hh_len) {
 			neigh_hh_bridge(&neigh->hh, skb);
 			skb->dev = nf_bridge->physindev;
 			ret = br_handle_frame_finish(net, sk, skb);
Signature · 1 line
2.7.4
maintainer
#1 lore raw

From: kchen <[email protected]>
Date: Sun, 6 Jan 2019 11:28:13 +0800

Quoted 12 lines

From: JianJhen Chen <[email protected]>

When handling DNAT'ed packets on a bridge device, the neighbour cache entry from lookup was used without checking its state. It means that a cache entry in the NUD_STALE state will be used directly instead of entering the NUD_DELAY state to confirm the reachability of the neighbor.

This problem becomes worse after commit 2724680bceee ("neigh: Keep neighbour cache entries if number of them is small enough."), since all neighbour cache entries in the NUD_STALE state will be kept in the neighbour table as long as the number of cache entries does not exceed the value specified in gc_thresh1.

Quoted 5 lines

This commit validates the state of a neighbour cache entry before using the entry.

Indeed, this looks correct.

Applied and queued up for -stable, thanks.

author
#2 lore raw

From: David Miller <[email protected]>
Date: Mon, 07 Jan 2019 09:10:31 -0800

Quoted 20 lines

From: David Miller <[email protected]>

From: kchen <[email protected]>
Date: Sun, 6 Jan 2019 11:28:13 +0800

Quoted 15 lines

From: JianJhen Chen <[email protected]>

When handling DNAT'ed packets on a bridge device, the neighbour cache entry from lookup was used without checking its state. It means that a cache entry in the NUD_STALE state will be used directly instead of entering the NUD_DELAY state to confirm the reachability of the neighbor.

This problem becomes worse after commit 2724680bceee ("neigh: Keep neighbour cache entries if number of them is small enough."), since all neighbour cache entries in the NUD_STALE state will be kept in the neighbour table as long as the number of cache entries does not exceed the value specified in gc_thresh1.

This commit validates the state of a neighbour cache entry before using the entry.

Quoted 7 lines
Quoted 2 lines

Indeed, this looks correct.

Applied and queued up for -stable, thanks.

Thank you for the confirmation.