Skip to content

Commit

Permalink
net: socket: add check for negative optlen in compat setsockopt
Browse files Browse the repository at this point in the history
__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 <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
thejh authored and davem330 committed Feb 22, 2019
1 parent f5b51fe commit 52baf98
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion net/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 52baf98

Please sign in to comment.