From patchwork Sat Oct 22 07:18:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1087622wrr; Sat, 22 Oct 2022 00:37:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6D7smXypA9AbZZAHUdjrhzUQHz8uOp4U9Dlw7fohDRQWR2CF1AiKuha3Fd4FYjjUn/xI8t X-Received: by 2002:a05:6402:3890:b0:45c:2b5:b622 with SMTP id fd16-20020a056402389000b0045c02b5b622mr21437463edb.69.1666424227815; Sat, 22 Oct 2022 00:37:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666424227; cv=none; d=google.com; s=arc-20160816; b=mcZYe2Z4FHyV5RfdXkV/7CxptAhk9+dF2vOvVo84IBj5sfbbhIR+lZP/ksSEkMm1h6 nvqaiR9fvVKYxPZugYx8wBdk/3RCR4sAKnHs9hOX5kHQpIAB1EL8E6+q7OYhLPWHjBBt VtZjYoJqnTCh0AilA8XWOvH0+M7eHMt7xPljwoui22WmNpKgMZSnXGase98mXix45IB1 IEyjfzawS8RtAcia344fharUVcZtPLswCPzHKbrmH20bs7UDqR3y0PdTjnVC2kMbilUW 3uh7ehhMD50riLVGXWmks/iNQDqO2n1Lr6yjOTeWhVNMZXJe3H5GBeqh8HBANXI/kgx4 5kAQ== 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=F4j8IraKba5r8jbZzh53laeM55SFpVoLsjWn3+W0o3c=; b=Ky+oGmvqnofRjM4HYNpJzzh0cmtKbh8FNTHlvST9FPomTr2LJYipGpv0awe+ygvpRu m6d6bQRl7cqmMB4paCeG95b9Oz/nkISNoCcNpgjoid927oIXYrHMHwZMrLtmUU0oESA8 CKmdoyMVHWyOVbJROrKo5enBqETJOtKvt2689dqvJo/WBWydvtDu8NlSLZ/WjRapFFex 8jUo9f8P5f5WpD2GDN1BeynYpdRT4gDDUMbai8q3nJAQcCOpsgjPjY4Dpcn6+vJLuigD DH81ALcUsp7eI1cJPL1vLxc4FQe5qW0V8TQgYF7FVFOauW3O5mERtIvHEdxFg4oGFHKQ vwWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="qYjgHV/h"; 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 o19-20020aa7dd53000000b00447dfae6181si18619799edw.235.2022.10.22.00.36.44; Sat, 22 Oct 2022 00:37:07 -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="qYjgHV/h"; 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 S230292AbiJVHfj (ORCPT + 99 others); Sat, 22 Oct 2022 03:35:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbiJVHfH (ORCPT ); Sat, 22 Oct 2022 03:35:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6248745229; Sat, 22 Oct 2022 00:34:37 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8EB7CB82DF1; Sat, 22 Oct 2022 07:34:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D9B61C433C1; Sat, 22 Oct 2022 07:34:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424074; bh=6Q8RJsXE1kESmQt7BuzCD7VcjKXu9zTMzzTGYbKSZ8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qYjgHV/hNVjp+lTMSSOn5pOk4RFNXHbOkNt9uGrSdSeKunzp2Fqjwyn7dgEm4/qxV CUM4lzKGdKFdUHfTFK2aJZipQklpshlZ7T+/1QURnjq6FP6xLAw1pb5bzbO1pt9G8z XViKRZXS5iumRwKiFOBygjKTAaz97izZaq3eXejg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai Subject: [PATCH 5.19 002/717] ALSA: oss: Fix potential deadlock at unregistration Date: Sat, 22 Oct 2022 09:18:01 +0200 Message-Id: <20221022072415.458280635@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747372450976441967?= X-GMAIL-MSGID: =?utf-8?q?1747372450976441967?= 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 @@ -162,7 +162,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); @@ -174,12 +173,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; }