From patchwork Mon Oct 24 11:29:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8444 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp401602wru; Mon, 24 Oct 2022 04:48:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gWhabHFYWmzCD22wBOennx8m7Ef40hu+5y5sHB9wcgzOkSLj7opTt+Go6KHVP4W5vHFX9 X-Received: by 2002:a17:907:84a:b0:733:735:2b1a with SMTP id ww10-20020a170907084a00b0073307352b1amr27302778ejb.290.1666612132676; Mon, 24 Oct 2022 04:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666612132; cv=none; d=google.com; s=arc-20160816; b=NRMnXlUnQ14lDHquMWnnEevDCNXAe4OF071lquqXm1CA5DrxtCbWLn5rkJ9WNgaBRQ Qrc+GUKN6oMYaPHIUn5vBh8eKvl2tZKZAmUVZf+hxwzdgHdpo18W9Iawh+c9PVojkCrE ksU9Xc1Gx0kRe2y/aFxt+TTEYTfNup40of5M7utVbCCcsVZWsskzYzIPD+VwaHe3kv5G YFa1CB0M97CmIQvQ76fSitSuq7V7MlSGGBHazBHlFNidOFpe5u5sF1pQy7ZeHadWfDxC QE5SsFQya4JFVg7iSQye3zPUJGkKypDc1dPf0xLbTPu0DWbgo8OKEEMjVR91jm63zwwP haRg== 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=tSVK4iUqtNVvEMscHEyPKfoQ2NMGePVPe7KTdafnG9U=; b=SuiII7Nw7G548PpL9tsDUVQ023jIyaXswoOsdKNktj22q3/8QAAA7l2pI+ZFWJs48R vM2DVRojx7o3lhGjJYTIFc9sNjicf7iR2klHHrXsOZhkIIArFu7fzpcAw//CpsqhtZgH wR47OadRHIWGzFHtvVUz1v2ET+BGs78z5UIvMM4ehFgsDggxC9Q58fr7NCLN8XW6VUmW l8BrOGA8x68alZI640LkBaOZK7DlYiiXbeMhBg2r5M5qowOV01O0BLfH9HXCYEaiq50l s38XbLNR/+zUulVsibC9Uv+niy8Mt0GP2rohMs1CKxZsXk+8cFkmK0zkpnTdtAStMcJU uH4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cNC3DlgL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020a1709060e4700b007315809ec88si23652924eji.399.2022.10.24.04.48.28; Mon, 24 Oct 2022 04:48:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cNC3DlgL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231654AbiJXLr6 (ORCPT + 99 others); Mon, 24 Oct 2022 07:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231650AbiJXLqy (ORCPT ); Mon, 24 Oct 2022 07:46:54 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1966617589; Mon, 24 Oct 2022 04:42:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id DA0EACE1320; Mon, 24 Oct 2022 11:40:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59B2EC433D6; Mon, 24 Oct 2022 11:40:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611604; bh=xAr3HtSz1TJSquIEdH3BGLK5XHEZT5yJ3V/u+aRLDLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cNC3DlgLTIawPyP/XKzq7Wcw8f5KvqkAP2A2c4DFRAQcKvIpb0LoyeLi2Wj6OTTeV yKLaDdJweg6GgY3WxnMTLFepvLppgVpT0Pv6X6ZdtisGSOtoF4wCxFeT4rfsY8mrIL WEu4FYCkRF4fQFb1wfCnZuvCVEWlzd/4PDzAYbjs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai Subject: [PATCH 4.9 041/159] ALSA: oss: Fix potential deadlock at unregistration Date: Mon, 24 Oct 2022 13:29:55 +0200 Message-Id: <20221024112950.885292336@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747569483411228078?= X-GMAIL-MSGID: =?utf-8?q?1747569483411228078?= From: Takashi Iwai commit 97d917879d7f92df09c3f21fd54609a8bcd654b2 upstream. We took sound_oss_mutex around the calls of unregister_sound_special() at unregistering OSS devices. This may, however, lead to a deadlock, because we manage the card release via the card's device object, and the release may happen at unregister_sound_special() call -- which will take sound_oss_mutex again in turn. Although the deadlock might be fixed by relaxing the rawmidi mutex in the previous commit, it's safer to move unregister_sound_special() calls themselves out of the sound_oss_mutex, too. The call is race-safe as the function has a spinlock protection by itself. Link: https://lore.kernel.org/r/CAB7eexJP7w1B0mVgDF0dQ+gWor7UdkiwPczmL7pn91xx8xpzOA@mail.gmail.com Cc: Link: https://lore.kernel.org/r/20221011070147.7611-2-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/sound_oss.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/sound/core/sound_oss.c +++ b/sound/core/sound_oss.c @@ -179,7 +179,6 @@ int snd_unregister_oss_device(int type, mutex_unlock(&sound_oss_mutex); return -ENOENT; } - unregister_sound_special(minor); switch (SNDRV_MINOR_OSS_DEVICE(minor)) { case SNDRV_MINOR_OSS_PCM: track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_AUDIO); @@ -191,12 +190,18 @@ int snd_unregister_oss_device(int type, track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1); break; } - if (track2 >= 0) { - unregister_sound_special(track2); + if (track2 >= 0) snd_oss_minors[track2] = NULL; - } snd_oss_minors[minor] = NULL; mutex_unlock(&sound_oss_mutex); + + /* call unregister_sound_special() outside sound_oss_mutex; + * otherwise may deadlock, as it can trigger the release of a card + */ + unregister_sound_special(minor); + if (track2 >= 0) + unregister_sound_special(track2); + kfree(mptr); return 0; }