Skip to contentSkip to conversation

netfilter: nfnetlink_cthelper: fix expect policy update copying only first class values to all classes

PATCH In review Dudu Lu 2 participants 2 messages Apr 13

Subsystems (2)
lore
Share & tools
lore

Dudu Lu

author
#0 lore raw

PATCH 1/1 netfilter: nfnetlink_cthelper: fix expect policy update copying only first class values to all classes

In nfnl_cthelper_update_policy_all(), when updating the expect policies of a multi-class conntrack helper, the loop iterates over all expect classes but always reads from new_policy[0] instead of new_policy[i]:

    for (i = 0; i < helper->expect_class_max + 1; i++) {
        policy = &helper->expect_policy[i];
        policy->max_expected = new_policy->max_expected;  /* always [0] */
        policy->timeout      = new_policy->timeout;       /* always [0] */
    }

The new_policy array was correctly parsed per-class by nfnl_cthelper_update_policy_one() in the validation loop above (line 336-342), with each new_policy[i] holding its respective class values. However, the copy loop dereferences new_policy as a pointer (new_policy->x) rather than indexing it as an array (new_policy[i].x), creating a security vulnerability.

As a result, all expect classes of a multi-class helper get overwritten with the values of class 0, discarding the per-class differentiation.

This affects helpers like H.323 which use multiple expect classes (RTP, RTCP, T.120) with different max_expected and timeout values. After a policy update, all classes get identical limits, breaking the per-class expect enforcement.

Fix by indexing new_policy with the loop variable.

Fixes 2c422257550f ("netfilter: nfnl_cthelper: fix runtime expectation policy updates")
---
 net/netfilter/nfnetlink_cthelper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nfnetlink_cthelper.c +2 -2
index d545fa459455..1e605d77796d 100644
@@ -346,8 +346,8 @@ static int nfnl_cthelper_update_policy_all(struct nlattr *tb[],
 	for (i = 0; i < helper->expect_class_max + 1; i++) {
 		policy = (struct nf_conntrack_expect_policy *)
 				&helper->expect_policy[i];
-		policy->max_expected = new_policy->max_expected;
-		policy->timeout	= new_policy->timeout;
+		policy->max_expected = new_policy[i].max_expected;
+		policy->timeout	= new_policy[i].timeout;
 	}
 
 err:
Signature · 1 line
2.39.3 (Apple Git-145)
#1 lore raw
Quoted 17 lines · Dudu Lu

In nfnl_cthelper_update_policy_all(), when updating the expect policies of a multi-class conntrack helper, the loop iterates over all expect classes but always reads from new_policy[0] instead of new_policy[i]:

    for (i = 0; i < helper->expect_class_max + 1; i++) {
        policy = &helper->expect_policy[i];
        policy->max_expected = new_policy->max_expected;  /* always [0] */
        policy->timeout      = new_policy->timeout;       /* always [0] */
    }

The new_policy array was correctly parsed per-class by nfnl_cthelper_update_policy_one() in the validation loop above (line 336-342), with each new_policy[i] holding its respective class values. However, the copy loop dereferences new_policy as a pointer (new_policy->x) rather than indexing it as an array (new_policy[i].x), creating a security vulnerability.

Quoted 7 lines

As a result, all expect classes of a multi-class helper get overwritten with the values of class 0, discarding the per-class differentiation.

This affects helpers like H.323 which use multiple expect classes (RTP, RTCP, T.120) with different max_expected and timeout values. After a policy update, all classes get identical limits, breaking the per-class expect enforcement.

Not really. Such helpers do not exists in userspace, and this is fully userspace conntrack helper infrastructure.

This is nf-next material: I think no userspace helper is using more than one single expectation class at this stage.

Quoted 26 lines

Fix by indexing new_policy with the loop variable.

Fixes 2c422257550f ("netfilter: nfnl_cthelper: fix runtime expectation policy updates")
---
 net/netfilter/nfnetlink_cthelper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nfnetlink_cthelper.c +2 -2
index d545fa459455..1e605d77796d 100644
@@ -346,8 +346,8 @@ static int nfnl_cthelper_update_policy_all(struct nlattr *tb[],
 	for (i = 0; i < helper->expect_class_max + 1; i++) {
 		policy = (struct nf_conntrack_expect_policy *)
 				&helper->expect_policy[i];
-		policy->max_expected = new_policy->max_expected;
-		policy->timeout	= new_policy->timeout;
+		policy->max_expected = new_policy[i].max_expected;
+		policy->timeout	= new_policy[i].timeout;
 	}
 
 err:
Signature · 1 line
2.39.3 (Apple Git-145)