Skip to content

Commit fbd0197

Browse files
lxindavem330
authored andcommitted
sctp: avoid running the sctp state machine recursively
Ying triggered a call trace when doing an asconf testing: BUG: scheduling while atomic: swapper/12/0/0x10000100 Call Trace: <IRQ> [<ffffffffa4375904>] dump_stack+0x19/0x1b [<ffffffffa436fcaf>] __schedule_bug+0x64/0x72 [<ffffffffa437b93a>] __schedule+0x9ba/0xa00 [<ffffffffa3cd5326>] __cond_resched+0x26/0x30 [<ffffffffa437bc4a>] _cond_resched+0x3a/0x50 [<ffffffffa3e22be8>] kmem_cache_alloc_node+0x38/0x200 [<ffffffffa423512d>] __alloc_skb+0x5d/0x2d0 [<ffffffffc0995320>] sctp_packet_transmit+0x610/0xa20 [sctp] [<ffffffffc098510e>] sctp_outq_flush+0x2ce/0xc00 [sctp] [<ffffffffc098646c>] sctp_outq_uncork+0x1c/0x20 [sctp] [<ffffffffc0977338>] sctp_cmd_interpreter.isra.22+0xc8/0x1460 [sctp] [<ffffffffc0976ad1>] sctp_do_sm+0xe1/0x350 [sctp] [<ffffffffc099443d>] sctp_primitive_ASCONF+0x3d/0x50 [sctp] [<ffffffffc0977384>] sctp_cmd_interpreter.isra.22+0x114/0x1460 [sctp] [<ffffffffc0976ad1>] sctp_do_sm+0xe1/0x350 [sctp] [<ffffffffc097b3a4>] sctp_assoc_bh_rcv+0xf4/0x1b0 [sctp] [<ffffffffc09840f1>] sctp_inq_push+0x51/0x70 [sctp] [<ffffffffc099732b>] sctp_rcv+0xa8b/0xbd0 [sctp] As it shows, the first sctp_do_sm() running under atomic context (NET_RX softirq) invoked sctp_primitive_ASCONF() that uses GFP_KERNEL flag later, and this flag is supposed to be used in non-atomic context only. Besides, sctp_do_sm() was called recursively, which is not expected. Vlad tried to fix this recursive call in Commit c078669 ("sctp: Fix oops when sending queued ASCONF chunks") by introducing a new command SCTP_CMD_SEND_NEXT_ASCONF. But it didn't work as this command is still used in the first sctp_do_sm() call, and sctp_primitive_ASCONF() will be called in this command again. To avoid calling sctp_do_sm() recursively, we send the next queued ASCONF not by sctp_primitive_ASCONF(), but by sctp_sf_do_prm_asconf() in the 1st sctp_do_sm() directly. Reported-by: Ying Xu <yinxu@redhat.com> Signed-off-by: Xin Long <lucien.xin@gmail.com> Acked-by: Neil Horman <nhorman@tuxdriver.com> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 37e9c08 commit fbd0197

3 files changed

Lines changed: 27 additions & 38 deletions

File tree

‎include/net/sctp/command.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ enum sctp_verb {
105105
SCTP_CMD_T1_RETRAN, /* Mark for retransmission after T1 timeout */
106106
SCTP_CMD_UPDATE_INITTAG, /* Update peer inittag */
107107
SCTP_CMD_SEND_MSG, /* Send the whole use message */
108-
SCTP_CMD_SEND_NEXT_ASCONF, /* Send the next ASCONF after ACK */
109108
SCTP_CMD_PURGE_ASCONF_QUEUE, /* Purge all asconf queues.*/
110109
SCTP_CMD_SET_ASOC, /* Restore association context */
111110
SCTP_CMD_LAST

‎net/sctp/sm_sideeffect.c‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,32 +1112,6 @@ static void sctp_cmd_send_msg(struct sctp_association *asoc,
11121112
}
11131113

11141114

1115-
/* Sent the next ASCONF packet currently stored in the association.
1116-
* This happens after the ASCONF_ACK was succeffully processed.
1117-
*/
1118-
static void sctp_cmd_send_asconf(struct sctp_association *asoc)
1119-
{
1120-
struct net *net = sock_net(asoc->base.sk);
1121-
1122-
/* Send the next asconf chunk from the addip chunk
1123-
* queue.
1124-
*/
1125-
if (!list_empty(&asoc->addip_chunk_list)) {
1126-
struct list_head *entry = asoc->addip_chunk_list.next;
1127-
struct sctp_chunk *asconf = list_entry(entry,
1128-
struct sctp_chunk, list);
1129-
list_del_init(entry);
1130-
1131-
/* Hold the chunk until an ASCONF_ACK is received. */
1132-
sctp_chunk_hold(asconf);
1133-
if (sctp_primitive_ASCONF(net, asoc, asconf))
1134-
sctp_chunk_free(asconf);
1135-
else
1136-
asoc->addip_last_asconf = asconf;
1137-
}
1138-
}
1139-
1140-
11411115
/* These three macros allow us to pull the debugging code out of the
11421116
* main flow of sctp_do_sm() to keep attention focused on the real
11431117
* functionality there.
@@ -1783,9 +1757,6 @@ static int sctp_cmd_interpreter(enum sctp_event_type event_type,
17831757
}
17841758
sctp_cmd_send_msg(asoc, cmd->obj.msg, gfp);
17851759
break;
1786-
case SCTP_CMD_SEND_NEXT_ASCONF:
1787-
sctp_cmd_send_asconf(asoc);
1788-
break;
17891760
case SCTP_CMD_PURGE_ASCONF_QUEUE:
17901761
sctp_asconf_queue_teardown(asoc);
17911762
break;

‎net/sctp/sm_statefuns.c‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3824,6 +3824,29 @@ enum sctp_disposition sctp_sf_do_asconf(struct net *net,
38243824
return SCTP_DISPOSITION_CONSUME;
38253825
}
38263826

3827+
static enum sctp_disposition sctp_send_next_asconf(
3828+
struct net *net,
3829+
const struct sctp_endpoint *ep,
3830+
struct sctp_association *asoc,
3831+
const union sctp_subtype type,
3832+
struct sctp_cmd_seq *commands)
3833+
{
3834+
struct sctp_chunk *asconf;
3835+
struct list_head *entry;
3836+
3837+
if (list_empty(&asoc->addip_chunk_list))
3838+
return SCTP_DISPOSITION_CONSUME;
3839+
3840+
entry = asoc->addip_chunk_list.next;
3841+
asconf = list_entry(entry, struct sctp_chunk, list);
3842+
3843+
list_del_init(entry);
3844+
sctp_chunk_hold(asconf);
3845+
asoc->addip_last_asconf = asconf;
3846+
3847+
return sctp_sf_do_prm_asconf(net, ep, asoc, type, asconf, commands);
3848+
}
3849+
38273850
/*
38283851
* ADDIP Section 4.3 General rules for address manipulation
38293852
* When building TLV parameters for the ASCONF Chunk that will add or
@@ -3915,14 +3938,10 @@ enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net,
39153938
SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
39163939

39173940
if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
3918-
asconf_ack)) {
3919-
/* Successfully processed ASCONF_ACK. We can
3920-
* release the next asconf if we have one.
3921-
*/
3922-
sctp_add_cmd_sf(commands, SCTP_CMD_SEND_NEXT_ASCONF,
3923-
SCTP_NULL());
3924-
return SCTP_DISPOSITION_CONSUME;
3925-
}
3941+
asconf_ack))
3942+
return sctp_send_next_asconf(net, ep,
3943+
(struct sctp_association *)asoc,
3944+
type, commands);
39263945

39273946
abort = sctp_make_abort(asoc, asconf_ack,
39283947
sizeof(struct sctp_errhdr));

0 commit comments

Comments
 (0)