ALSA: seq: Cover unsubscribe_port() in list_mutex
authorTakashi Iwai <tiwai@suse.de>
Fri, 12 Apr 2019 09:37:19 +0000 (11:37 +0200)
committerTakashi Iwai <tiwai@suse.de>
Fri, 12 Apr 2019 10:50:10 +0000 (12:50 +0200)
The call of unsubscribe_port() which manages the group count and
module refcount from delete_and_unsubscribe_port() looks racy; it's
not covered by the group list lock, and it's likely a cause of the
reported unbalance at port deletion.  Let's move the call inside the
group list_mutex to plug the hole.

Reported-by: syzbot+e4c8abb920efa77bace9@syzkaller.appspotmail.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/seq/seq_ports.c

index d964d728681e5603074ce2b26b950254611eef9a..ac7556ab531c0816b733c9f4b04b1fe4e42c6237 100644 (file)
@@ -547,10 +547,10 @@ static void delete_and_unsubscribe_port(struct snd_seq_client *client,
                list_del_init(list);
        grp->exclusive = 0;
        write_unlock_irq(&grp->list_lock);
-       up_write(&grp->list_mutex);
 
        if (!empty)
                unsubscribe_port(client, port, grp, &subs->info, ack);
+       up_write(&grp->list_mutex);
 }
 
 /* connect two ports */