Netdev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] net: remove duplicate fetch in sock_getsockopt
@ 2019-06-17  6:56 JingYi Hou
  2019-06-18 17:04 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: JingYi Hou @ 2019-06-17  6:56 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.

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.

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

diff --git a/net/core/sock.c b/net/core/sock.c
index 2b3701958486..932bcbf2d565 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -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));
-- 
2.20.1


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

* Re: [PATCH] net: remove duplicate fetch in sock_getsockopt
  2019-06-17  6:56 [PATCH] net: remove duplicate fetch in sock_getsockopt JingYi Hou
@ 2019-06-18 17:04 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2019-06-18 17:04 UTC (permalink / raw)
  To: houjingyi647; +Cc: netdev, linux-kernel

From: JingYi Hou <houjingyi647@gmail.com>
Date: Mon, 17 Jun 2019 14:56:05 +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.
> 
> 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.
> 
> Signed-off-by: JingYi Hou <houjingyi647@gmail.com>

Applied and queued up for -stable, thanks.

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-17  6:56 [PATCH] net: remove duplicate fetch in sock_getsockopt JingYi Hou
2019-06-18 17:04 ` David Miller

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org netdev@archiver.kernel.org
	public-inbox-index netdev


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/ public-inbox