From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27F07110A; Tue, 23 Jan 2024 02:09:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705975778; cv=none; b=uFENfz9siPckO4iumw19u6PPuOrlkUR2Jt0qNpcZTKSBVnYyfCT6LX5v3dCKG5gzK5FoUJ/M8VFcu9942hQTEclahO2wwjJzfNLfC/ZWbdHm+Wgbctv2zXkYRKWkjpCEhErQbEwfx0bOLxAxqbP7qdVOCLZwihfWUbXAJO1Uv/I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705975778; c=relaxed/simple; bh=BUbh6M/L+yomP5ID54aKq4cLOXuh0DU3h2c4J3CUE4g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jYNd+hawJFbBjxZ8L9+Rba9CYq47O4Z2mc7LaqOY/wvN43KtObhqj/SHApvOE+xGli+y9EM9+ym9MTnbebcvkvHOpQh01GingI94oOO+6RhvaBEy/YdmXr8pOuSU7/BYq7qm3aGIFyL9u+XSfalBI2v4Y5aEclmBuwC/96Fo7z0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=CohBfnhd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="CohBfnhd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE8C6C433F1; Tue, 23 Jan 2024 02:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705975778; bh=BUbh6M/L+yomP5ID54aKq4cLOXuh0DU3h2c4J3CUE4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CohBfnhd9KhGjtCXtHBSGoFVwuwfK8/Z0EZbkNp3kdcgDBYvE1krpiV9+vuNv5EBZ cyfMWOw4Mw9tBACJKIAlVuOYq+SfmMCoCWpLI+P9ZdzqmwHdlCi1zvW8G14YuiuNV9 IqRu1ddUTCso0ctIs2UFahQfgZDu+MrXsWURWbe0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.6 561/583] netfilter: nft_limit: do not ignore unsupported flags Date: Mon, 22 Jan 2024 16:00:12 -0800 Message-ID: <20240122235829.339878843@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122235812.238724226@linuxfoundation.org> References: <20240122235812.238724226@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pablo Neira Ayuso [ Upstream commit 91a139cee1202a4599a380810d93c69b5bac6197 ] Bail out if userspace provides unsupported flags, otherwise future extensions to the limit expression will be silently ignored by the kernel. Fixes: c7862a5f0de5 ("netfilter: nft_limit: allow to invert matching criteria") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nft_limit.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/net/netfilter/nft_limit.c b/net/netfilter/nft_limit.c index 145dc62c6247..79039afde34e 100644 --- a/net/netfilter/nft_limit.c +++ b/net/netfilter/nft_limit.c @@ -58,6 +58,7 @@ static inline bool nft_limit_eval(struct nft_limit_priv *priv, u64 cost) static int nft_limit_init(struct nft_limit_priv *priv, const struct nlattr * const tb[], bool pkts) { + bool invert = false; u64 unit, tokens; if (tb[NFTA_LIMIT_RATE] == NULL || @@ -90,19 +91,23 @@ static int nft_limit_init(struct nft_limit_priv *priv, priv->rate); } + if (tb[NFTA_LIMIT_FLAGS]) { + u32 flags = ntohl(nla_get_be32(tb[NFTA_LIMIT_FLAGS])); + + if (flags & ~NFT_LIMIT_F_INV) + return -EOPNOTSUPP; + + if (flags & NFT_LIMIT_F_INV) + invert = true; + } + priv->limit = kmalloc(sizeof(*priv->limit), GFP_KERNEL_ACCOUNT); if (!priv->limit) return -ENOMEM; priv->limit->tokens = tokens; priv->tokens_max = priv->limit->tokens; - - if (tb[NFTA_LIMIT_FLAGS]) { - u32 flags = ntohl(nla_get_be32(tb[NFTA_LIMIT_FLAGS])); - - if (flags & NFT_LIMIT_F_INV) - priv->invert = true; - } + priv->invert = invert; priv->limit->last = ktime_get_ns(); spin_lock_init(&priv->limit->lock); -- 2.43.0