Received: by 10.192.165.148 with SMTP id m20csp2471301imm; Sun, 22 Apr 2018 07:44:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx48aVMUf0Ac/7Dfc4rza692/7YDcYc3C4vbYRL0XPPJ3bfSNbAKrGYXt6MFoynedd8cah1LL X-Received: by 10.98.139.7 with SMTP id j7mr16748406pfe.28.1524408270000; Sun, 22 Apr 2018 07:44:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524408269; cv=none; d=google.com; s=arc-20160816; b=YcLgHn33H97E8gx68tDg41Gi6xmbT22gk635/RycbvlyatYNEvGRjRs4rlOxJN8SFj 7ba1QmBC0RQHXpiA/+6zbKZIPG9eY/qkxIhBeCdOPHbNOLMHi1h1cQTAeAfLBK4l6OTc usHwQ2r4PYKQrhA7feeo/eNOyvv1n0mO5DTLImvKxFPf92D/eGve23BEuED5WUh1HWdB +BAgI4/CnPyenO/9JWjH1d2VHfiwTQCCV8lzTHCNPU31JJ8WB2dSNxKz6fHGFuIcEW2O MbhfYyfm/vtvzArqGsSja9WRz4eXj52/s1HW5AcVxjRQZHVG/9Tpm4s1CsuDnqRNjmtb Yl6g== 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=+1gFRu5/i6QktzYS6h7fY0nE4lXtm2NbZVO6Ttcl3aQ=; b=Jt+EoseK6mS1ccaaPrw4ct08TDp6WkoK57/B93uUzGyBfFQMud3j3JE7xmxgRFbUY3 gQcYjIWX44nxe0u6dEqImfEj9oGpUJoBhZdvmbIQ8SvhPa44IWsuY1QeAbi3GIbjthCW gd6ApMHdcEFFWQrTmqj3rI7rys9A5fS1GnmB222BTrk1ewV0s/qY/2VfnW4Hcr1BzA7i kYDvRoicdhrcjgWmHVobd/0PoXiGiNLO/PSlYLbpc3xnksQni85bXF9FGlyPEGrrntH0 wNQpqKY5b0th4/5twYQPg9lEqxri8AIJgdHW8s8ooTxjTaMBL+ywWdtBxc2AFK5VqpnV dzEQ== 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 j2-v6si9073738pli.501.2018.04.22.07.44.15; Sun, 22 Apr 2018 07:44:29 -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 S932481AbeDVOm2 (ORCPT + 99 others); Sun, 22 Apr 2018 10:42:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58350 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932196AbeDVORb (ORCPT ); Sun, 22 Apr 2018 10:17:31 -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 5D7D3CD2; Sun, 22 Apr 2018 14:17:30 +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.4 53/97] ALSA: pcm: Fix UAF at PCM release via PCM timer access Date: Sun, 22 Apr 2018 15:53:31 +0200 Message-Id: <20180422135308.244077643@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135304.577223025@linuxfoundation.org> References: <20180422135304.577223025@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.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. 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--;