From patchwork Wed Jan 22 09:28:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 233613 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=ham 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 5BCBAC3F68F for ; Wed, 22 Jan 2020 09:31:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A08F2467B for ; Wed, 22 Jan 2020 09:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579685508; bh=DN5vqh6v+nIiSQbA8kK8Jk4vhjmMEXzuqJFLeL/FgA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gKEI83aFacZ6KwIZ5dufFeoKZm2SydlnZawTdJ/LyphY99bA0ZlmAjcFgeTUVq4Fp lt5srbWw7B4ISk6qVFKG9q1DgRKp8XCjenUuC1U14bnDT/w0gFi0jm4Vvt0p4eVIXg 8MCnlZqUXDFpB7qjMqf+tBX7Q4rgaeeZOZ+d2/uU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729273AbgAVJbr (ORCPT ); Wed, 22 Jan 2020 04:31:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:43944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729143AbgAVJbl (ORCPT ); Wed, 22 Jan 2020 04:31:41 -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 2B36024673; Wed, 22 Jan 2020 09:31:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579685500; bh=DN5vqh6v+nIiSQbA8kK8Jk4vhjmMEXzuqJFLeL/FgA4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ilctjNVf53QXlXAcW8jPb3Aj9XyCgN9pwpjTFcEr7wAKn7G2/G+MNcxhBqX++edcN +3Fp7Nz/3teaz1oi6mf943BrC+YFcjqkFxmwN3qisDVi3UxVgvN+MF0mlCGaIA5elr lu6hogVb8pTgZSnXVudL8E0NAJSQdJS+gdNew7eM= 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.4 40/76] ALSA: seq: Fix racy access for queue timer in proc read Date: Wed, 22 Jan 2020 10:28:56 +0100 Message-Id: <20200122092756.471783768@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092751.587775548@linuxfoundation.org> References: <20200122092751.587775548@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 @@ -484,15 +484,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); } }