History

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.

Taehee Yoo committed 4 years ago

Commit 98991841 parent e8828271 file · +6 −3Browse files

Showing the changes to drivers (1 of 1 file). Show all

Unified · Split

drivers/net/amt.c+6−3
@@ -2679,7 +2679,9 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) · 2678 unmodified lines
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 }
@@ -2687,8 +2689,10 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb) · 1 unmodified line
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) · 6 unmodified lines
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)));