register tracking infrastructure follow up
Subsystems (3)
Pablo Neira Ayuso
maintainerv2 cover register tracking infrastructure follow up
Hi,
The following patchset follows up on the register tracking infrastructure:
1) Add NFT_REDUCE_READONLY pointer cookie and use it, this is used to describe expressions that perform read-only operations on registers. Add WARN_ON_ONCE() to check for expr->ops->reduce, all expressions must have one.
v2: add missing ipv4 and ipv6 expressions. simplify cookie logic
2) Cancel register tracking information for operations that are larger than 32-bits (one register). Add update/cancel helper functions and adapt existing code to use them.
v2: track partial clobbering. add nft_reg_track_cmp()
3) Add .reduce support to nft_ct.
4) Add .reduce support to nft_lookup.
5) Add .reduce support for nft_meta_bridge.
6) Add .reduce support for nft_numgen.
7) Add .reduce support for nft_osf.
8) Add .reduce support for nft_hash (jhash and symhash)
9) Add .reduce support for nft_immediate
10) Add .reduce support for nft_socket
11) Add .reduce support for nft_xfrm
12) Add .reduce support for nft_tunnel
Missing expressions with no expr->ops->reduce after this round:
- exthdr
- fib
Florian Westphal (2):
netfilter: nft_lookup: only cancel tracking for clobbered dregs
netfilter: nft_meta: extend reduce support to bridge family
Pablo Neira Ayuso (10):
netfilter: nf_tables: do not reduce read-only expressions
netfilter: nf_tables: cancel tracking for clobbered destination registers
netfilter: nft_ct: track register operations
netfilter: nft_numgen: cancel register tracking
netfilter: nft_osf: track register operations
netfilter: nft_hash: track register operations
netfilter: nft_immediate: cancel register tracking for data destination register
netfilter: nft_socket: track register operations
netfilter: nft_xfrm: track register operations
netfilter: nft_tunnel: track register operations
include/net/netfilter/nf_tables.h | 22 ++++++++ include/net/netfilter/nft_meta.h | 3 ++ net/bridge/netfilter/nft_meta_bridge.c | 5 +- net/bridge/netfilter/nft_reject_bridge.c | 1 + net/ipv4/netfilter/nft_dup_ipv4.c | 1 + net/ipv4/netfilter/nft_reject_ipv4.c | 1 + net/ipv6/netfilter/nft_dup_ipv6.c | 1 + net/ipv6/netfilter/nft_reject_ipv6.c | 1 + net/netfilter/nf_tables_api.c | 69 +++++++++++++++++++++++- net/netfilter/nft_bitwise.c | 24 ++++++--- net/netfilter/nft_byteorder.c | 3 +- net/netfilter/nft_cmp.c | 3 ++ net/netfilter/nft_compat.c | 1 + net/netfilter/nft_connlimit.c | 1 + net/netfilter/nft_counter.c | 1 + net/netfilter/nft_ct.c | 48 +++++++++++++++++ net/netfilter/nft_dup_netdev.c | 1 + net/netfilter/nft_dynset.c | 1 + net/netfilter/nft_flow_offload.c | 1 + net/netfilter/nft_fwd_netdev.c | 2 + net/netfilter/nft_hash.c | 36 +++++++++++++ net/netfilter/nft_immediate.c | 12 +++++ net/netfilter/nft_last.c | 1 + net/netfilter/nft_limit.c | 2 + net/netfilter/nft_log.c | 1 + net/netfilter/nft_lookup.c | 12 +++++ net/netfilter/nft_masq.c | 3 ++ net/netfilter/nft_meta.c | 19 ++++--- net/netfilter/nft_nat.c | 2 + net/netfilter/nft_numgen.c | 22 ++++++++ net/netfilter/nft_objref.c | 2 + net/netfilter/nft_osf.c | 25 +++++++++ net/netfilter/nft_payload.c | 12 ++--- net/netfilter/nft_queue.c | 2 + net/netfilter/nft_quota.c | 1 + net/netfilter/nft_range.c | 1 + net/netfilter/nft_redir.c | 3 ++ net/netfilter/nft_reject_inet.c | 1 + net/netfilter/nft_reject_netdev.c | 1 + net/netfilter/nft_rt.c | 1 + net/netfilter/nft_socket.c | 28 ++++++++++ net/netfilter/nft_synproxy.c | 1 + net/netfilter/nft_tproxy.c | 1 + net/netfilter/nft_tunnel.c | 28 ++++++++++ net/netfilter/nft_xfrm.c | 28 ++++++++++ 45 files changed, 403 insertions(+), 32 deletions(-)
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 1/12 netfilter: nf_tables: do not reduce read-only expressions
Skip register tracking for expressions that perform read-only operations on the registers. Define and use a cookie pointer NFT_REDUCE_READONLY to avoid defining stubs for these expressions.
---
v2: - add ipv4 and ipv6 .reduce initialization
- add dynset .reduce initialization
- simplify cookie address logic.
include/net/netfilter/nf_tables.h | 8 ++++++++ net/bridge/netfilter/nft_reject_bridge.c | 1 + net/ipv4/netfilter/nft_dup_ipv4.c | 1 + net/ipv4/netfilter/nft_reject_ipv4.c | 1 + net/ipv6/netfilter/nft_dup_ipv6.c | 1 + net/ipv6/netfilter/nft_reject_ipv6.c | 1 + net/netfilter/nf_tables_api.c | 14 ++++++++++++-- net/netfilter/nft_cmp.c | 3 +++ net/netfilter/nft_compat.c | 1 + net/netfilter/nft_connlimit.c | 1 + net/netfilter/nft_counter.c | 1 + net/netfilter/nft_ct.c | 1 + net/netfilter/nft_dup_netdev.c | 1 + net/netfilter/nft_dynset.c | 1 + net/netfilter/nft_flow_offload.c | 1 + net/netfilter/nft_fwd_netdev.c | 2 ++ net/netfilter/nft_last.c | 1 + net/netfilter/nft_limit.c | 2 ++ net/netfilter/nft_log.c | 1 + net/netfilter/nft_masq.c | 3 +++ net/netfilter/nft_nat.c | 2 ++ net/netfilter/nft_objref.c | 2 ++ net/netfilter/nft_queue.c | 2 ++ net/netfilter/nft_quota.c | 1 + net/netfilter/nft_range.c | 1 + net/netfilter/nft_redir.c | 3 +++ net/netfilter/nft_reject_inet.c | 1 + net/netfilter/nft_reject_netdev.c | 1 + net/netfilter/nft_rt.c | 1 + net/netfilter/nft_synproxy.c | 1 + net/netfilter/nft_tproxy.c | 1 + 31 files changed, 60 insertions(+), 2 deletions(-)
include/net/netfilter/nf_tables.h +8 -0
@@ -1633,4 +1633,12 @@ static inline struct nftables_pernet *nft_pernet(const struct net *net) return net_generic(net, nf_tables_net_id); } +#define __NFT_REDUCE_READONLY 1UL +#define NFT_REDUCE_READONLY (void *)__NFT_REDUCE_READONLY + +static inline bool nft_reduce_is_readonly (const struct nft_expr *expr) +{ +return expr->ops->reduce ==NFT_REDUCE_READONLY ; +} +#endif /* _NET_NF_TABLES_H */
net/bridge/netfilter/nft_reject_bridge.c +1 -0
@@ -185,6 +185,7 @@ static const struct nft_expr_ops nft_reject_bridge_ops = { .init = nft_reject_init, .dump = nft_reject_dump, .validate = nft_reject_bridge_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_reject_bridge_type__read_mostly = {
net/ipv4/netfilter/nft_dup_ipv4.c +1 -0
@@ -75,6 +75,7 @@ static const struct nft_expr_ops nft_dup_ipv4_ops = { .eval = nft_dup_ipv4_eval, .init = nft_dup_ipv4_init, .dump = nft_dup_ipv4_dump, + .reduce = NFT_REDUCE_READONLY, };static const struct nla_policy nft_dup_ipv4_policy[NFTA_DUP_MAX +1 ] = {
net/ipv4/netfilter/nft_reject_ipv4.c +1 -0
@@ -45,6 +45,7 @@ static const struct nft_expr_ops nft_reject_ipv4_ops = { .init = nft_reject_init, .dump = nft_reject_dump, .validate = nft_reject_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_reject_ipv4_type__read_mostly = {
net/ipv6/netfilter/nft_dup_ipv6.c +1 -0
@@ -73,6 +73,7 @@ static const struct nft_expr_ops nft_dup_ipv6_ops = { .eval = nft_dup_ipv6_eval, .init = nft_dup_ipv6_init, .dump = nft_dup_ipv6_dump, + .reduce = NFT_REDUCE_READONLY, };static const struct nla_policy nft_dup_ipv6_policy[NFTA_DUP_MAX +1 ] = {
net/ipv6/netfilter/nft_reject_ipv6.c +1 -0
@@ -46,6 +46,7 @@ static const struct nft_expr_ops nft_reject_ipv6_ops = { .init = nft_reject_init, .dump = nft_reject_dump, .validate = nft_reject_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_reject_ipv6_type__read_mostly = {
net/netfilter/nf_tables_api.c +12 -2
@@ -8287,6 +8287,17 @@ void nf_tables_trans_destroy_flush_work(void) }EXPORT_SYMBOL_GPL (nf_tables_trans_destroy_flush_work); +static bool nft_expr_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +if (WARN_ON_ONCE (!expr->ops->reduce)) +return false; +if (nft_reduce_is_readonly (expr)) +return false; + +return expr->ops->reduce (track, expr); +} +static int nf_tables_commit_chain_prepare (struct net *net,struct nft_chain *chain) {const struct nft_expr *expr, *last;
@@ -8334,8 +8345,7 @@ static int nf_tables_commit_chain_prepare(struct net *net, struct nft_chain *chanft_rule_for_each_expr (expr, last, rule) { track.cur = expr; -if (expr->ops->reduce && - expr->ops->reduce (&track, expr)) { +if (nft_expr_reduce (&track, expr)) { expr = track.cur;continue ; }
net/netfilter/nft_cmp.c +3 -0
@@ -193,6 +193,7 @@ static const struct nft_expr_ops nft_cmp_ops = { .eval = nft_cmp_eval, .init = nft_cmp_init, .dump = nft_cmp_dump, + .reduce = NFT_REDUCE_READONLY, .offload = nft_cmp_offload, };
@@ -269,6 +270,7 @@ const struct nft_expr_ops nft_cmp_fast_ops = { .eval = NULL, /* inlined */ .init = nft_cmp_fast_init, .dump = nft_cmp_fast_dump, + .reduce = NFT_REDUCE_READONLY, .offload = nft_cmp_fast_offload, };
@@ -359,6 +361,7 @@ const struct nft_expr_ops nft_cmp16_fast_ops = { .eval = NULL, /* inlined */ .init = nft_cmp16_fast_init, .dump = nft_cmp16_fast_dump, + .reduce = NFT_REDUCE_READONLY, .offload = nft_cmp16_fast_offload, };
net/netfilter/nft_compat.c +1 -0
@@ -871,6 +871,7 @@ nft_target_select_ops(const struct nft_ctx *ctx, ops->dump = nft_target_dump; ops->validate = nft_target_validate; ops->data = target; + ops->reduce =NFT_REDUCE_READONLY ;if (family ==NFPROTO_BRIDGE ) ops->eval = nft_target_eval_bridge;
net/netfilter/nft_connlimit.c +1 -0
@@ -257,6 +257,7 @@ static const struct nft_expr_ops nft_connlimit_ops = { .destroy_clone = nft_connlimit_destroy_clone, .dump = nft_connlimit_dump, .gc = nft_connlimit_gc, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_connlimit_type__read_mostly = {
net/netfilter/nft_counter.c +1 -0
@@ -293,6 +293,7 @@ static const struct nft_expr_ops nft_counter_ops = { .destroy_clone = nft_counter_destroy, .dump = nft_counter_dump, .clone = nft_counter_clone, + .reduce = NFT_REDUCE_READONLY, .offload = nft_counter_offload, .offload_stats = nft_counter_offload_stats, };
net/netfilter/nft_ct.c +1 -0
@@ -785,6 +785,7 @@ static const struct nft_expr_ops nft_notrack_ops = { .type = &nft_notrack_type, .size = NFT_EXPR_SIZE(0), .eval = nft_notrack_eval, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_notrack_type__read_mostly = {
net/netfilter/nft_dup_netdev.c +1 -0
@@ -79,6 +79,7 @@ static const struct nft_expr_ops nft_dup_netdev_ops = { .eval = nft_dup_netdev_eval, .init = nft_dup_netdev_init, .dump = nft_dup_netdev_dump, + .reduce = NFT_REDUCE_READONLY, .offload = nft_dup_netdev_offload, .offload_action = nft_dup_netdev_offload_action, };
net/netfilter/nft_dynset.c +1 -0
@@ -413,6 +413,7 @@ static const struct nft_expr_ops nft_dynset_ops = { .activate = nft_dynset_activate, .deactivate = nft_dynset_deactivate, .dump = nft_dynset_dump, + .reduce = NFT_REDUCE_READONLY, };struct nft_expr_type nft_dynset_type__read_mostly = {
net/netfilter/nft_flow_offload.c +1 -0
@@ -441,6 +441,7 @@ static const struct nft_expr_ops nft_flow_offload_ops = { .destroy = nft_flow_offload_destroy, .validate = nft_flow_offload_validate, .dump = nft_flow_offload_dump, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_flow_offload_type__read_mostly = {
net/netfilter/nft_fwd_netdev.c +2 -0
@@ -217,6 +217,7 @@ static const struct nft_expr_ops nft_fwd_neigh_netdev_ops = { .init = nft_fwd_neigh_init, .dump = nft_fwd_neigh_dump, .validate = nft_fwd_validate, + .reduce = NFT_REDUCE_READONLY, };static const struct nft_expr_ops nft_fwd_netdev_ops = {
@@ -226,6 +227,7 @@ static const struct nft_expr_ops nft_fwd_netdev_ops = { .init = nft_fwd_netdev_init, .dump = nft_fwd_netdev_dump, .validate = nft_fwd_validate, + .reduce = NFT_REDUCE_READONLY, .offload = nft_fwd_netdev_offload, .offload_action = nft_fwd_netdev_offload_action, };
net/netfilter/nft_last.c +1 -0
@@ -120,6 +120,7 @@ static const struct nft_expr_ops nft_last_ops = { .destroy = nft_last_destroy, .clone = nft_last_clone, .dump = nft_last_dump, + .reduce = NFT_REDUCE_READONLY, };struct nft_expr_type nft_last_type__read_mostly = {
net/netfilter/nft_limit.c +2 -0
@@ -225,6 +225,7 @@ static const struct nft_expr_ops nft_limit_pkts_ops = { .destroy = nft_limit_pkts_destroy, .clone = nft_limit_pkts_clone, .dump = nft_limit_pkts_dump, + .reduce = NFT_REDUCE_READONLY, }; static void nft_limit_bytes_eval(const struct nft_expr *expr,
@@ -279,6 +280,7 @@ static const struct nft_expr_ops nft_limit_bytes_ops = { .dump = nft_limit_bytes_dump, .clone = nft_limit_bytes_clone, .destroy = nft_limit_bytes_destroy, + .reduce = NFT_REDUCE_READONLY, }; static const struct nft_expr_ops *
net/netfilter/nft_log.c +1 -0
@@ -290,6 +290,7 @@ static const struct nft_expr_ops nft_log_ops = { .init = nft_log_init, .destroy = nft_log_destroy, .dump = nft_log_dump, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_log_type__read_mostly = {
net/netfilter/nft_masq.c +3 -0
@@ -129,6 +129,7 @@ static const struct nft_expr_ops nft_masq_ipv4_ops = { .destroy = nft_masq_ipv4_destroy, .dump = nft_masq_dump, .validate = nft_masq_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_masq_ipv4_type__read_mostly = {
@@ -175,6 +176,7 @@ static const struct nft_expr_ops nft_masq_ipv6_ops = { .destroy = nft_masq_ipv6_destroy, .dump = nft_masq_dump, .validate = nft_masq_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_masq_ipv6_type__read_mostly = {
@@ -230,6 +232,7 @@ static const struct nft_expr_ops nft_masq_inet_ops = { .destroy = nft_masq_inet_destroy, .dump = nft_masq_dump, .validate = nft_masq_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_masq_inet_type__read_mostly = {
net/netfilter/nft_nat.c +2 -0
@@ -317,6 +317,7 @@ static const struct nft_expr_ops nft_nat_ops = { .destroy = nft_nat_destroy, .dump = nft_nat_dump, .validate = nft_nat_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_nat_type__read_mostly = {
@@ -346,6 +347,7 @@ static const struct nft_expr_ops nft_nat_inet_ops = { .destroy = nft_nat_destroy, .dump = nft_nat_dump, .validate = nft_nat_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_inet_nat_type__read_mostly = {
net/netfilter/nft_objref.c +2 -0
@@ -91,6 +91,7 @@ static const struct nft_expr_ops nft_objref_ops = { .activate = nft_objref_activate, .deactivate = nft_objref_deactivate, .dump = nft_objref_dump, + .reduce = NFT_REDUCE_READONLY, };struct nft_objref_map {
@@ -204,6 +205,7 @@ static const struct nft_expr_ops nft_objref_map_ops = { .deactivate = nft_objref_map_deactivate, .destroy = nft_objref_map_destroy, .dump = nft_objref_map_dump, + .reduce = NFT_REDUCE_READONLY, }; static const struct nft_expr_ops *
net/netfilter/nft_queue.c +2 -0
@@ -164,6 +164,7 @@ static const struct nft_expr_ops nft_queue_ops = { .eval = nft_queue_eval, .init = nft_queue_init, .dump = nft_queue_dump, + .reduce = NFT_REDUCE_READONLY, };static const struct nft_expr_ops nft_queue_sreg_ops = {
@@ -172,6 +173,7 @@ static const struct nft_expr_ops nft_queue_sreg_ops = { .eval = nft_queue_sreg_eval, .init = nft_queue_sreg_init, .dump = nft_queue_sreg_dump, + .reduce = NFT_REDUCE_READONLY, }; static const struct nft_expr_ops *
net/netfilter/nft_quota.c +1 -0
@@ -254,6 +254,7 @@ static const struct nft_expr_ops nft_quota_ops = { .destroy = nft_quota_destroy, .clone = nft_quota_clone, .dump = nft_quota_dump, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_quota_type__read_mostly = {
net/netfilter/nft_range.c +1 -0
@@ -140,6 +140,7 @@ static const struct nft_expr_ops nft_range_ops = { .eval = nft_range_eval, .init = nft_range_init, .dump = nft_range_dump, + .reduce = NFT_REDUCE_READONLY, };struct nft_expr_type nft_range_type__read_mostly = {
net/netfilter/nft_redir.c +3 -0
@@ -134,6 +134,7 @@ static const struct nft_expr_ops nft_redir_ipv4_ops = { .destroy = nft_redir_ipv4_destroy, .dump = nft_redir_dump, .validate = nft_redir_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_redir_ipv4_type__read_mostly = {
@@ -183,6 +184,7 @@ static const struct nft_expr_ops nft_redir_ipv6_ops = { .destroy = nft_redir_ipv6_destroy, .dump = nft_redir_dump, .validate = nft_redir_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_redir_ipv6_type__read_mostly = {
@@ -225,6 +227,7 @@ static const struct nft_expr_ops nft_redir_inet_ops = { .destroy = nft_redir_inet_destroy, .dump = nft_redir_dump, .validate = nft_redir_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_redir_inet_type__read_mostly = {
net/netfilter/nft_reject_inet.c +1 -0
@@ -80,6 +80,7 @@ static const struct nft_expr_ops nft_reject_inet_ops = { .init = nft_reject_init, .dump = nft_reject_dump, .validate = nft_reject_inet_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_reject_inet_type__read_mostly = {
net/netfilter/nft_reject_netdev.c +1 -0
@@ -159,6 +159,7 @@ static const struct nft_expr_ops nft_reject_netdev_ops = { .init = nft_reject_init, .dump = nft_reject_dump, .validate = nft_reject_netdev_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_reject_netdev_type__read_mostly = {
net/netfilter/nft_rt.c +1 -0
@@ -191,6 +191,7 @@ static const struct nft_expr_ops nft_rt_get_ops = { .init = nft_rt_get_init, .dump = nft_rt_get_dump, .validate = nft_rt_validate, + .reduce = NFT_REDUCE_READONLY, };struct nft_expr_type nft_rt_type__read_mostly = {
net/netfilter/nft_synproxy.c +1 -0
@@ -288,6 +288,7 @@ static const struct nft_expr_ops nft_synproxy_ops = { .dump = nft_synproxy_dump, .type = &nft_synproxy_type, .validate = nft_synproxy_validate, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_synproxy_type__read_mostly = {
net/netfilter/nft_tproxy.c +1 -0
@@ -320,6 +320,7 @@ static const struct nft_expr_ops nft_tproxy_ops = { .init = nft_tproxy_init, .destroy = nft_tproxy_destroy, .dump = nft_tproxy_dump, + .reduce = NFT_REDUCE_READONLY, };static struct nft_expr_type nft_tproxy_type__read_mostly = {
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH nf-next 01/12,v2] netfilter: nf_tables: do not reduce read-only expressions
I love your patch! Perhaps something to improve:
Hi Pablo,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20220310]
[cannot apply to nf-next/master nf/master linus/master v5.17-rc8 v5.17-rc7 v5.17-rc6 v5.17-rc8] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Pablo-Neira-Ayuso/register-tracking-infrastructure-follow-up/20220314-085726 base: 71941773e143369a73c9c4a3b62fbb60736a1182 config: riscv-randconfig-r042-20220314 (https://download.01.org/0day-ci/archive/20220314/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 3e4950d7fa78ac83f33bbf1658e2f49a73719236)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/95cc95fe1fe4ea0141d13453b818a3f14aacf4f0
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Pablo-Neira-Ayuso/register-tracking-infrastructure-follow-up/20220314-085726 git checkout 95cc95fe1fe4ea0141d13453b818a3f14aacf4f0
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux.o(.data+0x2b2500): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_authenticate to the function .init.text:set_reset_devices()
The variable trace_event_fields_rpcgss_svc_authenticate references the function __init set_reset_devices()
If the reference is valid then annotate the
variable with or __refdata (see linux/init.h) or name the variable:
Note: the below error/warnings can be found in parent commit:
<< WARNING: modpost: vmlinux.o(.text+0x1448baa): Section mismatch in reference from the function tcp4_proc_exit() to the function .init.text:set_reset_devices() << WARNING: modpost: vmlinux.o(.data+0x2b15cc): Section mismatch in reference from the variable event_rpcgss_ctx_init to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b15ec): Section mismatch in reference from the variable event_rpcgss_ctx_init to the variable .exit.text:.LBB0_1
<< WARNING: modpost: vmlinux.o(.data+0x2b1618): Section mismatch in reference from the variable event_rpcgss_ctx_destroy to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b1638): Section mismatch in reference from the variable event_rpcgss_ctx_destroy to the variable .exit.text:.LBB0_1 << WARNING: modpost: vmlinux.o(.data+0x2b1660): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_gssapi_class to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b1690): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_gssapi_class to the function .init.text:init_nls_cp737() << WARNING: modpost: vmlinux.o(.data+0x2b1be8): Section mismatch in reference from the variable event_rpcgss_svc_unwrap to the function .init.text:set_reset_devices() << WARNING: modpost: vmlinux.o(.data+0x293824): Section mismatch in reference from the variable nf_ct_proto_mutex to the function .init.text:loglevel()
<< WARNING: modpost: vmlinux.o(.data+0x2b1c08): Section mismatch in reference from the variable event_rpcgss_svc_unwrap to the variable .init.text:.LBB1_1
---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/[email protected]
Pablo Neira Ayuso
maintainerPATCH v2 2/12 netfilter: nf_tables: cancel tracking for clobbered destination registers
In reply to Pablo Neira AyusoOutput of expressions might be larger than one single register, this might clobber existing data. Reset tracking for all destination registers that required to store the expression output.
This patch adds three new helper functions:
- nft_reg_track_update: cancel previous register tracking and update it.
- nft_reg_track_cancel: cancel any previous register tracking info.
- __nft_reg_track_cancel: cancel only one single register tracking info.
Partial register clobbering detection is also supported by checking the .num_reg field which describes the number of register that are used.
This patch updates the following expressions:
- meta_bridge
- bitwise
- byteorder
- meta
- payload
to use these helper functions.
---
v2: - set on .selector and .bitwise (plus .num_reg) in all registers to detect
partial clobbering
- update nft_reg_track_update and nft_reg_track_cancel to deal with partial clobbering
- add nft_reg_track_cmp()
include/net/netfilter/nf_tables.h | 14 +++++++ include/net/netfilter/nft_meta.h | 1 + net/bridge/netfilter/nft_meta_bridge.c | 4 +- net/netfilter/nf_tables_api.c | 55 ++++++++++++++++++++++++++ net/netfilter/nft_bitwise.c | 23 +++++++---- net/netfilter/nft_byteorder.c | 3 +- net/netfilter/nft_meta.c | 14 +++---- net/netfilter/nft_payload.c | 12 ++---- 8 files changed, 98 insertions(+), 28 deletions(-)
include/net/netfilter/nf_tables.h +14 -0
@@ -126,6 +126,7 @@ struct nft_regs_track {struct {const struct nft_expr *selector;const struct nft_expr *bitwise; +u8 num_reg; } regs[NFT_REG32_NUM ];const struct nft_expr *cur;
@@ -1641,4 +1642,17 @@ static inline bool nft_reduce_is_readonly(const struct nft_expr *expr) return expr->ops->reduce == NFT_REDUCE_READONLY; } +void nft_reg_track_update (struct nft_regs_track *track, +const struct nft_expr *expr,u8 dreg,int len); +void nft_reg_track_cancel (struct nft_regs_track *track,u8 dreg,int len); +void __nft_reg_track_cancel (struct nft_regs_track *track,u8 dreg); + +static inline bool nft_reg_track_cmp (struct nft_regs_track *track, +const struct nft_expr *expr,u8 dreg) +{ +return track->regs[dreg].selector && + track->regs[dreg].selector->ops == expr->ops && + track->regs[dreg].num_reg ==0 ; +} +#endif /* _NET_NF_TABLES_H */
include/net/netfilter/nft_meta.h +1 -0
@@ -6,6 +6,7 @@struct nft_meta {enum nft_meta_keys key:8 ; +u8 len;union {u8 dreg;u8 sreg;
net/bridge/netfilter/nft_meta_bridge.c +2 -2
@@ -87,6 +87,7 @@ static int nft_meta_bridge_get_init(const struct nft_ctx *ctx,return nft_meta_get_init (ctx, expr, tb); } + priv->len = len;return nft_parse_register_store (ctx, tb[NFTA_META_DREG ], &priv->dreg,NULL ,NFT_DATA_VALUE , len); }
@@ -112,8 +113,7 @@ static bool nft_meta_bridge_set_reduce(struct nft_regs_track *track,if (track->regs[i].selector->ops != &nft_meta_bridge_get_ops)continue ; - track->regs[i].selector =NULL ; - track->regs[i].bitwise =NULL ; +__nft_reg_track_cancel (track, i); }return false;
net/netfilter/nf_tables_api.c +55 -0
61 lines not on this page · raw message
net/netfilter/nft_bitwise.c +15 -8
@@ -283,12 +283,16 @@ static bool nft_bitwise_reduce(struct nft_regs_track *track, {const struct nft_bitwise *priv =nft_expr_priv (expr);const struct nft_bitwise *bitwise; +unsigned int regcount; +u8 dreg; +int i;if (!track->regs[priv->sreg].selector)return false; bitwise =nft_expr_priv (expr); if (track->regs[priv->sreg].selector == track->regs[priv->dreg].selector && + track->regs[priv->sreg].num_reg == 0 && track->regs[priv->dreg].bitwise && track->regs[priv->dreg].bitwise->ops == expr->ops && priv->sreg == bitwise->sreg &&
@@ -302,17 +306,21 @@ static bool nft_bitwise_reduce(struct nft_regs_track *track,return true; } -if (track->regs[priv->sreg].bitwise) { - track->regs[priv->dreg].selector =NULL ; - track->regs[priv->dreg].bitwise =NULL ; +if (track->regs[priv->sreg].bitwise || + track->regs[priv->sreg].num_reg !=0 ) { +nft_reg_track_cancel (track, priv->dreg, priv->len);return false; }if (priv->sreg != priv->dreg) { - track->regs[priv->dreg].selector = - track->regs[priv->sreg].selector; +nft_reg_track_update (track, track->regs[priv->sreg].selector, + priv->dreg, priv->len); } - track->regs[priv->dreg].bitwise = expr; + + dreg = priv->dreg; + regcount =DIV_ROUND_UP (priv->len,NFT_REG32_SIZE ); +for (i =0 ; i < regcount; i++, dreg++) + track->regs[priv->dreg].bitwise = expr;return false; }
@@ -447,8 +455,7 @@ static bool nft_bitwise_fast_reduce(struct nft_regs_track *track, }if (track->regs[priv->sreg].bitwise) { - track->regs[priv->dreg].selector =NULL ; - track->regs[priv->dreg].bitwise =NULL ; +nft_reg_track_cancel (track, priv->dreg,NFT_REG32_SIZE );return false; }
net/netfilter/nft_byteorder.c +1 -2
@@ -172,8 +172,7 @@ static bool nft_byteorder_reduce(struct nft_regs_track *track, {struct nft_byteorder *priv =nft_expr_priv (expr); - track->regs[priv->dreg].selector =NULL ; - track->regs[priv->dreg].bitwise =NULL ; +nft_reg_track_cancel (track, priv->dreg, priv->len);return false; }
net/netfilter/nft_meta.c +6 -8
@@ -539,6 +539,7 @@ int nft_meta_get_init(const struct nft_ctx *ctx,return -EOPNOTSUPP ; } + priv->len = len;return nft_parse_register_store (ctx, tb[NFTA_META_DREG ], &priv->dreg,NULL ,NFT_DATA_VALUE , len); }
@@ -664,6 +665,7 @@ int nft_meta_set_init(const struct nft_ctx *ctx,return -EOPNOTSUPP ; } + priv->len = len; err =nft_parse_register_load (tb[NFTA_META_SREG ], &priv->sreg, len);if (err <0 )return err;
@@ -756,18 +758,15 @@ static bool nft_meta_get_reduce(struct nft_regs_track *track,const struct nft_meta *priv =nft_expr_priv (expr);const struct nft_meta *meta; -if (!track->regs[priv->dreg].selector || - track->regs[priv->dreg].selector->ops != expr->ops) { - track->regs[priv->dreg].selector = expr; - track->regs[priv->dreg].bitwise =NULL ; +if (!nft_reg_track_cmp (track, expr, priv->dreg)) { +nft_reg_track_update (track, expr, priv->dreg, priv->len);return false; } meta =nft_expr_priv (track->regs[priv->dreg].selector);if (priv->key != meta->key || priv->dreg != meta->dreg) { - track->regs[priv->dreg].selector = expr; - track->regs[priv->dreg].bitwise =NULL ; +nft_reg_track_update (track, expr, priv->dreg, priv->len);return false; }
@@ -800,8 +799,7 @@ static bool nft_meta_set_reduce(struct nft_regs_track *track,if (track->regs[i].selector->ops != &nft_meta_get_ops)continue ; - track->regs[i].selector =NULL ; - track->regs[i].bitwise =NULL ; +__nft_reg_track_cancel (track, i); }return false;
net/netfilter/nft_payload.c +4 -8
@@ -216,10 +216,8 @@ static bool nft_payload_reduce(struct nft_regs_track *track,const struct nft_payload *priv =nft_expr_priv (expr);const struct nft_payload *payload; -if (!track->regs[priv->dreg].selector || - track->regs[priv->dreg].selector->ops != expr->ops) { - track->regs[priv->dreg].selector = expr; - track->regs[priv->dreg].bitwise =NULL ; +if (!nft_reg_track_cmp (track, expr, priv->dreg)) { +nft_reg_track_update (track, expr, priv->dreg, priv->len);return false; }
@@ -227,8 +225,7 @@ static bool nft_payload_reduce(struct nft_regs_track *track,if (priv->base != payload->base || priv->offset != payload->offset || priv->len != payload->len) { - track->regs[priv->dreg].selector = expr; - track->regs[priv->dreg].bitwise =NULL ; +nft_reg_track_update (track, expr, priv->dreg, priv->len);return false; }
@@ -815,8 +812,7 @@ static bool nft_payload_set_reduce(struct nft_regs_track *track, track->regs[i].selector->ops != &nft_payload_fast_ops) continue; - track->regs[i].selector =NULL ; - track->regs[i].bitwise =NULL ; +__nft_reg_track_cancel (track, i); }return false;
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH nf-next 02/12,v2] netfilter: nf_tables: cancel tracking for clobbered destination registers
I love your patch! Perhaps something to improve:
Hi Pablo,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20220310]
[cannot apply to nf-next/master nf/master linus/master v5.17-rc8 v5.17-rc7 v5.17-rc6 v5.17-rc8] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Pablo-Neira-Ayuso/register-tracking-infrastructure-follow-up/20220314-085726 base: 71941773e143369a73c9c4a3b62fbb60736a1182 config: riscv-randconfig-r042-20220314 (https://download.01.org/0day-ci/archive/20220314/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 3e4950d7fa78ac83f33bbf1658e2f49a73719236)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/0day-ci/linux/commit/33636fda14d7c54d333c939eaac47768c7baf913
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Pablo-Neira-Ayuso/register-tracking-infrastructure-follow-up/20220314-085726 git checkout 33636fda14d7c54d333c939eaac47768c7baf913
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux.o(.data+0x2b2994): Section mismatch in reference from the variable trace_event_fields_rpcgss_need_reencode to the function .init.text:set_reset_devices()
The variable trace_event_fields_rpcgss_need_reencode references the function __init set_reset_devices()
If the reference is valid then annotate the
variable with or __refdata (see linux/init.h) or name the variable:
--
>> WARNING: modpost: vmlinux.o(.data+0x2940fc): Section mismatch in reference from the variable nft_range_type to the function .init.text:set_reset_devices()
The variable nft_range_type references
the function __init set_reset_devices()
If the reference is valid then annotate the
variable with or __refdata (see linux/init.h) or name the variable:
Note: the below error/warnings can be found in parent commit:
<< WARNING: modpost: vmlinux.o(.text+0x1448bbe): Section mismatch in reference from the function tcp4_proc_exit() to the function .init.text:set_reset_devices() << WARNING: modpost: vmlinux.o(.text+0x1448bc2): Section mismatch in reference from the function tcp4_proc_exit() to the variable .init.text:.LBB98_4
<< WARNING: modpost: vmlinux.o(.data+0x2b14a0): Section mismatch in reference from the variable trace_event_fields_rpcgss_ctx_class to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b14b4): Section mismatch in reference from the variable trace_event_fields_rpcgss_ctx_class to the variable .exit.text:.LBB0_1 << WARNING: modpost: vmlinux.o(.data+0x2b15e8): Section mismatch in reference from the variable event_rpcgss_ctx_init to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b1634): Section mismatch in reference from the variable event_rpcgss_ctx_destroy to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b1660): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_gssapi_class to the variable .init.text:.LBB1_1 << WARNING: modpost: vmlinux.o(.data+0x2b168c): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_gssapi_class to the variable .exit.text:.LBB0_1 << WARNING: modpost: vmlinux.o(.data+0x2b1690): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_gssapi_class to the function .init.text:set_reset_devices() << WARNING: modpost: vmlinux.o(.data+0x293824): Section mismatch in reference from the variable nf_ct_proto_mutex to the function .init.text:loglevel()
<< WARNING: modpost: vmlinux.o(.text+0x1448bbe): Section mismatch in reference from the function tcp4_proc_exit() to the function .init.text:set_reset_devices() << WARNING: modpost: vmlinux.o(.text+0x1448bc2): Section mismatch in reference from the function tcp4_proc_exit() to the variable .init.text:.LBB98_4
<< WARNING: modpost: vmlinux.o(.data+0x2b14a0): Section mismatch in reference from the variable trace_event_fields_rpcgss_ctx_class to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b14b4): Section mismatch in reference from the variable trace_event_fields_rpcgss_ctx_class to the variable .exit.text:.LBB0_1 << WARNING: modpost: vmlinux.o(.data+0x2b15e8): Section mismatch in reference from the variable event_rpcgss_ctx_init to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b1634): Section mismatch in reference from the variable event_rpcgss_ctx_destroy to the function .exit.text:test_ww_mutex_exit() << WARNING: modpost: vmlinux.o(.data+0x2b1660): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_gssapi_class to the variable .init.text:.LBB1_1 << WARNING: modpost: vmlinux.o(.data+0x2b168c): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_gssapi_class to the variable .exit.text:.LBB0_1 << WARNING: modpost: vmlinux.o(.data+0x2b1690): Section mismatch in reference from the variable trace_event_fields_rpcgss_svc_gssapi_class to the function .init.text:set_reset_devices() << WARNING: modpost: vmlinux.o(.data+0x293824): Section mismatch in reference from the variable nf_ct_proto_mutex to the function .init.text:loglevel()
---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/[email protected]
Pablo Neira Ayuso
maintainerPATCH v2 3/12 netfilter: nft_ct: track register operations
In reply to Pablo Neira AyusoCheck if the destination register already contains the data that this ct expression performs. This allows to skip this redundant operation. If the destination contains a different selector, update the register tracking information.
Export nft_expr_reduce_bitwise as a symbol since nft_ct might be compiled as a module.
---
v2: use nft_reg_track_cmp().
net/netfilter/nft_bitwise.c | 1 + net/netfilter/nft_ct.c | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+)
net/netfilter/nft_bitwise.c +1 -0
@@ -529,3 +529,4 @@ bool nft_expr_reduce_bitwise(struct nft_regs_track *track,return false; } +EXPORT_SYMBOL_GPL (nft_expr_reduce_bitwise);
net/netfilter/nft_ct.c +47 -0
91 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 4/12 netfilter: nft_lookup: only cancel tracking for clobbered dregs
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
In most cases, nft_lookup will be read-only, i.e. won't clobber registers. In case of map, we need to cancel the registers that will see stores.
---
v2: no changes.
net/netfilter/nft_lookup.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/netfilter/nft_lookup.c +12 -0
@@ -253,6 +253,17 @@ static int nft_lookup_validate(const struct nft_ctx *ctx,return 0 ; } +static bool nft_lookup_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +const struct nft_lookup *priv =nft_expr_priv (expr); + +if (priv->set->flags &NFT_SET_MAP ) +nft_reg_track_cancel (track, priv->dreg, priv->set->dlen); + +return false; +} +static const struct nft_expr_ops nft_lookup_ops = { .type = &nft_lookup_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_lookup )),
@@ -263,6 +274,7 @@ static const struct nft_expr_ops nft_lookup_ops = { .destroy = nft_lookup_destroy, .dump = nft_lookup_dump, .validate = nft_lookup_validate, + .reduce = nft_lookup_reduce, };struct nft_expr_type nft_lookup_type__read_mostly = {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 5/12 netfilter: nft_meta: extend reduce support to bridge family
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
its enough to export the meta get reduce helper and then call it from nft_meta_bridge too.
---
v2: no changes
include/net/netfilter/nft_meta.h | 2 ++ net/bridge/netfilter/nft_meta_bridge.c | 1 + net/netfilter/nft_meta.c | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-)
include/net/netfilter/nft_meta.h +2 -0
@@ -44,4 +44,6 @@ int nft_meta_set_validate(const struct nft_ctx *ctx,const struct nft_expr *expr, const struct nft_data **data); +bool nft_meta_get_reduce (struct nft_regs_track *track, +const struct nft_expr *expr);#endif
net/bridge/netfilter/nft_meta_bridge.c +1 -0
@@ -99,6 +99,7 @@ static const struct nft_expr_ops nft_meta_bridge_get_ops = { .eval = nft_meta_bridge_get_eval, .init = nft_meta_bridge_get_init, .dump = nft_meta_get_dump, + .reduce = nft_meta_get_reduce, }; static bool nft_meta_bridge_set_reduce(struct nft_regs_track *track,
net/netfilter/nft_meta.c +3 -2
@@ -752,8 +752,8 @@ static int nft_meta_get_offload(struct nft_offload_ctx *ctx,return 0 ; } -static bool nft_meta_get_reduce (struct nft_regs_track *track, -const struct nft_expr *expr) +bool nft_meta_get_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) {const struct nft_meta *priv =nft_expr_priv (expr);const struct nft_meta *meta;
@@ -775,6 +775,7 @@ static bool nft_meta_get_reduce(struct nft_regs_track *track,return nft_expr_reduce_bitwise (track, expr); } +EXPORT_SYMBOL_GPL (nft_meta_get_reduce);static const struct nft_expr_ops nft_meta_get_ops = { .type = &nft_meta_type,
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 6/12 netfilter: nft_numgen: cancel register tracking
In reply to Pablo Neira AyusoRandom and increment are stateful, each invocation results in fresh output. Cancel register tracking for these two expressions.
---
v2: no changes
net/netfilter/nft_numgen.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
net/netfilter/nft_numgen.c +22 -0
@@ -85,6 +85,16 @@ static int nft_ng_inc_init(const struct nft_ctx *ctx,return err; } +static bool nft_ng_inc_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +const struct nft_ng_inc *priv =nft_expr_priv (expr); + +nft_reg_track_cancel (track, priv->dreg,NFT_REG32_SIZE ); + +return false; +} +static int nft_ng_dump (struct sk_buff *skb,enum nft_registers dreg,u32 modulus,enum nft_ng_types type,u32 offset) {
@@ -172,6 +182,16 @@ static int nft_ng_random_dump(struct sk_buff *skb, const struct nft_expr *expr) priv->offset); } +static bool nft_ng_random_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +const struct nft_ng_random *priv =nft_expr_priv (expr); + +nft_reg_track_cancel (track, priv->dreg,NFT_REG32_SIZE ); + +return false; +} +static struct nft_expr_type nft_ng_type;static const struct nft_expr_ops nft_ng_inc_ops = { .type = &nft_ng_type,
@@ -180,6 +200,7 @@ static const struct nft_expr_ops nft_ng_inc_ops = { .init = nft_ng_inc_init, .destroy = nft_ng_inc_destroy, .dump = nft_ng_inc_dump, + .reduce = nft_ng_inc_reduce, };static const struct nft_expr_ops nft_ng_random_ops = {
@@ -188,6 +209,7 @@ static const struct nft_expr_ops nft_ng_random_ops = { .eval = nft_ng_random_eval, .init = nft_ng_random_init, .dump = nft_ng_random_dump, + .reduce = nft_ng_random_reduce, }; static const struct nft_expr_ops *
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 7/12 netfilter: nft_osf: track register operations
In reply to Pablo Neira AyusoAllow to recycle the previous output of the OS fingerprint expression if flags and ttl are the same.
---
v2: use nft_reg_track_cmp()
net/netfilter/nft_osf.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
net/netfilter/nft_osf.c +25 -0
@@ -120,6 +120,30 @@ static int nft_osf_validate(const struct nft_ctx *ctx, (1 << NF_INET_FORWARD)); } +static bool nft_osf_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +struct nft_osf *priv =nft_expr_priv (expr); +struct nft_osf *osf; + +if (!nft_reg_track_cmp (track, expr, priv->dreg)) { +nft_reg_track_update (track, expr, priv->dreg,NFT_OSF_MAXGENRELEN ); +return false; + } + + osf =nft_expr_priv (track->regs[priv->dreg].selector); +if (priv->flags != osf->flags || + priv->ttl != osf->ttl) { +nft_reg_track_update (track, expr, priv->dreg,NFT_OSF_MAXGENRELEN ); +return false; + } + +if (!track->regs[priv->dreg].bitwise) +return true; + +return false; +} +static struct nft_expr_type nft_osf_type;static const struct nft_expr_ops nft_osf_op = { .eval = nft_osf_eval,
@@ -128,6 +152,7 @@ static const struct nft_expr_ops nft_osf_op = { .dump = nft_osf_dump, .type = &nft_osf_type, .validate = nft_osf_validate, + .reduce = nft_osf_reduce, };static struct nft_expr_type nft_osf_type__read_mostly = {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 8/12 netfilter: nft_hash: track register operations
In reply to Pablo Neira AyusoCheck if the destination register already contains the data that this osf expression performs. Always cancel register tracking for jhash since this requires tracking multiple source registers in case of concatenations. Perform register tracking (without bitwise) for symhash since input does not come from source register.
---
v2: use nft_reg_track_cmp()
net/netfilter/nft_hash.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
net/netfilter/nft_hash.c +36 -0
@@ -165,6 +165,16 @@ static int nft_jhash_dump(struct sk_buff *skb,return -1 ; } +static bool nft_jhash_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +const struct nft_jhash *priv =nft_expr_priv (expr); + +nft_reg_track_cancel (track, priv->dreg,sizeof (u32)); + +return false; +} +static int nft_symhash_dump (struct sk_buff *skb,const struct nft_expr *expr) {
@@ -185,6 +195,30 @@ static int nft_symhash_dump(struct sk_buff *skb,return -1 ; } +static bool nft_symhash_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +struct nft_symhash *priv =nft_expr_priv (expr); +struct nft_symhash *symhash; + +if (!nft_reg_track_cmp (track, expr, priv->dreg)) { +nft_reg_track_update (track, expr, priv->dreg,sizeof (u32)); +return false; + } + + symhash =nft_expr_priv (track->regs[priv->dreg].selector); +if (priv->offset != symhash->offset || + priv->modulus != symhash->modulus) { +nft_reg_track_update (track, expr, priv->dreg,sizeof (u32)); +return false; + } + +if (!track->regs[priv->dreg].bitwise) +return true; + +return false; +} +static struct nft_expr_type nft_hash_type;static const struct nft_expr_ops nft_jhash_ops = { .type = &nft_hash_type,
@@ -192,6 +226,7 @@ static const struct nft_expr_ops nft_jhash_ops = { .eval = nft_jhash_eval, .init = nft_jhash_init, .dump = nft_jhash_dump, + .reduce = nft_jhash_reduce, };static const struct nft_expr_ops nft_symhash_ops = {
@@ -200,6 +235,7 @@ static const struct nft_expr_ops nft_symhash_ops = { .eval = nft_symhash_eval, .init = nft_symhash_init, .dump = nft_symhash_dump, + .reduce = nft_symhash_reduce, }; static const struct nft_expr_ops *
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 9/12 netfilter: nft_immediate: cancel register tracking for data destination register
In reply to Pablo Neira AyusoThe immediate expression might clobber existing data on the registers, cancel register tracking for the destination register.
---
v2: use nft_reg_track_cancel() instead of __nft_reg_track_cancel()
net/netfilter/nft_immediate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/netfilter/nft_immediate.c +12 -0
@@ -223,6 +223,17 @@ static bool nft_immediate_offload_action(const struct nft_expr *expr)return false; } +static bool nft_immediate_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +const struct nft_immediate_expr *priv =nft_expr_priv (expr); + +if (priv->dreg !=NFT_REG_VERDICT ) +nft_reg_track_cancel (track, priv->dreg, priv->dlen); + +return false; +} +static const struct nft_expr_ops nft_imm_ops = { .type = &nft_imm_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_immediate_expr )),
@@ -233,6 +244,7 @@ static const struct nft_expr_ops nft_imm_ops = { .destroy = nft_immediate_destroy, .dump = nft_immediate_dump, .validate = nft_immediate_validate, + .reduce = nft_immediate_reduce, .offload = nft_immediate_offload, .offload_action = nft_immediate_offload_action, };
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 10/12 netfilter: nft_socket: track register operations
In reply to Pablo Neira AyusoCheck if the destination register already contains the data that this socket expression performs. This allows to skip this redundant operation. If the destination contains a different selector, update the register tracking information.
---
v2: new in this series
net/netfilter/nft_socket.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
net/netfilter/nft_socket.c +28 -0
@@ -10,6 +10,7 @@struct nft_socket {enum nft_socket_keys key:8 ;u8 level; +u8 len;union {u8 dreg; };
@@ -179,6 +180,7 @@ static int nft_socket_init(const struct nft_ctx *ctx,return -EOPNOTSUPP ; } + priv->len = len;return nft_parse_register_store (ctx, tb[NFTA_SOCKET_DREG ], &priv->dreg,NULL ,NFT_DATA_VALUE , len); }
@@ -198,6 +200,31 @@ static int nft_socket_dump(struct sk_buff *skb,return 0 ; } +static bool nft_socket_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +const struct nft_socket *priv =nft_expr_priv (expr); +const struct nft_socket *socket; + +if (!nft_reg_track_cmp (track, expr, priv->dreg)) { +nft_reg_track_update (track, expr, priv->dreg, priv->len); +return false; + } + + socket =nft_expr_priv (track->regs[priv->dreg].selector); +if (priv->key != socket->key || + priv->dreg != socket->dreg || + priv->level != socket->level) { +nft_reg_track_update (track, expr, priv->dreg, priv->len); +return false; + } + +if (!track->regs[priv->dreg].bitwise) +return true; + +return nft_expr_reduce_bitwise (track, expr); +} +static struct nft_expr_type nft_socket_type;static const struct nft_expr_ops nft_socket_ops = { .type = &nft_socket_type,
@@ -205,6 +232,7 @@ static const struct nft_expr_ops nft_socket_ops = { .eval = nft_socket_eval, .init = nft_socket_init, .dump = nft_socket_dump, + .reduce = nft_socket_reduce, };static struct nft_expr_type nft_socket_type__read_mostly = {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 11/12 netfilter: nft_xfrm: track register operations
In reply to Pablo Neira AyusoCheck if the destination register already contains the data that this xfrm expression performs. This allows to skip this redundant operation. If the destination contains a different selector, update the register tracking information.
---
v2: new in this series
net/netfilter/nft_xfrm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
net/netfilter/nft_xfrm.c +28 -0
@@ -27,6 +27,7 @@ struct nft_xfrm {u8 dreg;u8 dir;u8 spnum; +u8 len; }; static int nft_xfrm_get_init(const struct nft_ctx *ctx,
@@ -86,6 +87,7 @@ static int nft_xfrm_get_init(const struct nft_ctx *ctx, priv->spnum = spnum; + priv->len = len;return nft_parse_register_store (ctx, tb[NFTA_XFRM_DREG ], &priv->dreg,NULL ,NFT_DATA_VALUE , len); }
@@ -252,6 +254,31 @@ static int nft_xfrm_validate(const struct nft_ctx *ctx, const struct nft_expr *ereturn nft_chain_validate_hooks (ctx->chain, hooks); } +static bool nft_xfrm_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +const struct nft_xfrm *priv =nft_expr_priv (expr); +const struct nft_xfrm *xfrm; + +if (!nft_reg_track_cmp (track, expr, priv->dreg)) { +nft_reg_track_update (track, expr, priv->dreg, priv->len); +return false; + } + + xfrm =nft_expr_priv (track->regs[priv->dreg].selector); +if (priv->key != xfrm->key || + priv->dreg != xfrm->dreg || + priv->dir != xfrm->dir || + priv->spnum != xfrm->spnum) { +nft_reg_track_update (track, expr, priv->dreg, priv->len); +return false; + } + +if (!track->regs[priv->dreg].bitwise) +return true; + +return nft_expr_reduce_bitwise (track, expr); +}static struct nft_expr_type nft_xfrm_type;static const struct nft_expr_ops nft_xfrm_get_ops = {
@@ -261,6 +288,7 @@ static const struct nft_expr_ops nft_xfrm_get_ops = { .init = nft_xfrm_get_init, .dump = nft_xfrm_get_dump, .validate = nft_xfrm_validate, + .reduce = nft_xfrm_reduce, };static struct nft_expr_type nft_xfrm_type__read_mostly = {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH v2 12/12 netfilter: nft_tunnel: track register operations
In reply to Pablo Neira AyusoCheck if the destination register already contains the data that this tunnel expression performs. This allows to skip this redundant operation. If the destination contains a different selector, update the register tracking information. This patch does not perform bitwise tracking.
---
v2: new in this series
net/netfilter/nft_tunnel.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
net/netfilter/nft_tunnel.c +28 -0
@@ -17,6 +17,7 @@ struct nft_tunnel { enum nft_tunnel_keys key:8;u8 dreg; enum nft_tunnel_mode mode:8; +u8 len; }; static void nft_tunnel_get_eval(const struct nft_expr *expr,
@@ -101,6 +102,7 @@ static int nft_tunnel_get_init(const struct nft_ctx *ctx, priv->mode =NFT_TUNNEL_MODE_NONE ; } + priv->len = len;return nft_parse_register_store (ctx, tb[NFTA_TUNNEL_DREG ], &priv->dreg,NULL ,NFT_DATA_VALUE , len); }
@@ -122,6 +124,31 @@ static int nft_tunnel_get_dump(struct sk_buff *skb,return -1 ; } +static bool nft_tunnel_get_reduce (struct nft_regs_track *track, +const struct nft_expr *expr) +{ +const struct nft_tunnel *priv =nft_expr_priv (expr); +const struct nft_tunnel *tunnel; + +if (!nft_reg_track_cmp (track, expr, priv->dreg)) { +nft_reg_track_update (track, expr, priv->dreg, priv->len); +return false; + } + + tunnel =nft_expr_priv (track->regs[priv->dreg].selector); +if (priv->key != tunnel->key || + priv->dreg != tunnel->dreg || + priv->mode != tunnel->mode) { +nft_reg_track_update (track, expr, priv->dreg, priv->len); +return false; + } + +if (!track->regs[priv->dreg].bitwise) +return true; + +return false; +} +static struct nft_expr_type nft_tunnel_type;static const struct nft_expr_ops nft_tunnel_get_ops = { .type = &nft_tunnel_type,
@@ -129,6 +156,7 @@ static const struct nft_expr_ops nft_tunnel_get_ops = { .eval = nft_tunnel_get_eval, .init = nft_tunnel_get_init, .dump = nft_tunnel_get_dump, + .reduce = nft_tunnel_get_reduce, };static struct nft_expr_type nft_tunnel_type__read_mostly = {
Signature · 1 line
2.30.2