Skip to content

Commit be364c8

Browse files
rantaladavem330
authored andcommitted
sctp: fix memory leak in sctp_datamsg_from_user() when copy from user space fails
Trinity (the syscall fuzzer) discovered a memory leak in SCTP, reproducible e.g. with the sendto() syscall by passing invalid user space pointer in the second argument: #include <string.h> #include <arpa/inet.h> #include <sys/socket.h> int main(void) { int fd; struct sockaddr_in sa; fd = socket(AF_INET, SOCK_STREAM, 132 /*IPPROTO_SCTP*/); if (fd < 0) return 1; memset(&sa, 0, sizeof(sa)); sa.sin_family = AF_INET; sa.sin_addr.s_addr = inet_addr("127.0.0.1"); sa.sin_port = htons(11111); sendto(fd, NULL, 1, 0, (struct sockaddr *)&sa, sizeof(sa)); return 0; } As far as I can tell, the leak has been around since ~2003. Signed-off-by: Tommi Rantala <[email protected]> Acked-by: Vlad Yasevich <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b49d3c1 commit be364c8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

net/sctp/chunk.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
284284
goto errout;
285285
err = sctp_user_addto_chunk(chunk, offset, len, msgh->msg_iov);
286286
if (err < 0)
287-
goto errout;
287+
goto errout_chunk_free;
288288

289289
offset += len;
290290

@@ -324,14 +324,17 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
324324
__skb_pull(chunk->skb, (__u8 *)chunk->chunk_hdr
325325
- (__u8 *)chunk->skb->data);
326326
if (err < 0)
327-
goto errout;
327+
goto errout_chunk_free;
328328

329329
sctp_datamsg_assign(msg, chunk);
330330
list_add_tail(&chunk->frag_list, &msg->chunks);
331331
}
332332

333333
return msg;
334334

335+
errout_chunk_free:
336+
sctp_chunk_free(chunk);
337+
335338
errout:
336339
list_for_each_safe(pos, temp, &msg->chunks) {
337340
list_del_init(pos);

0 commit comments

Comments
 (0)