Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4627381ybl; Wed, 22 Jan 2020 01:33:17 -0800 (PST) X-Google-Smtp-Source: APXvYqx8jBU4iaP8hPOTTRy+9OV6p4+/sJuLhjcXzqq7FeV9p8NOdFfWrDR6Xqc554/dgx7u9b7H X-Received: by 2002:a9d:2de5:: with SMTP id g92mr6665686otb.217.1579685596995; Wed, 22 Jan 2020 01:33:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579685596; cv=none; d=google.com; s=arc-20160816; b=UHqEpd6t3HmPDXox3VUx1sqDdPcPweeywhczIRKXbeGfcdqPck4UP0iAEAxLhKgRGE 33rtBzUqjjihOTXpj464WXrPuI/WwNEUFuL4zI5d6Q+yJ8UoLFMUUBIYvehj2Uxmjl7J lHUuxQ7anjfLHymZb8YXRu/eykYkgGYCq6RgrHUFk18L2Pb9aTT5WMggubMRG/QFYkTF xSZ7VsjAbqLPusZC2w+3n0oib21n7Fg+M4ir8ao5UP9e1vYT40fQMCBH9+C/u0VCmaKC J2A8wo2aWmLN9MQ4enWZuJqyFkk2xxeWNJqh+n59KsMHzdkm/idrFYfq6PUP+0D6LMBe yziw== 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=CEweWuQM4jq1eApjOLNU4pGxJ8tXvZT9qmq1xax1IoE=; b=cQx3dUA6aKW7R8U1Xc6nSyrRlSLu5m/2YaFtNql4Chr9k2d2CkuLeJXYbByLYzHE2A xTt07QekOq3tDjtQC1qb/8BWXUVkHNJqB6m4cbvDSeuDTrAMpoBvijcVFLGvsonR9kzq ip1o5b7xEGduWEFCUrUElCnoc6j7YE0HJ2ZMFRBm98WmdKPPAPJ9i9BNfjTUtgvIfwx2 gclikGtmnFTat9Q2W0B2rn8pBFp96I84lTbFJHkcJ7a5B3dB35r2yJJmNdQ2wIWwr7jt +jurz9NsV2M951E/WND+rChsJZOumEZwNpWG5hiO69TG5ohtjd1wW96rQOwhObAMbw6M L8iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ilctjNVf; 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 m26si23472698otn.307.2020.01.22.01.33.05; Wed, 22 Jan 2020 01:33:16 -0800 (PST) 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=ilctjNVf; 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 S1729093AbgAVJbx (ORCPT + 99 others); Wed, 22 Jan 2020 04:31:53 -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 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 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); } }