pipe_rdwr_fasync: fix the error handling to prevent the leak/crash
PATCH 1/1 pipe_rdwr_fasync: fix the error handling to prevent the leak/crash
If the second fasync_helper() fails, pipe_rdwr_fasync() returns the error but leaves the file on ->fasync_readers.
This was always wrong, but since 233e70f4228e78eb2f80dc6650f65d3ae3dbf17c "saner FASYNC handling on file close" we have the new problem. Because in this case setfl() doesn't set FASYNC bit, __fput() will not do ->fasync(0), and we leak fasync_struct with ->fa_file pointing to the freed file.
Signed-off-by Oleg Nesterov <[email protected]>
fs/pipe.c renamed from fs/pipe.c~PIPE_FASYNC +4 -3
@@ -699,12 +699,13 @@ pipe_rdwr_fasync(int fd, struct file *fiint retval;mutex_lock (&inode->i_mutex); - retval =fasync_helper (fd, filp, on, &pipe->fasync_readers); -if (retval >=0 ) +if (retval >=0 ) { retval =fasync_helper (fd, filp, on, &pipe->fasync_writers); - +if (retval <0 )/* this can happen only if on == T */ +fasync_helper (-1 , filp,0 , &pipe->fasync_readers); + }mutex_unlock (&inode->i_mutex);if (retval <0 )