Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2295462ybl; Thu, 19 Dec 2019 11:09:25 -0800 (PST) X-Google-Smtp-Source: APXvYqzEWRE4kDYVfwT+rfwCuxo0QPlC7qOJSYo2bAKfhP9PMyw7p+GwM1guPe0b22pIAgQpTs6n X-Received: by 2002:aca:500f:: with SMTP id e15mr3053122oib.172.1576782565529; Thu, 19 Dec 2019 11:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782565; cv=none; d=google.com; s=arc-20160816; b=fBU4IUuKFOQKRbKugAaPQfz12tVpg7IFP81omsYUSGBr3Qh20Oy/dh0mfudBgCf1M0 idAho0t5XdaOSwmIyMec4p8pZH3Ut2GtUppHg0bnn9JK0LRki4rdIuUdh9CEtCcuEy5V U9sI2061HXXwz2uI1ijk5D0oAq+Dz0wM1eRO8Yci/9XqhsrsjcCWSqKroaGpVPIVr/mP 8g+Tiyju2wZ2yIzwB3ahh0RjNHd4HcnFLLExC/qN1L7yVsni2TwlHq8c569LxjHmBRQK xAPe/9DX2ncSA5wTh4kyTRxckBJWlNfuxf1x/2rJ9hhshV5kwZsZe20D2yz4yjEgpULk 8dug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3OYFuIBk2PqJX83V/pEYCTtm1GX/GSeiAnRXzNRIQf4=; b=nyZxN+gJw62HnTkTWqhVTesL6rRwalwm+Cf/GlOXBhVqBIGOocxV9HoA7dvJorv2Pl l3D6P74DNyKkPT1ngnJmhuvrRhhIR6XmasvgW4FKLPkE4PE9hTOtW3depHVz9Lqx4LDt JIfcrWZ1WbpnytBZVem5hHNbF4P8cPXX+IWpRxVI1IxIJIW26i/BXz+Cv/Ub73MXQzIJ Smua8LADw/c75p0VrJdxp8MLGiT4X1f1umIpklT4ba8bXgfDBv/67hBs70oAvVAgW3Lc W2NoChbLcdAwXY0ZjI92uy6pTgYEUrpjFKSaPL9JIfGHgxNMpdI94pvj/Duh052mvpFo rVCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="PVp/clR4"; 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 m19si3346805oig.91.2019.12.19.11.09.13; Thu, 19 Dec 2019 11:09:25 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="PVp/clR4"; 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 S1728656AbfLSSmP (ORCPT + 99 others); Thu, 19 Dec 2019 13:42:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:33258 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728647AbfLSSmL (ORCPT ); Thu, 19 Dec 2019 13:42:11 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EB88E206D7; Thu, 19 Dec 2019 18:42:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780931; bh=vu3BNhVtu/OVi6DJ35glNw192nWK9hfAbzabOyJgl4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PVp/clR4PjWlkU35IJZJI0a4GQsFfglwDLfMj215Vyolqlb8Vq+3Cb41F9bV/q1zh Pt7xZCL8rh9Y5aAdOSbi6HW8ApoI51qa75vICso7WcBIfzBS8FF5BUrQn52yEuFPio WnjuEsIUwpFV4f0eEfg+mUP+5O3jlt252/7+3Qao= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, paulhsia , Takashi Iwai , Sasha Levin Subject: [PATCH 4.9 014/199] ALSA: pcm: Fix stream lock usage in snd_pcm_period_elapsed() Date: Thu, 19 Dec 2019 19:31:36 +0100 Message-Id: <20191219183215.551455232@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183214.629503389@linuxfoundation.org> References: <20191219183214.629503389@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: paulhsia [ Upstream commit f5cdc9d4003a2f66ea57b3edd3e04acc2b1a4439 ] If the nullity check for `substream->runtime` is outside of the lock region, it is possible to have a null runtime in the critical section if snd_pcm_detach_substream is called right before the lock. Signed-off-by: paulhsia Link: https://lore.kernel.org/r/20191112171715.128727-2-paulhsia@chromium.org Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/core/pcm_lib.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 3acb373674c37..f09ae7efc6957 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -1877,11 +1877,14 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime; unsigned long flags; - if (PCM_RUNTIME_CHECK(substream)) + if (snd_BUG_ON(!substream)) return; - runtime = substream->runtime; snd_pcm_stream_lock_irqsave(substream, flags); + if (PCM_RUNTIME_CHECK(substream)) + goto _unlock; + runtime = substream->runtime; + if (!snd_pcm_running(substream) || snd_pcm_update_hw_ptr0(substream, 1) < 0) goto _end; @@ -1892,6 +1895,7 @@ void snd_pcm_period_elapsed(struct snd_pcm_substream *substream) #endif _end: kill_fasync(&runtime->fasync, SIGIO, POLL_IN); + _unlock: snd_pcm_stream_unlock_irqrestore(substream, flags); } -- 2.20.1