diff mbox series

fix double-fetch bug in sock_getsockopt()

Message ID 20190613104457.GA6296@hjy-HP-Notebook
State Changes Requested
Delegated to: David Miller
Headers show
Series fix double-fetch bug in sock_getsockopt() | expand

Commit Message

JingYi Hou June 13, 2019, 10:44 a.m. UTC
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 without check.

if a malicious user can change it between two fetches may cause security
problems or unexpected behaivor.

To fix this, we need to recheck it in the second fetch.

Signed-off-by: JingYi Hou <houjingyi647@gmail.com>
---
 net/core/sock.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

David Miller June 15, 2019, 8:32 p.m. UTC | #1
From: JingYi Hou <houjingyi647@gmail.com>
Date: Thu, 13 Jun 2019 18:44:57 +0800

> 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 without check.
> 
> if a malicious user can change it between two fetches may cause security
> problems or unexpected behaivor.
> 
> To fix this, we need to recheck it in the second fetch.
> 
> Signed-off-by: JingYi Hou <houjingyi647@gmail.com>

THere is no reason to fetch len a second time, so please just remove
the get_user() call here instead.

Also, please format your Subject line properly with appropriate subsystem
prefixes etc.
diff mbox series

Patch

diff --git a/net/core/sock.c b/net/core/sock.c
index 2b3701958486..577780c935ee 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1479,6 +1479,8 @@  int sock_getsockopt(struct socket *sock, int level, int optname,
 
 		if (get_user(len, optlen))
 			return -EFAULT;
+		if (len < 0)
+			return -EINVAL;
 
 		sk_get_meminfo(sk, meminfo);