pipe: fix potential inode leak in create_pipe_files()
PATCH 1/1 pipe: fix potential inode leak in create_pipe_files()
In create_pipe_files(), if alloc_file_clone() fails, we will call put_pipe_info to release pipe, and call fput() to release f. However, we donot call iput() to free inode.
--- fs/pipe.c | 1 + 1 file changed, 1 insertion(+)
fs/pipe.c +1 -0
@@ -924,6 +924,7 @@ int create_pipe_files(struct file **res, int flags)if (IS_ERR (res[0 ])) {put_pipe_info (inode, inode->i_pipe);fput (f); +iput (inode);return PTR_ERR (res[0 ]); } res[0 ]->private_data = inode->i_pipe;
Signature · 1 line
2.19.1
Quoted 4 lines · Zhiqiang Liu
In
create_pipe_files(), ifalloc_file_clone()fails, we will callput_pipe_infoto release pipe, and callfput()to release f. However, we donot calliput()to free inode.
Huh? Have you actually tried to trigger that failure exit?
Quoted 11 lines
Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by Feilong Lin <[email protected]>--- fs/pipe.c | 1 + 1 file changed, 1 insertion(+)fs/pipe.c +0
-0
fs/pipe.c int create_pipe_files(struct file **res, int flags) · line 928
Quoted 5 lines
fs/pipe.c +1
-0@@ -924,6 +924,7 @@ int create_pipe_files(struct file **res, int flags)if (IS_ERR (res[0 ])) {put_pipe_info (inode, inode->i_pipe);fput (f); +iput (inode);return PTR_ERR (res[0 ]);
No. That inode is created with refcount 1. If alloc_file_pseudo() succeeds, the reference we'd been holding has been transferred into dentry allocated by alloc_file_pseudo() (and attached to f). From that point on we do *NOT* own a reference to inode and no subsequent failure exits have any business releasing it.
In particular, alloc_file_clone() DOES NOT create extra references to inode, whether it succeeds or fails. Dropping the reference to f will take care of everything.
If you tried to trigger that failure exit with your patch applied, you would've seen double iput(), as soon as you return from sys_pipe() to userland and task_work is processed (which is where the real destructor of struct file will happen).
NAK.
Quoted 35 lines · Al Viro
Quoted 4 lines · Zhiqiang Liu
In
create_pipe_files(), ifalloc_file_clone()fails, we will callput_pipe_infoto release pipe, and callfput()to release f. However, we donot calliput()to free inode.Huh? Have you actually tried to trigger that failure exit?
Quoted 11 lines
Signed-off-by Zhiqiang Liu <[email protected]>Signed-off-by Feilong Lin <[email protected]>--- fs/pipe.c | 1 + 1 file changed, 1 insertion(+)fs/pipe.c +0
-0fs/pipe.c int create_pipe_files(struct file **res, int flags) · line 928
Quoted 5 lines
fs/pipe.c +1
-0@@ -924,6 +924,7 @@ int create_pipe_files(struct file **res, int flags)if (IS_ERR (res[0 ])) {put_pipe_info (inode, inode->i_pipe);fput (f); +iput (inode);return PTR_ERR (res[0 ]);No. That inode is created with refcount 1. If
alloc_file_pseudo()succeeds, the reference we'd been holding has been transferred into dentry allocated byalloc_file_pseudo()(and attached to f).Quoted 1 line
From that point on we do *NOT* own a reference to inode and no
subsequent failure exits have any business releasing it.
In particular,
alloc_file_clone()DOES NOT create extra references to inode, whether it succeeds or fails. Dropping the reference to f will take care of everything.
Quoted 7 lines
If you tried to trigger that failure exit with your patch applied, you would've seen double
iput(), as soon as you return fromsys_pipe()to userland andtask_workis processed (which is where the real destructor of struct file will happen).NAK.
Thanks for your patient response. Learned a lot from your reply. Please ignore the patch.
Quoted 2 lines
.