Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6744523rwi; Mon, 24 Oct 2022 05:41:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wT0cUQKYe1Y7Kr4li01mqYMaSH16Tk/Zs0vaVrKFWMCbdV3dkznq5fzlotwZGxAyaccFg X-Received: by 2002:a17:907:7f02:b0:73d:dffa:57b3 with SMTP id qf2-20020a1709077f0200b0073ddffa57b3mr28145599ejc.19.1666615290658; Mon, 24 Oct 2022 05:41:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615290; cv=none; d=google.com; s=arc-20160816; b=UoUucGqiS2pUQhEaYnb1hArJ3ZhslxOgkV8bJQ4T1sHLgZK5PMP0e8dp4IJjIGZDUk zDc0D8xibGtM/diRjldqCJ9QWf24OeA5KmnrXOAfdV5025SXdMfg2mAfPV2hJQmpvyOx Dh2dTwomVpypvWOJ8TLIE12dlA5TVCjP6Wa96f6YqXDmFF3Ba0o17/1CHZHyh14KtZeI 2d1VgtgqZ1n6nx+PZ1PoQJnM6FoRyBFX1zCgyYZARWwnDxkYTJTdnaH6fCdMxWU0rrNy j7nYZ5Oh74/++k1LasqSR08IjkUv82nucNhit6ZiVhiiLv92DeloQgvTutk1AXe9CGEu QTJQ== 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=gN7jk0Xhi3/BEiKKS6QP5iTWR2q0fhJCPOYGLlBKmHmQgBDwYxYAhy7YprxAWgp4UE kHZsxsIPG8mgB/VpTkAOpZkxruExVFMnPx3HJxMFmM2zEGT2JI/mAXfA4m91WEjX2IRz 2JSkMxbvVMoq51PHDbbBPxwo7QOS5BIYgLfchuNLJ59WZhW7w4zxq7cFbui2/DahE7nS fdUE8/ny72PJOtjE2arDx9wL6ByCZ/zFv4xJoT8XGTLEZk3mINVZt4tCGfKyKueTa415 LZYV8MMBSkKt3Sc5hZ5TQtoVAMEzQLGIEUVyrvE94PbiUzpBub2iM9zKNpv+mRXQ16cn IyLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qBtGccXi; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t8-20020a1709066bc800b0073d61f9a7b6si21797377ejs.263.2022.10.24.05.41.06; Mon, 24 Oct 2022 05:41:30 -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=qBtGccXi; 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 S233451AbiJXMV7 (ORCPT + 99 others); Mon, 24 Oct 2022 08:21:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233546AbiJXMTr (ORCPT ); Mon, 24 Oct 2022 08:19:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C36F7B1ED; Mon, 24 Oct 2022 04:58:14 -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 D88646127C; Mon, 24 Oct 2022 11:47:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9BCAC433C1; Mon, 24 Oct 2022 11:47:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612046; bh=3WzImQnkbjG9/1b+5+7IqgwI/RK4Rp5ceJx3SH2/qCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qBtGccXifl6eBT+IonzvQGiuBKGYbi6Ar5p0Miv3yJjvvS0mXVXPgYjIJUXkzxYpg kQFRQuXuodQFSUBk9g4Hh76Jz6eeT2/YrRU1w0nPehAGgPm5yhdJyExSKpnNDFjQi+ RHAC600CtDsrrM0yDqX31tovYFU1U7mI/oRU+QZs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai Subject: [PATCH 4.14 050/210] ALSA: oss: Fix potential deadlock at unregistration Date: Mon, 24 Oct 2022 13:29:27 +0200 Message-Id: <20221024112958.610709500@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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; }