diff options
author | Oleg Nesterov <oleg@redhat.com> | 2017-10-03 19:15:48 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-10-03 20:54:25 -0400 |
commit | 83f918274e4b841d6fb817861ea0c896fba0c179 (patch) | |
tree | 0dd2089b951b17b706cf1701149092cf56e75503 /fs | |
parent | baba1b29731c79d605100087b8f02f9e1cf5a344 (diff) |
exec: binfmt_misc: shift filp_close(interp_file) from kill_node() to bm_evict_inode()
To ensure that load_misc_binary() can't use the partially destroyed
Node, see also the next patch.
The current logic looks wrong in any case, once we close interp_file it
doesn't make any sense to delay kfree(inode->i_private), this Node is no
longer valid. Even if the MISC_FMT_OPEN_FILE/interp_file checks were
not racy (they are), load_misc_binary() should not try to reopen
->interpreter if MISC_FMT_OPEN_FILE is set but ->interp_file is NULL.
And I can't understand why do we use filp_close(), not fput().
Link: http://lkml.kernel.org/r/20170922143644.GA17216@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Kees Cook <keescook@chromium.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Ben Woodard <woodard@redhat.com>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Jim Foraker <foraker1@llnl.gov>
Cc: <tdhooge@llnl.gov>
Cc: Travis Gummels <tgummels@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/binfmt_misc.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c index 6451e7520e05..203598ccb40a 100644 --- a/fs/binfmt_misc.c +++ b/fs/binfmt_misc.c | |||
@@ -594,8 +594,13 @@ static struct inode *bm_get_inode(struct super_block *sb, int mode) | |||
594 | 594 | ||
595 | static void bm_evict_inode(struct inode *inode) | 595 | static void bm_evict_inode(struct inode *inode) |
596 | { | 596 | { |
597 | Node *e = inode->i_private; | ||
598 | |||
599 | if ((e->flags & MISC_FMT_OPEN_FILE) && e->interp_file) | ||
600 | filp_close(e->interp_file, NULL); | ||
601 | |||
597 | clear_inode(inode); | 602 | clear_inode(inode); |
598 | kfree(inode->i_private); | 603 | kfree(e); |
599 | } | 604 | } |
600 | 605 | ||
601 | static void kill_node(Node *e) | 606 | static void kill_node(Node *e) |
@@ -606,11 +611,6 @@ static void kill_node(Node *e) | |||
606 | list_del_init(&e->list); | 611 | list_del_init(&e->list); |
607 | write_unlock(&entries_lock); | 612 | write_unlock(&entries_lock); |
608 | 613 | ||
609 | if ((e->flags & MISC_FMT_OPEN_FILE) && e->interp_file) { | ||
610 | filp_close(e->interp_file, NULL); | ||
611 | e->interp_file = NULL; | ||
612 | } | ||
613 | |||
614 | dentry = e->dentry; | 614 | dentry = e->dentry; |
615 | drop_nlink(d_inode(dentry)); | 615 | drop_nlink(d_inode(dentry)); |
616 | d_drop(dentry); | 616 | d_drop(dentry); |