Received: by 10.192.165.148 with SMTP id m20csp2487261imm; Sun, 22 Apr 2018 08:03:24 -0700 (PDT) X-Google-Smtp-Source: AIpwx496CE/Hxh9ECDyWhMV5zNHG9ttchZqR8W09ORmT/ZeCtvXsh5aOh1kuVeqcYaNJQrEJQhND X-Received: by 10.98.61.84 with SMTP id k81mr16859035pfa.193.1524409404326; Sun, 22 Apr 2018 08:03:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524409404; cv=none; d=google.com; s=arc-20160816; b=PWcsTtB1ac9M/cISaAgZohs3MYPEhTXPF8wQK+rmRVlpb6G8OyfBN8hphiFTGk45KD San2NnmNWWtX+Q3j6do/TIr3xLTEGAYgqcMr+h6lI8k4cIwmmPwU69gUdAi2ThBmJl66 N6IibLV8cKYAQueRMW/ff82NAM0J0HG4nI4JgeMMnDR3nZDThdRtGA519xkjTYsdYIqw lxug7x5lFfOhho/xN5/7n2VIfkLUgQAz2YJwqQsUYFkiGcjncDG1D+As7juhHiDNtIUG RiVFG7lKH6jmABDvYiGp5lcD56oH0bN/MfodjZqfrK4KjjUGNnsy0WXBYQc9JfWYPTMx mJRQ== 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=Fxn8Jz1LqDsv2mYAF5FLAzha31PVQJQm9Ymvv93KDFs=; b=IECIcV/qRbWBIuqBh5PVGKdDiIYKA9+OZAFvRE0VNe4az4YGwmwTluU+IXlq/rdyPr YkIbQlc6i2FqcymPlKUFN2qXnD4Dnl9kOBz5BYsryLF+aoOG3SCBqo2wOkXHgvp7wuWd z2HP83kHO23/yoNdb8W0K484giXgvi2pcRACrIEm1vBq2P4Rfn4d98xlIDRJAqqXCgJ2 PVlexiN1Gyx9uwdDJukjaVL2m1+ozIJ+LhfK19GNDkKbEoAbB3RdbfUzZBIGDB8kbE71 d2qvjX3N+6aVOFWrCTN/8uC3ROZGXUL7GS1Q13lM8RYsLO2i6h8Rf6JcDba0PEDecW56 Dk8Q== 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 f123si9160373pfa.364.2018.04.22.08.03.09; Sun, 22 Apr 2018 08:03:24 -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 S1753705AbeDVPCH (ORCPT + 99 others); Sun, 22 Apr 2018 11:02:07 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55164 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756712AbeDVOMh (ORCPT ); Sun, 22 Apr 2018 10:12:37 -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 396C2CC6; Sun, 22 Apr 2018 14:12:36 +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.9 41/95] ALSA: pcm: Fix UAF at PCM release via PCM timer access Date: Sun, 22 Apr 2018 15:53:10 +0200 Message-Id: <20180422135212.101094226@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@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.9-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 @@ -1025,8 +1026,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--;