Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2999608ybi; Mon, 17 Jun 2019 14:22:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqznY5ohehBjn4LkrLc7oj3J7AgaoJEL2CluQqChE2Oj9+Lz9TpLnyBNMZgkgQjzoD95Yf5a X-Received: by 2002:a17:90a:1b0c:: with SMTP id q12mr1174665pjq.76.1560806562958; Mon, 17 Jun 2019 14:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560806562; cv=none; d=google.com; s=arc-20160816; b=Wt7ODaCpa98jWHUGAPl36m6SXTJVeR4hdG5ic35bFTzKhTxJD4YdvGiDKhiaidxTQr 4b0FP9H39LlnJKnJVyn8GuQffjJ2CPwmfnz5i5fhEkquQ5zgS/2yN3+R7oJrARxOhT/v X7zcnYF4hDPdV95nl8T0Y7AcB0G41KFcMFvbNfFQOH+RddHTI1doaMyICIZ4VKLEFFX3 AMyzwOJWUAqI4iHGnT8L7WiZnvhlq3a1r3BDDwGoIjfsVPCqmyfDv2HtCOm7LBc5SYgS mhEsJzXV2zRg21YJP69uxaPTyrr1I76NLLCqR2BFJXhbURveatE/Q0TugCcaGd4bo03n GNYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k7JCw/ZQm7i7NjgnNCo2sLgu9jU/o1R0r5XxoXMDWRA=; b=L5VaWictsGRJj2oET6DCoa+jAYcDj7//T10mRhSgHP4KNzzMI+x7uJPxb32uKPkbA2 6M4tCfottII//mXSGMGtHVAjI9uuZAt+duBX4viGz8Lz0zLcb8U6uNFYUkVQoMfftDmp TKE6VRsOYmsLQetkfXumRoofaqpKZMPBmBWNwZmz68q51qaoXFiyIPFS7WoLInHP7rDf y4aCC09DNQGnr51RaiC2h7znt7FqpWaQ/fJl7z82r75KKs3wVEbWo5IaIlzwSqDvSDdK CLags0T5xkBcsXerN7cyyGuA3xrSJELtSgQ2hRISHmmxMlYApaGUlu5eWoaqhPYfY4r2 KpDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZBan9yxP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11si10914559plo.360.2019.06.17.14.22.27; Mon, 17 Jun 2019 14:22:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZBan9yxP; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729387AbfFQVVg (ORCPT + 99 others); Mon, 17 Jun 2019 17:21:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:46098 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728904AbfFQVVf (ORCPT ); Mon, 17 Jun 2019 17:21:35 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3E54C2089E; Mon, 17 Jun 2019 21:21:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806493; bh=C84SnixK0vcc3hScpam/cnjcq0vDT3Nt64nsnV6q0jU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZBan9yxPiJj9fzEdBEIuBopjT5n7pjAKRudWXFGjH0/V+KvBnOonHpSO9Afvf76U2 Gr9nfSiTronU9HtOfYZdCz3DQIBHq/LC6YhvGzEC8sTwES7FH2gJC2IWnTA5gvyWsu tDaUpqcnc7obGDKkn5QSJmFDMLgJ1hbvRoMGU2Jo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+9437020c82413d00222d@syzkaller.appspotmail.com, Takashi Iwai , Sasha Levin Subject: [PATCH 5.1 044/115] ALSA: seq: Fix race of get-subscription call vs port-delete ioctls Date: Mon, 17 Jun 2019 23:09:04 +0200 Message-Id: <20190617210802.304772741@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 Signed-off-by: Sasha Levin --- 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 b3280e81bfd1..8599f2937ac1 100644 --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -1900,20 +1900,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 da31aa8e216e..16289aefb443 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