mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
[NET]: Fix memory leak in sys_{send,recv}msg() w/compat
From: Dave Johnson <djohnson+linux-kernel@sw.starentnetworks.com> sendmsg()/recvmsg() syscalls from o32/n32 apps to a 64bit kernel will cause a kernel memory leak if iov_len > UIO_FASTIOV for each syscall! This is because both sys_sendmsg() and verify_compat_iovec() kmalloc a new iovec structure. Only the one from sys_sendmsg() is free'ed. I wrote a simple test program to confirm this after identifying the problem: http://davej.org/programs/testsendmsg.c Note that the below fix will break solaris_sendmsg()/solaris_recvmsg() as it also calls verify_compat_iovec() but expects it to malloc internally. [ I fixed that. -DaveM ] Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
3501466941
commit
d64d387372
2 changed files with 121 additions and 85 deletions
|
@ -91,20 +91,11 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
|
|||
} else
|
||||
kern_msg->msg_name = NULL;
|
||||
|
||||
if(kern_msg->msg_iovlen > UIO_FASTIOV) {
|
||||
kern_iov = kmalloc(kern_msg->msg_iovlen * sizeof(struct iovec),
|
||||
GFP_KERNEL);
|
||||
if(!kern_iov)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
tot_len = iov_from_user_compat_to_kern(kern_iov,
|
||||
(struct compat_iovec __user *)kern_msg->msg_iov,
|
||||
kern_msg->msg_iovlen);
|
||||
if(tot_len >= 0)
|
||||
kern_msg->msg_iov = kern_iov;
|
||||
else if(kern_msg->msg_iovlen > UIO_FASTIOV)
|
||||
kfree(kern_iov);
|
||||
|
||||
return tot_len;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue