From patchwork Mon Oct 24 11:29:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp421739wru; Mon, 24 Oct 2022 05:21:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6OC/QppOr7sVe2cl5Pkx4DAFy3dZfHpIGg14bYW9MiwA41cdy+reDPnemmKHfPo58RGBMd X-Received: by 2002:a17:906:4fd1:b0:787:434f:d755 with SMTP id i17-20020a1709064fd100b00787434fd755mr26373402ejw.356.1666614067566; Mon, 24 Oct 2022 05:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614067; cv=none; d=google.com; s=arc-20160816; b=HBxDlogUHPvAu+k5lBUoS27bqAZ8js/+1/ESnFbxdPaZ8Wf7GLfiILlcWVZBW/NeiM qNCNqw81Ah0ReRgQ6dc0qtGmS+4I2y0cxc3X0e5/XHpnHrIZQt5/7fhscSyC70AyBvtj i/scuAM3vdv+UpSW++WK/Jk0L6ZT754rAfUe1g3X0v8uzUAnni/CM3SZb3YsMGRecPkv G5bhShgV49WY0oWjOmZWngGYumfkjiuWUvJk7jqJrZXchfxDI/6OzIbNiKNJvTaFnyiI jOQNsk/lmBTiyu6hktfLQy9jvdIMjCXOttTMFezsA0aklhpoJL8VW+1Jdq/nyk1ydMOL fe/w== 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=/rVgWEN/XvYtdR9D5WlUOGgkhy8f36m8Xe4TlpkiVu8=; b=uSn8RozZ92biFXSFe1rfNy//7wU21iZpjG1KK30jfjzQk9ouwXFpRcCPUB5Vz1gz51 UpQtwbMbw/hc4yI1LhhJdLJT75wEoN3AkRia4aLvfjwT5HNvE98r/jCfmAFclLbyI7hQ VW0VnJs/o8lt/g6zvhX8s/iTXQ3ZsOjfQip7S19ZkIFNpMdd4O5NPfiSfApBneacegfk OVLIyyS6M0oPugtR+AvvwqK8Hg+VP4Rc9mwlrG2YbbKzwMR4d/Sbda+bsJV0VGFEK2+y G4LlxBxkr3aYCOGaM1gqwppFhTjdzCC3w/3zw0eM2M1t1QJpnf2NZeaHI71W0bjFL+hV LzfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JhYGwyK2; 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 fk24-20020a056402399800b0045cafc51fbfsi26877479edb.525.2022.10.24.05.20.42; Mon, 24 Oct 2022 05:21: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=JhYGwyK2; 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 S232968AbiJXMRD (ORCPT + 99 others); Mon, 24 Oct 2022 08:17:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233428AbiJXMPG (ORCPT ); Mon, 24 Oct 2022 08:15:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C042880531; Mon, 24 Oct 2022 04:56:00 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 03AEA612E6; Mon, 24 Oct 2022 11:55:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14FA6C433D6; Mon, 24 Oct 2022 11:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612555; bh=3WzImQnkbjG9/1b+5+7IqgwI/RK4Rp5ceJx3SH2/qCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JhYGwyK2KzLbYK2vh6bfBV5xZ/bSWBfLRA3EpqZv1YNn0nyzu9SKEpuTUv8+mWTT/ Ghv/U5cOCZs9oQkr6f7nWo2SvtMynXl2cYdtChBpVqC6C1ym5BB9WGbVRoe84Ykp3l emueMsbYgtm6SCy1qUj1fJpTmzaLVCoI+BRMSayI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai Subject: [PATCH 4.19 032/229] ALSA: oss: Fix potential deadlock at unregistration Date: Mon, 24 Oct 2022 13:29:11 +0200 Message-Id: <20221024113000.158366599@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@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?1747571512151200078?= X-GMAIL-MSGID: =?utf-8?q?1747571512151200078?= 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 @@ -177,7 +177,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); @@ -189,12 +188,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; }