Skip to content
  • Davide Libenzi's avatar
    anonfd: split interface into file creation and install · 562787a5
    Davide Libenzi authored
    
    
    Split the anonfd interface into a bare file pointer creation one, and a
    file pointer creation plus install one.
    
    There are cases, like the usage of eventfds inside other kernel
    interfaces, where the file pointer created by anonfd needs to be used
    inside the initialization of other structures.
    
    As it is right now, as soon as anon_inode_getfd() returns, the kenrle can
    race with userspace closing the newly installed file descriptor.
    
    This patch, while keeping the old anon_inode_getfd(), introduces a new
    anon_inode_getfile() (whose services are reused in anon_inode_getfd())
    that allows to split the file creation phase and the fd install one.
    
    Once all the kernel structures are initialized, the code can call the
    proper fd_install().
    
    Gregory manifested the need for something like this inside KVM.
    
    Signed-off-by: default avatarDavide Libenzi <davidel@xmailserver.org>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: James Morris <jmorris@namei.org>
    Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
    Cc: Gregory Haskins <ghaskins@novell.com>
    Acked-by: default avatarSerge Hallyn <serue@us.ibm.com>
    Acked-by: default avatarRoland Dreier <rolandd@cisco.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    562787a5