Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6779872rwn; Tue, 13 Sep 2022 08:56:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR574qcUFtx5KYK60ljQpMLdFhgebuAdEIj/IwPwhQ7fYSUSj5Sdqi3gb+1J+DIV60H0VkgW X-Received: by 2002:a17:906:8466:b0:77b:43e9:48b5 with SMTP id hx6-20020a170906846600b0077b43e948b5mr11078697ejc.254.1663084563746; Tue, 13 Sep 2022 08:56:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663084563; cv=none; d=google.com; s=arc-20160816; b=lP5RQQ9xn4UQrrkyPuXYTvb2nBIWOyG9s1/3ANB8EDLIcGJwkue2AzTN74or7Y7u7I 2V1Zhc0SlbdESwKA7a85/x5q90JPqbHva4+JfRQz0ikQFbePuEYBYAQ8oBw4IfFPwFOd FDsIZ5LxZBhsoVs5u3R2T0/cCiEiWrzIj1mNdeXTHxK3OXDQlopDvKiBb02y+0CCYc4e tiDtDz6TVozS2yoQad6lNWuO41Xx0nSrJnKkE3j4Qa8+xMopoCDAmpLcJOjTKSUNRBY8 XDfsLmYCIa7Y66MtlDAGctMLKW3rWhLH0+rLaks/K8uWgAwuq5Dbc+CTCJsI2uIyWafR dUKw== 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=yS2I39166h6MXib63HDdIjyIB0TRhGKGqsV7TP++5cTHpN2TdbWQHnieRRRpcX5hc/ 6+lfznLoKJ1cfvgmvp9EEDnnR0b2FgG8JXEIXCmoDTneMp46E0H8NZtIhY6N6RWK02BU a6CMru+fS954sWRziUyQRX8Llj15BL3LvxPVjJOmx13gkeYjXB9jdQo3kjfCvqtniN2h lHY1URxcwubOr+IsBPrFvP1cx08YVAi0prj9Rm0Y8YKxvlhAlMk+BohyMbgGHSkNRQGM DtKeDW1UV3Hn2O0Xe8xYkp3I5uRqk7IONBCgX3FOW6/pLpyaJui32rkfGuqGsHXyx0aE Se7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RbZJbz9K; 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 a12-20020a170906244c00b00730936657d1si8720202ejb.552.2022.09.13.08.55.35; Tue, 13 Sep 2022 08:56:03 -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=RbZJbz9K; 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 S232744AbiIMPjl (ORCPT + 99 others); Tue, 13 Sep 2022 11:39:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236697AbiIMPio (ORCPT ); Tue, 13 Sep 2022 11:38:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A3C22AE9; Tue, 13 Sep 2022 07:44:30 -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 84953614D2; Tue, 13 Sep 2022 14:28:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FB42C433D6; Tue, 13 Sep 2022 14:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079315; bh=K4dGkykxDeQfgG8iJRdoD0/3YR3v+GjHk/N6AhY71Gw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RbZJbz9K+lULo5D5zUQEBEuH2m5uKLn4f6Xyl/ZtWGAb9XO/j1clgce4IX2jzqv+3 RgILUdC5J6j+GvDfStMeuFYN3G3jtpVvZ10ropKuGa9g6iSdNH0yzGC629civJVgnP 4Q5RuKRKjsnqzoQyVNoisHULdDPIW9hQK7lgDF/U= 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.4 060/108] ALSA: seq: Fix data-race at module auto-loading Date: Tue, 13 Sep 2022 16:06:31 +0200 Message-Id: <20220913140356.202147261@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@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(); } }