From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nf-next v3 3/5] netfiler: nf_tables: preemitve fix for audit failure
Date: Wed, 16 Oct 2024 15:19:10 +0200 [thread overview]
Message-ID: <20241016131917.17193-4-fw@strlen.de> (raw)
In-Reply-To: <20241016131917.17193-1-fw@strlen.de>
Nftables audit log unfortunately leaks implementation detail, the
transaction log size, to userspace.
Without this, nft_audit.sh selftest fails once subsequenct NEW/DELELEM
transactions can be compressed.
Thus increment the audit counter by the number of elements to keep
the output identical.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
v3: this patch is new to prevent nft_audit.sh from breaking
after next patch.
net/netfilter/nf_tables_api.c | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index d88adbd96ebe..bcb069057a53 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -10373,9 +10373,26 @@ static void nf_tables_commit_audit_free(struct list_head *adl)
}
}
+/* Silly, but existing test audit test cases require a count
+ * value derived from the (INTERNAL!) transaction log length.
+ *
+ * Thus, compaction of NEW/DELSETELEM breaks such tests.
+ */
+static unsigned int nf_tables_commit_audit_entrycount(const struct nft_trans *trans)
+{
+ switch (trans->msg_type) {
+ case NFT_MSG_NEWSETELEM:
+ case NFT_MSG_DELSETELEM:
+ return nft_trans_container_elem(trans)->nelems;
+ }
+
+ return 1;
+}
+
static void nf_tables_commit_audit_collect(struct list_head *adl,
- struct nft_table *table, u32 op)
+ const struct nft_trans *trans, u32 op)
{
+ const struct nft_table *table = trans->table;
struct nft_audit_data *adp;
list_for_each_entry(adp, adl, list) {
@@ -10385,7 +10402,7 @@ static void nf_tables_commit_audit_collect(struct list_head *adl,
WARN_ONCE(1, "table=%s not expected in commit list", table->name);
return;
found:
- adp->entries++;
+ adp->entries += nf_tables_commit_audit_entrycount(trans);
if (!adp->op || adp->op > op)
adp->op = op;
}
@@ -10544,7 +10561,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)
nft_ctx_update(&ctx, trans);
- nf_tables_commit_audit_collect(&adl, table, trans->msg_type);
+ nf_tables_commit_audit_collect(&adl, trans, trans->msg_type);
switch (trans->msg_type) {
case NFT_MSG_NEWTABLE:
if (nft_trans_table_update(trans)) {
--
2.45.2
next prev parent reply other threads:[~2024-10-16 14:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-16 13:19 [PATCH nf-next v3 0/5] netfilter: nf_tables: reduce set element transaction size Florian Westphal
2024-10-16 13:19 ` [PATCH nf-next v3 1/5] netfilter: nf_tables: add nft_trans_commit_list_add_elem helper Florian Westphal
2024-10-16 13:19 ` [PATCH nf-next v3 2/5] netfilter: nf_tables: prepare for multiple elements in nft_trans_elem structure Florian Westphal
2024-10-16 13:19 ` Florian Westphal [this message]
2024-10-16 13:19 ` [PATCH nf-next v3 4/5] netfilter: nf_tables: switch trans_elem to real flex array Florian Westphal
2024-10-16 13:19 ` [PATCH nf-next v3 5/5] netfilter: nf_tables: allocate element update information dynamically Florian Westphal
2024-10-16 14:36 ` [PATCH nf-next v3 0/5] netfilter: nf_tables: reduce set element transaction size Pablo Neira Ayuso
2024-10-16 16:10 ` Florian Westphal
2024-10-17 16:23 ` Pablo Neira Ayuso
2024-10-17 19:33 ` Paul Moore
2024-10-17 22:53 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241016131917.17193-4-fw@strlen.de \
--to=fw@strlen.de \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).