Skip to content

Commit 20a3d5b

Browse files
j00rudavem330
authored andcommitted
caif: Add sockaddr length check before accessing sa_family in connect handler
Verify that the caller-provided sockaddr structure is large enough to contain the sa_family field, before accessing it in the connect() handler of the AF_CAIF socket. Since the syscall doesn't enforce a minimum size of the corresponding memory region, very short sockaddrs (zero or one byte long) result in operating on uninitialized memory while referencing sa_family. Signed-off-by: Mateusz Jurczyk <mjurczyk@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7de8440 commit 20a3d5b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/caif/caif_socket.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,10 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
754754

755755
lock_sock(sk);
756756

757+
err = -EINVAL;
758+
if (addr_len < offsetofend(struct sockaddr, sa_family))
759+
goto out;
760+
757761
err = -EAFNOSUPPORT;
758762
if (uaddr->sa_family != AF_CAIF)
759763
goto out;

0 commit comments

Comments
 (0)