Skip to content

Commit 2eabc5e

Browse files
committed
ALSA: seq: Fix race of get-subscription call vs port-delete ioctls
The snd_seq_ioctl_get_subscription() retrieves the port subscriber information as a pointer, while the object isn't protected, hence it may be deleted before the actual reference. This race was spotted by syzkaller and may lead to a UAF. The fix is simply copying the data in the lookup function that performs in the rwsem to protect against the deletion. Reported-by: syzbot+9437020c82413d00222d@syzkaller.appspotmail.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent feb6890 commit 2eabc5e

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

‎sound/core/seq/seq_clientmgr.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,20 +1897,14 @@ static int snd_seq_ioctl_get_subscription(struct snd_seq_client *client,
18971897
int result;
18981898
struct snd_seq_client *sender = NULL;
18991899
struct snd_seq_client_port *sport = NULL;
1900-
struct snd_seq_subscribers *p;
19011900

19021901
result = -EINVAL;
19031902
if ((sender = snd_seq_client_use_ptr(subs->sender.client)) == NULL)
19041903
goto __end;
19051904
if ((sport = snd_seq_port_use_ptr(sender, subs->sender.port)) == NULL)
19061905
goto __end;
1907-
p = snd_seq_port_get_subscription(&sport->c_src, &subs->dest);
1908-
if (p) {
1909-
result = 0;
1910-
*subs = p->info;
1911-
} else
1912-
result = -ENOENT;
1913-
1906+
result = snd_seq_port_get_subscription(&sport->c_src, &subs->dest,
1907+
subs);
19141908
__end:
19151909
if (sport)
19161910
snd_seq_port_unlock(sport);

‎sound/core/seq/seq_ports.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,20 +632,23 @@ int snd_seq_port_disconnect(struct snd_seq_client *connector,
632632

633633

634634
/* get matched subscriber */
635-
struct snd_seq_subscribers *snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
636-
struct snd_seq_addr *dest_addr)
635+
int snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
636+
struct snd_seq_addr *dest_addr,
637+
struct snd_seq_port_subscribe *subs)
637638
{
638-
struct snd_seq_subscribers *s, *found = NULL;
639+
struct snd_seq_subscribers *s;
640+
int err = -ENOENT;
639641

640642
down_read(&src_grp->list_mutex);
641643
list_for_each_entry(s, &src_grp->list_head, src_list) {
642644
if (addr_match(dest_addr, &s->info.dest)) {
643-
found = s;
645+
*subs = s->info;
646+
err = 0;
644647
break;
645648
}
646649
}
647650
up_read(&src_grp->list_mutex);
648-
return found;
651+
return err;
649652
}
650653

651654
/*

‎sound/core/seq/seq_ports.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ int snd_seq_port_subscribe(struct snd_seq_client_port *port,
135135
struct snd_seq_port_subscribe *info);
136136

137137
/* get matched subscriber */
138-
struct snd_seq_subscribers *snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
139-
struct snd_seq_addr *dest_addr);
138+
int snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
139+
struct snd_seq_addr *dest_addr,
140+
struct snd_seq_port_subscribe *subs);
140141

141142
#endif

0 commit comments

Comments
 (0)