sctp: change to hold/put transport for proto_unreach_timer
authorXin Long <lucien.xin@gmail.com>
Sat, 14 Nov 2020 05:22:53 +0000 (13:22 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 24 Nov 2020 12:05:41 +0000 (13:05 +0100)
[ Upstream commit 057a10fa1f73d745c8e69aa54ab147715f5630ae ]

A call trace was found in Hangbin's Codenomicon testing with debug kernel:

  [ 2615.981988] ODEBUG: free active (active state 0) object type: timer_list hint: sctp_generate_proto_unreach_event+0x0/0x3a0 [sctp]
  [ 2615.995050] WARNING: CPU: 17 PID: 0 at lib/debugobjects.c:328 debug_print_object+0x199/0x2b0
  [ 2616.095934] RIP: 0010:debug_print_object+0x199/0x2b0
  [ 2616.191533] Call Trace:
  [ 2616.194265]  <IRQ>
  [ 2616.202068]  debug_check_no_obj_freed+0x25e/0x3f0
  [ 2616.207336]  slab_free_freelist_hook+0xeb/0x140
  [ 2616.220971]  kfree+0xd6/0x2c0
  [ 2616.224293]  rcu_do_batch+0x3bd/0xc70
  [ 2616.243096]  rcu_core+0x8b9/0xd00
  [ 2616.256065]  __do_softirq+0x23d/0xacd
  [ 2616.260166]  irq_exit+0x236/0x2a0
  [ 2616.263879]  smp_apic_timer_interrupt+0x18d/0x620
  [ 2616.269138]  apic_timer_interrupt+0xf/0x20
  [ 2616.273711]  </IRQ>

This is because it holds asoc when transport->proto_unreach_timer starts
and puts asoc when the timer stops, and without holding transport the
transport could be freed when the timer is still running.

So fix it by holding/putting transport instead for proto_unreach_timer
in transport, just like other timers in transport.

v1->v2:
  - Also use sctp_transport_put() for the "out_unlock:" path in
    sctp_generate_proto_unreach_event(), as Marcelo noticed.

Fixes: 50b5d6ad6382 ("sctp: Fix a race between ICMP protocol unreachable and connect()")
Reported-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Link: https://lore.kernel.org/r/102788809b554958b13b95d33440f5448113b8d6.1605331373.git.lucien.xin@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/sctp/input.c
net/sctp/sm_sideeffect.c
net/sctp/transport.c

index 3c0affecf2726085ce7d5bdd8e75f81c153f75b1..fab6a34fb89f8814517d1d3b0b74cee6b997721f 100644 (file)
@@ -453,7 +453,7 @@ void sctp_icmp_proto_unreachable(struct sock *sk,
                else {
                        if (!mod_timer(&t->proto_unreach_timer,
                                                jiffies + (HZ/20)))
-                               sctp_association_hold(asoc);
+                               sctp_transport_hold(t);
                }
        } else {
                struct net *net = sock_net(sk);
@@ -462,7 +462,7 @@ void sctp_icmp_proto_unreachable(struct sock *sk,
                         "encountered!\n", __func__);
 
                if (del_timer(&t->proto_unreach_timer))
-                       sctp_association_put(asoc);
+                       sctp_transport_put(t);
 
                sctp_do_sm(net, SCTP_EVENT_T_OTHER,
                           SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH),
index 91f921afae343efe20ad1b0d8907d3846c3871a6..1a1128355d8636ef01e216d69f609e8c0fba7abd 100644 (file)
@@ -418,7 +418,7 @@ void sctp_generate_proto_unreach_event(unsigned long data)
                /* Try again later.  */
                if (!mod_timer(&transport->proto_unreach_timer,
                                jiffies + (HZ/20)))
-                       sctp_association_hold(asoc);
+                       sctp_transport_hold(transport);
                goto out_unlock;
        }
 
@@ -434,7 +434,7 @@ void sctp_generate_proto_unreach_event(unsigned long data)
 
 out_unlock:
        bh_unlock_sock(sk);
-       sctp_association_put(asoc);
+       sctp_transport_put(transport);
 }
 
  /* Handle the timeout of the RE-CONFIG timer. */
index 4c55b759a58ec17a21c47adea7b9284f50a41d91..af56651169b2fd9f45e6aee5695fcf8d8755bccb 100644 (file)
@@ -151,7 +151,7 @@ void sctp_transport_free(struct sctp_transport *transport)
 
        /* Delete the ICMP proto unreachable timer if it's active. */
        if (del_timer(&transport->proto_unreach_timer))
-               sctp_association_put(transport->asoc);
+               sctp_transport_put(transport);
 
        sctp_transport_put(transport);
 }