Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1182221rdb; Wed, 20 Sep 2023 01:51:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFypp1DUqztobI9AaewT1vBPoKu4AO7ypE82ov2Y/6gOKilxw/AYc8rAuz99mj6FC0ER1fq X-Received: by 2002:a05:6a20:144c:b0:148:658a:a73d with SMTP id a12-20020a056a20144c00b00148658aa73dmr2364142pzi.5.1695199869509; Wed, 20 Sep 2023 01:51:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695199869; cv=none; d=google.com; s=arc-20160816; b=USzZV1OFtopYFOEbNGcvzqglu4aSJQivYD/oAsJPSlpV6sc7szzRW3QPrGgSGEoFVb y7StpnlQs1TTh0wZI97lcwP5J4Jj9KpSrlvPZ7+rNPu+1g/5Q7fk/geC/2tIGz7N+BQx s0+gnl4d6xi4FU8PPVaftPgbyGDlTLnTI17SGqn/Khq6VYj9PsUjAmzzxB0lXC4y18eC +TEf/PIrn84d859DzkPpUT9lwCI47QPlDjAuxDbOIZNu7yjvKYtZDUoe6aq8PKmkUMDu 126g1z32nmAZArvASwj6pcmotWZg6Plcr+dYKrGFbBeuMRUc872HQe0Pa9IqZv13aVCX Cvug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=YtpT9rmsvNdD25C52w/dsFnFom7gmr6h8hTnMT9pppA=; fh=N9/9YhSMBqLF5CGUE92USh/gpIAvqeCe4wmA0HMVaoA=; b=ERb3bilekDNFYOXvEoifa8JHd0Dtl6byxAWUqcKBqHd9xUf2UNcLEpLbeis/59ddTT IVUyKli+l1pgDl+iIolbtWvEno8x0/5IMmBfv+sb7RBAAL5y53PxR/rdsX2XswP8DQPF VSjQaEqjnyZuHlG5clwP3M+LK8VP/Ab1EunH9UKI0aOC0fvQzghNs4npvvAkfSbpCnsM 1LqVPlnON/6XKWxYJjXmsRzTkFM3/iKGEuu4vxR1/PmECJtQiR4Gi0I8YLvkvXDCHsnF F0M9tzYn17v7htCrkQ8T8rMSWLRKEOMFKCdQnKN4z6DHPjv0sKG83Vjy+7345dFZWipQ +O8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=VUdNbspt; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id d15-20020a170902654f00b001bc1b018964si11620886pln.435.2023.09.20.01.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 01:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=VUdNbspt; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4D6DB8370D9F; Wed, 20 Sep 2023 00:05:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233534AbjITHFN (ORCPT + 99 others); Wed, 20 Sep 2023 03:05:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232386AbjITHFL (ORCPT ); Wed, 20 Sep 2023 03:05:11 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF33C92 for ; Wed, 20 Sep 2023 00:05:05 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 953072251C; Wed, 20 Sep 2023 07:05:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695193504; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YtpT9rmsvNdD25C52w/dsFnFom7gmr6h8hTnMT9pppA=; b=VUdNbsptH6xtu8SuSD1phRT0W/65IBdC356rMtSp3IQLekQbLsJxbwDlmZjGBov3oaLqRB c/RiR3ah/OzaVhc+F0ig/I9Vlzp645LprpNEG8znmpmzCYGfbSr5pNmFf+wWcvMdtjCNkN H31bI+i0XvPIYCvOeI3NHFp31r0uEI4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695193504; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=YtpT9rmsvNdD25C52w/dsFnFom7gmr6h8hTnMT9pppA=; b=5Sa7R9OcmwNsSJDDy17+/1xNUt5/Qo67Eu1e4a9fpmRM2Y3HvpWjCY+kmyG0My/2mWR799 rLVDYboGJxWv1GBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 523051333E; Wed, 20 Sep 2023 07:05:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id iygqE6CZCmXUJgAAMHmgww (envelope-from ); Wed, 20 Sep 2023 07:05:04 +0000 Date: Wed, 20 Sep 2023 09:05:03 +0200 Message-ID: <871qetwcio.wl-tiwai@suse.de> From: Takashi Iwai To: Ma Ke Cc: perex@perex.cz, tiwai@suse.com, mhocko@suse.com, akpm@linux-foundation.org, mgorman@techsingularity.net, 42.hyeyoo@gmail.com, surenb@google.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] ALSA: pcm: oss: Fix race at SNDCTL_DSP_SETTRIGGER There is a small race window at snd_pcm_oss_set_trigger() that is called from OSS PCM SNDCTL_DSP_SETTRIGGER ioctl; namely the function calls snd_pcm_oss_make_ready() at first, then takes the params_lock mutex for the rest. When the stream is set up again by another thread between them, it leads to inconsistency, and may result in unexpected results such as NULL dereference of OSS buffer as a fuzzer spotted recently. In-Reply-To: <20230920023536.3535439-1-make_ruc2021@163.com> References: <20230920023536.3535439-1-make_ruc2021@163.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 20 Sep 2023 00:05:12 -0700 (PDT) On Wed, 20 Sep 2023 04:35:36 +0200, Ma Ke wrote: > > The fix is simply to cover snd_pcm_oss_make_ready() call into the same > params_lock mutex with snd_pcm_oss_make_ready_locked() variant. > > Signed-off-by: Ma Ke The patch subject needs to be fixed. The subject line can't be that long. It must be concise. Put more text in the patch description instead. About the code change: the error handling is different after the patch. The current code returns an error immediately while your patch does "goto _skip1" etc, which doesn't abort but continues. thanks, Takashi > --- > sound/core/oss/pcm_oss.c | 16 ++++++---------- > 1 file changed, 6 insertions(+), 10 deletions(-) > > diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c > index 728c211142d1..9a830aeeba63 100644 > --- a/sound/core/oss/pcm_oss.c > +++ b/sound/core/oss/pcm_oss.c > @@ -2083,21 +2083,14 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr > psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK]; > csubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE]; > > - if (psubstream) { > - err = snd_pcm_oss_make_ready(psubstream); > - if (err < 0) > - return err; > - } > - if (csubstream) { > - err = snd_pcm_oss_make_ready(csubstream); > - if (err < 0) > - return err; > - } > if (psubstream) { > runtime = psubstream->runtime; > cmd = 0; > if (mutex_lock_interruptible(&runtime->oss.params_lock)) > return -ERESTARTSYS; > + err = snd_pcm_oss_make_ready_locked(psubstream); > + if (err < 0) > + goto _skip1; > if (trigger & PCM_ENABLE_OUTPUT) { > if (runtime->oss.trigger) > goto _skip1; > @@ -2128,6 +2121,9 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr > cmd = 0; > if (mutex_lock_interruptible(&runtime->oss.params_lock)) > return -ERESTARTSYS; > + err = snd_pcm_oss_make_ready_locked(csubstream); > + if (err < 0) > + goto _skip2; > if (trigger & PCM_ENABLE_INPUT) { > if (runtime->oss.trigger) > goto _skip2; > -- > 2.37.2 >