Skip to content

Commit

Permalink
sys_pipe(): fix file descriptor leaks
Browse files Browse the repository at this point in the history
Remember to close the files if copy_to_user() failed.

Spotted by [email protected].

Signed-off-by: Ulrich Drepper <[email protected]>
Cc: DM <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ulrich Drepper authored and torvalds committed May 8, 2008
1 parent c1236d3 commit ba719ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion arch/cris/kernel/sys_cris.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ asmlinkage int sys_pipe(unsigned long __user * fildes)
error = do_pipe(fd);
unlock_kernel();
if (!error) {
if (copy_to_user(fildes, fd, 2*sizeof(int)))
if (copy_to_user(fildes, fd, 2*sizeof(int))) {
sys_close(fd[0]);
sys_close(fd[1]);
error = -EFAULT;
}
}
return error;
}
Expand Down
5 changes: 4 additions & 1 deletion arch/m32r/kernel/sys_m32r.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ sys_pipe(unsigned long r0, unsigned long r1, unsigned long r2,

error = do_pipe(fd);
if (!error) {
if (copy_to_user((void __user *)r0, fd, 2*sizeof(int)))
if (copy_to_user((void __user *)r0, fd, 2*sizeof(int))) {
sys_close(fd[0]);
sys_close(fd[1]);
error = -EFAULT;
}
}
return error;
}
Expand Down
6 changes: 5 additions & 1 deletion fs/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <linux/highmem.h>
#include <linux/pagemap.h>
#include <linux/audit.h>
#include <linux/syscalls.h>

#include <asm/uaccess.h>
#include <asm/ioctls.h>
Expand Down Expand Up @@ -1086,8 +1087,11 @@ asmlinkage long __weak sys_pipe(int __user *fildes)

error = do_pipe(fd);
if (!error) {
if (copy_to_user(fildes, fd, sizeof(fd)))
if (copy_to_user(fildes, fd, sizeof(fd))) {
sys_close(fd[0]);
sys_close(fd[1]);
error = -EFAULT;
}
}
return error;
}
Expand Down

0 comments on commit ba719ba

Please sign in to comment.