Skip to content

Commit 9899184

Browse files
TaeheeYooPaolo Abeni
authored andcommitted
amt: do not use amt->nr_tunnels outside of lock
amt->nr_tunnels is protected by amt->lock. But, amt_request_handler() has been using this variable without the amt->lock. So, it expands context of amt->lock in the amt_request_handler() to protect amt->nr_tunnels variable. Fixes: cbc21dc ("amt: add data plane of amt interface") Signed-off-by: Taehee Yoo <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent e882827 commit 9899184

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/net/amt.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,16 +2679,20 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
26792679
if (tunnel->ip4 == iph->saddr)
26802680
goto send;
26812681

2682+
spin_lock_bh(&amt->lock);
26822683
if (amt->nr_tunnels >= amt->max_tunnels) {
2684+
spin_unlock_bh(&amt->lock);
26832685
icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
26842686
return true;
26852687
}
26862688

26872689
tunnel = kzalloc(sizeof(*tunnel) +
26882690
(sizeof(struct hlist_head) * amt->hash_buckets),
26892691
GFP_ATOMIC);
2690-
if (!tunnel)
2692+
if (!tunnel) {
2693+
spin_unlock_bh(&amt->lock);
26912694
return true;
2695+
}
26922696

26932697
tunnel->source_port = udph->source;
26942698
tunnel->ip4 = iph->saddr;
@@ -2701,10 +2705,9 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
27012705

27022706
INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire);
27032707

2704-
spin_lock_bh(&amt->lock);
27052708
list_add_tail_rcu(&tunnel->list, &amt->tunnel_list);
27062709
tunnel->key = amt->key;
2707-
amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true);
2710+
__amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true);
27082711
amt->nr_tunnels++;
27092712
mod_delayed_work(amt_wq, &tunnel->gc_wq,
27102713
msecs_to_jiffies(amt_gmi(amt)));

0 commit comments

Comments
 (0)