From patchwork Tue Oct 27 13:48:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 311749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A8B2C55178 for ; Tue, 27 Oct 2020 18:19:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48CB421D7B for ; Tue, 27 Oct 2020 18:19:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603822767; bh=i9oJ/VJPFfBpsXI5rxMAoa8OBIlBSDzFD9FLvmBU3xs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Enb67Op3tG7jPwMbryJvFq3dlqvfshb+Ux6mA+CeaHsca6vjkWFHV6MYNBo2ewMaA thDcimfH/BNVS6dnwpxAVVQCuEPJgJqWViRuM1+pC3xu1QoCZV3WEYldT2MHj5u6dH n09kvbgGvs4uc4n9vYgl1BzkbyqZPfptDoRiArMw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1826353AbgJ0ST0 (ORCPT ); Tue, 27 Oct 2020 14:19:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:51820 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2440854AbgJ0ODf (ORCPT ); Tue, 27 Oct 2020 10:03:35 -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 1C9D522281; Tue, 27 Oct 2020 14:03:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603807414; bh=i9oJ/VJPFfBpsXI5rxMAoa8OBIlBSDzFD9FLvmBU3xs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aCHlUh2a7+ORKZXim8bJKNmKu00O6s57rpYeikIlg2VquZGXF3n3XD1AothQVza0v H/tBmUI4hcOIGRkh58cb8vtcbg4lJhoSQ9N7H7OxMd1jtxZq6qUuQtUJWiUtIWtQ27 v8CEl4TJ0MzEWp7DJjcr32mXArE4zBh5sy1lZFmk= 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 4.9 045/139] ALSA: seq: oss: Avoid mutex lock for a long-time ioctl Date: Tue, 27 Oct 2020 14:48:59 +0100 Message-Id: <20201027134904.269687484@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027134902.130312227@linuxfoundation.org> References: <20201027134902.130312227@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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 4b78979599131..ade880fe24a41 100644 --- a/sound/core/seq/oss/seq_oss.c +++ b/sound/core/seq/oss/seq_oss.c @@ -187,9 +187,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; }