From patchwork Wed Jan 22 09:28:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233508 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62334C33CB6 for ; Wed, 22 Jan 2020 09:50:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FEE72467C for ; Wed, 22 Jan 2020 09:50:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579686627; bh=kkBMsYslEkYNPYzHKXDUibNKOCy004q3kA+dqlieGVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=HQxLvXSeUk61ya6wRQGl7P9+6to/XJ9bFxKF7gXpV+RXNjmKfex+aIRSt3S9pQw2r aAYQjBteqhu9YvpEpLQvd1nLTuAgb3r6tlH6ke2uWC/daQA3FOoFKhxC0RzzyIaAHI YQJQ0lzpOzTnoGtZKoO/9RP6DKhzPyczZCkUq2Rs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732448AbgAVJiX (ORCPT ); Wed, 22 Jan 2020 04:38:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:55046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729148AbgAVJiU (ORCPT ); Wed, 22 Jan 2020 04:38:20 -0500 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 1D58D2467F; Wed, 22 Jan 2020 09:38:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579685899; bh=kkBMsYslEkYNPYzHKXDUibNKOCy004q3kA+dqlieGVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CdJm9x9FqmtlOv962KcpLJf5pfaeL5cjdVUl9xox342Xztd8okNAstNA4Y4u4VHoH DsLhUF+2HrgHkKeZm4+m50jvsCnZdlFJRed/PoDfdclWr4XZ7kEGzKm+F3/uoJnnxN 4GIPXZGu46qmd4nwyhkBoljW6oAtpbhHO9bPnY2E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+2b2ef983f973e5c40943@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 4.14 04/65] ALSA: seq: Fix racy access for queue timer in proc read Date: Wed, 22 Jan 2020 10:28:49 +0100 Message-Id: <20200122092752.109061533@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092750.976732974@linuxfoundation.org> References: <20200122092750.976732974@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Takashi Iwai commit 60adcfde92fa40fcb2dbf7cc52f9b096e0cd109a upstream. snd_seq_info_timer_read() reads the information of the timer assigned for each queue, but it's done in a racy way which may lead to UAF as spotted by syzkaller. This patch applies the missing q->timer_mutex lock while accessing the timer object as well as a slight code change to adapt the standard coding style. Reported-by: syzbot+2b2ef983f973e5c40943@syzkaller.appspotmail.com Cc: Link: https://lore.kernel.org/r/20200115203733.26530-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/seq/seq_timer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) --- a/sound/core/seq/seq_timer.c +++ b/sound/core/seq/seq_timer.c @@ -479,15 +479,19 @@ void snd_seq_info_timer_read(struct snd_ q = queueptr(idx); if (q == NULL) continue; - if ((tmr = q->timer) == NULL || - (ti = tmr->timeri) == NULL) { - queuefree(q); - continue; - } + mutex_lock(&q->timer_mutex); + tmr = q->timer; + if (!tmr) + goto unlock; + ti = tmr->timeri; + if (!ti) + goto unlock; snd_iprintf(buffer, "Timer for queue %i : %s\n", q->queue, ti->timer->name); resolution = snd_timer_resolution(ti) * tmr->ticks; snd_iprintf(buffer, " Period time : %lu.%09lu\n", resolution / 1000000000, resolution % 1000000000); snd_iprintf(buffer, " Skew : %u / %u\n", tmr->skew, tmr->skew_base); +unlock: + mutex_unlock(&q->timer_mutex); queuefree(q); } }