Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795057206; b=2cEPRMBtf13Xs+804kMIlWHraRP5wZKSZE2AyQs0t9X8Ta/3OoMuU1sP3I/+JJX3VrXJ ilNipASxQT0BNVRN/BY6lz6HgK10viwK0yqC5Lbr5wkUPanUQO4ZQh//kDuWXM8esbAhj ddVUWjuRa6bLnEWI81FyI2fz0w2WTv0XCl0SMP23XfyTqgMKco2l/o5OPReU0KgOrBbtI ZrFaYC9LN3OSH5uYVKit6iPg7E/WIWYvm+AQ3pyJtwmAmY/TSwQLivOu/tzgzf9uDWCCK QBEjY624yCV4NMQjM1ukPyC/hH6h/0QejpcY/smqxd00XoecUyFsg687VT65rQZvkoA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795057206; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=m0kaLJaTrqJ48HiSNijgO3r+/kJyMr4hUfR8CSJyP1U=; b=CuWBrfXMIEgpQedk1C94hGzyxpa6fGCCvOWSWSabzJ9Ria29BV3C4fnN+gHOw0MviUP2 TxRHJm0lcyPbclN2w9WvOgjhyQcGxon7dJ+ht+YLUvhQuDPS6zCMfh3/l19A+GG7xV1Y1 xsE/aXU0/UDU6lR/mkgf1W6yXjqbed6VVVHKHQUO6sv5N8fhmclReCOL506dmTzRkqFbI pFyogtveBwJ87POy276cIiOt094mpYYRF6pjsz+zDL9GKzcmvToqLDcRBUZ8obA5oPBZt stGhPntgK0gjyjz2nksosgvZv1ORR7Rk6115iB+unl9r1HvkmQKBr0FsBoKz7Jh5vIg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VIdHhSPg; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2688060A2607; Thu, 19 Nov 2026 03:00:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=VIdHhSPg Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E1FB1F000C8; Thu, 19 Nov 2026 03:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795057206; bh=m0kaLJaTrqJ48HiSNijgO3r+/kJyMr4hUfR8CSJyP1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VIdHhSPgl+2CFvCMr6Ziofbw6pFybbLe38HDybECjMDsP0BdRJrDgUbpCDHFaAKuA Zf2MrEC+cUM/e3T0Q2MYIgE4DETJcpz7q492aEnvCSVqNQEq760umscPyPP6YIyTQ3 IhsEzGT0qu3qKgzam4ZklZzyKjY8Bf2SLz5zkfUI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiayuan Chen , Florian Westphal , Sasha Levin Subject: [PATCH 5.10 0046/1848] netfilter: ebtables: bound num_counters like nentries in do_replace() Date: Wed, 18 Nov 2026 15:34:44 +0100 Message-ID: <20261118145913.034696148@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118145911.150052362@linuxfoundation.org> References: <20261118145911.150052362@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiayuan Chen [ Upstream commit 43ae85af154b27f9a0ff602f7a01e3a7583ffdab ] do_replace_finish() allocates the counter buffer before it is validated: counterstmp = vmalloc_array(repl->num_counters, sizeof(*counterstmp)); do_replace() only checks num_counters against INT_MAX / sizeof(struct ebt_counter), so vmalloc_array() can be asked for up to 134217726 * 16 = 2147483616 bytes (~2 GiB). num_counters must in fact equal nentries: do_replace_finish() later rejects the request when repl->num_counters != t->private->nentries. get_counters() folds the per-CPU counters back into one entry per rule, so what userspace gets is bounded by nentries, never by nentries * nr_cpus. Apply the same upper bound used for nentries (MAX_EBT_ENTRIES) to the incoming num_counters so the over-sized allocation can no longer be requested. The allocation is still kept outside the ebt_mutex, since vmalloc() may sleep and trigger reclaim; only the bound is tightened. Signed-off-by: Jiayuan Chen Signed-off-by: Florian Westphal Signed-off-by: Sasha Levin --- net/bridge/netfilter/ebtables.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c index 426a28ed68ce4..fef9aa64acf3e 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -38,6 +38,8 @@ #define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter))) #define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \ COUNTER_OFFSET(n) * cpu)) +#define MAX_EBT_ENTRIES (((INT_MAX - sizeof(struct ebt_table_info)) / \ + NR_CPUS - SMP_CACHE_BYTES) / sizeof(struct ebt_counter)) @@ -1084,10 +1086,9 @@ static int do_replace(struct net *net, sockptr_t arg, unsigned int len) return -EINVAL; /* overflow check */ - if (tmp.nentries >= ((INT_MAX - sizeof(struct ebt_table_info)) / - NR_CPUS - SMP_CACHE_BYTES) / sizeof(struct ebt_counter)) + if (tmp.nentries >= MAX_EBT_ENTRIES) return -ENOMEM; - if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter)) + if (tmp.num_counters >= MAX_EBT_ENTRIES) return -ENOMEM; tmp.name[sizeof(tmp.name) - 1] = 0; @@ -2151,10 +2152,9 @@ static int compat_copy_ebt_replace_from_user(struct ebt_replace *repl, if (tmp.entries_size == 0) return -EINVAL; - if (tmp.nentries >= ((INT_MAX - sizeof(struct ebt_table_info)) / - NR_CPUS - SMP_CACHE_BYTES) / sizeof(struct ebt_counter)) + if (tmp.nentries >= MAX_EBT_ENTRIES) return -ENOMEM; - if (tmp.num_counters >= INT_MAX / sizeof(struct ebt_counter)) + if (tmp.num_counters >= MAX_EBT_ENTRIES) return -ENOMEM; memcpy(repl, &tmp, offsetof(struct ebt_replace, hook_entry)); -- 2.53.0