netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fix double-fetch bug in sock_getsockopt()
@ 2019-06-13 10:44 JingYi Hou
  2019-06-15 20:32 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: JingYi Hou @ 2019-06-13 10:44 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-kernel

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(+)

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);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fix double-fetch bug in sock_getsockopt()
  2019-06-13 10:44 [PATCH] fix double-fetch bug in sock_getsockopt() JingYi Hou
@ 2019-06-15 20:32 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-06-15 20:32 UTC (permalink / raw)
  To: houjingyi647; +Cc: netdev, linux-kernel

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-15 20:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-13 10:44 [PATCH] fix double-fetch bug in sock_getsockopt() JingYi Hou
2019-06-15 20:32 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).