Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934071AbdDFJc0 (ORCPT ); Thu, 6 Apr 2017 05:32:26 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:51160 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754830AbdDFIkj (ORCPT ); Thu, 6 Apr 2017 04:40:39 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Vyukov , Takashi Iwai Subject: [PATCH 4.4 06/26] ALSA: seq: Fix race during FIFO resize Date: Thu, 6 Apr 2017 10:38:28 +0200 Message-Id: <20170406083604.654363280@linuxfoundation.org> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170406083604.362636628@linuxfoundation.org> References: <20170406083604.362636628@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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1199 Lines: 38 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit 2d7d54002e396c180db0c800c1046f0a3c471597 upstream. When a new event is queued while processing to resize the FIFO in snd_seq_fifo_clear(), it may lead to a use-after-free, as the old pool that is being queued gets removed. For avoiding this race, we need to close the pool to be deleted and sync its usage before actually deleting it. The issue was spotted by syzkaller. Reported-by: Dmitry Vyukov Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/seq/seq_fifo.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/sound/core/seq/seq_fifo.c +++ b/sound/core/seq/seq_fifo.c @@ -265,6 +265,10 @@ int snd_seq_fifo_resize(struct snd_seq_f /* NOTE: overflow flag is not cleared */ spin_unlock_irqrestore(&f->lock, flags); + /* close the old pool and wait until all users are gone */ + snd_seq_pool_mark_closing(oldpool); + snd_use_lock_sync(&f->use_lock); + /* release cells in old pool */ for (cell = oldhead; cell; cell = next) { next = cell->next;