net: sctp: Convert timers to use timer_setup()

In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly.

Cc: Vlad Yasevich <vyasevich@gmail.com>
Cc: Neil Horman <nhorman@tuxdriver.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: linux-sctp@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Kees Cook 2017-10-24 01:45:31 -07:00 committed by David S. Miller
parent a4cdd9ff1f
commit 9c3b575183
5 changed files with 66 additions and 52 deletions

View File

@ -72,7 +72,7 @@ typedef enum sctp_disposition (sctp_state_fn_t) (
const union sctp_subtype type,
void *arg,
struct sctp_cmd_seq *commands);
typedef void (sctp_timer_event_t) (unsigned long);
typedef void (sctp_timer_event_t) (struct timer_list *);
struct sctp_sm_table_entry {
sctp_state_fn_t *fn;
const char *name;
@ -314,10 +314,10 @@ int sctp_do_sm(struct net *net, enum sctp_event event_type,
void *event_arg, gfp_t gfp);
/* 2nd level prototypes */
void sctp_generate_t3_rtx_event(unsigned long peer);
void sctp_generate_heartbeat_event(unsigned long peer);
void sctp_generate_reconf_event(unsigned long peer);
void sctp_generate_proto_unreach_event(unsigned long peer);
void sctp_generate_t3_rtx_event(struct timer_list *t);
void sctp_generate_heartbeat_event(struct timer_list *t);
void sctp_generate_reconf_event(struct timer_list *t);
void sctp_generate_proto_unreach_event(struct timer_list *t);
void sctp_ootb_pkt_free(struct sctp_packet *packet);

View File

@ -149,8 +149,7 @@ static struct sctp_association *sctp_association_init(
/* Initializes the timers */
for (i = SCTP_EVENT_TIMEOUT_NONE; i < SCTP_NUM_TIMEOUT_TYPES; ++i)
setup_timer(&asoc->timers[i], sctp_timer_events[i],
(unsigned long)asoc);
timer_setup(&asoc->timers[i], sctp_timer_events[i], 0);
/* Pull default initialization values from the sock options.
* Note: This assumes that the values have already been

View File

@ -622,9 +622,9 @@ static void sctp_v4_ecn_capable(struct sock *sk)
INET_ECN_xmit(sk);
}
static void sctp_addr_wq_timeout_handler(unsigned long arg)
static void sctp_addr_wq_timeout_handler(struct timer_list *t)
{
struct net *net = (struct net *)arg;
struct net *net = from_timer(net, t, sctp.addr_wq_timer);
struct sctp_sockaddr_entry *addrw, *temp;
struct sctp_sock *sp;
@ -1304,8 +1304,7 @@ static int __net_init sctp_defaults_init(struct net *net)
INIT_LIST_HEAD(&net->sctp.auto_asconf_splist);
spin_lock_init(&net->sctp.addr_wq_lock);
net->sctp.addr_wq_timer.expires = 0;
setup_timer(&net->sctp.addr_wq_timer, sctp_addr_wq_timeout_handler,
(unsigned long)net);
timer_setup(&net->sctp.addr_wq_timer, sctp_addr_wq_timeout_handler, 0);
return 0;

View File

@ -243,9 +243,10 @@ nomem:
/* When the T3-RTX timer expires, it calls this function to create the
* relevant state machine event.
*/
void sctp_generate_t3_rtx_event(unsigned long peer)
void sctp_generate_t3_rtx_event(struct timer_list *t)
{
struct sctp_transport *transport = (struct sctp_transport *) peer;
struct sctp_transport *transport =
from_timer(transport, t, T3_rtx_timer);
struct sctp_association *asoc = transport->asoc;
struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk);
@ -319,50 +320,63 @@ out_unlock:
sctp_association_put(asoc);
}
static void sctp_generate_t1_cookie_event(unsigned long data)
static void sctp_generate_t1_cookie_event(struct timer_list *t)
{
struct sctp_association *asoc = (struct sctp_association *) data;
struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_T1_COOKIE]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_COOKIE);
}
static void sctp_generate_t1_init_event(unsigned long data)
static void sctp_generate_t1_init_event(struct timer_list *t)
{
struct sctp_association *asoc = (struct sctp_association *) data;
struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_T1_INIT]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T1_INIT);
}
static void sctp_generate_t2_shutdown_event(unsigned long data)
static void sctp_generate_t2_shutdown_event(struct timer_list *t)
{
struct sctp_association *asoc = (struct sctp_association *) data;
struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T2_SHUTDOWN);
}
static void sctp_generate_t4_rto_event(unsigned long data)
static void sctp_generate_t4_rto_event(struct timer_list *t)
{
struct sctp_association *asoc = (struct sctp_association *) data;
struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_T4_RTO]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_T4_RTO);
}
static void sctp_generate_t5_shutdown_guard_event(unsigned long data)
static void sctp_generate_t5_shutdown_guard_event(struct timer_list *t)
{
struct sctp_association *asoc = (struct sctp_association *)data;
struct sctp_association *asoc =
from_timer(asoc, t,
timers[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]);
sctp_generate_timeout_event(asoc,
SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD);
} /* sctp_generate_t5_shutdown_guard_event() */
static void sctp_generate_autoclose_event(unsigned long data)
static void sctp_generate_autoclose_event(struct timer_list *t)
{
struct sctp_association *asoc = (struct sctp_association *) data;
struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_AUTOCLOSE]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_AUTOCLOSE);
}
/* Generate a heart beat event. If the sock is busy, reschedule. Make
* sure that the transport is still valid.
*/
void sctp_generate_heartbeat_event(unsigned long data)
void sctp_generate_heartbeat_event(struct timer_list *t)
{
struct sctp_transport *transport = (struct sctp_transport *) data;
struct sctp_transport *transport = from_timer(transport, t, hb_timer);
struct sctp_association *asoc = transport->asoc;
struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk);
@ -405,9 +419,10 @@ out_unlock:
/* Handle the timeout of the ICMP protocol unreachable timer. Trigger
* the correct state machine transition that will close the association.
*/
void sctp_generate_proto_unreach_event(unsigned long data)
void sctp_generate_proto_unreach_event(struct timer_list *t)
{
struct sctp_transport *transport = (struct sctp_transport *)data;
struct sctp_transport *transport =
from_timer(transport, t, proto_unreach_timer);
struct sctp_association *asoc = transport->asoc;
struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk);
@ -439,9 +454,10 @@ out_unlock:
}
/* Handle the timeout of the RE-CONFIG timer. */
void sctp_generate_reconf_event(unsigned long data)
void sctp_generate_reconf_event(struct timer_list *t)
{
struct sctp_transport *transport = (struct sctp_transport *)data;
struct sctp_transport *transport =
from_timer(transport, t, reconf_timer);
struct sctp_association *asoc = transport->asoc;
struct sock *sk = asoc->base.sk;
struct net *net = sock_net(sk);
@ -471,24 +487,27 @@ out_unlock:
}
/* Inject a SACK Timeout event into the state machine. */
static void sctp_generate_sack_event(unsigned long data)
static void sctp_generate_sack_event(struct timer_list *t)
{
struct sctp_association *asoc = (struct sctp_association *)data;
struct sctp_association *asoc =
from_timer(asoc, t, timers[SCTP_EVENT_TIMEOUT_SACK]);
sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
}
sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
NULL,
sctp_generate_t1_cookie_event,
sctp_generate_t1_init_event,
sctp_generate_t2_shutdown_event,
NULL,
sctp_generate_t4_rto_event,
sctp_generate_t5_shutdown_guard_event,
NULL,
NULL,
sctp_generate_sack_event,
sctp_generate_autoclose_event,
[SCTP_EVENT_TIMEOUT_NONE] = NULL,
[SCTP_EVENT_TIMEOUT_T1_COOKIE] = sctp_generate_t1_cookie_event,
[SCTP_EVENT_TIMEOUT_T1_INIT] = sctp_generate_t1_init_event,
[SCTP_EVENT_TIMEOUT_T2_SHUTDOWN] = sctp_generate_t2_shutdown_event,
[SCTP_EVENT_TIMEOUT_T3_RTX] = NULL,
[SCTP_EVENT_TIMEOUT_T4_RTO] = sctp_generate_t4_rto_event,
[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD] =
sctp_generate_t5_shutdown_guard_event,
[SCTP_EVENT_TIMEOUT_HEARTBEAT] = NULL,
[SCTP_EVENT_TIMEOUT_RECONF] = NULL,
[SCTP_EVENT_TIMEOUT_SACK] = sctp_generate_sack_event,
[SCTP_EVENT_TIMEOUT_AUTOCLOSE] = sctp_generate_autoclose_event,
};

View File

@ -87,14 +87,11 @@ static struct sctp_transport *sctp_transport_init(struct net *net,
INIT_LIST_HEAD(&peer->send_ready);
INIT_LIST_HEAD(&peer->transports);
setup_timer(&peer->T3_rtx_timer, sctp_generate_t3_rtx_event,
(unsigned long)peer);
setup_timer(&peer->hb_timer, sctp_generate_heartbeat_event,
(unsigned long)peer);
setup_timer(&peer->reconf_timer, sctp_generate_reconf_event,
(unsigned long)peer);
setup_timer(&peer->proto_unreach_timer,
sctp_generate_proto_unreach_event, (unsigned long)peer);
timer_setup(&peer->T3_rtx_timer, sctp_generate_t3_rtx_event, 0);
timer_setup(&peer->hb_timer, sctp_generate_heartbeat_event, 0);
timer_setup(&peer->reconf_timer, sctp_generate_reconf_event, 0);
timer_setup(&peer->proto_unreach_timer,
sctp_generate_proto_unreach_event, 0);
/* Initialize the 64-bit random nonce sent with heartbeat. */
get_random_bytes(&peer->hb_nonce, sizeof(peer->hb_nonce));