netfilter: x_tables: fix build with CONFIG_COMPAT=n
Subsystems (5)
Pablo Neira Ayuso
maintainerPATCH 20/47 netfilter: x_tables: fix build with CONFIG_COMPAT=n
From: Florian Westphal <[email protected]>
I placed the helpers within CONFIG_COMPAT section, move them outside.
--- net/netfilter/x_tables.c | 62 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 31 deletions(-)
net/netfilter/x_tables.c +31 -31
@@ -577,6 +577,37 @@ int xt_check_table_hooks(const struct xt_table_info *info, unsigned int valid_ho }EXPORT_SYMBOL (xt_check_table_hooks); +static bool verdict_ok (int verdict) +{ +if (verdict >0 ) +return true; + +if (verdict <0 ) { +int v = -verdict -1 ; + +if (verdict ==XT_RETURN ) +return true; + +switch (v) { +case NF_ACCEPT :return true; +case NF_DROP :return true; +case NF_QUEUE :return true; +default : +break ; + } + +return false; + } + +return false; +} + +static bool error_tg_ok (unsigned int usersize,unsigned int kernsize, +const char *msg,unsigned int msglen) +{ +return usersize == kernsize &&strnlen (msg, msglen) < msglen; +} +#ifdef CONFIG_COMPAT int xt_compat_add_offset (u_int8_t af,unsigned int offset,int delta) {
@@ -736,37 +767,6 @@ struct compat_xt_error_target {char errorname[XT_FUNCTION_MAXNAMELEN ]; }; -static bool verdict_ok (int verdict) -{ -if (verdict >0 ) -return true; - -if (verdict <0 ) { -int v = -verdict -1 ; - -if (verdict ==XT_RETURN ) -return true; - -switch (v) { -case NF_ACCEPT :return true; -case NF_DROP :return true; -case NF_QUEUE :return true; -default : -break ; - } - -return false; - } - -return false; -} - -static bool error_tg_ok (unsigned int usersize,unsigned int kernsize, -const char *msg,unsigned int msglen) -{ -return usersize == kernsize &&strnlen (msg, msglen) < msglen; -} -int xt_compat_check_entry_offsets (const void *base,const char *elems,unsigned int target_offset,unsigned int next_offset)
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 21/47 ipvs: use true and false for boolean values
From: "Gustavo A. R. Silva" <[email protected]>
Assign true or false to boolean variables instead of an integer value.
This issue was detected with the help of Coccinelle.
--- net/netfilter/ipvs/ip_vs_lblc.c | 4 ++-- net/netfilter/ipvs/ip_vs_lblcr.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
net/netfilter/ipvs/ip_vs_lblc.c +2 -2
@@ -238,7 +238,7 @@ static void ip_vs_lblc_flush(struct ip_vs_service *svc)int i;spin_lock_bh (&svc->sched_lock); - tbl->dead =1 ; + tbl->dead = true;for (i =0 ; i <IP_VS_LBLC_TAB_SIZE ; i++) {hlist_for_each_entry_safe (en, next, &tbl->bucket[i], list) {ip_vs_lblc_del (en);
@@ -369,7 +369,7 @@ static int ip_vs_lblc_init_svc(struct ip_vs_service *svc) tbl->max_size =IP_VS_LBLC_TAB_SIZE *16 ; tbl->rover =0 ; tbl->counter =1 ; - tbl->dead =0 ; + tbl->dead = false; tbl->svc = svc;/*
net/netfilter/ipvs/ip_vs_lblcr.c +2 -2
@@ -404,7 +404,7 @@ static void ip_vs_lblcr_flush(struct ip_vs_service *svc)struct hlist_node *next;spin_lock_bh (&svc->sched_lock); - tbl->dead =1 ; + tbl->dead = true;for (i =0 ; i <IP_VS_LBLCR_TAB_SIZE ; i++) {hlist_for_each_entry_safe (en, next, &tbl->bucket[i], list) {ip_vs_lblcr_free (en);
@@ -532,7 +532,7 @@ static int ip_vs_lblcr_init_svc(struct ip_vs_service *svc) tbl->max_size =IP_VS_LBLCR_TAB_SIZE *16 ; tbl->rover =0 ; tbl->counter =1 ; - tbl->dead =0 ; + tbl->dead = false; tbl->svc = svc;/*
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 22/47 netfilter: Refactor nf_conncount
In reply to Pablo Neira AyusoFrom: Yi-Hung Wei <[email protected]>
Remove parameter 'family' in nf_conncount_count() and count_tree(). It is because the parameter is not useful after commit 625c556118f3 ("netfilter: connlimit: split xt_connlimit into front and backend").
--- include/net/netfilter/nf_conntrack_count.h | 1 - net/netfilter/nf_conncount.c | 4 +--- net/netfilter/xt_connlimit.c | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-)
include/net/netfilter/nf_conntrack_count.h +0 -1
@@ -11,7 +11,6 @@ void nf_conncount_destroy(struct net *net, unsigned int family,unsigned int nf_conncount_count (struct net *net,struct nf_conncount_data *data,const u32 *key, -unsigned int family,const struct nf_conntrack_tuple *tuple,const struct nf_conntrack_zone *zone);#endif
net/netfilter/nf_conncount.c +1 -3
@@ -158,7 +158,6 @@ static void tree_nodes_free(struct rb_root *root,static unsigned int count_tree (struct net *net,struct rb_root *root,const u32 *key,u8 keylen, -u8 family,const struct nf_conntrack_tuple *tuple,const struct nf_conntrack_zone *zone) {
@@ -246,7 +245,6 @@ count_tree(struct net *net, struct rb_root *root,unsigned int nf_conncount_count (struct net *net,struct nf_conncount_data *data,const u32 *key, -unsigned int family,const struct nf_conntrack_tuple *tuple,const struct nf_conntrack_zone *zone) {
@@ -259,7 +257,7 @@ unsigned int nf_conncount_count(struct net *net,spin_lock_bh (&nf_conncount_locks[hash %CONNCOUNT_LOCK_SLOTS ]); - count =count_tree (net, root, key, data->keylen, family, tuple, zone); + count =count_tree (net, root, key, data->keylen, tuple, zone);spin_unlock_bh (&nf_conncount_locks[hash %CONNCOUNT_LOCK_SLOTS ]);
net/netfilter/xt_connlimit.c +2 -2
@@ -67,8 +67,8 @@ connlimit_mt(const struct sk_buff *skb, struct xt_action_param *par) key[1 ] = zone->id; } - connections =nf_conncount_count (net, info->data, key, -xt_family (par), tuple_ptr, zone); + connections =nf_conncount_count (net, info->data, key, tuple_ptr, + zone);if (connections ==0 )/* kmalloc failed, drop it entirely */ goto hotdrop;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 23/47 netfilter: conncount: Support count only use case
In reply to Pablo Neira AyusoFrom: Yi-Hung Wei <[email protected]>
Currently, nf_conncount_count() counts the number of connections that matches key and inserts a conntrack 'tuple' with the same key into the accounting data structure. This patch supports another use case that only counts the number of connections where 'tuple' is not provided. Therefore, proper changes are made on nf_conncount_count() to support the case where 'tuple' is NULL. This could be useful for querying statistics or debugging purpose.
--- net/netfilter/nf_conncount.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/netfilter/nf_conncount.c +8 -2
@@ -104,7 +104,7 @@ static unsigned int check_hlist(struct net *net,struct nf_conn *found_ct;unsigned int length =0 ; - *addit = true; + *addit = tuple ? true : false;/* check the saved connections */ hlist_for_each_entry_safe (conn, n, head, node) {
@@ -117,7 +117,7 @@ static unsigned int check_hlist(struct net *net, found_ct =nf_ct_tuplehash_to_ctrack (found); -if (nf_ct_tuple_equal (&conn->tuple, tuple)) { +if (tuple &&nf_ct_tuple_equal (&conn->tuple, tuple)) {/* * Just to be sure we have it only once in the list. * We should not see tuples twice unless someone hooks
@@ -220,6 +220,9 @@ count_tree(struct net *net, struct rb_root *root, goto restart; } +if (!tuple) +return 0 ; +/* no match, need to insert new node */ rbconn =kmem_cache_alloc (conncount_rb_cachep,GFP_ATOMIC );if (rbconn ==NULL )
@@ -242,6 +245,9 @@ count_tree(struct net *net, struct rb_root *root,return 1 ; } +/* Count and return number of conntrack entries in 'net' with particular 'key'. +* If 'tuple' is not null, insert it into the accounting data structure. +*/ unsigned int nf_conncount_count(struct net *net, struct nf_conncount_data *data, const u32 *key,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 24/47 netfilter: nft_ct: add NFT_CT_{SRC,DST}_{IP,IP6}
In reply to Pablo Neira AyusoAll existing keys, except the NFT_CT_SRC and NFT_CT_DST are assumed to have strict datatypes. This is causing problems with sets and concatenations given the specific length of these keys is not known.
--- include/uapi/linux/netfilter/nf_tables.h | 12 ++++++++-- net/netfilter/nft_ct.c | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +10 -2
@@ -909,8 +909,8 @@ enum nft_rt_attributes {* @NFT_CT_EXPIRATION: relative conntrack expiration time in ms * @NFT_CT_HELPER: connection tracking helper assigned to conntrack * @NFT_CT_L3PROTOCOL: conntrack layer 3 protocol -* @NFT_CT_SRC: conntrack layer 3 protocol source (IPv4/IPv6 address) -* @NFT_CT_DST: conntrack layer 3 protocol destination (IPv4/IPv6 address) +* @NFT_CT_SRC: conntrack layer 3 protocol source (IPv4/IPv6 address, deprecated) +* @NFT_CT_DST: conntrack layer 3 protocol destination (IPv4/IPv6 address, deprecated) * @NFT_CT_PROTOCOL: conntrack layer 4 protocol * @NFT_CT_PROTO_SRC: conntrack layer 4 protocol source * @NFT_CT_PROTO_DST: conntrack layer 4 protocol destination
@@ -920,6 +920,10 @@ enum nft_rt_attributes {* @NFT_CT_AVGPKT: conntrack average bytes per packet * @NFT_CT_ZONE: conntrack zone * @NFT_CT_EVENTMASK: ctnetlink events to be generated for this conntrack +* @NFT_CT_SRC_IP: conntrack layer 3 protocol source (IPv4 address) +* @NFT_CT_DST_IP: conntrack layer 3 protocol destination (IPv4 address) +* @NFT_CT_SRC_IP6: conntrack layer 3 protocol source (IPv6 address) +* @NFT_CT_DST_IP6: conntrack layer 3 protocol destination (IPv6 address) */ enum nft_ct_keys {NFT_CT_STATE ,
@@ -941,6 +945,10 @@ enum nft_ct_keys {NFT_CT_AVGPKT ,NFT_CT_ZONE ,NFT_CT_EVENTMASK , +NFT_CT_SRC_IP , +NFT_CT_DST_IP , +NFT_CT_SRC_IP6 , + NFT_CT_DST_IP6, };/**
net/netfilter/nft_ct.c +38 -0
@@ -196,6 +196,26 @@ static void nft_ct_get_eval(const struct nft_expr *expr,case NFT_CT_PROTO_DST :nft_reg_store16 (dest, (__force u16 )tuple->dst.u.all);return ; +case NFT_CT_SRC_IP : +if (nf_ct_l3num (ct) !=NFPROTO_IPV4 ) + goto err; + *dest = tuple->src.u3.ip; +return ; +case NFT_CT_DST_IP : +if (nf_ct_l3num (ct) !=NFPROTO_IPV4 ) + goto err; + *dest = tuple->dst.u3.ip; +return ; +case NFT_CT_SRC_IP6 : +if (nf_ct_l3num (ct) !=NFPROTO_IPV6 ) + goto err; +memcpy (dest, tuple->src.u3.ip6,sizeof (struct in6_addr )); +return ; +case NFT_CT_DST_IP6 : +if (nf_ct_l3num (ct) !=NFPROTO_IPV6 ) + goto err; +memcpy (dest, tuple->dst.u3.ip6,sizeof (struct in6_addr )); +return ;default :break ; }
@@ -419,6 +439,20 @@ static int nft_ct_get_init(const struct nft_ctx *ctx,return -EAFNOSUPPORT ; }break ; +case NFT_CT_SRC_IP : +case NFT_CT_DST_IP : +if (tb[NFTA_CT_DIRECTION ] ==NULL ) +return -EINVAL ; + + len = FIELD_SIZEOF(struct nf_conntrack_tuple, src.u3.ip); +break ; +case NFT_CT_SRC_IP6 : +case NFT_CT_DST_IP6 : +if (tb[NFTA_CT_DIRECTION ] ==NULL ) +return -EINVAL ; + + len = FIELD_SIZEOF(struct nf_conntrack_tuple, src.u3.ip6); +break ;case NFT_CT_PROTO_SRC :case NFT_CT_PROTO_DST :if (tb[NFTA_CT_DIRECTION ] ==NULL )
@@ -588,6 +622,10 @@ static int nft_ct_get_dump(struct sk_buff *skb, const struct nft_expr *expr)switch (priv->key) {case NFT_CT_SRC :case NFT_CT_DST : +case NFT_CT_SRC_IP : +case NFT_CT_DST_IP : +case NFT_CT_SRC_IP6 : +case NFT_CT_DST_IP6 :case NFT_CT_PROTO_SRC :case NFT_CT_PROTO_DST :if (nla_put_u8 (skb,NFTA_CT_DIRECTION , priv->dir))
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 25/47 netfilter: cttimeout: remove VLA usage
In reply to Pablo Neira AyusoFrom: "Gustavo A. R. Silva" <[email protected]>
In preparation to enabling -Wvla, remove VLA and replace it with dynamic memory allocation.
Quoted 1 line
From a security viewpoint, the use of Variable Length Arrays can be
a vector for stack overflow attacks. Also, in general, as the code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having segfaults that are hard to debug.
Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621
While at it, remove likely() notation which is not necessary from the control plane code.
--- net/netfilter/nfnetlink_cttimeout.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)
net/netfilter/nfnetlink_cttimeout.c +17 -9
@@ -51,19 +51,27 @@ ctnl_timeout_parse_policy(void *timeouts,const struct nf_conntrack_l4proto *l4proto, struct net *net, const struct nlattr *attr) { + struct nlattr **tb;int ret =0 ; -if (likely (l4proto->ctnl_timeout.nlattr_to_obj)) { -struct nlattr *tb[l4proto->ctnl_timeout.nlattr_max+1 ]; +if (!l4proto->ctnl_timeout.nlattr_to_obj) +return 0 ; - ret =nla_parse_nested (tb, l4proto->ctnl_timeout.nlattr_max, - attr, l4proto->ctnl_timeout.nla_policy, -NULL ); -if (ret <0 ) -return ret; + tb =kcalloc (l4proto->ctnl_timeout.nlattr_max +1 ,sizeof (*tb), +GFP_KERNEL ); - ret = l4proto->ctnl_timeout.nlattr_to_obj (tb, net, timeouts); - } +if (!tb) +return -ENOMEM ; + + ret =nla_parse_nested (tb, l4proto->ctnl_timeout.nlattr_max, attr, + l4proto->ctnl_timeout.nla_policy,NULL ); +if (ret <0 ) + goto err; + + ret = l4proto->ctnl_timeout.nlattr_to_obj (tb, net, timeouts); + +err: +kfree (tb);return ret; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 26/47 netfilter: nfnetlink_cthelper: Remove VLA usage
In reply to Pablo Neira AyusoFrom: "Gustavo A. R. Silva" <[email protected]>
In preparation to enabling -Wvla, remove VLA and replace it with dynamic memory allocation.
Quoted 1 line
From a security viewpoint, the use of Variable Length Arrays can be
a vector for stack overflow attacks. Also, in general, as the code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having segfaults that are hard to debug.
Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621
--- net/netfilter/nfnetlink_cthelper.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
net/netfilter/nfnetlink_cthelper.c +17 -8
@@ -314,23 +314,30 @@ nfnl_cthelper_update_policy_one(const struct nf_conntrack_expect_policy *policy,static int nfnl_cthelper_update_policy_all (struct nlattr *tb[],struct nf_conntrack_helper *helper) { -struct nf_conntrack_expect_policy new_policy[helper->expect_class_max +1 ]; +struct nf_conntrack_expect_policy *new_policy;struct nf_conntrack_expect_policy *policy; -int i, err; +int i, ret =0 ; + + new_policy =kmalloc_array (helper->expect_class_max +1 , +sizeof (*new_policy),GFP_KERNEL ); +if (!new_policy) +return -ENOMEM ;/* Check first that all policy attributes are well-formed, so we don't * leave things in inconsistent state on errors. */ for (i =0 ; i < helper->expect_class_max +1 ; i++) { -if (!tb[NFCTH_POLICY_SET + i]) -return -EINVAL ; +if (!tb[NFCTH_POLICY_SET + i]) { + ret = -EINVAL ; + goto err; + } - err =nfnl_cthelper_update_policy_one (&helper->expect_policy[i], + ret =nfnl_cthelper_update_policy_one (&helper->expect_policy[i], &new_policy[i], tb[NFCTH_POLICY_SET + i]); -if (err <0 ) -return err; +if (ret <0 ) + goto err; }/* Now we can safely update them. */ for (i =0 ; i < helper->expect_class_max +1 ; i++) {
@@ -340,7 +347,9 @@ static int nfnl_cthelper_update_policy_all(struct nlattr *tb[], policy->timeout = new_policy->timeout; } -return 0 ; +err: +kfree (new_policy); +return ret; } static int nfnl_cthelper_update_policy(struct nf_conntrack_helper *helper,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 27/47 netfilter: nf_tables: remove VLA usage
In reply to Pablo Neira AyusoFrom: "Gustavo A. R. Silva" <[email protected]>
In preparation to enabling -Wvla, remove VLA and replace it with dynamic memory allocation.
Quoted 1 line
From a security viewpoint, the use of Variable Length Arrays can be
a vector for stack overflow attacks. Also, in general, as the code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having segfaults that are hard to debug.
Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621
--- net/netfilter/nf_tables_api.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
net/netfilter/nf_tables_api.c +15 -8
@@ -4357,16 +4357,20 @@ static struct nft_object *nft_obj_init(const struct nft_ctx *ctx,const struct nft_object_type *type, const struct nlattr *attr) { - struct nlattr *tb[type->maxattr + 1]; + struct nlattr **tb;const struct nft_object_ops *ops;struct nft_object *obj; -int err; +int err = -ENOMEM ; + + tb =kmalloc_array (type->maxattr +1 ,sizeof (*tb),GFP_KERNEL ); +if (!tb) + goto err1;if (attr) { err =nla_parse_nested (tb, type->maxattr, attr, type->policy,NULL );if (err <0 ) - goto err1; + goto err2; }else {memset (tb,0 ,sizeof (tb[0 ]) * (type->maxattr +1 )); }
@@ -4375,7 +4379,7 @@ static struct nft_object *nft_obj_init(const struct nft_ctx *ctx, ops = type->select_ops (ctx, (const struct nlattr *const *)tb);if (IS_ERR (ops)) { err =PTR_ERR (ops); - goto err1; + goto err2; } }else { ops = type->ops;
@@ -4383,18 +4387,21 @@ static struct nft_object *nft_obj_init(const struct nft_ctx *ctx, err = -ENOMEM ; obj =kzalloc (sizeof (*obj) + ops->size,GFP_KERNEL ); -if (obj ==NULL ) - goto err1; +if (!obj) + goto err2; err = ops->init (ctx, (const struct nlattr *const *)tb, obj);if (err <0 ) - goto err2; + goto err3; obj->ops = ops; +kfree (tb);return obj; -err2: +err3:kfree (obj); +err2: +kfree (tb); err1:return ERR_PTR (err); }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 28/47 netfilter: ebtables: use ADD_COUNTER macro
In reply to Pablo Neira AyusoFrom: Taehee Yoo <[email protected]>
xtables uses ADD_COUNTER macro to increase packet and byte count. ebtables also can use this.
--- net/bridge/netfilter/ebtables.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
net/bridge/netfilter/ebtables.c +6 -11
@@ -223,9 +223,7 @@ unsigned int ebt_do_table(struct sk_buff *skb,return NF_DROP ; } -/* increase counter */ - (*(counter_base + i)).pcnt++; - (*(counter_base + i)).bcnt += skb->len; +ADD_COUNTER (*(counter_base + i),1 , skb->len);/* these should only watch: not modify, nor tell us * what to do with the packet
@@ -968,10 +966,9 @@ static void get_counters(const struct ebt_counter *oldcounters,if (cpu ==0 )continue ; counter_base =COUNTER_BASE (oldcounters, nentries, cpu); -for (i =0 ; i < nentries; i++) { - counters[i].pcnt += counter_base[i].pcnt; - counters[i].bcnt += counter_base[i].bcnt; - } +for (i =0 ; i < nentries; i++) +ADD_COUNTER (counters[i], counter_base[i].pcnt, + counter_base[i].bcnt); } }
@@ -1324,10 +1321,8 @@ static int do_update_counters(struct net *net, const char *name,write_lock_bh (&t->lock);/* we add to the counters of the first cpu */ -for (i =0 ; i < num_counters; i++) { - t->private->counters[i].pcnt += tmp[i].pcnt; - t->private->counters[i].bcnt += tmp[i].bcnt; - } +for (i =0 ; i < num_counters; i++) +ADD_COUNTER (t->private->counters[i], tmp[i].pcnt, tmp[i].bcnt);write_unlock_bh (&t->lock); ret =0 ;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 29/47 netfilter: xt_conntrack: Support bit-shifting for CONNMARK & MARK targets.
In reply to Pablo Neira AyusoFrom: Jack Ma <[email protected]>
This patch introduces a new feature that allows bitshifting (left and right) operations to co-operate with existing iptables options.
--- include/uapi/linux/netfilter/xt_connmark.h | 10 ++++ net/netfilter/xt_connmark.c | 77 +++++++++++++++++++++++------- 2 files changed, 70 insertions(+), 17 deletions(-)
include/uapi/linux/netfilter/xt_connmark.h +10 -0
@@ -19,11 +19,21 @@ enum {XT_CONNMARK_RESTORE }; +enum { +D_SHIFT_LEFT =0 , +D_SHIFT_RIGHT , +}; +struct xt_connmark_tginfo1 {__u32 ctmark, ctmask, nfmask;__u8 mode; }; +struct xt_connmark_tginfo2 { +__u32 ctmark, ctmask, nfmask; +__u8 shift_dir, shift_bits, mode; +}; +struct xt_connmark_mtinfo1 {__u32 mark, mask;__u8 invert;
net/netfilter/xt_connmark.c +60 -17
130 lines not on this page · raw message
Signature · 1 line
2.11.0