Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2335069ybz; Thu, 23 Apr 2020 16:14:28 -0700 (PDT) X-Google-Smtp-Source: APiQypJ6Ci7lyjF0Wwe3ZSkFsiqfUcBI4RjY9v6WLQfouPv7rgYpGryOF+7dXdDCGlqEYnHwQLu3 X-Received: by 2002:a05:6402:6cb:: with SMTP id n11mr4962474edy.210.1587683667983; Thu, 23 Apr 2020 16:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587683667; cv=none; d=google.com; s=arc-20160816; b=FtNvGzQyrofuH0SxxPJjFy3vAmL/ZuNsI07mowoc2dI0Y4x5stGGt1a5P0UojNJ8Pg TPQMW/zcff7Vttlac2wgdrV7l75tFxeYHRYX74AW8N0ds4Cqg2ueVdOduufn2/aJkLJU mG3YHWZnA6ZPoXtsNjK8mrLAfLaJU4Q1b9u+36lwBlYZcuDSTi5dwdxyzNlAT2v+Cdl/ M1H0yIFL1Qn4eKg/PZk9q/vbM4jdRL6LuGiksBmB0YQPORmjYGoWJX4FDCXuT6mfDYqw yVccwTO+XyQkviXa2QFMuQT6zzikALY48qbQSj4VQYX2wV0uebGeK8I37JJ8K/Qw7OF9 ebMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=MIJBihvB5zmD+AGa5Lekckk/93fg3T7GS1HDJbS2k6w=; b=tq2IFM5wADJmKJslNa4UYfHI2HT+wowaXaR5vSn5PKzxuTPe4t1KbcWZSgFFEF1b6h zAPMA+1JO3fdUz/WXFbyWvmpk3dwtmyb6C89YVmi+erwPur03i2nAdDytmVgodnDgUdF v8FtLWykpATiENGB1hIVcD2QWc0hStcUEDfm2R8IjVSF1CjUI65R/eclYx71yp579xy0 +BdUvuvkhA1tdT2PGbR50vNVTE8SjrYLy28HfavtfU3cev08XY7RdDfhnuzK5JmKj3bI T13cn9x10lFIEGOBQ6/y0bl/bF2HwS8OsD1EtTSEGJOX6uIb81EOi+3TcWtSltA5SYC/ 0tmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cc27si2318810edb.544.2020.04.23.16.14.04; Thu, 23 Apr 2020 16:14:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728573AbgDWXL3 (ORCPT + 99 others); Thu, 23 Apr 2020 19:11:29 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50156 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728530AbgDWXGw (ORCPT ); Thu, 23 Apr 2020 19:06:52 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvb-0004n6-0u; Fri, 24 Apr 2020 00:06:43 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvW-00E6wt-PO; Fri, 24 Apr 2020 00:06:38 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , syzbot+2b2ef983f973e5c40943@syzkaller.appspotmail.com, "Takashi Iwai" Date: Fri, 24 Apr 2020 00:06:54 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 187/245] ALSA: seq: Fix racy access for queue timer in proc read In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ 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 Link: https://lore.kernel.org/r/20200115203733.26530-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Ben Hutchings --- 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); } }