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
14 struct list_head list;14 struct list_head list;
15 struct rhash_head hash_node;15 struct rhash_head hash_node;
16 struct sk_buff *skb;16 struct sk_buff *skb;
17 struct net_device *skb_dev;
17 unsigned int id;18 unsigned int id;
18 unsigned int hook_index; /* index in hook_entries->hook[] */19 unsigned int hook_index; /* index in hook_entries->hook[] */
19#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)20#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
61 struct nf_hook_state *state = &entry->state;61 struct nf_hook_state *state = &entry->state;
62 62
63 /* Release those devices we held, or Alexey will kill me. */63 /* Release those devices we held, or Alexey will kill me. */
64 dev_put(entry->skb_dev);
64 dev_put(state->in);65 dev_put(state->in);
65 dev_put(state->out);66 dev_put(state->out);
66 if (state->sk)67 if (state->sk)
@@ -102,6 +103,7 @@ bool nf_queue_entry_get_refs(struct nf_queue_entry *entry) · 35 unmodified lines
102 if (state->sk && !refcount_inc_not_zero(&state->sk->sk_refcnt))103 if (state->sk && !refcount_inc_not_zero(&state->sk->sk_refcnt))
103 return false;104 return false;
104 105
106 dev_hold(entry->skb_dev);
105 dev_hold(state->in);107 dev_hold(state->in);
106 dev_hold(state->out);108 dev_hold(state->out);
107 109
@@ -202,11 +204,11 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state, · 94 unmodified lines
202 204
203 *entry = (struct nf_queue_entry) {205 *entry = (struct nf_queue_entry) {
204 .skb = skb,206 .skb = skb,
207 .skb_dev = skb->dev,
205 .state = *state,208 .state = *state,
206 .hook_index = index,209 .hook_index = index,
207 .size = sizeof(*entry) + route_key_size,210 .size = sizeof(*entry) + route_key_size,
208 };211 };
209
210 __nf_queue_entry_init_physdevs(entry);212 __nf_queue_entry_init_physdevs(entry);
211 213
212 if (!nf_queue_entry_get_refs(entry)) {214 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
1212 if (physinif == ifindex || physoutif == ifindex)1212 if (physinif == ifindex || physoutif == ifindex)
1213 return 1;1213 return 1;
1214#endif1214#endif
1215 if (entry->skb_dev && entry->skb_dev->ifindex == ifindex)
1216 return 1;
1215 if (entry->state.in)1217 if (entry->state.in)
1216 if (entry->state.in->ifindex == ifindex)1218 if (entry->state.in->ifindex == ifindex)
1217 return 1;1219 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