Skip to contentSkip to conversation

netfilter: cthelper: report absent filtered deletes

PATCH New Baek Kyu, Kim 2 participants 2 messages Oct 31

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: cthelper: report absent filtered deletes

nfnl_cthelper_del() returns success when the helper list is empty, even if the request names a helper that does not exist. The same request returns -ENOENT when an unrelated helper is present. This makes the ACK depend on unrelated list contents.

The empty-list success case is needed only for an unfiltered flush. Return success when a helper was deleted or when neither a name nor a tuple filter was supplied. Otherwise return the existing -ENOENT.

Fixes 12f7a505331e ("netfilter: add user-space connection tracking helper infrastructure")

---
An arm64 QEMU/KVM kernel received NETLINK_NETFILTER cthelper DEL, NEW and GET requests. Deleting an absent named helper from an empty list returned success before the change and -ENOENT afterward. Deleting an existing helper and an unfiltered empty-list flush kept their success responses. Tuple-only deletion and packet traffic were not exercised.

 net/netfilter/nfnetlink_cthelper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_cthelper.c +4 -3
index 5b6a09f46903f..774edb07fb1a3 100644
@@ -700,7 +700,7 @@ static int nfnl_cthelper_del(struct sk_buff *skb, const struct nfnl_info *info,
 	struct nf_conntrack_tuple tuple;
 	bool tuple_set = false, found = false;
 	struct nfnl_cthelper *nlcth, *n;
-	int j = 0, ret;
+	int ret;
 
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
@@ -719,7 +719,6 @@ static int nfnl_cthelper_del(struct sk_buff *skb, const struct nfnl_info *info,
 	ret = -ENOENT;
 	list_for_each_entry_safe(nlcth, n, &nfnl_cthelper_list, list) {
 		cur = nlcth->helper;
-		j++;
 
 		if (helper_name &&
 		    strncmp(cur->name, helper_name, NF_CT_HELPER_NAME_LEN))
@@ -738,7 +737,9 @@ static int nfnl_cthelper_del(struct sk_buff *skb, const struct nfnl_info *info,
 	}
 
 	/* Make sure we return success if we flush and there is no helpers */
-	return (found || j == 0) ? 0 : ret;
+	if (found || (!helper_name && !tuple_set))
+		return 0;
+	return ret;
 }
 
 static const struct nla_policy nfnl_cthelper_policy[NFCTH_MAX+1] = {
Signature · 1 line
2.55.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.