diff options
author | Herton R. Krzesinski <herton@redhat.com> | 2016-01-14 17:56:58 -0200 |
---|---|---|
committer | Sasha Levin <sasha.levin@oracle.com> | 2016-02-28 00:09:50 -0500 |
commit | 38bdf7e3fb81c3d9cbbacab6f96e9fd28ff6c704 (patch) | |
tree | e18bdca137a95b12698783854deff81e81f05e69 /fs | |
parent | 614f8734d11ad22ee17a5faecf355b70756904ef (diff) | |
download | lwn-38bdf7e3fb81c3d9cbbacab6f96e9fd28ff6c704.tar.gz lwn-38bdf7e3fb81c3d9cbbacab6f96e9fd28ff6c704.zip |
pty: make sure super_block is still valid in final /dev/tty close
[ Upstream commit 1f55c718c290616889c04946864a13ef30f64929 ]
Considering current pty code and multiple devpts instances, it's possible
to umount a devpts file system while a program still has /dev/tty opened
pointing to a previosuly closed pty pair in that instance. In the case all
ptmx and pts/N files are closed, umount can be done. If the program closes
/dev/tty after umount is done, devpts_kill_index will use now an invalid
super_block, which was already destroyed in the umount operation after
running ->kill_sb. This is another "use after free" type of issue, but now
related to the allocated super_block instance.
To avoid the problem (warning at ida_remove and potential crashes) for
this specific case, I added two functions in devpts which grabs additional
references to the super_block, which pty code now uses so it makes sure
the super block structure is still valid until pty shutdown is done.
I also moved the additional inode references to the same functions, which
also covered similar case with inode being freed before /dev/tty final
close/shutdown.
Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
Cc: stable@vger.kernel.org # 2.6.29+
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/devpts/inode.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index add566303c68..91360444adf5 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c @@ -569,6 +569,26 @@ void devpts_kill_index(struct inode *ptmx_inode, int idx) mutex_unlock(&allocated_ptys_lock); } +/* + * pty code needs to hold extra references in case of last /dev/tty close + */ + +void devpts_add_ref(struct inode *ptmx_inode) +{ + struct super_block *sb = pts_sb_from_inode(ptmx_inode); + + atomic_inc(&sb->s_active); + ihold(ptmx_inode); +} + +void devpts_del_ref(struct inode *ptmx_inode) +{ + struct super_block *sb = pts_sb_from_inode(ptmx_inode); + + iput(ptmx_inode); + deactivate_super(sb); +} + /** * devpts_pty_new -- create a new inode in /dev/pts/ * @ptmx_inode: inode of the master |