Skip to content

Commit cacc062

Browse files
marceloleitnerdavem330
authored andcommitted
sctp: use GFP_USER for user-controlled kmalloc
Dmitry Vyukov reported that the user could trigger a kernel warning by using a large len value for getsockopt SCTP_GET_LOCAL_ADDRS, as that value directly affects the value used as a kmalloc() parameter. This patch thus switches the allocation flags from all user-controllable kmalloc size to GFP_USER to put some more restrictions on it and also disables the warn, as they are not necessary. Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 38ee8fb commit cacc062

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

net/sctp/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ static int sctp_setsockopt_bindx(struct sock *sk,
972972
return -EFAULT;
973973

974974
/* Alloc space for the address array in kernel memory. */
975-
kaddrs = kmalloc(addrs_size, GFP_KERNEL);
975+
kaddrs = kmalloc(addrs_size, GFP_USER | __GFP_NOWARN);
976976
if (unlikely(!kaddrs))
977977
return -ENOMEM;
978978

@@ -4928,7 +4928,7 @@ static int sctp_getsockopt_local_addrs(struct sock *sk, int len,
49284928
to = optval + offsetof(struct sctp_getaddrs, addrs);
49294929
space_left = len - offsetof(struct sctp_getaddrs, addrs);
49304930

4931-
addrs = kmalloc(space_left, GFP_KERNEL);
4931+
addrs = kmalloc(space_left, GFP_USER | __GFP_NOWARN);
49324932
if (!addrs)
49334933
return -ENOMEM;
49344934

0 commit comments

Comments
 (0)