Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp524760pxx; Wed, 28 Oct 2020 10:16:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfupPufvIxpC8AdznqNX/iBMSMJSfDNEorsprhoEkUH1Xhv5aBNp4MvZ7H9DODxeUVq39m X-Received: by 2002:a17:906:3641:: with SMTP id r1mr45460ejb.391.1603905391748; Wed, 28 Oct 2020 10:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603905391; cv=none; d=google.com; s=arc-20160816; b=oVnzha54dq8Web4rlZi6jhq7Sm/qVVL5zm4I+vHXIaKohRVT+ztvGCfvSaW8mfeV0I gg67ypgMquTH7BY9Ppyv1veBo2NWO6oiqyYQNUs6ibjmTCvvIbgrqckwwum7xAwQT8fw v9BTNBsLTBV4nBa8xQDOCUuPzLywOXYcviRb3xZsbVhzy2cT92czNLR3fhPR7MhO+XfI YukRv70qlGj5Im61QC2RQPAOIqJv020bQKJLKYcK4fVZFLSon9WHByWSBJuoNrko1h41 mRq3DhaFPRXD5XO24zqBNbCHlNvRhPJWFJhJ4ZtF0sUyeAFom1duoTQmWs6X0vJSehXJ yrDg== 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=x1QoiOifHvIi68QuZQuCPrMS0F2OBtB0tHB6ulX+vMY=; b=xfdF0jvdDXp4AmhTapNIcJUCPj1pOoyrDdggUYHMcqVoRTURo53yekYOuGoE8ee3y7 urzU3bKPOXaThsoc3xaAEnRUzEoymce9kedcmspuL4Z6RoruuUvDxawT9W1zSC+H4+xK cbpPcfGGONgh0KZcnkTquXhCd9KiSn2LcPY7tltnrWxycyyTx0BbbmWHo1xboQwwxTjM wiPDspnMmyDOayeVU1+uJbtu87oQI1XZxwHYHwZj8JFPWJKUoMkXRQpDSAMxZTZcZ2Pn PpH6sNPwMe9z2uBAyQtUZZ0DEmQUg5t/kk6NWGaVAJLz1RlVHXb8mnSqyaDw9Da5TZSD amUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zNwnW+Xj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i9si3854304eje.410.2020.10.28.10.16.08; Wed, 28 Oct 2020 10:16:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zNwnW+Xj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1820677AbgJ0RhM (ORCPT + 99 others); Tue, 27 Oct 2020 13:37:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:34478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760653AbgJ0Ofm (ORCPT ); Tue, 27 Oct 2020 10:35:42 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4617B22202; Tue, 27 Oct 2020 14:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809340; bh=1NVx5rLyal8hpuvHe85OB/FAzDsAwKW3xaNGwbHZY2E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zNwnW+XjKvrEMpdVxtJc+4qSZhZKWM7nFFatEY2aCsEeNpz24v8VWTxOSpTAUw/cl jSghJACd9vyF8UCK0GDKN868cKk8qCPO+3CHXVjIhbkd2vumoq1Lha7FfvwoI8Pgp0 TjVGqjCZot7/koJDkUYaPxhOfcNG0z/+YPi1yq8Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Machek , Takashi Iwai , Sasha Levin Subject: [PATCH 5.4 162/408] ALSA: seq: oss: Avoid mutex lock for a long-time ioctl Date: Tue, 27 Oct 2020 14:51:40 +0100 Message-Id: <20201027135502.611856996@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit 2759caad2600d503c3b0ed800e7e03d2cd7a4c05 ] Recently we applied a fix to cover the whole OSS sequencer ioctls with the mutex for dealing with the possible races. This works fine in general, but in theory, this may lead to unexpectedly long stall if an ioctl like SNDCTL_SEQ_SYNC is issued and an event with the far future timestamp was queued. For fixing such a potential stall, this patch changes the mutex lock applied conditionally excluding such an ioctl command. Also, change the mutex_lock() with the interruptible version for user to allow escaping from the big-hammer mutex. Fixes: 80982c7e834e ("ALSA: seq: oss: Serialize ioctls") Suggested-by: Pavel Machek Link: https://lore.kernel.org/r/20200922083856.28572-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/core/seq/oss/seq_oss.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c index c8b9c0b315d8f..250a92b187265 100644 --- a/sound/core/seq/oss/seq_oss.c +++ b/sound/core/seq/oss/seq_oss.c @@ -174,9 +174,12 @@ odev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (snd_BUG_ON(!dp)) return -ENXIO; - mutex_lock(®ister_mutex); + if (cmd != SNDCTL_SEQ_SYNC && + mutex_lock_interruptible(®ister_mutex)) + return -ERESTARTSYS; rc = snd_seq_oss_ioctl(dp, cmd, arg); - mutex_unlock(®ister_mutex); + if (cmd != SNDCTL_SEQ_SYNC) + mutex_unlock(®ister_mutex); return rc; } -- 2.25.1