Skip to contentSkip to conversation

net: remove duplicate fetch in sock_getsockopt

PATCH In review JingYi Hou 2 participants 2 messages Jun 17, 2019 – Jun 18, 2019

Subsystems (3)
lore
Share & tools
lore

JingYi Hou

author
#0 lore raw

PATCH 1/1 net: remove duplicate fetch in sock_getsockopt

In sock_getsockopt(), 'optlen' is fetched the first time from userspace. 'len < 0' is then checked. Then in condition 'SO_MEMINFO', 'optlen' is fetched the second time from userspace.

If change it between two fetches may cause security problems or unexpected behaivor, and there is no reason to fetch it a second time.

To fix this, we need to remove the second fetch.

---
 net/core/sock.c | 3 ---
 1 file changed, 3 deletions(-)
net/core/sock.c +0 -3
index 2b3701958486..932bcbf2d565 100644
@@ -1477,9 +1477,6 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
 	{
 		u32 meminfo[SK_MEMINFO_VARS];
 
-		if (get_user(len, optlen))
-			return -EFAULT;
-
 		sk_get_meminfo(sk, meminfo);
 
 		len = min_t(unsigned int, len, sizeof(meminfo));
Signature · 1 line
2.20.1
maintainer
#1 lore raw

From: JingYi Hou <[email protected]>
Date: Mon, 17 Jun 2019 14:56:05 +0800

Quoted 10 lines

In sock_getsockopt(), 'optlen' is fetched the first time from userspace. 'len < 0' is then checked. Then in condition 'SO_MEMINFO', 'optlen' is fetched the second time from userspace.

If change it between two fetches may cause security problems or unexpected behaivor, and there is no reason to fetch it a second time.

To fix this, we need to remove the second fetch.

Applied and queued up for -stable, thanks.