Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1022087ybe; Wed, 4 Sep 2019 11:16:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJ9c4gwjErBmXCvLPqqEes8ZR6JYu0d+gOy7L6R/yySJYp9IEZprLyfpXQ2HK6NTCFG3Vt X-Received: by 2002:a17:90a:1c01:: with SMTP id s1mr3319168pjs.76.1567620988265; Wed, 04 Sep 2019 11:16:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620988; cv=none; d=google.com; s=arc-20160816; b=jmVJRSfalE3kPJgmjNv+IoH8qdGD86SP+KtlGw+Ulm99XAwJvMUbJWIbGoKT9ZfI11 RCWN1GMFxzsFAJ+miVCPsMCKnH6erLWd0XuSemaya8N01VLmMUJLlGuyMFLmqUu/dFxe F+nTqicrYBpwiUxbLXmna9M3ynJ7YMvUNquvA107ZWirEOzfmcQNVOxRgcmyvz0IT6LZ hqXrkxT+/4OrfSQQ+m9f30pphJoQNXj2G9E60+voJgrT5oli+fUtukGBT2vTlQ3ENp95 RrE8ylRXU5N2Otub9BXfJNrEJrPMJSjnk7Cw1QP0av6DNpEp+hHHWTQrYD6VT8yqF8F+ PfoA== 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=ko0qKdFbo8nDOltqnh6gSKPGgfnfJM1O8Hiib3SNm98=; b=bE18G9lQoYBIu1dyO47ERNMRlLA2KRzXt13d/mRDw2Lk8z1+ut4WF2K0WitQJJ4Q2J kqqwcUbxJX4RGMK31WZzE/lTUxN8Bz2/wAlGahtf9XP6vaDSnYKLAu04ZIm9sgiAn7XF u+r6jiDW5PCFIMimbIdcbLjRfKGxLrO16hLilPvweaqGMT4QMr/HAyLw5/wS9iykIGgQ X3dPU+N3DWnNp8xncjHxVWwvSBXdZxwYb7s4VoSFilOUX8W/fjFKpYSzv8418b1bQBp8 DsTXuGXIXPIDHGntN5Io0bG1CXkMsuqpnwzZMfYdJD3HQu4SM3s1HzawoM25E4cRWowx EpJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="g/MouZNs"; 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 x6si18263244pgq.473.2019.09.04.11.16.12; Wed, 04 Sep 2019 11:16:28 -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="g/MouZNs"; 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 S2390712AbfIDSNh (ORCPT + 99 others); Wed, 4 Sep 2019 14:13:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:58484 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390705AbfIDSNf (ORCPT ); Wed, 4 Sep 2019 14:13: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 C41502339E; Wed, 4 Sep 2019 18:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620814; bh=A2LNTAbowGHYsvP0o7t9CSW2UkgGnnhpFRXPYW18W8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g/MouZNsdau//ViHEeeebnp/BaB2Z0RlFD+TlAbM2LBDRqcZvdTndhH4xzELAg4UK NodVBqhYdHWXl9nhtkToHcu12mxx94OZ8XfGT4wLxGQUrHYnYPwWjHyVyPpn2S1GGF i1ZRFvYngvPT/ztonw3qGAT10HGe/Legf7V+MMwc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+4a75454b9ca2777f35c7@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 5.2 064/143] ALSA: seq: Fix potential concurrent access to the deleted pool Date: Wed, 4 Sep 2019 19:53:27 +0200 Message-Id: <20190904175316.576668488@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@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 From: Takashi Iwai commit 75545304eba6a3d282f923b96a466dc25a81e359 upstream. The input pool of a client might be deleted via the resize ioctl, the the access to it should be covered by the proper locks. Currently the only missing place is the call in snd_seq_ioctl_get_client_pool(), and this patch papers over it. Reported-by: syzbot+4a75454b9ca2777f35c7@syzkaller.appspotmail.com Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/seq/seq_clientmgr.c | 3 +-- sound/core/seq/seq_fifo.c | 17 +++++++++++++++++ sound/core/seq/seq_fifo.h | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -1835,8 +1835,7 @@ static int snd_seq_ioctl_get_client_pool if (cptr->type == USER_CLIENT) { info->input_pool = cptr->data.user.fifo_pool_size; info->input_free = info->input_pool; - if (cptr->data.user.fifo) - info->input_free = snd_seq_unused_cells(cptr->data.user.fifo->pool); + info->input_free = snd_seq_fifo_unused_cells(cptr->data.user.fifo); } else { info->input_pool = 0; info->input_free = 0; --- a/sound/core/seq/seq_fifo.c +++ b/sound/core/seq/seq_fifo.c @@ -263,3 +263,20 @@ int snd_seq_fifo_resize(struct snd_seq_f return 0; } + +/* get the number of unused cells safely */ +int snd_seq_fifo_unused_cells(struct snd_seq_fifo *f) +{ + unsigned long flags; + int cells; + + if (!f) + return 0; + + snd_use_lock_use(&f->use_lock); + spin_lock_irqsave(&f->lock, flags); + cells = snd_seq_unused_cells(f->pool); + spin_unlock_irqrestore(&f->lock, flags); + snd_use_lock_free(&f->use_lock); + return cells; +} --- a/sound/core/seq/seq_fifo.h +++ b/sound/core/seq/seq_fifo.h @@ -53,5 +53,7 @@ int snd_seq_fifo_poll_wait(struct snd_se /* resize pool in fifo */ int snd_seq_fifo_resize(struct snd_seq_fifo *f, int poolsize); +/* get the number of unused cells safely */ +int snd_seq_fifo_unused_cells(struct snd_seq_fifo *f); #endif