Skip to contentSkip to conversation

netlink: Fix portid type in netlink_notify

PATCH Superseded Richard Weinberger 4 participants 9 messages Apr 9, 2015 – Apr 10, 2015

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/5 netlink: Fix portid type in netlink_notify

portid is an unsigned integer. Fix netlink_notify to match all other portid user in the kernel.

---
 include/linux/netlink.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/netlink.h +1 -1
index 02fc86d..6835c12 100644
@@ -134,7 +134,7 @@ struct netlink_callback {
 
 struct netlink_notify {
 	struct net *net;
-	int portid;
+	u32 portid;
 	int protocol;
 };
 
Signature · 1 line
1.8.4.5
#1 lore raw

PATCH v2 2/5 nfc: Fix portid type in urelease_work

portid is an unsigned integer. Fix urelease_work to match all other portid user in the kernel.

---
 net/nfc/netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/nfc/netlink.c +1 -1
index 14a2d11..3763036 100644
@@ -1584,7 +1584,7 @@ static const struct genl_ops nfc_genl_ops[] = {
 
 struct urelease_work {
 	struct	work_struct w;
-	int	portid;
+	u32	portid;
 };
 
 static void nfc_urelease_event_work(struct work_struct *work)
Signature · 1 line
1.8.4.5
#2 lore raw

PATCH v2 3/5 netfilter: Fix portid types

In reply to Richard Weinberger

The netlink portid is an unsigned integer, use this type also in netfilter.

---
 net/netfilter/nfnetlink_log.c        | 4 ++--
 net/netfilter/nfnetlink_queue_core.c | 7 +++----
 2 files changed, 5 insertions(+), 6 deletions(-)
net/netfilter/nfnetlink_log.c +2 -2
index 11d85b3..7150d11 100644
@@ -62,7 +62,7 @@ struct nfulnl_instance {
 	struct timer_list timer;
 	struct net *net;
 	struct user_namespace *peer_user_ns;	/* User namespace of the peer process */
-	int peer_portid;			/* PORTID of the peer process */
+	u32 peer_portid;		/* PORTID of the peer process */
 
 	/* configurable parameters */
 	unsigned int flushtimeout;	/* timeout until queue flush */
@@ -151,7 +151,7 @@ static void nfulnl_timer(unsigned long data);
 
 static struct nfulnl_instance *
 instance_create(struct net *net, u_int16_t group_num,
-		int portid, struct user_namespace *user_ns)
+		u32 portid, struct user_namespace *user_ns)
 {
 	struct nfulnl_instance *inst;
 	struct nfnl_log_net *log = nfnl_log_pernet(net);
net/netfilter/nfnetlink_queue_core.c +3 -4
index 0db8515..0aba0b9 100644
@@ -54,7 +54,7 @@ struct nfqnl_instance {
 	struct hlist_node hlist;		/* global list of queues */
 	struct rcu_head rcu;
 
-	int peer_portid;
+	u32 peer_portid;
 	unsigned int queue_maxlen;
 	unsigned int copy_range;
 	unsigned int queue_dropped;
@@ -109,8 +109,7 @@ instance_lookup(struct nfnl_queue_net *q, u_int16_t queue_num)
 }
 
 static struct nfqnl_instance *
-instance_create(struct nfnl_queue_net *q, u_int16_t queue_num,
-		int portid)
+instance_create(struct nfnl_queue_net *q, u_int16_t queue_num, u32 portid)
 {
 	struct nfqnl_instance *inst;
 	unsigned int h;
@@ -860,7 +859,7 @@ static const struct nla_policy nfqa_verdict_batch_policy[NFQA_MAX+1] = {
 };
 
 static struct nfqnl_instance *
-verdict_instance_lookup(struct nfnl_queue_net *q, u16 queue_num, int nlportid)
+verdict_instance_lookup(struct nfnl_queue_net *q, u16 queue_num, u32 nlportid)
 {
 	struct nfqnl_instance *queue;
 
Signature · 1 line
1.8.4.5
#3 lore raw

PATCH v2 4/5 netfilter: Fix format string of nfnetlink_queue proc file

In reply to Richard Weinberger

The printed values are all of type unsigned integer, therefore use %u instead of %d. Otherwise an user can face negative values.

Fixes:

$ cat /proc/net/netfilter/nfnetlink_queue
    0  29508   278 2 65531     0 2004213241 -2129885586  1
    1 -27747     0 2 65531     0     0        0  1
    2 -27748     0 2 65531     0     0        0  1
---
 net/netfilter/nfnetlink_queue_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink_queue_core.c +1 -1
index 0aba0b9..017e3cd 100644
@@ -1241,7 +1241,7 @@ static int seq_show(struct seq_file *s, void *v)
 {
 	const struct nfqnl_instance *inst = v;
 
-	seq_printf(s, "%5d %6d %5d %1d %5d %5d %5d %8d %2d\n",
+	seq_printf(s, "%5u %6u %5u %1u %5u %5u %5u %8u %2d\n",
 		   inst->queue_num,
 		   inst->peer_portid, inst->queue_total,
 		   inst->copy_mode, inst->copy_range,
Signature · 1 line
1.8.4.5
#4 lore raw

PATCH v2 5/5 netfilter: Fix format string of nfnetlink_log proc file

In reply to Richard Weinberger

The printed values are all of type unsigned integer, therefore use %u instead of %d. Otherwise an user can face negative values.

---
 net/netfilter/nfnetlink_log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink_log.c +1 -1
index 7150d11..313c26c 100644
@@ -998,7 +998,7 @@ static int seq_show(struct seq_file *s, void *v)
 {
 	const struct nfulnl_instance *inst = v;
 
-	return seq_printf(s, "%5d %6d %5d %1d %5d %6d %2d\n",
+	return seq_printf(s, "%5u %6u %5u %1u %5u %6u %2u\n",
 			  inst->group_num,
 			  inst->peer_portid, inst->qlen,
 			  inst->copy_mode, inst->copy_range,
Signature · 1 line
1.8.4.5
#5 lore raw

Re: [PATCH 5/5 v2] netfilter: Fix format string of nfnetlink_log proc file

Quoted 2 lines · Richard Weinberger

The printed values are all of type unsigned integer, therefore use %u instead of %d. Otherwise an user can face negative values.

Hey Richard.

Just to clarify, this patch is for net and not for net-next as net-next has removed the seq_printf return uses.

Are you going to submit an equivalent patch for net-next?

net/netfilter/nfnetlink_log.c

Quoted 1 line
net/netfilter/nfnetlink_log.c +0 -0

[]

net/netfilter/nfnetlink_log.c static int seq_show(struct seq_file *s, void *v) · line 1004

Quoted 9 lines
net/netfilter/nfnetlink_log.c +1 -1
@@ -998,7 +998,7 @@ static int seq_show(struct seq_file *s, void *v)
 {
 	const struct nfulnl_instance *inst = v;
 
-	return seq_printf(s, "%5d %6d %5d %1d %5d %6d %2d\n",
+	return seq_printf(s, "%5u %6u %5u %1u %5u %6u %2u\n",
 			  inst->group_num,
 			  inst->peer_portid, inst->qlen,
 			  inst->copy_mode, inst->copy_range,

And Steven,

commit e71456ae9871
("netfilter: Remove checks of seq_printf() return values") mistakenly converted this to use seq_has_overflowed()

Ideally all seq_show functions would be converted from

int foo_seq_show(...)

{
	seq_printf(s, ...);
	return seq_has_overflowed(s);
}

to

int foo_seq_show(...)

{
	seq_printf(s, ...);
	return 0;
}

I made that mistake in a patch and corrected it later.

Here's a suggested -next patch:

Perhaps it shouldn't be submitted now as it may conflict with what Richard might submit if he propses an equivalent patch to above for -next.

There is an appropriate use of return seq_has_overflowed in:

net/netfilter/xt_hashlimit.c:825: return seq_has_overflowed(s);

That's not a seq_show function, it's a helper for one.

---
 net/netfilter/nfnetlink_queue_core.c |  3 ++-
 net/netfilter/x_tables.c             | 11 +++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
net/netfilter/nfnetlink_queue_core.c +2 -1
index 6e74655..5f827a1 100644
@@ -1248,7 +1248,8 @@ static int seq_show(struct seq_file *s, void *v)
 		   inst->copy_mode, inst->copy_range,
 		   inst->queue_dropped, inst->queue_user_dropped,
 		   inst->id_sequence, 1);
-	return seq_has_overflowed(s);
+
+	return 0;
 }
 
 static const struct seq_operations nfqnl_seq_ops = {
net/netfilter/x_tables.c +5 -6
index 51a459c..4dcbea8 100644
@@ -947,11 +947,10 @@ static int xt_table_seq_show(struct seq_file *seq, void *v)
 {
 	struct xt_table *table = list_entry(v, struct xt_table, list);
 
-	if (strlen(table->name)) {
+	if (strlen(table->name))
 		seq_printf(seq, "%s\n", table->name);
-		return seq_has_overflowed(seq);
-	} else
-		return 0;
+
+	return 0;
 }
 
 static const struct seq_operations xt_table_seq_ops = {
@@ -1090,7 +1089,7 @@ static int xt_match_seq_show(struct seq_file *seq, void *v)
 		if (*match->name == '\0')
 			return 0;
 		seq_printf(seq, "%s\n", match->name);
-		return seq_has_overflowed(seq);
+		break;
 	}
 	return 0;
 }
@@ -1145,7 +1144,7 @@ static int xt_target_seq_show(struct seq_file *seq, void *v)
 		if (*target->name == '\0')
 			return 0;
 		seq_printf(seq, "%s\n", target->name);
-		return seq_has_overflowed(seq);
+		break;
 	}
 	return 0;
 }
#6 lore raw

Re: [PATCH 5/5 v2] netfilter: Fix format string of nfnetlink_log proc file

Quoted 30 lines · On Thu, 09 Apr 2015 15:39:37 -0700 Joe Perches <[email protected]> wrote:

And Steven,

commit e71456ae9871
("netfilter: Remove checks of seq_printf() return values") mistakenly converted this to use seq_has_overflowed()

Ideally all seq_show functions would be converted from

int foo_seq_show(...)

{
	seq_printf(s, ...);
	return seq_has_overflowed(s);
}

to

int foo_seq_show(...)

{
	seq_printf(s, ...);
	return 0;
}

I made that mistake in a patch and corrected it later.

Here's a suggested -next patch:

Perhaps it shouldn't be submitted now as it may conflict with what Richard might submit if he propses an equivalent patch to above for -next.

Quoted 5 lines

There is an appropriate use of return seq_has_overflowed in:

net/netfilter/xt_hashlimit.c:825: return seq_has_overflowed(s);

That's not a seq_show function, it's a helper for one.

I have other things to work on, so feel free to fix it up among yourselves.

-- Steve

#7 lore raw

Re: [PATCH 5/5 v2] netfilter: Fix format string of nfnetlink_log proc file

In reply to Joe Perches

Am 10.04.2015 um 00:39 schrieb Joe Perches:

Quoted 10 lines · Richard Weinberger
Quoted 2 lines

The printed values are all of type unsigned integer, therefore use %u instead of %d. Otherwise an user can face negative values.

Hey Richard.

Just to clarify, this patch is for net and not for net-next as net-next has removed the seq_printf return uses.

Are you going to submit an equivalent patch for net-next?

Hmm, you are right. It took me a few minutes to figure out what happened because I did rebase my patches to net-next and fixed up 5/5 already. Reading yesterday's bash history shows that I've used
git format-patch in a wrong way such that the comments from the old branch were taken.

Thanks,
//richard

maintainer
#8 lore raw

Re: [PATCH 5/5 v2] netfilter: Fix format string of nfnetlink_log proc file

From: Richard Weinberger <[email protected]>
Date: Fri, 10 Apr 2015 09:31:19 +0200

Quoted 10 lines

Am 10.04.2015 um 00:39 schrieb Joe Perches:

Quoted 9 lines · Richard Weinberger
Quoted 2 lines

The printed values are all of type unsigned integer, therefore use %u instead of %d. Otherwise an user can face negative values.

Hey Richard.

Just to clarify, this patch is for net and not for net-next as net-next has removed the seq_printf return uses.

Quoted 7 lines
Quoted 1 line

Are you going to submit an equivalent patch for net-next?

Hmm, you are right. It took me a few minutes to figure out what happened because I did rebase my patches to net-next and fixed up 5/5 already. Reading yesterday's bash history shows that I've used
git format-patch in a wrong way such that the comments from the old branch were taken.

I'm waiting for you to respin this series against net-next, thanks.