Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp253703pxx; Wed, 28 Oct 2020 04:11:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxb3zJYewLRiC/zknRdiIVKbTYCgYqzzUDO6jWFglrcQ+Nwp4BMcCvyMZH8vK+yPWp/QLp4 X-Received: by 2002:a17:906:4a98:: with SMTP id x24mr6783951eju.319.1603883471828; Wed, 28 Oct 2020 04:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603883471; cv=none; d=google.com; s=arc-20160816; b=dfgRxCvq+YS8mHWJ4qbTfyvcTrVk/s6iDKMxsDCRWJ9C+oMkWsDlTYQHYNXCMukDNY eRnrQqU7xmK57k9a+6rhldSOiZRCR2o0ZoOak5FuDHDFmUqHm/OfXufymAyvjcywWg8D +XzBqRb7xB3Ik8uYBcxOVq5x2yz+Jk1KMzwAHNfPlbAAAhD07SOJu4oO5Xga7kXi7Wvr JGCKSBWAOOYahMHmUqilHR0EqYrNRcFPEVrnlt5ajXVQlH42jbfjonsC/gPm4XZJCgGD lLr14tukFpC6WFtxJnfGAPgYvxJeNaSC1r21x3lNKkwXJBTSTHh+xjOZ9oyMmA//Ogy/ K0/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FSFvAc0NP/JV0uFMuJT9wC+QgAyEoOWmvoEdOLzLvSE=; b=m3/pl+kWr6TR0DSsfCZ488p24ohvGOyU1zbgzaOPdXPAQKPOlCrum12q0T3/cdRvZy d60L7tt5MAUm6EL0iyWbSAp52B9111+QSfSroqK2ddQoNXPymGkB/LfFANrEefDVuedu kqauNHCOO9baeTDRyyfYBuIAbC1oibWMH1oTMwK+NF/GFCbOZ0SXwNblajP7uma8qFUD guEfECBcgqoKO5Quod7zYemiCcsH8LTPZXYwIwT+O9r1NYc/GBkncIv7Y/jMqcYrszxy 3cO4xWNoNZF82/Uw/5UuTSbhLkTDgkHHR6UgGjlPVa0t2dQ4jHcFksH+dA2vg5CBhyuf SylQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=009UCXPs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o10si2705925ejr.482.2020.10.28.04.10.49; Wed, 28 Oct 2020 04:11:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=009UCXPs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1786866AbgJ0O75 (ORCPT + 99 others); Tue, 27 Oct 2020 10:59:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:48912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1766429AbgJ0Osq (ORCPT ); Tue, 27 Oct 2020 10:48:46 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 68305207DE; Tue, 27 Oct 2020 14:48:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810126; bh=jmHugs3VjpA01qVeewWyVhwcSlx+PkVyhYQqHXLe4y8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=009UCXPs6iNriidWo15dLta2xvrrZolw92T8jr/XNmrLG8e57OckcpekSO0TAeF0A hWT2sy8pLLML/HoVH9GiFX3hkB2rXvfxJVbr0SEkyC+SGs7jWz1Y76cIscxtaOo+3N GN4Qi4icVTEyjXF/VtIaA/p2SsDa1ODh7UpodCoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kai Vehmanen , Takashi Iwai Subject: [PATCH 5.8 029/633] ALSA: hda/hdmi: fix incorrect locking in hdmi_pcm_close Date: Tue, 27 Oct 2020 14:46:12 +0100 Message-Id: <20201027135524.075147878@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kai Vehmanen commit ce1558c285f9ad04c03b46833a028230771cc0a7 upstream. A race exists between closing a PCM and update of ELD data. In hdmi_pcm_close(), hinfo->nid value is modified without taking spec->pcm_lock. If this happens concurrently while processing an ELD update in hdmi_pcm_setup_pin(), converter assignment may be done incorrectly. This bug was found by hitting a WARN_ON in snd_hda_spdif_ctls_assign() in a HDMI receiver connection stress test: [2739.684569] WARNING: CPU: 5 PID: 2090 at sound/pci/hda/patch_hdmi.c:1898 check_non_pcm_per_cvt+0x41/0x50 [snd_hda_codec_hdmi] ... [2739.684707] Call Trace: [2739.684720] update_eld+0x121/0x5a0 [snd_hda_codec_hdmi] [2739.684736] hdmi_present_sense+0x21e/0x3b0 [snd_hda_codec_hdmi] [2739.684750] check_presence_and_report+0x81/0xd0 [snd_hda_codec_hdmi] [2739.684842] intel_audio_codec_enable+0x122/0x190 [i915] Fixes: 42b2987079ec ("ALSA: hda - hdmi playback without monitor in dynamic pcm bind mode") Signed-off-by: Kai Vehmanen Cc: Link: https://lore.kernel.org/r/20201013152628.920764-1-kai.vehmanen@linux.intel.com Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/pci/hda/patch_hdmi.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c @@ -1989,22 +1989,25 @@ static int hdmi_pcm_close(struct hda_pcm int pinctl; int err = 0; + mutex_lock(&spec->pcm_lock); if (hinfo->nid) { pcm_idx = hinfo_to_pcm_index(codec, hinfo); - if (snd_BUG_ON(pcm_idx < 0)) - return -EINVAL; + if (snd_BUG_ON(pcm_idx < 0)) { + err = -EINVAL; + goto unlock; + } cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid); - if (snd_BUG_ON(cvt_idx < 0)) - return -EINVAL; + if (snd_BUG_ON(cvt_idx < 0)) { + err = -EINVAL; + goto unlock; + } per_cvt = get_cvt(spec, cvt_idx); - snd_BUG_ON(!per_cvt->assigned); per_cvt->assigned = 0; hinfo->nid = 0; azx_stream(get_azx_dev(substream))->stripe = 0; - mutex_lock(&spec->pcm_lock); snd_hda_spdif_ctls_unassign(codec, pcm_idx); clear_bit(pcm_idx, &spec->pcm_in_use); pin_idx = hinfo_to_pin_index(codec, hinfo); @@ -2034,10 +2037,11 @@ static int hdmi_pcm_close(struct hda_pcm per_pin->setup = false; per_pin->channels = 0; mutex_unlock(&per_pin->lock); - unlock: - mutex_unlock(&spec->pcm_lock); } +unlock: + mutex_unlock(&spec->pcm_lock); + return err; }