Skip to content

Commit d97af30

Browse files
Dave Watsondavem330
authored andcommitted
tcp: fix null ptr deref in getsockopt(..., TCP_ULP, ...)
If icsk_ulp_ops is unset, it dereferences a null ptr. Add a null ptr check. BUG: KASAN: null-ptr-deref in copy_to_user include/linux/uaccess.h:168 [inline] BUG: KASAN: null-ptr-deref in do_tcp_getsockopt.isra.33+0x24f/0x1e30 net/ipv4/tcp.c:3057 Read of size 4 at addr 0000000000000020 by task syz-executor1/15452 Signed-off-by: Dave Watson <[email protected]> Reported-by: "Levin, Alexander (Sasha Levin)" <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 019b13a commit d97af30

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

net/ipv4/tcp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,6 +3062,11 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
30623062
if (get_user(len, optlen))
30633063
return -EFAULT;
30643064
len = min_t(unsigned int, len, TCP_ULP_NAME_MAX);
3065+
if (!icsk->icsk_ulp_ops) {
3066+
if (put_user(0, optlen))
3067+
return -EFAULT;
3068+
return 0;
3069+
}
30653070
if (put_user(len, optlen))
30663071
return -EFAULT;
30673072
if (copy_to_user(optval, icsk->icsk_ulp_ops->name, len))

0 commit comments

Comments
 (0)