Skip to content

Commit db8facf

Browse files
dhowellstorvalds
authored andcommitted
watch_queue, pipe: Free watchqueue state after clearing pipe ring
In free_pipe_info(), free the watchqueue state after clearing the pipe ring as each pipe ring descriptor has a release function, and in the case of a notification message, this is watch_queue_pipe_buf_release() which tries to mark the allocation bitmap that was previously released. Fix this by moving the put of the pipe's ref on the watch queue to after the ring has been cleared. We still need to call watch_queue_clear() before doing that to make sure that the pipe is disconnected from any notification sources first. Fixes: c73be61 ("pipe: Add general notification queue support") Reported-by: Jann Horn <jannh@google.com> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent c993ee0 commit db8facf

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

fs/pipe.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,8 @@ void free_pipe_info(struct pipe_inode_info *pipe)
831831
int i;
832832

833833
#ifdef CONFIG_WATCH_QUEUE
834-
if (pipe->watch_queue) {
834+
if (pipe->watch_queue)
835835
watch_queue_clear(pipe->watch_queue);
836-
put_watch_queue(pipe->watch_queue);
837-
}
838836
#endif
839837

840838
(void) account_pipe_buffers(pipe->user, pipe->nr_accounted, 0);
@@ -844,6 +842,10 @@ void free_pipe_info(struct pipe_inode_info *pipe)
844842
if (buf->ops)
845843
pipe_buf_release(pipe, buf);
846844
}
845+
#ifdef CONFIG_WATCH_QUEUE
846+
if (pipe->watch_queue)
847+
put_watch_queue(pipe->watch_queue);
848+
#endif
847849
if (pipe->tmp_page)
848850
__free_page(pipe->tmp_page);
849851
kfree(pipe->bufs);

0 commit comments

Comments
 (0)