Skip to content

Commit 3b2e290

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
net: bridge: fix per-port af_packet sockets
When the commit below was introduced it changed two visible things: - the skb was no longer passed through the protocol handlers with the original device - the skb was passed up the stack with skb->dev = bridge The first change broke af_packet sockets on bridge ports. For example we use them for hostapd which listens for ETH_P_PAE packets on the ports. We discussed two possible fixes: - create a clone and pass it through NF_HOOK(), act on the original skb based on the result - somehow signal to the caller from the okfn() that it was called, meaning the skb is ok to be passed, which this patch is trying to implement via returning 1 from the bridge link-local okfn() Note that we rely on the fact that NF_QUEUE/STOLEN would return 0 and drop/error would return < 0 thus the okfn() is called only when the return was 1, so we signal to the caller that it was called by preserving the return value from nf_hook(). Fixes: 8626c56 ("bridge: fix potential use-after-free when hook returns QUEUE or STOLEN verdict") Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 614c70f commit 3b2e290

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

‎net/bridge/br_input.c‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,10 @@ static void __br_handle_local_finish(struct sk_buff *skb)
197197
/* note: already called with rcu_read_lock */
198198
static int br_handle_local_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
199199
{
200-
struct net_bridge_port *p = br_port_get_rcu(skb->dev);
201-
202200
__br_handle_local_finish(skb);
203201

204-
BR_INPUT_SKB_CB(skb)->brdev = p->br->dev;
205-
br_pass_frame_up(skb);
206-
return 0;
202+
/* return 1 to signal the okfn() was called so it's ok to use the skb */
203+
return 1;
207204
}
208205

209206
/*
@@ -280,10 +277,18 @@ rx_handler_result_t br_handle_frame(struct sk_buff **pskb)
280277
goto forward;
281278
}
282279

283-
/* Deliver packet to local host only */
284-
NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN, dev_net(skb->dev),
285-
NULL, skb, skb->dev, NULL, br_handle_local_finish);
286-
return RX_HANDLER_CONSUMED;
280+
/* The else clause should be hit when nf_hook():
281+
* - returns < 0 (drop/error)
282+
* - returns = 0 (stolen/nf_queue)
283+
* Thus return 1 from the okfn() to signal the skb is ok to pass
284+
*/
285+
if (NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_IN,
286+
dev_net(skb->dev), NULL, skb, skb->dev, NULL,
287+
br_handle_local_finish) == 1) {
288+
return RX_HANDLER_PASS;
289+
} else {
290+
return RX_HANDLER_CONSUMED;
291+
}
287292
}
288293

289294
forward:

0 commit comments

Comments
 (0)