All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Takashi Iwai <tiwai@suse.de>,
	syzbot+9437020c82413d00222d@syzkaller.appspotmail.com,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH AUTOSEL 4.9 03/17] ALSA: seq: Fix race of get-subscription call vs port-delete ioctls
Date: Tue,  4 Jun 2019 19:24:44 -0400	[thread overview]
Message-ID: <20190604232459.7745-3-sashal@kernel.org> (raw)
In-Reply-To: <20190604232459.7745-1-sashal@kernel.org>

From: Takashi Iwai <tiwai@suse.de>

[ Upstream commit 2eabc5ec8ab4d4748a82050dfcb994119b983750 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 sound/core/seq/seq_clientmgr.c | 10 ++--------
 sound/core/seq/seq_ports.c     | 13 ++++++++-----
 sound/core/seq/seq_ports.h     |  5 +++--
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c
index 3b1b2e9fb33e..881c965555c5 100644
--- a/sound/core/seq/seq_clientmgr.c
+++ b/sound/core/seq/seq_clientmgr.c
@@ -1905,20 +1905,14 @@ static int snd_seq_ioctl_get_subscription(struct snd_seq_client *client,
 	int result;
 	struct snd_seq_client *sender = NULL;
 	struct snd_seq_client_port *sport = NULL;
-	struct snd_seq_subscribers *p;
 
 	result = -EINVAL;
 	if ((sender = snd_seq_client_use_ptr(subs->sender.client)) == NULL)
 		goto __end;
 	if ((sport = snd_seq_port_use_ptr(sender, subs->sender.port)) == NULL)
 		goto __end;
-	p = snd_seq_port_get_subscription(&sport->c_src, &subs->dest);
-	if (p) {
-		result = 0;
-		*subs = p->info;
-	} else
-		result = -ENOENT;
-
+	result = snd_seq_port_get_subscription(&sport->c_src, &subs->dest,
+					       subs);
       __end:
       	if (sport)
 		snd_seq_port_unlock(sport);
diff --git a/sound/core/seq/seq_ports.c b/sound/core/seq/seq_ports.c
index f04714d70bf7..faf7ceffbeca 100644
--- a/sound/core/seq/seq_ports.c
+++ b/sound/core/seq/seq_ports.c
@@ -635,20 +635,23 @@ int snd_seq_port_disconnect(struct snd_seq_client *connector,
 
 
 /* get matched subscriber */
-struct snd_seq_subscribers *snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
-							  struct snd_seq_addr *dest_addr)
+int snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
+				  struct snd_seq_addr *dest_addr,
+				  struct snd_seq_port_subscribe *subs)
 {
-	struct snd_seq_subscribers *s, *found = NULL;
+	struct snd_seq_subscribers *s;
+	int err = -ENOENT;
 
 	down_read(&src_grp->list_mutex);
 	list_for_each_entry(s, &src_grp->list_head, src_list) {
 		if (addr_match(dest_addr, &s->info.dest)) {
-			found = s;
+			*subs = s->info;
+			err = 0;
 			break;
 		}
 	}
 	up_read(&src_grp->list_mutex);
-	return found;
+	return err;
 }
 
 /*
diff --git a/sound/core/seq/seq_ports.h b/sound/core/seq/seq_ports.h
index 26bd71f36c41..06003b36652e 100644
--- a/sound/core/seq/seq_ports.h
+++ b/sound/core/seq/seq_ports.h
@@ -135,7 +135,8 @@ int snd_seq_port_subscribe(struct snd_seq_client_port *port,
 			   struct snd_seq_port_subscribe *info);
 
 /* get matched subscriber */
-struct snd_seq_subscribers *snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
-							  struct snd_seq_addr *dest_addr);
+int snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp,
+				  struct snd_seq_addr *dest_addr,
+				  struct snd_seq_port_subscribe *subs);
 
 #endif
-- 
2.20.1


  parent reply	other threads:[~2019-06-04 23:27 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 23:24 [PATCH AUTOSEL 4.9 01/17] x86/uaccess, kcov: Disable stack protector Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 02/17] ALSA: seq: Protect in-kernel ioctl calls with mutex Sasha Levin
2019-06-04 23:24 ` Sasha Levin [this message]
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 04/17] Revert "ALSA: seq: Protect in-kernel ioctl calls with mutex" Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 05/17] ALSA: seq: Cover unsubscribe_port() in list_mutex Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 06/17] driver core: platform: Fix the usage of platform device name(pdev->name) Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 07/17] Drivers: misc: fix out-of-bounds access in function param_set_kgdbts_var Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 08/17] configfs: fix possible use-after-free in configfs_register_group Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 09/17] ipc: prevent lockup on alloc_msg and free_msg Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 10/17] scsi: lpfc: add check for loss of ndlp when sending RRQ Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 11/17] arm64/mm: Inhibit huge-vmap with ptdump Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 12/17] scsi: bnx2fc: fix incorrect cast to u64 on shift operation Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 13/17] selftests/timers: Add missing fflush(stdout) calls sashal
2019-06-04 23:24   ` Sasha Levin
2019-06-04 23:24   ` Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 14/17] usbnet: ipheth: fix racing condition Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 15/17] usbnet: fix kernel crash after disconnect Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 16/17] KVM: x86/pmu: do not mask the value that is written to fixed PMUs Sasha Levin
2019-06-04 23:24 ` [PATCH AUTOSEL 4.9 17/17] KVM: s390: fix memory slot handling for KVM_SET_USER_MEMORY_REGION Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190604232459.7745-3-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+9437020c82413d00222d@syzkaller.appspotmail.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.