Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4310495pxu; Tue, 1 Dec 2020 01:34:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6g/SLrPdoS2cydYmTXIcZAeYgnC0nBtmLnNo71y0xRdpSVutV7thkTQobKIV2REcNGaz8 X-Received: by 2002:a05:6402:1d18:: with SMTP id dg24mr2049091edb.221.1606815271884; Tue, 01 Dec 2020 01:34:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606815271; cv=none; d=google.com; s=arc-20160816; b=K/TbiMFQDyeanuXq3IAPLSG59hJM6ZHSgb6zJfLkMqNf1H8LLR+mSBMUkD+6FFuyCJ 0rtM4CX5q/6TaIVo9X1WeCE/Y/goXHqP9oQbSgZU+9+pfSO07LjlNaIOjmk8cpB07F+s SPWkNTBHrkhdCd1EcOI0tUEPTcM0b6/93vmKwtkjAa7tT0cehYY4dKUX2gGdXSNd2i9q gcaYtyxxGL+1vditlw7Skbvj7y12s8yZZHiD77GrY41cB/Kp75v6LjPVAzf4nUZJ0DUF 4E+E8S77tspn5O1C6pvmQ+tmN89H5YDnQQMtURgl6Ugj46Xsm1NTS7Mphu91Xjh88s4j R1mg== 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=+Lu84dVOfaSGi690zkKNLRpculiIItu5l4YEdQOLV+Q=; b=NGcb0nr4alO1aDtsbj0fuZTzNdBFxL614CrlVHEOCP9Gz64DMuu7a0caEXqeVOC0Zg ypdpGDCMTmYM8nyG7GWPwj557Q6BdFmYgXXC2KQKB01fhH+mIV7dvkwNMBDT5z13GmwE OIs4kqEjwqinaL+oD/4lQ1uFBPt+xAOi6DuiOfMOb/s8+2OHpvZS52nkFMPFWTXuqLag ua1t//0WAh+v0LqdD++rAppIRXXxCXVXvh2PRCOGaP45vVInixRZrWFebIMkRSSqlYZo 4qlAapQ7rYlV39H5dEJvM/gylIffN6skQte7+jTBYrC70O1dRkgXgentZjNtVtp4Nd1e DZKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="pX/nZIaP"; 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=pass (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 mj25si578135ejb.337.2020.12.01.01.34.08; Tue, 01 Dec 2020 01:34:31 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b="pX/nZIaP"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391220AbgLAJax (ORCPT + 99 others); Tue, 1 Dec 2020 04:30:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:57812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729094AbgLAIzV (ORCPT ); Tue, 1 Dec 2020 03:55:21 -0500 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 3F56A2224A; Tue, 1 Dec 2020 08:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606812886; bh=tEZInM+WfGE1A4X4Z9b+R38fgTJgTSLTutPMsWrI3gU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pX/nZIaPCNe20Bo+GOolPVoTKFn/Cmv+hE/6ZJg1oGehWjPHPzRG7T2r5KmfSCtQ/ 5IgBC6Hox72U4Lg8/5vW88qxp6fWMCLpRubhZkwiYoA+NBfRyGjAN6hm0PT7JMG5Vh WjoF/93qtUE35j9SBwBudD5Gsmt4814kbpjRqX5Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kai Vehmanen , Takashi Iwai , Sudip Mukherjee Subject: [PATCH 4.9 10/42] ALSA: hda/hdmi: fix incorrect locking in hdmi_pcm_close Date: Tue, 1 Dec 2020 09:53:08 +0100 Message-Id: <20201201084642.672626692@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084642.194933793@linuxfoundation.org> References: <20201201084642.194933793@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 [sudip: adjust context] Signed-off-by: Sudip Mukherjee 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 @@ -1803,20 +1803,23 @@ 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; - 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); @@ -1844,10 +1847,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; }