Skip to contentSkip to conversation

netfilter: ipset: small potential read beyond the end of buffer

PATCH Applied Dan Carpenter 3 participants 7 messages Nov 7, 2014 – Nov 11, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: ipset: small potential read beyond the end of buffer

We could be reading 8 bytes into a 4 byte buffer here. It seems harmless but adding a check is the right thing to do and it silences a static checker warning.

net/netfilter/ipset/ip_set_core.c +2 -1
index 86f9d76..ac08a3f 100644
@@ -1863,7 +1863,8 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
 	if (*op < IP_SET_OP_VERSION) {
 		/* Check the version at the beginning of operations */
 		struct ip_set_req_version *req_version = data;
-		if (req_version->version != IPSET_PROTOCOL) {
+		if (*len < sizeof(struct ip_set_req_version) ||
+		    req_version->version != IPSET_PROTOCOL) {
 			ret = -EPROTO;
 			goto done;
 		}
#1 lore raw
Quoted 11 lines · Dan Carpenter

We could be reading 8 bytes into a 4 byte buffer here. It seems harmless but adding a check is the right thing to do and it silences a static checker warning.

net/netfilter/ipset/ip_set_core.c +0 -0
index 86f9d76..ac08a3f 100644

net/netfilter/ipset/ip_set_core.c ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len) · line 1869

Quoted 8 lines
net/netfilter/ipset/ip_set_core.c +2 -1
@@ -1863,7 +1863,8 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
 	if (*op < IP_SET_OP_VERSION) {
 		/* Check the version at the beginning of operations */
 		struct ip_set_req_version *req_version = data;
-		if (req_version->version != IPSET_PROTOCOL) {
+		if (*len < sizeof(struct ip_set_req_version) ||
+		    req_version->version != IPSET_PROTOCOL) {
 			ret = -EPROTO;
 			goto done;

Thanks for catching up this.

Quoted 1 line

From other similar code in that location, I can see Jozsef is using

this pattern:

                if (*len != sizeof(struct ip_set_req_version)) {
                        ret = -EINVAL;
                        goto done;
                }

I think it would be good to stick to that for consistency. Thanks.

#2 lore raw
Quoted 24 lines · Pablo Neira Ayuso
Quoted 11 lines · Dan Carpenter

We could be reading 8 bytes into a 4 byte buffer here. It seems harmless but adding a check is the right thing to do and it silences a static checker warning.

net/netfilter/ipset/ip_set_core.c +0 -0
index 86f9d76..ac08a3f 100644

net/netfilter/ipset/ip_set_core.c ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len) · line 1869

Quoted 8 lines
net/netfilter/ipset/ip_set_core.c +2 -1
@@ -1863,7 +1863,8 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
 	if (*op < IP_SET_OP_VERSION) {
 		/* Check the version at the beginning of operations */
 		struct ip_set_req_version *req_version = data;
-		if (req_version->version != IPSET_PROTOCOL) {
+		if (*len < sizeof(struct ip_set_req_version) ||
+		    req_version->version != IPSET_PROTOCOL) {
 			ret = -EPROTO;
 			goto done;

Thanks for catching up this.

Quoted 1 line

From other similar code in that location, I can see Jozsef is using

Quoted 8 lines

this pattern:

                if (*len != sizeof(struct ip_set_req_version)) {
                        ret = -EINVAL;
                        goto done;
                }

I think it would be good to stick to that for consistency. Thanks.

Absolutely, yes.

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
#3 lore raw
Quoted 9 lines · Jozsef Kadlecsik
Quoted 8 lines · Pablo Neira Ayuso
Quoted 1 line

From other similar code in that location, I can see Jozsef is using

this pattern:

                if (*len != sizeof(struct ip_set_req_version)) {
                        ret = -EINVAL;
                        goto done;
                }
Quoted 5 lines
Quoted 1 line

I think it would be good to stick to that for consistency. Thanks.

Absolutely, yes.

OK, then does this look fine to you? I took over Dan's patch and gave it another spin. See it attached, thanks.

Quoted 1 line

From d67bad383d4ea9dea8872e3999324ccbeb2a5815 Mon Sep 17 00:00:00 2001

From: Dan Carpenter <[email protected]>
Date: Fri, 7 Nov 2014 09:21:40 +0300
Subject: [PATCH] netfilter: ipset: small potential read beyond the end of
buffer

We could be reading 8 bytes into a 4 byte buffer here. It seems harmless but adding a check is the right thing to do and it silences a static checker warning.

---
 net/netfilter/ipset/ip_set_core.c |    6 ++++++
 1 file changed, 6 insertions(+)
net/netfilter/ipset/ip_set_core.c +6 -0
index 86f9d76..d259da3 100644
@@ -1863,6 +1863,12 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
 	if (*op < IP_SET_OP_VERSION) {
 		/* Check the version at the beginning of operations */
 		struct ip_set_req_version *req_version = data;
+
+		if (*len < sizeof(struct ip_set_req_version)) {
+			ret = -EINVAL;
+			goto done;
+		}
+
 		if (req_version->version != IPSET_PROTOCOL) {
 			ret = -EPROTO;
 			goto done;
Signature · 1 line
1.7.10.4
#4 lore raw
Quoted 10 lines · Pablo Neira Ayuso
Quoted 9 lines · Jozsef Kadlecsik
Quoted 8 lines · Pablo Neira Ayuso
Quoted 1 line

From other similar code in that location, I can see Jozsef is using

this pattern:

                if (*len != sizeof(struct ip_set_req_version)) {
                        ret = -EINVAL;
                        goto done;
                }
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I think it would be good to stick to that for consistency. Thanks.

Absolutely, yes.

OK, then does this look fine to you? I took over Dan's patch and gave it another spin. See it attached, thanks.

Yes, it's better this way, 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
maintainer Applied
#5 lore raw
Quoted 14 lines · Jozsef Kadlecsik
Quoted 12 lines · Pablo Neira Ayuso
Quoted 11 lines · Jozsef Kadlecsik
Quoted 9 lines · Pablo Neira Ayuso
Quoted 1 line

From other similar code in that location, I can see Jozsef is using

this pattern:

                if (*len != sizeof(struct ip_set_req_version)) {
                        ret = -EINVAL;
                        goto done;
                }

I think it would be good to stick to that for consistency. Thanks.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Absolutely, yes.

OK, then does this look fine to you? I took over Dan's patch and gave it another spin. See it attached, thanks.

Yes, it's better this way, thanks!

Applied, thanks Dan and Jozsef.

#6 lore raw
In reply to Pablo Neira Ayuso
Quoted 2 lines · Pablo Neira Ayuso

OK, then does this look fine to you? I took over Dan's patch and gave it another spin. See it attached, thanks.

Looks good to me, thanks.

regards,
dan carpenter