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

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).