Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13329379ybl; Sun, 29 Dec 2019 09:25:54 -0800 (PST) X-Google-Smtp-Source: APXvYqwP0N1bzfrgqs7HZhntJPZoLR280w/kAMUI8TRWlZQgfwDSoorEXJG/8rKoOxyPH9rDYZzK X-Received: by 2002:a05:6830:681:: with SMTP id q1mr71667774otr.162.1577640354703; Sun, 29 Dec 2019 09:25:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577640354; cv=none; d=google.com; s=arc-20160816; b=bc892S77OROcwstR8li6AALM8eJRjgcm9UiiVN3UboDK2GwusplR18Mgql2x195ZFL RTRtk35oCgovfAdCmXdpDCEd9Oo9xZCc/jIR7WYCwPET75RNdB5xMj4rXYY5TxXzInx2 JZRk34Zed0T3lplScI66Li5qXc5UFp9hMpH4eXENRMTj/bkekefniVZ37yEINTNq5mGD IlcysMcB9OYGnFCCshTqdm6H+vUb9kjelYcO/c3aV80nrXh+V/y31a8fMz+N2jmPCLEn WrXgvxFJ9/pvMefBIClXVFEoqiVdxqgSP6LlRNGtOmEV+ZSvu5R09/9+WV+rGhZNVeFv vcAw== 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=uy44tmV5g4tFELspzVvgI4lyu+ya384rVCxWwIlM/8M=; b=yWAMy/RXdhK2AC1yfXvc4NAKqfibl+s+SkbksyJPdM1b/45k5tWwQISKJ0BMX9MHRM WXd56zrtmn0ZXwFajAL+oeomXoBylBqFpSHBkcK7nOo/Q51YdQH3YZ03O9Nfdh9piIr/ p0dG6KJByvEitIImue5EJVEzf6LEXkzbtRrTtZIGcLyExs2irWcRFs1p4aiXTpfoZUZM 08Z8qhzmSXDGs3aSHJMmqNfQQxDB4/LBvgfh2iYcib/SmLjhnjsYcdG2SJEAkqHCaaah eG7lQIrZh6grSXZgWUgzv5NIavLlCIcRF6x6rXyBbAuhYQLZRAoSPTLxOOPnVRxGHB4v bwLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s4cfU9PC; 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 92si22013065otr.25.2019.12.29.09.25.43; Sun, 29 Dec 2019 09:25:54 -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=s4cfU9PC; 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 S1727772AbfL2RYh (ORCPT + 99 others); Sun, 29 Dec 2019 12:24:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:43358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727725AbfL2RYc (ORCPT ); Sun, 29 Dec 2019 12:24:32 -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 C8AB421744; Sun, 29 Dec 2019 17:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640272; bh=XAC7PQHi96qa4UWxS6o55uWp4UYVdUGfXDnuhqGpsAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s4cfU9PCZTn+5kZMO0VXlU6G7YxEx24VHAAmkQ0wnRgUEM5nSeZjGuWv6rgOIx+LA QKbPiGcRKFXyzTdGsXacSew4Mlb7iBFBou+B01ghXLzBpX5GV9kVt0RBjrp7hY/Yv4 tfZCsVBjj0mTBRJAxcbotb1MyeVWh/49m54q7+ZU= 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.14 090/161] ALSA: timer: Limit max amount of slave instances Date: Sun, 29 Dec 2019 18:18:58 +0100 Message-Id: <20191229162425.790607612@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162355.500086350@linuxfoundation.org> References: <20191229162355.500086350@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 c60dfd52e8a6..22589a073423 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