Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3006348ybi; Mon, 17 Jun 2019 14:31:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnJeep9j5J1qnsP2co+GouSCscHyNhYxcDjk1E0G01Em9DyCEukoexPND1/2z4L7O5WGx3 X-Received: by 2002:a17:902:d887:: with SMTP id b7mr3760916plz.28.1560807115500; Mon, 17 Jun 2019 14:31:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807115; cv=none; d=google.com; s=arc-20160816; b=WAndRzQhtdWLVEt0XJZAAyPiCbtJuqFK1gXyXClhKwbX6q0gkg9I4VQmTkrK5/DcgI ndQp+jtpEmzECzfJJNywaBwrA9wi6CPNzdAr8XhJ19GNceIA0ZeLqEJMx6DeqazFvPa/ SEUpmRzlUS2Xg5X65iCPzR57QS2TNaxARLp01ulo4OwWHY/ZVU0zBSKHXHjDcE2E6ZwY h5aiMnREusea/5aWZJoNx5emiz6hL28oUhdUbV/+GPH1+Qr6FQ+vRbcqlvnybHgV6rey WNzTuYETt7vxs7g9i7rfCbMmhNhUdT7o8v5KFAr9K22MbzXdDhkBXIuWIGVnkzmgsYM3 4Kpg== 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=NV9HTza57c7q3moL64FFgOPXgQm8pnLuL7cssiKII9w=; b=ziO9H0Sgh8uGze90V1b7vjDQ5xgFZLLTYh5uzRKgNx6577XxORIQcJHjrAM8nnFsJn JZNfk5HcpXke2X/Qng5ZzFFR98mFDtzLJOxuRveDKBIzxRPf9uFX5GDzCBewzJB4HSeX avE7EuBGj3fAni1IWaYdz95hztJpKBvEl/u9k70dHwEzI6j2ta55zKg33NVpTnfOtXG4 W5/gdCU6f55YegH4MP3UJ5r3RjKNhnQ2oumoG+Ko64HSIsH0ZOLVFByTrmKkFevsuWk2 dHNzZLzXapdBnXPxy/HfxAxabFt7h9VuCKxuRSEitoTJEtdq2HwA6BUQyxpIqzssc9/6 jXwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YMxFLr+G; 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 y4si10681027plk.357.2019.06.17.14.31.40; Mon, 17 Jun 2019 14:31:55 -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=YMxFLr+G; 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 S1730615AbfFQV2x (ORCPT + 99 others); Mon, 17 Jun 2019 17:28:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:55950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729031AbfFQV2t (ORCPT ); Mon, 17 Jun 2019 17:28:49 -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 34097204FD; Mon, 17 Jun 2019 21:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806928; bh=01JgqLU+q/jditVF0XnE6iIetBdTeaxf7YEBoD9AiAg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMxFLr+Gh/T3nvyFie3z1ngr0niiAbj8mK2n2/SfyOTDG+Zb1t3T3KpbfHFZRXjjE BvsE9jmyh7UUykoBmztOwBJhdSPS0GSGASJA+Vuj8OzuqF2XH5gT5U0FL7Ro9W/2pT Bta/TGe9RDMwXNPRXSFnbruSCOin4i8uuoFOrytg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+e4c8abb920efa77bace9@syzkaller.appspotmail.com, Takashi Iwai , Sasha Levin Subject: [PATCH 4.14 23/53] ALSA: seq: Protect in-kernel ioctl calls with mutex Date: Mon, 17 Jun 2019 23:10:06 +0200 Message-Id: <20190617210749.935047820@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210745.104187490@linuxfoundation.org> References: <20190617210745.104187490@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 feb689025fbb6f0aa6297d3ddf97de945ea4ad32 ] ALSA OSS sequencer calls the ioctl function indirectly via snd_seq_kernel_client_ctl(). While we already applied the protection against races between the normal ioctls and writes via the client's ioctl_mutex, this code path was left untouched. And this seems to be the cause of still remaining some rare UAF as spontaneously triggered by syzkaller. For the sake of robustness, wrap the ioctl_mutex also for the call via snd_seq_kernel_client_ctl(), too. Reported-by: syzbot+e4c8abb920efa77bace9@syzkaller.appspotmail.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/core/seq/seq_clientmgr.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sound/core/seq/seq_clientmgr.c b/sound/core/seq/seq_clientmgr.c index 3bcd7a2f0394..692631bd4a35 100644 --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -2348,14 +2348,19 @@ int snd_seq_kernel_client_ctl(int clientid, unsigned int cmd, void *arg) { const struct ioctl_handler *handler; struct snd_seq_client *client; + int err; client = clientptr(clientid); if (client == NULL) return -ENXIO; for (handler = ioctl_handlers; handler->cmd > 0; ++handler) { - if (handler->cmd == cmd) - return handler->func(client, arg); + if (handler->cmd == cmd) { + mutex_lock(&client->ioctl_mutex); + err = handler->func(client, arg); + mutex_unlock(&client->ioctl_mutex); + return err; + } } pr_debug("ALSA: seq unknown ioctl() 0x%x (type='%c', number=0x%02x)\n", -- 2.20.1