Skip to contentSkip to conversation

netfilter: nf_tables: restore check for NFTA_SET_ELEM_LIST_ELEMENTS

PATCH New Pablo Neira Ayuso 1 participant 2 messages Dec 6, 2016

Subsystems (2)
lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/2 netfilter: nf_tables: restore check for NFTA_SET_ELEM_LIST_ELEMENTS

It seems git rebase and branch rmerge resulted patching the wrong spot, restore check when adding elements, remove it from the deletion path so flushing sets still works. The original patch applying this chunk in the right spot: http://patchwork.ozlabs.org/patch/702919/.

Fixes 34d360415a92 ("netfilter: nf_tables: support for set flushing")
---
 net/netfilter/nf_tables_api.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nf_tables_api.c +3 -3
index 9ead6a7514c3..a019a87e58ee 100644
@@ -3767,6 +3767,9 @@ static int nf_tables_newsetelem(struct net *net, struct sock *nlsk,
 	struct nft_ctx ctx;
 	int rem, err = 0;
 
+	if (nla[NFTA_SET_ELEM_LIST_ELEMENTS] == NULL)
+		return -EINVAL;
+
 	err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, genmask);
 	if (err < 0)
 		return err;
@@ -3917,9 +3920,6 @@ static int nf_tables_delsetelem(struct net *net, struct sock *nlsk,
 	struct nft_ctx ctx;
 	int rem, err = 0;
 
-	if (nla[NFTA_SET_ELEM_LIST_ELEMENTS] == NULL)
-		return -EINVAL;
-
 	err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, genmask);
 	if (err < 0)
 		return err;
Signature · 1 line
2.1.4
author maintainer
#1 lore raw

PATCH 2/2 netfilter: nft_counter: move counter reset into separated function

This patch moves the reset path from nft_counter_fetch() to nft_counter_reset(), this patch aims to solve gcc compilation warning:

net/netfilter/nft_counter.c: In function 'nft_counter_fetch':

Quoted 2 lines
Quoted 2 lines

net/netfilter/nft_counter.c:128:18: warning: 'packets' may be used uninitialized in this function [-Wmaybe-uninitialized]

      total->packets += packets;
                     ^~
Quoted 2 lines
Quoted 2 lines

net/netfilter/nft_counter.c:129:16: warning: 'bytes' may be used uninitialized in this function [-Wmaybe-uninitialized]

      total->bytes += bytes;
                   ^~
---
 net/netfilter/nft_counter.c | 43 +++++++++++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 12 deletions(-)
net/netfilter/nft_counter.c +31 -12
index 90e42140ee7b..3d2ff23be8d6 100644
@@ -101,7 +101,7 @@ static void nft_counter_obj_destroy(struct nft_object *obj)
 }
 
 static void nft_counter_fetch(struct nft_counter_percpu __percpu *counter,
-			      struct nft_counter *total, bool reset)
+			      struct nft_counter *total)
 {
 	struct nft_counter_percpu *cpu_stats;
 	u64 bytes, packets;
@@ -110,19 +110,35 @@ static void nft_counter_fetch(struct nft_counter_percpu __percpu *counter,
 
 	memset(total, 0, sizeof(*total));
 	for_each_possible_cpu(cpu) {
-		if (reset)
-			bytes = packets = 0;
+		cpu_stats = per_cpu_ptr(counter, cpu);
+		do {
+			seq	= u64_stats_fetch_begin_irq(&cpu_stats->syncp);
+			bytes	= cpu_stats->counter.bytes;
+			packets	= cpu_stats->counter.packets;
+		} while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, seq));
+
+		total->packets += packets;
+		total->bytes += bytes;
+	}
+}
+
+static void nft_counter_reset(struct nft_counter_percpu __percpu *counter,
+			      struct nft_counter *total)
+{
+	struct nft_counter_percpu *cpu_stats;
+	u64 bytes, packets;
+	unsigned int seq;
+	int cpu;
+
+	memset(total, 0, sizeof(*total));
+	for_each_possible_cpu(cpu) {
+		bytes = packets = 0;
 
 		cpu_stats = per_cpu_ptr(counter, cpu);
 		do {
 			seq	= u64_stats_fetch_begin_irq(&cpu_stats->syncp);
-			if (reset) {
-				packets += xchg(&cpu_stats->counter.packets, 0);
-				bytes	+= xchg(&cpu_stats->counter.bytes, 0);
-			} else {
-				bytes	= cpu_stats->counter.bytes;
-				packets	= cpu_stats->counter.packets;
-			}
+			packets += xchg(&cpu_stats->counter.packets, 0);
+			bytes	+= xchg(&cpu_stats->counter.bytes, 0);
 		} while (u64_stats_fetch_retry_irq(&cpu_stats->syncp, seq));
 
 		total->packets += packets;
@@ -136,7 +152,10 @@ static int nft_counter_do_dump(struct sk_buff *skb,
 {
 	struct nft_counter total;
 
-	nft_counter_fetch(priv->counter, &total, reset);
+	if (reset)
+		nft_counter_reset(priv->counter, &total);
+	else
+		nft_counter_fetch(priv->counter, &total);
 
 	if (nla_put_be64(skb, NFTA_COUNTER_BYTES, cpu_to_be64(total.bytes),
 			 NFTA_COUNTER_PAD) ||
@@ -215,7 +234,7 @@ static int nft_counter_clone(struct nft_expr *dst, const struct nft_expr *src)
 	struct nft_counter_percpu *this_cpu;
 	struct nft_counter total;
 
-	nft_counter_fetch(priv->counter, &total, false);
+	nft_counter_fetch(priv->counter, &total);
 
 	cpu_stats = __netdev_alloc_pcpu_stats(struct nft_counter_percpu,
 					      GFP_ATOMIC);
Signature · 1 line
2.1.4