Skip to contentSkip to conversation

net: socket: add check for negative optlen in compat setsockopt

PATCH In review Jann Horn 2 participants 2 messages Feb 20, 2019 – Feb 22, 2019

Subsystems (2)
lore
Share & tools
lore

Jann Horn

author
#0 lore raw

PATCH 1/1 net: socket: add check for negative optlen in compat setsockopt

__sys_setsockopt() already checks for optlen < 0. Add an equivalent check to the compat path for robustness. This has to be > INT_MAX instead of < 0 because the signedness of optlen is different here.

---
 net/compat.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/compat.c +5 -1
index 959d1c51826d..3d348198004f 100644
@@ -388,8 +388,12 @@ static int __compat_sys_setsockopt(int fd, int level, int optname,
 				   char __user *optval, unsigned int optlen)
 {
 	int err;
-	struct socket *sock = sockfd_lookup(fd, &err);
+	struct socket *sock;
+
+	if (optlen > INT_MAX)
+		return -EINVAL;
 
+	sock = sockfd_lookup(fd, &err);
 	if (sock) {
 		err = security_socket_setsockopt(sock, level, optname);
 		if (err) {
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
maintainer
#1 lore raw

From: Jann Horn <[email protected]>
Date: Wed, 20 Feb 2019 22:34:54 +0100

Quoted 5 lines

__sys_setsockopt() already checks for optlen < 0. Add an equivalent check to the compat path for robustness. This has to be > INT_MAX instead of < 0 because the signedness of optlen is different here.

Applied and queued up for -stable, thanks Jann.