History

netfilter: nf_queue: hold bridge skb->dev while queued

br_pass_frame_up() rewrites skb->dev from the ingress port to the bridge master before queueing bridge LOCAL_IN packets. NFQUEUE only holds references on state.in/out and bridge physdevs, so a queued bridge packet can retain a freed bridge master in skb->dev until reinjection. When the verdict is reinjected later, br_netif_receive_skb() re-enters the receive path with skb->dev still pointing at the freed bridge master, triggering a use-after-free. Store skb->dev in the queue entry, hold a reference on it for the queue lifetime, and use the saved device when dropping queued packets during NETDEV_DOWN handling.

Haoze Xie committed 6 months ago

Commit e1961151 parent b2870fc3 files · +6 −1Browse files

Unified · Split

3 files
  1. include/net/netfilter/nf_queue.h +1 −0
  2. net/netfilter/nf_queue.c +3 −1
  3. net/netfilter/nfnetlink_queue.c +2 −0
include/net/netfilter/nf_queue.h+1−0
@@ -14,6 +14,7 @@ struct nf_queue_entry { · 13 unmodified lines
1414 struct list_head list;
1515 struct rhash_head hash_node;
1616 struct sk_buff *skb;
17+ struct net_device *skb_dev;
1718 unsigned int id;
1819 unsigned int hook_index; /* index in hook_entries->hook[] */
1920 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
net/netfilter/nf_queue.c+3−1
@@ -61,6 +61,7 @@ static void nf_queue_entry_release_refs(struct nf_queue_entry *entry) · 60 unmodified lines
6161 struct nf_hook_state *state = &entry->state;
6262
6363 /* Release those devices we held, or Alexey will kill me. */
64+ dev_put(entry->skb_dev);
6465 dev_put(state->in);
6566 dev_put(state->out);
6667 if (state->sk)
@@ -102,6 +103,7 @@ bool nf_queue_entry_get_refs(struct nf_queue_entry *entry) · 35 unmodified lines
102103 if (state->sk && !refcount_inc_not_zero(&state->sk->sk_refcnt))
103104 return false;
104105
106+ dev_hold(entry->skb_dev);
105107 dev_hold(state->in);
106108 dev_hold(state->out);
107109
@@ -202,11 +204,11 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state, · 94 unmodified lines
202204
203205 *entry = (struct nf_queue_entry) {
204206 .skb = skb,
207+ .skb_dev = skb->dev,
205208 .state = *state,
206209 .hook_index = index,
207210 .size = sizeof(*entry) + route_key_size,
208211 };
209−
210212 __nf_queue_entry_init_physdevs(entry);
211213
212214 if (!nf_queue_entry_get_refs(entry)) {
net/netfilter/nfnetlink_queue.c+2−0
@@ -1212,6 +1212,8 @@ dev_cmp(struct nf_queue_entry *entry, unsigned long ifindex) · 1211 unmodified lines
12121212 if (physinif == ifindex || physoutif == ifindex)
12131213 return 1;
12141214 #endif
1215+ if (entry->skb_dev && entry->skb_dev->ifindex == ifindex)
1216+ return 1;
12151217 if (entry->state.in)
12161218 if (entry->state.in->ifindex == ifindex)
12171219 return 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t