From: Takashi Iwai Subject: Re: [PATCH 3/3] ALSA: seq: Protect racy pool manipulation from OSS sequencer Date: Mon, 15 Apr 2019 08:46:05 +0200 Message-ID: References: <20190412122935.4092-1-tiwai@suse.de> <20190412122935.4092-4-tiwai@suse.de> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 47F35F80CAB for ; Mon, 15 Apr 2019 08:46:05 +0200 (CEST) In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" To: Kai Vehmanen Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org On Mon, 15 Apr 2019 08:37:18 +0200, Kai Vehmanen wrote: > > Hi Takashi, > > On Fri, 12 Apr 2019, Takashi Iwai wrote: > > > +/* Unlock and unref the given client; for OSS sequencer use only */ > > +void snd_seq_client_ioctl_unlock(int clientid) > > +{ > > + struct snd_seq_client *client; > > + > > + client = snd_seq_client_use_ptr(clientid); > > + if (WARN_ON(!client)) > > + return; > > + mutex_unlock(&client->ioctl_mutex); > > + snd_use_lock_free(&client->use_lock); > > + snd_seq_client_unlock(client); > > is that double-unlock intentional? snd_seq_client_unlock() seems to call > the same snd_use_lock_free for the same handle as on the previous line. Yes, it's intentional. The trick is snd_seq_client_ioctl_lock() doesn't call snd_seq_client_unlock(), i.e. keeps refcount up. This is, in turn, released in snd_seq_client_ioctl_unlock(). snd_seq_client_ioctl_unlock() gets its refcount at use_ptr(), hence this releases twice. Maybe it's worth for more comments. thanks, Takashi