net/sched: forbid 'goto_chain' on fallback actions
Subsystems (4)
cover net/sched: forbid 'goto_chain' on fallback actions
the following command:
# tc actions add action police rate 1mbit burst 1k conform-exceed \
Quoted 1 line
pass / goto chain 42
generates a NULL pointer dereference when packets exceed the configured rate. Similarly, the following command:
# tc actions add action pass random determ goto chain 42 2
makes the kernel crash with NULL dereference when the first packet does not match the 'pass' action.
gact and police allow users to specify a fallback control action, that is stored in the action private data. 'goto chain x' never worked for these cases, since a->goto_chain handle was never initialized. There is only one goto_chain handle per TC action, and it is designed to be non-NULL only if tcf_action contains a 'goto chain' command. So, let's forbid 'goto chain' on fallback actions.
Patch 1/4 and 2/4 change the .init() functions of police and gact, to let them return an error when users try to set 'goto chain x' in the fallback action. Patch 3/4 and 4/4 add TDC selftest coverage to this new behavior.
Davide Caratti (4):
net/sched: act_gact: disallow 'goto chain' on fallback control action net/sched: act_police: disallow 'goto chain' on fallback control
action
tc-tests: test denial of 'goto chain' on 'random' traffic in gact.json
tc-tests: test denial of 'goto chain' for exceed traffic in
police.json
net/sched/act_gact.c | 5 ++++ net/sched/act_police.c | 12 ++++++++-- .../tc-testing/tc-tests/actions/gact.json | 24 +++++++++++++++++++ .../tc-testing/tc-tests/actions/police.json | 24 +++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/4 net/sched: act_gact: disallow 'goto chain' on fallback control action
in the following command:
# tc action add action <c1> random <rand_type> <c2> <rand_param>
'goto chain x' is allowed only for c1: setting it for c2 makes the kernel crash with NULL pointer dereference, since TC core doesn't initialize the chain handle.
--- net/sched/act_gact.c | 5 +++++ 1 file changed, 5 insertions(+)
net/sched/act_gact.c +5 -0
@@ -88,6 +88,11 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla, p_parm =nla_data (tb[TCA_GACT_PROB ]);if (p_parm->ptype >=MAX_RAND )return -EINVAL ; +if (TC_ACT_EXT_CMP (p_parm->paction,TC_ACT_GOTO_CHAIN )) { +NL_SET_ERR_MSG (extack, +"goto chain not allowed on fallback" ); +return -EINVAL ; + } }#endif
Signature · 1 line
2.17.1
PATCH 2/4 net/sched: act_police: disallow 'goto chain' on fallback control action
In reply to Davide Carattiin the following command:
# tc action add action police rate <r> burst <b> conform-exceed <c1>/<c2>
'goto chain x' is allowed only for c1: setting it for c2 makes the kernel crash with NULL pointer dereference, since TC core doesn't initialize the chain handle.
--- net/sched/act_police.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/sched/act_police.c +10 -2
@@ -150,6 +150,16 @@ static int tcf_police_init(struct net *net, struct nlattr *nla, goto failure; } +if (tb[TCA_POLICE_RESULT ]) { + police->tcfp_result =nla_get_u32 (tb[TCA_POLICE_RESULT ]); +if (TC_ACT_EXT_CMP (police->tcfp_result,TC_ACT_GOTO_CHAIN )) { +NL_SET_ERR_MSG (extack, +"goto chain not allowed on fallback" ); + err = -EINVAL ; + goto failure; + } + } +spin_lock_bh (&police->tcf_lock);/* No failure allowed after this point */ police->tcfp_mtu = parm->mtu;
@@ -173,8 +183,6 @@ static int tcf_police_init(struct net *net, struct nlattr *nla, police->peak_present = false; } -if (tb[TCA_POLICE_RESULT ]) - police->tcfp_result =nla_get_u32 (tb[TCA_POLICE_RESULT ]); police->tcfp_burst =PSCHED_TICKS2NS (parm->burst); police->tcfp_toks = police->tcfp_burst;if (police->peak_present) {
Signature · 1 line
2.17.1
PATCH 3/4 tc-tests: test denial of 'goto chain' on 'random' traffic in gact.json
In reply to Davide Carattiadd test to verify if act_gact forbids 'goto chain' control actions on 'random' traffic in gact.json.
--- .../tc-testing/tc-tests/actions/gact.json | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/actions/gact.json +24 -0
@@ -536,5 +536,29 @@ "matchPattern": "^[ \t]+index [0-9]+ ref", "matchCount": "0", "teardown": [] + }, + { + "id": "8e47", + "name": "Add gact action with random determ goto chain control action", + "category": [ + "actions", + "gact" + ], + "setup": [ + [ + "$TC actions flush action gact", + 0, + 1, + 255 + ] + ], + "cmdUnderTest": "$TC actions add action pass random determ goto chain 1 2 index 90", + "expExitCode": "255", + "verifyCmd": "$TC actions list action gact", + "matchPattern": "action order [0-9]*: gact action pass random type determ goto chain 1 val 2.*index 90 ref", + "matchCount": "0", + "teardown": [ + "$TC actions flush action gact" + ] } ]
Signature · 1 line
2.17.1
PATCH 4/4 tc-tests: test denial of 'goto chain' for exceed traffic in police.json
In reply to Davide Carattiadd test to verify if act_police forbids 'goto chain' control actions for 'exceed' traffic.
--- .../tc-testing/tc-tests/actions/police.json | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+)
tools/testing/selftests/tc-testing/tc-tests/actions/police.json +24 -0
@@ -715,5 +715,29 @@ "teardown": [ "$TC actions flush action police" ] + }, + { + "id": "b48b", + "name": "Add police action with exceed goto chain control action", + "category": [ + "actions", + "police" + ], + "setup": [ + [ + "$TC actions flush action police", + 0, + 1, + 255 + ] + ], + "cmdUnderTest": "$TC actions add action police rate 1mbit burst 1k conform-exceed pass / goto chain 42", + "expExitCode": "255", + "verifyCmd": "$TC actions ls action police", + "matchPattern": "action order [0-9]*: police 0x1 rate 1Mbit burst 1Kb mtu 2Kb action pass/goto chain 42", + "matchCount": "0", + "teardown": [ + "$TC actions flush action police" + ] } ]
Signature · 1 line
2.17.1
Re: [PATCH net 1/4] net/sched: act_gact: disallow 'goto chain' on fallback control action
In reply to Davide CarattiQuoted 10 lines · Davide Caratti
in the following command:
# tc action add action <c1> random <rand_type> <c2> <rand_param>'goto chain x' is allowed only for c1: setting it for c2 makes the kernel crash with NULL pointer dereference, since TC core doesn't initialize the chain handle.
Signed-off-by Davide Caratti <[email protected]>
Re: [PATCH net 2/4] net/sched: act_police: disallow 'goto chain' on fallback control action
In reply to Davide CarattiQuoted 10 lines · Davide Caratti
in the following command:
# tc action add action police rate <r> burst <b> conform-exceed <c1>/<c2>'goto chain x' is allowed only for c1: setting it for c2 makes the kernel crash with NULL pointer dereference, since TC core doesn't initialize the chain handle.
Signed-off-by Davide Caratti <[email protected]>
Quoted 20 lines · Davide Caratti
the following command:
# tc actions add action police rate 1mbit burst 1k conform-exceed \Quoted 1 line
pass / goto chain 42
generates a NULL pointer dereference when packets exceed the configured rate. Similarly, the following command:
# tc actions add action pass random determ goto chain 42 2makes the kernel crash with NULL dereference when the first packet does not match the 'pass' action.
gact and police allow users to specify a fallback control action, that is stored in the action private data. 'goto chain x' never worked for these cases, since
a->goto_chainhandle was never initialized. There is only onegoto_chainhandle per TC action, and it is designed to be non-NULL only iftcf_actioncontains a 'goto chain' command. So, let's forbid 'goto chain' on fallback actions.
Quoted 4 lines
Patch 1/4 and 2/4 change the .init() functions of police and gact, to let them return an error when users try to set 'goto chain x' in the fallback action. Patch 3/4 and 4/4 add TDC selftest coverage to this new behavior.
For the series,
cheers,
jamal
Re: [PATCH net 1/4] net/sched: act_gact: disallow 'goto chain' on fallback control action
In reply to Davide CarattiQuoted 18 lines · Sat, Oct 20, 2018 at 11:33:07PM CEST, [email protected] wrote:
in the following command:
# tc action add action <c1> random <rand_type> <c2> <rand_param>'goto chain x' is allowed only for c1: setting it for c2 makes the kernel crash with NULL pointer dereference, since TC core doesn't initialize the chain handle.
Signed-off-by Davide Caratti <[email protected]>---
net/sched/act_gact.c| 5 +++++1 file changed, 5 insertions(+)net/sched/act_gact.c +0
-0
net/sched/act_gact.c static int tcf_gact_init(struct net *net, struct nlattr *nla, · line 93
Quoted 6 lines
net/sched/act_gact.c +3
-0@@ -88,6 +88,11 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla, p_parm =nla_data (tb[TCA_GACT_PROB ]);if (p_parm->ptype >=MAX_RAND )return -EINVAL ; +if (TC_ACT_EXT_CMP (p_parm->paction,TC_ACT_GOTO_CHAIN )) { +NL_SET_ERR_MSG (extack, +"goto chain not allowed on fallback" );
No need for a line-wrap. Otherwise
Re: [PATCH net 2/4] net/sched: act_police: disallow 'goto chain' on fallback control action
In reply to Davide CarattiQuoted 18 lines · Sat, Oct 20, 2018 at 11:33:08PM CEST, [email protected] wrote:
in the following command:
# tc action add action police rate <r> burst <b> conform-exceed <c1>/<c2>'goto chain x' is allowed only for c1: setting it for c2 makes the kernel crash with NULL pointer dereference, since TC core doesn't initialize the chain handle.
Signed-off-by Davide Caratti <[email protected]>---
net/sched/act_police.c| 12 ++++++++++--1 file changed, 10 insertions(+), 2 deletions(-)net/sched/act_police.c +0
-0
net/sched/act_police.c static int tcf_police_init(struct net *net, struct nlattr *nla, · line 157
Quoted 8 lines
net/sched/act_police.c +5
-0@@ -150,6 +150,16 @@ static int tcf_police_init(struct net *net, struct nlattr *nla, goto failure; } +if (tb[TCA_POLICE_RESULT ]) { + police->tcfp_result =nla_get_u32 (tb[TCA_POLICE_RESULT ]); +if (TC_ACT_EXT_CMP (police->tcfp_result,TC_ACT_GOTO_CHAIN )) { +NL_SET_ERR_MSG (extack, +"goto chain not allowed on fallback" );
Also, no need for line-wrap
Quoted 20 lines
net/sched/act_police.c +5
-2+ err = -EINVAL ; + goto failure; + } + } +spin_lock_bh (&police->tcf_lock);/* No failure allowed after this point */ police->tcfp_mtu = parm->mtu;@@ -173,8 +183,6 @@ static int tcf_police_init(struct net *net, struct nlattr *nla, police->peak_present = false; } -if (tb[TCA_POLICE_RESULT ]) - police->tcfp_result =nla_get_u32 (tb[TCA_POLICE_RESULT ]); police->tcfp_burst =PSCHED_TICKS2NS (parm->burst); police->tcfp_toks = police->tcfp_burst;if (police->peak_present) {Signature · 1 line
2.17.1
David Miller
maintainerFrom: Davide Caratti <[email protected]>
Date: Sat, 20 Oct 2018 23:33:06 +0200
Quoted 20 lines
the following command:
# tc actions add action police rate 1mbit burst 1k conform-exceed \Quoted 1 line
pass / goto chain 42
generates a NULL pointer dereference when packets exceed the configured rate. Similarly, the following command:
# tc actions add action pass random determ goto chain 42 2makes the kernel crash with NULL dereference when the first packet does not match the 'pass' action.
gact and police allow users to specify a fallback control action, that is stored in the action private data. 'goto chain x' never worked for these cases, since
a->goto_chainhandle was never initialized. There is only onegoto_chainhandle per TC action, and it is designed to be non-NULL only iftcf_actioncontains a 'goto chain' command. So, let's forbid 'goto chain' on fallback actions.
Quoted 3 lines
Patch 1/4 and 2/4 change the .init() functions of police and gact, to let them return an error when users try to set 'goto chain x' in the fallback action. Patch 3/4 and 4/4 add TDC selftest coverage to this new behavior.
Series applied.