]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
pipe: Fix memory leaks in create_pipe_files()
authorQian Cai <cai@redhat.com>
Thu, 1 Oct 2020 12:50:55 +0000 (08:50 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Oct 2020 09:55:55 +0000 (11:55 +0200)
commit04f31610f34fb9a8493347e9b5fe5b77e8fd90ac
tree7d254b50d33ee4b0fb9838de451a2e02ee3d7e72
parentce1dde1980792a4e383ed9be12363a2e8bbe55a5
pipe: Fix memory leaks in create_pipe_files()

[ Upstream commit 8a018eb55e3ac033592afbcb476b0ffe64465b12 ]

        Calling pipe2() with O_NOTIFICATION_PIPE could results in memory
leaks unless watch_queue_init() is successful.

        In case of watch_queue_init() failure in pipe2() we are left
with inode and pipe_inode_info instances that need to be freed.  That
failure exit has been introduced in commit c73be61cede5 ("pipe: Add
general notification queue support") and its handling should've been
identical to nearby treatment of alloc_file_pseudo() failures - it
is dealing with the same situation.  As it is, the mainline kernel
leaks in that case.

        Another problem is that CONFIG_WATCH_QUEUE and !CONFIG_WATCH_QUEUE
cases are treated differently (and the former leaks just pipe_inode_info,
the latter - both pipe_inode_info and inode).

        Fixed by providing a dummy wacth_queue_init() in !CONFIG_WATCH_QUEUE
case and by having failures of wacth_queue_init() handled the same way
we handle alloc_file_pseudo() ones.

Fixes: c73be61cede5 ("pipe: Add general notification queue support")
Signed-off-by: Qian Cai <cai@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/pipe.c
include/linux/watch_queue.h