Skip to contentSkip to conversation

net_sched: reject unknown tcfa_action values

PATCH Superseded Paolo Abeni 2 participants 4 messages Aug 28, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Paolo Abeni

author maintainer
#0 lore raw

cover net_sched: reject unknown tcfa_action values

As agreed some time ago, this changeset reject unknown tcfa_action values, instead of changing such values under the hood.

A tdc test is included to verify the new behavior.

Paolo Abeni (2):
net_sched: reject unknown tcfa_action values
tc-testing: add test-cases for numeric and invalid control action

 net/sched/act_api.c                           | 14 ++++--
 .../tc-testing/tc-tests/actions/police.json   | 48 +++++++++++++++++++
 2 files changed, 58 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 1/2 net_sched: reject unknown tcfa_action values

After the commit 802bfb19152c ("net/sched: user-space can't set unknown tcfa_action values"), unknown tcfa_action values are converted to TC_ACT_UNSPEC, but the common agreement is instead rejecting such configurations.

This change also introduce an helper to simplify the destruction of a single action, avoding code duplication.

Fixes 802bfb19152c ("net/sched: user-space can't set unknown tcfa_action values")
---
 net/sched/act_api.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
net/sched/act_api.c +10 -4
index db83dac1e7f4..8614f2c282e8 100644
@@ -662,6 +662,13 @@ int tcf_action_destroy(struct tc_action *actions[], int bind)
 	return ret;
 }
 
+int tcf_action_destroy_one(struct tc_action *a, int bind)
+{
+	struct tc_action *actions[] = { a, NULL };
+
+	return tcf_action_destroy(actions, bind);
+}
+
 static int tcf_action_put(struct tc_action *p)
 {
 	return __tcf_action_put(p, false);
@@ -881,17 +888,16 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
 	if (TC_ACT_EXT_CMP(a->tcfa_action, TC_ACT_GOTO_CHAIN)) {
 		err = tcf_action_goto_chain_init(a, tp);
 		if (err) {
-			struct tc_action *actions[] = { a, NULL };
-
-			tcf_action_destroy(actions, bind);
 			NL_SET_ERR_MSG(extack, "Failed to init TC action chain");
+			tcf_action_destroy_one(a, bind);
 			return ERR_PTR(err);
 		}
 	}
 
 	if (!tcf_action_valid(a->tcfa_action)) {
 		NL_SET_ERR_MSG(extack, "invalid action value, using TC_ACT_UNSPEC instead");
-		a->tcfa_action = TC_ACT_UNSPEC;
+		tcf_action_destroy_one(a, bind);
+		return ERR_PTR(-EINVAL);
 	}
 
 	return a;
Signature · 1 line
2.17.1
#2 lore raw

net/sched/act_api.c int tcf_action_destroy(struct tc_action *actions[], int bind) · line 670

Quoted 7 lines · Paolo Abeni
net/sched/act_api.c +6 -0
+int tcf_action_destroy_one(struct tc_action *a, int bind)
+{
+       struct tc_action *actions[] = { a, NULL };
+
+       return tcf_action_destroy(actions, bind);
+}

Make it static.

Quoted 9 lines
net/sched/act_api.c +1 -1
+
 static int tcf_action_put(struct tc_action *p)
 {
        return __tcf_action_put(p, false);
@@ -881,17 +888,16 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
        if (TC_ACT_EXT_CMP(a->tcfa_action, TC_ACT_GOTO_CHAIN)) {
                err = tcf_action_goto_chain_init(a, tp);
                if (err) {
-                       struct tc_action *actions[] = { a, NULL };

net/sched/act_api.c struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, · line 898

Quoted 10 lines
net/sched/act_api.c +1 -2
-
-                       tcf_action_destroy(actions, bind);
                        NL_SET_ERR_MSG(extack, "Failed to init TC action chain");
+                       tcf_action_destroy_one(a, bind);
                        return ERR_PTR(err);
                }
        }
 
        if (!tcf_action_valid(a->tcfa_action)) {
                NL_SET_ERR_MSG(extack, "invalid action value, using TC_ACT_UNSPEC instead");

You need to adjust this extack too.

net/sched/act_api.c struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, · line 901

Quoted 4 lines
net/sched/act_api.c +2 -1
-               a->tcfa_action = TC_ACT_UNSPEC;
+               tcf_action_destroy_one(a, bind);
+               return ERR_PTR(-EINVAL);
        }

Thanks.

author maintainer
#3 lore raw

PATCH 2/2 tc-testing: add test-cases for numeric and invalid control action

In reply to Paolo Abeni

Only the police action allows us to specify an arbitrary numeric value for the control action. This change introduces an explicit test case for the above feature and then leverage it for testing the kernel behavior for invalid control actions (reject).

---
 .../tc-testing/tc-tests/actions/police.json   | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/actions/police.json +48 -0
index f03763d81617..30f9b54bd666 100644
@@ -312,6 +312,54 @@
             "$TC actions flush action police"
         ]
     },
+    {
+        "id": "6aaf",
+        "name": "Add police actions with conform-exceed control pass/pipe [with numeric values]",
+        "category": [
+            "actions",
+            "police"
+        ],
+        "setup": [
+            [
+                "$TC actions flush action police",
+                0,
+                1,
+                255
+            ]
+        ],
+        "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed 0/3 index 1",
+        "expExitCode": "0",
+        "verifyCmd": "$TC actions get action police index 1",
+        "matchPattern": "action order [0-9]*:  police 0x1 rate 3Mbit burst 250Kb mtu 2Kb action pass/pipe",
+        "matchCount": "1",
+        "teardown": [
+            "$TC actions flush action police"
+        ]
+    },
+    {
+        "id": "29b1",
+        "name": "Add police actions with conform-exceed control <invalid>/drop",
+        "category": [
+            "actions",
+            "police"
+        ],
+        "setup": [
+            [
+                "$TC actions flush action police",
+                0,
+                1,
+                255
+            ]
+        ],
+        "cmdUnderTest": "$TC actions add action police rate 3mbit burst 250k conform-exceed 10/drop index 1",
+        "expExitCode": "255",
+        "verifyCmd": "$TC actions ls action police",
+        "matchPattern": "action order [0-9]*:  police 0x1 rate 3Mbit burst 250Kb mtu 2Kb action ",
+        "matchCount": "0",
+        "teardown": [
+            "$TC actions flush action police"
+        ]
+    },
     {
         "id": "c26f",
         "name": "Add police action with invalid peakrate value",
Signature · 1 line
2.17.1