Received: by 10.192.165.148 with SMTP id m20csp2530258imm; Sun, 22 Apr 2018 08:58:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx48t0E/3kB+BQzyCShQ8kJqldrPmTyu43XvvJwTUAdxi9ojNOUwiQWDfthYzpKQYx05g1J/i X-Received: by 10.99.181.89 with SMTP id u25mr14077908pgo.302.1524412736436; Sun, 22 Apr 2018 08:58:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524412736; cv=none; d=google.com; s=arc-20160816; b=Ojm2squoBH1NNcRhNznDp5IkBn9ys2TZylHS/GA5bLAXN2/AMLoTwC6cbnMZoL1SGb YazxYyAOXntXv8sCuQcE17LJJe/QdD1IPW2lKkaRzrWE0Yo3AfYAQZK0GJoIyx0d8NHY cN8imd1TWHBsYotYHgKMRajOBSaTfMdcmidgfAL0YvYAqTejqDekHuk2K9lpnK2A+gvi XOe+D6dcVDXJxPBGF+RTzyLaDEboVozmEAmVv86Y+rSd/IpduLbYINgUDhwKmQRvFGbU Vktwrtxvy3cHXmMEisNKe2C4i0HRa1GFdDOzv/x3AGk5PZv0lveuxVB7tUslSXhDEm4h h+Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=dKzJkZag3Gab3CR/i6kVnbXuQ6QCppXFQWXQhnaOS+I=; b=MacX1/DUA5Yi0XT2aavQu5QtZD1XtmPPB9KVAtQn1vwbo41UT4VR8nT2+DuQIne5Co FTUfAnJT1EOZTBWTBtt6IIBMvCUyt0r4h1q4zvBnf1o6R5nc5O5xX8T9sliL3JviZ7h9 fYyyk7xEMrX+yZbPnJgO3sPQbh/p/IBhTU9KW/TMoSX++qoWL5P/9/J2b2ynGaf9vOwO U6wfirxwNr36cta2V3QnOdsQC/PGFvyD0cpshRBCss5/Vfjzy4xDA8MJQ0/cpzLfracP MtruRJo5X81Pa/vV+A5id9Du8EEKxO0ZnQJOMQ8c5xvS/Q9WqBe48OrBG5oe/8/K0eaK Lz6Q== ARC-Authentication-Results: i=1; mx.google.com; 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 f8si8191767pgt.243.2018.04.22.08.58.42; Sun, 22 Apr 2018 08:58:56 -0700 (PDT) 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; 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 S1754702AbeDVP5i (ORCPT + 99 others); Sun, 22 Apr 2018 11:57:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46830 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754325AbeDVN7W (ORCPT ); Sun, 22 Apr 2018 09:59:22 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 103929C; Sun, 22 Apr 2018 13:59:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+8e62ff4e07aa2ce87826@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 4.16 111/196] ALSA: pcm: Fix UAF at PCM release via PCM timer access Date: Sun, 22 Apr 2018 15:52:11 +0200 Message-Id: <20180422135110.009761064@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-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. Reported-by: syzbot+8e62ff4e07aa2ce87826@syzkaller.appspotmail.com Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/pcm.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -1054,8 +1055,13 @@ void snd_pcm_detach_substream(struct snd snd_free_pages((void*)runtime->control, PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))); kfree(runtime->hw_constraints.rules); - kfree(runtime); + /* Avoid concurrent access to runtime via PCM timer interface */ + if (substream->timer) + spin_lock_irq(&substream->timer->lock); substream->runtime = NULL; + if (substream->timer) + spin_unlock_irq(&substream->timer->lock); + kfree(runtime); put_pid(substream->pid); substream->pid = NULL; substream->pstr->substream_opened--;