From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B04D2C2D0C6 for ; Wed, 11 Dec 2019 16:08:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7CAFD208C3 for ; Wed, 11 Dec 2019 16:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576080482; bh=LrQPLvA8WyI77d5sSR7uzqf48NSFbyjdzRk8D4zjZlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=yDCLumqGkALg4idbijI9MqBW2p49jJm6dgLmMO+VKWqhFTtvoiplGxu31pB8rrWxS SdfXbmea2JG8sM6paWJYlU07uPDWPAYDNfVwQIPwNV7rFv/3f9+taa+KxVr3QKqf99 oVbZFZBKgtKAW0XPNzoMCHvDavFgMGeGEODf1VsY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388838AbfLKQIB (ORCPT ); Wed, 11 Dec 2019 11:08:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:33884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731113AbfLKPMX (ORCPT ); Wed, 11 Dec 2019 10:12:23 -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 5DDE62465A; Wed, 11 Dec 2019 15:12:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077142; bh=LrQPLvA8WyI77d5sSR7uzqf48NSFbyjdzRk8D4zjZlI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=psBo7x7ZJqHKlBdnxP89ndCFewLpWqz/ETw290LBFDwTpymV7u0x8tJXNLBtBDvJl LPSYPtPTQSFjSFAWklfOTuiF0q1dvFWlcToHQmRCLi9aNpEw4fjv1hSCMLVxEOVhbx tNi0FvsR/eIl1tls/LyLW87+ksgTildOwM49e/+c= 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 5.3 032/105] ALSA: pcm: Fix stream lock usage in snd_pcm_period_elapsed() Date: Wed, 11 Dec 2019 16:05:21 +0100 Message-Id: <20191211150231.942028611@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@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 d80041ea4e01c..2236b5e0c1f25 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -1782,11 +1782,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; @@ -1797,6 +1800,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); } EXPORT_SYMBOL(snd_pcm_period_elapsed); -- 2.20.1