From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.kernel.org ([198.145.29.99]:45806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751804AbeEQIyT (ORCPT ); Thu, 17 May 2018 04:54:19 -0400 Date: Thu, 17 May 2018 10:54:00 +0200 From: Greg Kroah-Hartman To: Takashi Iwai Cc: Ben Hutchings , linux-kernel@vger.kernel.org, stable@vger.kernel.org, syzbot+8e62ff4e07aa2ce87826@syzkaller.appspotmail.com Subject: Re: [PATCH 4.4 53/97] ALSA: pcm: Fix UAF at PCM release via PCM timer access Message-ID: <20180517085400.GA25318@kroah.com> References: <20180422135304.577223025@linuxfoundation.org> <20180422135308.244077643@linuxfoundation.org> <1526503907.9159.150.camel@codethink.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: stable-owner@vger.kernel.org List-ID: On Thu, May 17, 2018 at 12:09:55AM +0200, Takashi Iwai wrote: > On Wed, 16 May 2018 22:51:47 +0200, > Ben Hutchings wrote: > > > > On Sun, 2018-04-22 at 15:53 +0200, Greg Kroah-Hartman wrote: > > > 4.4-stable review patch.��If anyone has any objections, please let me know. > > > > > > ------------------ > > > > > > From: Takashi Iwai > > > > > > commit a820ccbe21e8ce8e86c39cd1d3bc8c7d1cbb949b upstream. > > > > > > The PCM runtime object is created and freed dynamically at PCM stream > > > open / close time.��This is tracked via substream->runtime, and it's > > > cleared at snd_pcm_detach_substream(). > > > > > > The runtime object assignment is protected by PCM open_mutex, so for > > > all PCM operations, it's safely handled.��However, each PCM substream > > > provides also an ALSA timer interface, and user-space can access to > > > this while closing a PCM substream.��This may eventually lead to a > > > UAF, as snd_pcm_timer_resolution() tries to access the runtime while > > > clearing it in other side. > > > > > > Fortunately, it's the only concurrent access from the PCM timer, and > > > it merely reads runtime->timer_resolution field.��So, we can avoid the > > > race by reordering kfree() and wrapping the substream->runtime > > > clearance with the corresponding timer lock. > > [...] > > > > This seems to depend on: > > > > commit f65e0d299807d8a11812845c972493c3f9a18e10 > > Author: Takashi Iwai > > Date:���Wed Feb 10 12:47:03 2016 +0100 > > > > ����ALSA: timer: Call notifier in the same spinlock > > > > (But I'm not totally convinced that snd_pcm_timer_resolution() is > > always called with the timer lock held, even after that.) Good catch, I'll queue this up now, thanks. greg k-h