Received: by 10.223.176.5 with SMTP id f5csp970566wra; Fri, 2 Feb 2018 09:03:09 -0800 (PST) X-Google-Smtp-Source: AH8x224mDM7Z8hQBVRdTzqCgBPJ235hm4Iw1axiTqO2kF/9yDBLfJmrw+WnpJ1gB4XtBfqi87E0O X-Received: by 2002:a17:902:5aca:: with SMTP id g10-v6mr19978939plm.334.1517590989591; Fri, 02 Feb 2018 09:03:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517590989; cv=none; d=google.com; s=arc-20160816; b=gymtfwxbcKq1qWBxsXxAfXtbqGvOz7dyQeKF/zJXIAL41ZbEPiHAr/3sSJkgWO4DFM nN0GT72Zv6hZJqQJ/O5TxNbchddULUBGH0wYWbINEjooyquJZnb/+b1cfJ+CjHliUo/p lqbM/VfUJ0IGvQCLv3e3rXCd/B1jmsJiuMmYuL9PQpzMs67n5in5q9MfCJEDORq199Wc 4bLBMB1OyB5kkOh6xZS89oseIat9cOD+e1PqltO97igFRKwZLcKVewL06IwfQwuGsl+W XrY3yC8DhvDMgUkb9l+vQCkEW1GwXFelKVW0Ywk11agnrWuZYgDoUdaQRGfu5PDGVl4i zm7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hLl0kcmq+bNvjGOXJM7sTSoAQkTCuhbbnADjOh+9qcc=; b=vMwFU4oa8DziDUhHe00mFEgUL2mHa42LK/AE68zT/qLhZiB0SxQ4LeVxoMhoLcORkj 072wGnlEDebE+ix+LxHBDtEofqLvZ0hZ0budcfXrVUJbfyfZJPG3GjTxYMVl405U4d7e /+R/YOLzTUM+xC/KuWPTmcXL7sLtezPWFhex5WaleZhN0sWgzslCEmlEPph2MbklUMAr gu6JczPSLMQf4IKnlhiDVTjnLTC3pOyY4n9NJUS8TUQMQ926vPT6Atp/iopHr70mv3zs ua+Cv+1g2MEHQ7C3GcoUCoj1qa7jB/dO/2i4gJz/TdYj+0PHdcltPqZg1Bs+qy9B4OQX XT7g== ARC-Authentication-Results: i=1; mx.google.com; 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 b13si2116236pfm.305.2018.02.02.09.02.54; Fri, 02 Feb 2018 09:03:09 -0800 (PST) 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; 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 S1752569AbeBBRAK (ORCPT + 99 others); Fri, 2 Feb 2018 12:00:10 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:34518 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752518AbeBBQ7p (ORCPT ); Fri, 2 Feb 2018 11:59:45 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C567BDCF; Fri, 2 Feb 2018 16:59:44 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luo Quan , Kees Cook , Takashi Iwai , Ben Hutchings Subject: [PATCH 4.4 13/67] ALSA: seq: Make ioctls race-free Date: Fri, 2 Feb 2018 17:57:42 +0100 Message-Id: <20180202140816.773212940@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140815.091718203@linuxfoundation.org> References: <20180202140815.091718203@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit b3defb791b26ea0683a93a4f49c77ec45ec96f10 upstream. The ALSA sequencer ioctls have no protection against racy calls while the concurrent operations may lead to interfere with each other. As reported recently, for example, the concurrent calls of setting client pool with a combination of write calls may lead to either the unkillable dead-lock or UAF. As a slightly big hammer solution, this patch introduces the mutex to make each ioctl exclusive. Although this may reduce performance via parallel ioctl calls, usually it's not demanded for sequencer usages, hence it should be negligible. Reported-by: Luo Quan Reviewed-by: Kees Cook Reviewed-by: Greg Kroah-Hartman Signed-off-by: Takashi Iwai [bwh: Backported to 4.4: ioctl dispatch is done from snd_seq_do_ioctl(); take the mutex and add ret variable there.] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- sound/core/seq/seq_clientmgr.c | 10 ++++++++-- sound/core/seq/seq_clientmgr.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -236,6 +236,7 @@ static struct snd_seq_client *seq_create rwlock_init(&client->ports_lock); mutex_init(&client->ports_mutex); INIT_LIST_HEAD(&client->ports_list_head); + mutex_init(&client->ioctl_mutex); /* find free slot in the client table */ spin_lock_irqsave(&clients_lock, flags); @@ -2195,6 +2196,7 @@ static int snd_seq_do_ioctl(struct snd_s void __user *arg) { struct seq_ioctl_table *p; + int ret; switch (cmd) { case SNDRV_SEQ_IOCTL_PVERSION: @@ -2208,8 +2210,12 @@ static int snd_seq_do_ioctl(struct snd_s if (! arg) return -EFAULT; for (p = ioctl_tables; p->cmd; p++) { - if (p->cmd == cmd) - return p->func(client, arg); + if (p->cmd == cmd) { + mutex_lock(&client->ioctl_mutex); + ret = p->func(client, arg); + mutex_unlock(&client->ioctl_mutex); + return ret; + } } pr_debug("ALSA: seq unknown ioctl() 0x%x (type='%c', number=0x%02x)\n", cmd, _IOC_TYPE(cmd), _IOC_NR(cmd)); --- a/sound/core/seq/seq_clientmgr.h +++ b/sound/core/seq/seq_clientmgr.h @@ -59,6 +59,7 @@ struct snd_seq_client { struct list_head ports_list_head; rwlock_t ports_lock; struct mutex ports_mutex; + struct mutex ioctl_mutex; int convert32; /* convert 32->64bit */ /* output pool */