Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13342230ybl; Sun, 29 Dec 2019 09:41:52 -0800 (PST) X-Google-Smtp-Source: APXvYqyRYc9nKUeK1g24cIbDhumk5+T87KL1gKlU2ain9ewmgfuXrdBprG/dbO2E7QoYeCRyWPV2 X-Received: by 2002:a9d:7ada:: with SMTP id m26mr71715130otn.111.1577641312802; Sun, 29 Dec 2019 09:41:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577641312; cv=none; d=google.com; s=arc-20160816; b=Vcjnue4+afe8erlionEaeILNFCW/O7/gczAkgE0VKQgwgCOFzmTu02JWY7nbWZRrdy 5T21xRa4vzapOKAXGXUfXBO+0F+daTqrbc4CEdZcpLEav/4P5tpFpLslecfqo3icNT2e eWGCDIUc9EZlKHfWPIFWIPm2m34ySKnSn4Z3aE2NebglpAGBesS4GLMNnEfRCrHpfo6f cBdvMuPjOLkSYWvJxq6PnbksEwPrr5JnbN5KHMEm8/PSN0ScRiLaXbT3NWeH8CuNf4Cq hpN8JW0e3kkq7UQcV2/BN7SD0Z4lmz1JAUV/7JZ+LnxnjaWV60+zroa1/Q94L1rNAVOx ijuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OQhVPBib/HdK4B5WEUlW3d9mLsIPpPEijK2EqUGIDUA=; b=HYn6drr6oFMZIk8Z8miJjllG26OJUkYYU/Xu0nSjV2Ygkg4+qV1lxyk7TNjIld+bfC Jl5fhwReP0pmE8iLGizTP3IpAmANPQrwFbAwnHech2jIlD7efnNdi0nR0FxkM6k6D9kN /NOJmoa9YH/IcyNzimqgTMOLkhbJCBlUHEJCwhACdSz4VePtFfMPNjRbjvOKYCHTtBfK dU4cDW4fCXToEC8OFcMZD9G0qxUy29Lg5ZaShPrZCxT9uCZDE7U3bdu8Wdk6QEyab06Q 6M6QsOG1Hy9blrzRoe8hPcnp+HdnuwH7pfOXJc6nlJAh4ueprRaWZhGAtL4r2zeRynLs NHtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VnBNp0UD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h125si19523556oia.253.2019.12.29.09.41.42; Sun, 29 Dec 2019 09:41:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VnBNp0UD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729651AbfL2Rjv (ORCPT + 99 others); Sun, 29 Dec 2019 12:39:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:32868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729066AbfL2Rc2 (ORCPT ); Sun, 29 Dec 2019 12:32:28 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 832B3207FF; Sun, 29 Dec 2019 17:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640748; bh=DeAFUOqIJW9mvBBsACK0JeC7VLRp80XShrXQniWA2dA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VnBNp0UD/S0ENeFVjIl9TUDN3kXj3akZQRa1e+QVesCSBquv8Zvyvdcx9fDu9RdW1 jr0KbniI6VFnpfx/UKJOKR6GBO0WbX9D/FBRmOyDN7tFi2yQumAFAyf3YgMC+MhynN AkQM+2e781+m14gJbadOpjXVB+8R9xaSwzp1mR44= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Sasha Levin Subject: [PATCH 4.19 121/219] ALSA: timer: Limit max amount of slave instances Date: Sun, 29 Dec 2019 18:18:43 +0100 Message-Id: <20191229162526.773826147@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162508.458551679@linuxfoundation.org> References: <20191229162508.458551679@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai [ Upstream commit fdea53fe5de532969a332d6e5e727f2ad8bf084d ] The fuzzer tries to open the timer instances as much as possible, and this may cause a system hiccup easily. We've already introduced the cap for the max number of available instances for the h/w timers, and we should put such a limit also to the slave timers, too. This patch introduces the limit to the multiple opened slave timers. The upper limit is hard-coded to 1000 for now, which should suffice for any practical usages up to now. Link: https://lore.kernel.org/r/20191106154257.5853-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/core/timer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sound/core/timer.c b/sound/core/timer.c index 86a31e69fc7d..b5dc51030316 100644 --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -88,6 +88,9 @@ static LIST_HEAD(snd_timer_slave_list); /* lock for slave active lists */ static DEFINE_SPINLOCK(slave_active_lock); +#define MAX_SLAVE_INSTANCES 1000 +static int num_slaves; + static DEFINE_MUTEX(register_mutex); static int snd_timer_free(struct snd_timer *timer); @@ -266,6 +269,10 @@ int snd_timer_open(struct snd_timer_instance **ti, err = -EINVAL; goto unlock; } + if (num_slaves >= MAX_SLAVE_INSTANCES) { + err = -EBUSY; + goto unlock; + } timeri = snd_timer_instance_new(owner, NULL); if (!timeri) { err = -ENOMEM; @@ -275,6 +282,7 @@ int snd_timer_open(struct snd_timer_instance **ti, timeri->slave_id = tid->device; timeri->flags |= SNDRV_TIMER_IFLG_SLAVE; list_add_tail(&timeri->open_list, &snd_timer_slave_list); + num_slaves++; err = snd_timer_check_slave(timeri); if (err < 0) { snd_timer_close_locked(timeri, &card_dev_to_put); @@ -364,6 +372,8 @@ static int snd_timer_close_locked(struct snd_timer_instance *timeri, struct snd_timer_instance *slave, *tmp; list_del(&timeri->open_list); + if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) + num_slaves--; /* force to stop the timer */ snd_timer_stop(timeri); -- 2.20.1