Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4467760rwb; Tue, 6 Sep 2022 07:59:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6YjBW6aIuIHwPCR6MuywAtBIvdMwKE/bBArdUsw4gBgAutnJk3IzLSeumShbVa3HrfGlN3 X-Received: by 2002:a17:907:9493:b0:73b:e605:f3b with SMTP id dm19-20020a170907949300b0073be6050f3bmr41397079ejc.37.1662476366464; Tue, 06 Sep 2022 07:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662476366; cv=none; d=google.com; s=arc-20160816; b=tKy6uixKmAYV5J9ANv1UTbJ9o2oA0zFTZIG7cRmC9l2H2vTF2vAjEuX7dIWJ6woXX3 Zqzv8tPBl/zhPmOlaB98PNq596vzPQDoJ1mwfaY9Tio2rS0qlSYCyMq84zRerhaS+51c oskLPtOV/Hd+D/s3uyCnX8M6UZOZrD6xTKz2Z+PFJy1nBbBl5bUKnI0MxdSpxSHLsB9b XmsRdLfrUMiJxxBaUQKSNJlIoxOpsrkPTAig3dgahwTLrqhG78eLhmqJ+szUqAYStaL5 ncU0qaCAisqkU/mWL5K0cy9UCiz/oJhlnVoviV7cSnuuY7qXN0FfHlIN2qd78a/5dvyd bPeQ== 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=DN4Ls3iHnklCnuOMl24e5bhwXfZ6dAakE0Dc2ZwBOEg=; b=fIQuNoWBwqvklj/D0CtVCdxsChct6IIIuLVniChG7uu6oh0Xh3R0Ils1wWqPakidU2 t2hiIGu4U14L44/DEAAcMAhF9RyZOIvX+s/2adyWYoyvWiXudn1Zksi63AxTtQyM04LJ V/l6Nl4hsLkkmhYtX+7kijX41KX9DtHv4ZSym5JH1vNW21v9LjRQSVVlPNubAoJupmG9 97KZd4zz4PXaMlo9as1R1JY/JqoArzDq4Ma64MEtvwwVMVQ3+KrFvMhqXe+nbjjzbfqx VJcduEW2otHrzeMz5tvCXHjPK7ffbPqnlNdejm5X8QS4+P558DLDzPFCLbIybZLWG9UN 7JgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KJs+WIcH; 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 s19-20020a1709060c1300b00741a3548ca5si277552ejf.761.2022.09.06.07.59.01; Tue, 06 Sep 2022 07:59:26 -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=KJs+WIcH; 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 S231196AbiIFNkz (ORCPT + 99 others); Tue, 6 Sep 2022 09:40:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233678AbiIFNkF (ORCPT ); Tue, 6 Sep 2022 09:40:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85DB17C52A; Tue, 6 Sep 2022 06:36:45 -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 890EAB8162F; Tue, 6 Sep 2022 13:35:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0D94C433D6; Tue, 6 Sep 2022 13:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471323; bh=euG67sgDvwLXIEgTY2TWW6s7v4hP9aP7Kb+DIRT65rc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KJs+WIcHBJ50ADvaVaa3MflUj9O+W1uo3/+1d2kLmJ1wyF7nYfwAHEFeCDutYV6Wq 6JVcfeFFQ9c0VRRFPcngKu3ZkR94mMDBnl1tB4dkSWab9GHidBPzJpFWtDXfa+UNHe wL06BrbY/l0iqL8qV5RsLyrIv2dGFZS2Uqt46wMc= 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 71/80] ALSA: seq: oss: Fix data-race for max_midi_devs access Date: Tue, 6 Sep 2022 15:31:08 +0200 Message-Id: <20220906132820.086643364@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 22dec134dbfa825b963f8a1807ad19b943e46a56 upstream. ALSA OSS sequencer refers to a global variable max_midi_devs at creating a new port, storing it to its own field. Meanwhile this variable may be changed by other sequencer events at snd_seq_oss_midi_check_exit_port() in parallel, which may cause a data race. OTOH, this data race itself is almost harmless, as the access to the MIDI device is done via get_mdev() and it's protected with a refcount, hence its presence is guaranteed. Though, it's sill better to address the data-race from the code sanity POV, and this patch adds the proper spinlock for the protection. Reported-by: Abhishek Shah Cc: Link: https://lore.kernel.org/r/CAEHB2493pZRXs863w58QWnUTtv3HHfg85aYhLn5HJHCwxqtHQg@mail.gmail.com Link: https://lore.kernel.org/r/20220823072717.1706-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/seq/oss/seq_oss_midi.c | 2 ++ 1 file changed, 2 insertions(+) --- a/sound/core/seq/oss/seq_oss_midi.c +++ b/sound/core/seq/oss/seq_oss_midi.c @@ -267,7 +267,9 @@ snd_seq_oss_midi_clear_all(void) void snd_seq_oss_midi_setup(struct seq_oss_devinfo *dp) { + spin_lock_irq(®ister_lock); dp->max_mididev = max_midi_devs; + spin_unlock_irq(®ister_lock); } /*