Skip to content

Commit 802bfb1

Browse files
Paolo Abenidavem330
authored andcommitted
net/sched: user-space can't set unknown tcfa_action values
Currently, when initializing an action, the user-space can specify and use arbitrary values for the tcfa_action field. If the value is unknown by the kernel, is implicitly threaded as TC_ACT_UNSPEC. This change explicitly checks for unknown values at action creation time, and explicitly convert them to TC_ACT_UNSPEC. No functional changes are introduced, but this will allow introducing tcfa_action values not exposed to user-space in a later patch. Note: we can't use the above to hide TC_ACT_REDIRECT from user-space, as the latter is already part of uAPI. v3 -> v4: - use an helper to check for action validity (JiriP) - emit an extack for invalid actions (JiriP) v4 -> v5: - keep messages on a single line, drop net_warn (Marcelo) Signed-off-by: Paolo Abeni <[email protected]> Acked-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c87fffc commit 802bfb1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

include/uapi/linux/pkt_cls.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ enum {
4545
* the skb and act like everything
4646
* is alright.
4747
*/
48+
#define TC_ACT_VALUE_MAX TC_ACT_TRAP
4849

4950
/* There is a special kind of actions called "extended actions",
5051
* which need a value parameter. These have a local opcode located in
@@ -55,11 +56,12 @@ enum {
5556
#define __TC_ACT_EXT_SHIFT 28
5657
#define __TC_ACT_EXT(local) ((local) << __TC_ACT_EXT_SHIFT)
5758
#define TC_ACT_EXT_VAL_MASK ((1 << __TC_ACT_EXT_SHIFT) - 1)
58-
#define TC_ACT_EXT_CMP(combined, opcode) \
59-
(((combined) & (~TC_ACT_EXT_VAL_MASK)) == opcode)
59+
#define TC_ACT_EXT_OPCODE(combined) ((combined) & (~TC_ACT_EXT_VAL_MASK))
60+
#define TC_ACT_EXT_CMP(combined, opcode) (TC_ACT_EXT_OPCODE(combined) == opcode)
6061

6162
#define TC_ACT_JUMP __TC_ACT_EXT(1)
6263
#define TC_ACT_GOTO_CHAIN __TC_ACT_EXT(2)
64+
#define TC_ACT_EXT_OPCODE_MAX TC_ACT_GOTO_CHAIN
6365

6466
/* Action type identifiers*/
6567
enum {

net/sched/act_api.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,15 @@ static struct tc_cookie *nla_memdup_cookie(struct nlattr **tb)
786786
return c;
787787
}
788788

789+
static bool tcf_action_valid(int action)
790+
{
791+
int opcode = TC_ACT_EXT_OPCODE(action);
792+
793+
if (!opcode)
794+
return action <= TC_ACT_VALUE_MAX;
795+
return opcode <= TC_ACT_EXT_OPCODE_MAX || action == TC_ACT_UNSPEC;
796+
}
797+
789798
struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
790799
struct nlattr *nla, struct nlattr *est,
791800
char *name, int ovr, int bind,
@@ -895,6 +904,11 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
895904
}
896905
}
897906

907+
if (!tcf_action_valid(a->tcfa_action)) {
908+
NL_SET_ERR_MSG(extack, "invalid action value, using TC_ACT_UNSPEC instead");
909+
a->tcfa_action = TC_ACT_UNSPEC;
910+
}
911+
898912
return a;
899913

900914
err_mod:

0 commit comments

Comments
 (0)