Skip to content

Commit 6fadb49

Browse files
committed
ALSA: seq: Set upper limit of processed events
Currently ALSA sequencer core tries to process the queued events as much as possible when they become dispatchable. If applications try to queue too massive events to be processed at the very same timing, the sequencer core would still try to process such all events, either in the interrupt context or via some notifier; in either away, it might be a cause of RCU stall or such problems. As a potential workaround for those problems, this patch adds the upper limit of the amount of events to be processed. The remaining events are processed in the next batch, so they won't be lost. For the time being, it's limited up to 1000 events per queue, which should be high enough for any normal usages. Reported-by: Zqiang <qiang.zhang1211@gmail.com> Reported-by: syzbot+bb950e68b400ab4f65f8@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/20211102033222.3849-1-qiang.zhang1211@gmail.com Link: https://lore.kernel.org/r/20211207165146.2888-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 403c521 commit 6fadb49

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

sound/core/seq/seq_queue.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,15 @@ struct snd_seq_queue *snd_seq_queue_find_name(char *name)
235235

236236
/* -------------------------------------------------------- */
237237

238+
#define MAX_CELL_PROCESSES_IN_QUEUE 1000
239+
238240
void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
239241
{
240242
unsigned long flags;
241243
struct snd_seq_event_cell *cell;
242244
snd_seq_tick_time_t cur_tick;
243245
snd_seq_real_time_t cur_time;
246+
int processed = 0;
244247

245248
if (q == NULL)
246249
return;
@@ -263,6 +266,8 @@ void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
263266
if (!cell)
264267
break;
265268
snd_seq_dispatch_event(cell, atomic, hop);
269+
if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
270+
goto out; /* the rest processed at the next batch */
266271
}
267272

268273
/* Process time queue... */
@@ -272,14 +277,19 @@ void snd_seq_check_queue(struct snd_seq_queue *q, int atomic, int hop)
272277
if (!cell)
273278
break;
274279
snd_seq_dispatch_event(cell, atomic, hop);
280+
if (++processed >= MAX_CELL_PROCESSES_IN_QUEUE)
281+
goto out; /* the rest processed at the next batch */
275282
}
276283

284+
out:
277285
/* free lock */
278286
spin_lock_irqsave(&q->check_lock, flags);
279287
if (q->check_again) {
280288
q->check_again = 0;
281-
spin_unlock_irqrestore(&q->check_lock, flags);
282-
goto __again;
289+
if (processed < MAX_CELL_PROCESSES_IN_QUEUE) {
290+
spin_unlock_irqrestore(&q->check_lock, flags);
291+
goto __again;
292+
}
283293
}
284294
q->check_blocked = 0;
285295
spin_unlock_irqrestore(&q->check_lock, flags);

0 commit comments

Comments
 (0)