Skip to content

Commit 52baf98

Browse files
thejhdavem330
authored andcommitted
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. Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f5b51fe commit 52baf98

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

net/compat.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,12 @@ static int __compat_sys_setsockopt(int fd, int level, int optname,
388388
char __user *optval, unsigned int optlen)
389389
{
390390
int err;
391-
struct socket *sock = sockfd_lookup(fd, &err);
391+
struct socket *sock;
392+
393+
if (optlen > INT_MAX)
394+
return -EINVAL;
392395

396+
sock = sockfd_lookup(fd, &err);
393397
if (sock) {
394398
err = security_socket_setsockopt(sock, level, optname);
395399
if (err) {

0 commit comments

Comments
 (0)