Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp830902ybl; Wed, 11 Dec 2019 08:09:21 -0800 (PST) X-Google-Smtp-Source: APXvYqwmK7ESiLTmCn9Yj6LaPQPWkErBICyuecqA+Th5CmCsa5ciprjqYcFPdXmn8w+7UOPQKf9Z X-Received: by 2002:aca:c08b:: with SMTP id q133mr3209203oif.46.1576080561774; Wed, 11 Dec 2019 08:09:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576080561; cv=none; d=google.com; s=arc-20160816; b=ETG3dGfetf4jHZT1UIatwnSWrwgWF2PRKL9M7nibIzDoGcuqUNv38vZzySHeAvg0np 9DehcC98Fi42ESOXm090rrRw4ShK57SAmXe2tFJeUNNL2IoLyrZ99D26ZiJo2yvT1ch8 N5G7PS9e0s/y2wZyb0lIqMKv7vbCwpUTprxrHl28CUTzGOp11R3/luiWnKpiWYDnsD3w 1lwyqWCjrhqr8JOtIktERf/p1Eak/yu1XPZYI+74SierCv36V6eHWMwRGyfM6kiGPGlj iYwt12YNBidloDDuJdzi4gRREfq14BfbLvm3K20NvbnPLU7HezBqEBlENGYfgTJL8HJo TWEw== 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=Y0JUaoEl/s3LstST37IsgfHcWDM5OBNICAW+oq1Pi8Q=; b=YQtdy/T5it3B1fUGpE0WoqSJ9iLtIs3Z3nu9uk7cpZSxKYm9DNN+4ZCuLcCau8Ym19 SLVoQreI1q8jROf9kilJuQ/Cm98k020Ou8rZjKkvEBE2+NIkXmoux0NOy/cI54XKLJXX giQxpseycFW9+FiGdPAihjGwUJWaQKo1i00b5xS3BlwbohtnN/pZwEGvneoQH9TK6KY+ n+o2mpblgbxwnLxfzCsP3jqujoz3dYT4mqTPUK9Cv/lv5dxq5lEjmXbgGD12b4Ue14dk 2NoOKK166JGyvRoLG3YM+woov5Ol1hDkv1svzktxFVWlu/9uTPo8A+hKI4gsRfm93elb AA7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=psBo7x7Z; 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 o25si1325926oic.63.2019.12.11.08.09.08; Wed, 11 Dec 2019 08:09:21 -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=psBo7x7Z; 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 S2388815AbfLKQIB (ORCPT + 99 others); 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