netfilter: ipset: small potential read beyond the end of buffer
Subsystems (3)
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
@@ -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; }
Pablo Neira Ayuso
maintainerQuoted 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.
Signed-off-by Dan Carpenter <[email protected]>net/netfilter/ipset/ip_set_core.c +0
-0
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.
Jozsef Kadlecsik
Acked-byQuoted 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.
Signed-off-by Dan Carpenter <[email protected]>net/netfilter/ipset/ip_set_core.c +0
-0net/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
Pablo Neira Ayuso
maintainerQuoted 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.
Acked-by Jozsef Kadlecsik <[email protected]>
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
d67bad383d4ea9dea8872e3999324ccbeb2a5815Mon 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
@@ -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
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.
Acked-by Jozsef Kadlecsik <[email protected]>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
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.
Acked-by Jozsef Kadlecsik <[email protected]>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.
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