Skip to contentSkip to conversation

lib: fix ifname 'physdev:' prefix parsing

PATCH In review Florian Westphal 2 participants 8 messages Feb 12, 2014 – Feb 13, 2014

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/2 lib: fix ifname 'physdev:' prefix parsing

hash:net,iface supports matching on the bridge port as well, but userspace currently doesn't handle it correctly as it passes in 'physdev:eth0' instead of 'eth0'+IPSET_OPT_PHYSDEV.

---
 lib/parse.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/parse.c +3 -2
index f1c1f0e..4db872e 100644
@@ -1753,14 +1753,15 @@ ipset_parse_iface(struct ipset_session *session,
 {
 	struct ipset_data *data;
 	int offset = 0, err = 0;
+	static const char pdev_prefix[]="physdev:";
 
 	assert(session);
 	assert(opt == IPSET_OPT_IFACE);
 	assert(str);
 
 	data = ipset_session_data(session);
-	if (STREQ(str, "physdev:")) {
-		offset = 8;
+	if (STRNEQ(str, pdev_prefix, strlen(pdev_prefix))) {
+		offset = strlen(pdev_prefix);
 		err = ipset_data_set(data, IPSET_OPT_PHYSDEV, str);
 		if (err < 0)
 			return err;
Signature · 1 line
1.8.1.5
author maintainer
#1 lore raw

PATCH 2/2 lib: don't segfault when ipset_data_get returns NULL

ipset_data_get returns NULL if the attribute is not available, causes when running 'ipset list':

$ ipset -N foo hash:ip
$ ipset list
Segmentation fault (core dumped)

---
Not sure about this patch, the missing attr is IPSET_OPT_MEMSIZE. Is the kernel supposed to send it along (i am on latest nf tree)?

lib/print.c +2 -0
index f81c074..9ad4bab 100644
@@ -378,6 +378,8 @@ ipset_print_number(char *buf, unsigned int len,
 	assert(data);
 
 	number = ipset_data_get(data, opt);
+	if (!number)
+		return 0;
 	maxsize = ipset_data_sizeof(opt, AF_INET);
 	D("opt: %u, maxsize %zu", opt, maxsize);
 	if (maxsize == sizeof(uint8_t))
Signature · 1 line
1.8.1.5
#2 lore raw

Re: [PATCH ipset 2/2] lib: don't segfault when ipset_data_get returns NULL

Hi Florian,

Quoted 6 lines · Florian Westphal

ipset_data_get returns NULL if the attribute is not available, causes when running 'ipset list':

$ ipset -N foo hash:ip
$ ipset list
Segmentation fault (core dumped)

I'm unable to reproduce it. Please give me more information on the
environment: architecture, kernel, ipset userspace versions, compiler version.

Quoted 4 lines

---
Not sure about this patch, the missing attr is IPSET_OPT_MEMSIZE. Is the kernel supposed to send it along (i am on latest nf tree)?

How do you know which attr is missing? IPSET_OPT_MEMSIZE should always be sent by the kernel, look at mtype_head in ip_set_hash_gen.h.

Quoted 16 lines
lib/print.c +2 -0
index f81c074..9ad4bab 100644
@@ -378,6 +378,8 @@ ipset_print_number(char *buf, unsigned int len,
 	assert(data);
 
 	number = ipset_data_get(data, opt);
+	if (!number)
+		return 0;
 	maxsize = ipset_data_sizeof(opt, AF_INET);
 	D("opt: %u, maxsize %zu", opt, maxsize);
 	if (maxsize == sizeof(uint8_t))
Signature · 1 line
1.8.1.5

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary
author maintainer
#3 lore raw

Re: [PATCH ipset 2/2] lib: don't segfault when ipset_data_get returns NULL

Quoted 5 lines · Jozsef Kadlecsik
Quoted 3 lines · Florian Westphal

ipset_data_get returns NULL if the attribute is not available, causes when running 'ipset list':

Quoted 7 lines
Quoted 3 lines
$ ipset -N foo hash:ip
$ ipset list
Segmentation fault (core dumped)

I'm unable to reproduce it. Please give me more information on the
environment: architecture, kernel, ipset userspace versions, compiler version.

latest ipset git version, net-next tree from this morning.

Quoted 5 lines
Quoted 2 lines

Not sure about this patch, the missing attr is IPSET_OPT_MEMSIZE. Is the kernel supposed to send it along (i am on latest nf tree)?

How do you know which attr is missing? IPSET_OPT_MEMSIZE should always be sent by the kernel, look at mtype_head in ip_set_hash_gen.h.

You are right. The attribute is there. I bisected this down to commit

commit 2dfb973c0dcc6d22113e2370f461f1733035baaf

Author: Vytas Dauksa <[email protected]>
Date:   Tue Dec 17 14:01:44 2013 +0000

add markmask for hash:ip,mark data type

The problem is that this commit breaks userspace abi. Minimum fix that makes latest ipset userspace work again is this, most likely this needs to be corrected on kernel side as well (afaics its not yet in net-next or nf trees):

include/libipset/linux_ip_set.h +2 -2
index c2bae85..d9beec5 100644
@@ -90,7 +90,6 @@ enum {
 	IPSET_ATTR_GC,
 	IPSET_ATTR_HASHSIZE,
 	IPSET_ATTR_MAXELEM,
-	IPSET_ATTR_MARKMASK,
 	IPSET_ATTR_NETMASK,
 	IPSET_ATTR_PROBES,
 	IPSET_ATTR_RESIZE,
@@ -99,6 +98,7 @@ enum {
 	IPSET_ATTR_ELEMENTS,
 	IPSET_ATTR_REFERENCES,
 	IPSET_ATTR_MEMSIZE,
+	IPSET_ATTR_MARKMASK,
 
 	__IPSET_ATTR_CREATE_MAX,
 };
@@ -140,7 +140,6 @@ enum ipset_errno {
 	IPSET_ERR_EXIST,
 	IPSET_ERR_INVALID_CIDR,
 	IPSET_ERR_INVALID_NETMASK,
-	IPSET_ERR_INVALID_MARKMASK,
 	IPSET_ERR_INVALID_FAMILY,
 	IPSET_ERR_TIMEOUT,
 	IPSET_ERR_REFERENCED,
@@ -148,6 +147,7 @@ enum ipset_errno {
 	IPSET_ERR_IPADDR_IPV6,
 	IPSET_ERR_COUNTER,
 	IPSET_ERR_COMMENT,
+	IPSET_ERR_INVALID_MARKMASK,
 
 	/* Type specific error codes */
 	IPSET_ERR_TYPE_SPECIFIC = 4352,
#4 lore raw

Re: [PATCH ipset 2/2] lib: don't segfault when ipset_data_get returns NULL

Quoted 28 lines · Florian Westphal
Quoted 5 lines · Jozsef Kadlecsik
Quoted 3 lines · Florian Westphal

ipset_data_get returns NULL if the attribute is not available, causes when running 'ipset list':

Quoted 7 lines
Quoted 3 lines
$ ipset -N foo hash:ip
$ ipset list
Segmentation fault (core dumped)

I'm unable to reproduce it. Please give me more information on the
environment: architecture, kernel, ipset userspace versions, compiler version.

latest ipset git version, net-next tree from this morning.

Quoted 5 lines
Quoted 2 lines

Not sure about this patch, the missing attr is IPSET_OPT_MEMSIZE. Is the kernel supposed to send it along (i am on latest nf tree)?

How do you know which attr is missing? IPSET_OPT_MEMSIZE should always be sent by the kernel, look at mtype_head in ip_set_hash_gen.h.

You are right. The attribute is there. I bisected this down to commit

commit 2dfb973c0dcc6d22113e2370f461f1733035baaf

Author: Vytas Dauksa <[email protected]>
Date:   Tue Dec 17 14:01:44 2013 +0000
Quoted 6 lines

add markmask for hash:ip,mark data type

The problem is that this commit breaks userspace abi. Minimum fix that makes latest ipset userspace work again is this, most likely this needs to be corrected on kernel side as well (afaics its not yet in net-next or nf trees):

Good catch indeed! The attribute then should be moved just after IPSET_ATTR_MARK in include/uapi/linux/netfilter/ipset/ipset.h and run "make update_includes" so that include/libipset/linux_ip_set.h gets refreshed.

Could you prepare a patch?

Best regards,
Jozsef

Quoted 37 lines
include/libipset/linux_ip_set.h +2 -3
index c2bae85..d9beec5 100644
@@ -90,7 +90,6 @@ enum {
 	IPSET_ATTR_GC,
 	IPSET_ATTR_HASHSIZE,
 	IPSET_ATTR_MAXELEM,
-	IPSET_ATTR_MARKMASK,
 	IPSET_ATTR_NETMASK,
 	IPSET_ATTR_PROBES,
 	IPSET_ATTR_RESIZE,
@@ -99,6 +98,7 @@ enum {
 	IPSET_ATTR_ELEMENTS,
 	IPSET_ATTR_REFERENCES,
 	IPSET_ATTR_MEMSIZE,
+	IPSET_ATTR_MARKMASK,
 
 	__IPSET_ATTR_CREATE_MAX,
 };
@@ -140,7 +140,6 @@ enum ipset_errno {
 	IPSET_ERR_EXIST,
 	IPSET_ERR_INVALID_CIDR,
 	IPSET_ERR_INVALID_NETMASK,
-	IPSET_ERR_INVALID_MARKMASK,
 	IPSET_ERR_INVALID_FAMILY,
 	IPSET_ERR_TIMEOUT,
 	IPSET_ERR_REFERENCED,
@@ -148,6 +147,7 @@ enum ipset_errno {
 	IPSET_ERR_IPADDR_IPV6,
 	IPSET_ERR_COUNTER,
 	IPSET_ERR_COMMENT,
+	IPSET_ERR_INVALID_MARKMASK,
 
 	/* Type specific error codes */
 	IPSET_ERR_TYPE_SPECIFIC = 4352,
--
Quoted 4 lines

To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary
#5 lore raw
In reply to Florian Westphal

Hi Florian,

Quoted 3 lines · Florian Westphal

hash:net,iface supports matching on the bridge port as well, but userspace currently doesn't handle it correctly as it passes in 'physdev:eth0' instead of 'eth0'+IPSET_OPT_PHYSDEV.

I think the userspace does handle the case: looking at your patch, it's exactly the same as the original one. It is nicer, so I'm happy to apply it, but the description - as far as I see - doesn't fit.

Maybe your kernel is not compiled with BRIDGE_NETFILTER enabled? That's required for the functionality at the kernel side.

Quoted 29 lines
---
 lib/parse.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/parse.c +3 -2
index f1c1f0e..4db872e 100644
@@ -1753,14 +1753,15 @@ ipset_parse_iface(struct ipset_session *session,
 {
 	struct ipset_data *data;
 	int offset = 0, err = 0;
+	static const char pdev_prefix[]="physdev:";
 
 	assert(session);
 	assert(opt == IPSET_OPT_IFACE);
 	assert(str);
 
 	data = ipset_session_data(session);
-	if (STREQ(str, "physdev:")) {
-		offset = 8;
+	if (STRNEQ(str, pdev_prefix, strlen(pdev_prefix))) {
+		offset = strlen(pdev_prefix);
 		err = ipset_data_set(data, IPSET_OPT_PHYSDEV, str);
 		if (err < 0)
 			return err;
Signature · 1 line
1.8.1.5

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary
author maintainer
#6 lore raw
Quoted 11 lines · Jozsef Kadlecsik

Hi Florian,

Quoted 3 lines · Florian Westphal

hash:net,iface supports matching on the bridge port as well, but userspace currently doesn't handle it correctly as it passes in 'physdev:eth0' instead of 'eth0'+IPSET_OPT_PHYSDEV.

I think the userspace does handle the case: looking at your patch, it's exactly the same as the original one. It is nicer, so I'm happy to apply it, but the description - as far as I see - doesn't fit.

It will expand to

if (strcmp("physdev:eth0", "physdev:") == 0)

which is not true.

#7 lore raw
Quoted 12 lines · Florian Westphal
Quoted 10 lines · Jozsef Kadlecsik
Quoted 3 lines · Florian Westphal

hash:net,iface supports matching on the bridge port as well, but userspace currently doesn't handle it correctly as it passes in 'physdev:eth0' instead of 'eth0'+IPSET_OPT_PHYSDEV.

I think the userspace does handle the case: looking at your patch, it's exactly the same as the original one. It is nicer, so I'm happy to apply it, but the description - as far as I see - doesn't fit.

Quoted 5 lines

It will expand to

if (strcmp("physdev:eth0", "physdev:") == 0)

which is not true.

Ohh, right. And then the whole string is passed to the kernel and therefore the "physdev:" part is kept at listing.

Patch is applied, thanks!

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences

          H-1525 Budapest 114, POB. 49, Hungary