Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4475154rwb; Tue, 6 Sep 2022 08:03:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR6q+keTyZDR7gtCsKegjkupeeAuQNYbc12kbFxBgAZMSuJE/G92SLuH9g8wys79tu3SLfkW X-Received: by 2002:a17:902:b70a:b0:173:1a17:451f with SMTP id d10-20020a170902b70a00b001731a17451fmr54527709pls.81.1662476632815; Tue, 06 Sep 2022 08:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662476632; cv=none; d=google.com; s=arc-20160816; b=N4LkDh8LfT67coOVrLA5h+a05tz/ydym43RxizsLTPC82Mx33NQ5+5I006tP2dwOBl vc14pyQB+V1tvNkPrTDPhip1fU4sbUC6s8iHgR+QjeUOJ+DDs5Ikf5tq1HiG5D7OYHqy 6B5CVXYnV/dAE1G0/CwZrNT3pw2AD94XURQH1tg7Nnqb/Vlu9mSKvpBek9bBgNV3xscs dhhwNHp8A+nADcImK7vaW/Xhw8x9RQSzlCMUsY+TRmd9JwdN1ToJ8COgihS05zLULwV8 VXRx0CktzKOPf7ozmho3RsnH+2ALNAUzIXue5BzM0duQ75idBPafXht588+8KN8a4g5h /XZQ== 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=cljnZpbJ3tgDrKNtK7kWuZwMdXc8akXhnnVZiJrUqjg=; b=ICvF0g6oCZBHvay9cHMTOhLS2tyXvS3Ub91u1xVsaLkWBXCWGLnnKt0kk1Z3hofulH 8vcrRVSyE8aBLDBFbQcAgfdcNXh50MJlniW/Oqkzk22WYhPuZNOgdW1lAtDiRrpvcoPe iB1/oP7Gqg8n6BoQ8Ie1UYIPYJ8tzxeo0WxAO2XEI/BHd42ouUIOZWaPN6gcRRbXbjTc qSWk0nu5hx+DhXYrZIBjwuPoXDihQsBmnGufJ45DlkbntuMtXx2kQs2ubZE7CHHGwPUy o7xVD1l27/JAa2cpsMOszZV4JEkZAovDykaQ9YSbM2eOT3aJVapEbWJ4svaiNsjkK3hG L8bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vP0XsmiV; 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 i4-20020a63b304000000b0041bfb11f138si16666747pgf.442.2022.09.06.08.03.41; Tue, 06 Sep 2022 08:03: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=vP0XsmiV; 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 S240016AbiIFN43 (ORCPT + 99 others); Tue, 6 Sep 2022 09:56:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239826AbiIFNyM (ORCPT ); Tue, 6 Sep 2022 09:54:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8390680B67; Tue, 6 Sep 2022 06:41:06 -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 068E461547; Tue, 6 Sep 2022 13:35:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08D05C433D7; Tue, 6 Sep 2022 13:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471329; bh=K4dGkykxDeQfgG8iJRdoD0/3YR3v+GjHk/N6AhY71Gw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vP0XsmiVvTracQBw4no34MPXE+Kp+Gy0UZvLoj5kbAXrW9Q0ULiKmo7xBsH6f0FM9 GFQBgRtEya8cglbckv6G4eCqnKnNQnoNZTD7iSkUGzpzcNB7VS9wsmRVEbJMejHGDQ hs8ubtW0IcEjdI7OoduT1x7PiToGUj15TmyblZbI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Abhishek Shah , Takashi Iwai Subject: [PATCH 5.10 72/80] ALSA: seq: Fix data-race at module auto-loading Date: Tue, 6 Sep 2022 15:31:09 +0200 Message-Id: <20220906132820.135185572@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132816.936069583@linuxfoundation.org> References: <20220906132816.936069583@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.1 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,T_SCC_BODY_TEXT_LINE 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 3e7e04b747adea36f349715d9f0998eeebf15d72 upstream. It's been reported that there is a possible data-race accessing to the global card_requested[] array at ALSA sequencer core, which is used for determining whether to call request_module() for the card or not. This data race itself is almost harmless, as it might end up with one extra request_module() call for the already loaded module at most. But it's still better to fix. This patch addresses the possible data race of card_requested[] and client_requested[] arrays by replacing them with bitmask. It's an atomic operation and can work without locks. Reported-by: Abhishek Shah Cc: Link: https://lore.kernel.org/r/CAEHB24_ay6YzARpA1zgCsE7=H9CSJJzux618E=Ka4h0YdKn=qA@mail.gmail.com Link: https://lore.kernel.org/r/20220823072717.1706-2-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/seq/seq_clientmgr.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) --- a/sound/core/seq/seq_clientmgr.c +++ b/sound/core/seq/seq_clientmgr.c @@ -121,13 +121,13 @@ struct snd_seq_client *snd_seq_client_us spin_unlock_irqrestore(&clients_lock, flags); #ifdef CONFIG_MODULES if (!in_interrupt()) { - static char client_requested[SNDRV_SEQ_GLOBAL_CLIENTS]; - static char card_requested[SNDRV_CARDS]; + static DECLARE_BITMAP(client_requested, SNDRV_SEQ_GLOBAL_CLIENTS); + static DECLARE_BITMAP(card_requested, SNDRV_CARDS); + if (clientid < SNDRV_SEQ_GLOBAL_CLIENTS) { int idx; - if (!client_requested[clientid]) { - client_requested[clientid] = 1; + if (!test_and_set_bit(clientid, client_requested)) { for (idx = 0; idx < 15; idx++) { if (seq_client_load[idx] < 0) break; @@ -142,10 +142,8 @@ struct snd_seq_client *snd_seq_client_us int card = (clientid - SNDRV_SEQ_GLOBAL_CLIENTS) / SNDRV_SEQ_CLIENTS_PER_CARD; if (card < snd_ecards_limit) { - if (! card_requested[card]) { - card_requested[card] = 1; + if (!test_and_set_bit(card, card_requested)) snd_request_card(card); - } snd_seq_device_load_drivers(); } }