All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] udp: fix the len check in udp_lib_getsockopt
@ 2021-05-27 19:12 Xin Long
  2021-05-27 19:13 ` Xin Long
  0 siblings, 1 reply; 9+ messages in thread
From: Xin Long @ 2021-05-27 19:12 UTC (permalink / raw)
  To: network dev, davem, kuba; +Cc: Eric Dumazet, David Ahern, Paolo Abeni

Currently, when calling UDP's getsockopt, it only makes sure 'len'
is not less than 0, then copys 'len' bytes back to usespace while
all data is 'int' type there.

If userspace sets 'len' with a value N (N < sizeof(int)), it will
only copy N bytes of the data to userspace with no error returned,
which doesn't seem right. Like in Chen Yi's case where N is 0, it
called getsockopt and got an incorrect value but with no error
returned.

The patch is to fix the len check and make sure it's not less than
sizeof(int). Otherwise, '-EINVAL' is returned, as it does in other
protocols like SCTP/TIPC.

Reported-by: Chen Yi <yiche@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/ipv4/udp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 15f5504adf5b..90de2ac70ea9 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -2762,11 +2762,11 @@ int udp_lib_getsockopt(struct sock *sk, int level, int optname,
 	if (get_user(len, optlen))
 		return -EFAULT;
 
-	len = min_t(unsigned int, len, sizeof(int));
-
-	if (len < 0)
+	if (len < sizeof(int))
 		return -EINVAL;
 
+	len = sizeof(int);
+
 	switch (optname) {
 	case UDP_CORK:
 		val = up->corkflag;
-- 
2.27.0


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

end of thread, other threads:[~2021-05-31 10:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27 19:12 [PATCH net] udp: fix the len check in udp_lib_getsockopt Xin Long
2021-05-27 19:13 ` Xin Long
2021-05-28 22:39   ` Jakub Kicinski
2021-05-29  1:47     ` Xin Long
2021-05-29  1:57       ` David Ahern
2021-05-29 16:47         ` Xin Long
2021-05-31  1:31           ` David Ahern
2021-05-31  2:02             ` Xin Long
2021-05-31 10:13         ` David Laight

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.