Commit Graph

12 Commits

Author SHA1 Message Date
Jeff Moyer fb1b2f09ee io_uring: enable audit and restrict cred override for IORING_OP_FIXED_FD_INSTALL
JIRA: https://issues.redhat.com/browse/RHEL-27755

commit 16bae3e1377846734ec6b87eee459c0f3551692c
Author: Paul Moore <paul@paul-moore.com>
Date:   Tue Jan 23 16:55:02 2024 -0500

    io_uring: enable audit and restrict cred override for IORING_OP_FIXED_FD_INSTALL
    
    We need to correct some aspects of the IORING_OP_FIXED_FD_INSTALL
    command to take into account the security implications of making an
    io_uring-private file descriptor generally accessible to a userspace
    task.
    
    The first change in this patch is to enable auditing of the FD_INSTALL
    operation as installing a file descriptor into a task's file descriptor
    table is a security relevant operation and something that admins/users
    may want to audit.
    
    The second change is to disable the io_uring credential override
    functionality, also known as io_uring "personalities", in the
    FD_INSTALL command.  The credential override in FD_INSTALL is
    particularly problematic as it affects the credentials used in the
    security_file_receive() LSM hook.  If a task were to request a
    credential override via REQ_F_CREDS on a FD_INSTALL operation, the LSM
    would incorrectly check to see if the overridden credentials of the
    io_uring were able to "receive" the file as opposed to the task's
    credentials.  After discussions upstream, it's difficult to imagine a
    use case where we would want to allow a credential override on a
    FD_INSTALL operation so we are simply going to block REQ_F_CREDS on
    IORING_OP_FIXED_FD_INSTALL operations.
    
    Fixes: dc18b89ab113 ("io_uring/openclose: add support for IORING_OP_FIXED_FD_INSTALL")
    Signed-off-by: Paul Moore <paul@paul-moore.com>
    Link: https://lore.kernel.org/r/20240123215501.289566-2-paul@paul-moore.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-07-02 14:33:37 -04:00
Jeff Moyer 179f7a7dba io_uring/openclose: add support for IORING_OP_FIXED_FD_INSTALL
JIRA: https://issues.redhat.com/browse/RHEL-27755
Conflicts: RHEL is missing commit 4e94ddfe2aab ("file: remove
  __receive_fd()"), which changes the calling convention of receive_fd.

commit dc18b89ab113e9c6c7a529316ddf7029fb55132d
Author: Jens Axboe <axboe@kernel.dk>
Date:   Thu Dec 7 20:06:02 2023 -0700

    io_uring/openclose: add support for IORING_OP_FIXED_FD_INSTALL
    
    io_uring can currently open/close regular files or fixed/direct
    descriptors. Or you can instantiate a fixed descriptor from a regular
    one, and then close the regular descriptor. But you currently can't turn
    a purely fixed/direct descriptor into a regular file descriptor.
    
    IORING_OP_FIXED_FD_INSTALL adds support for installing a direct
    descriptor into the normal file table, just like receiving a file
    descriptor or opening a new file would do. This is all nicely abstracted
    into receive_fd(), and hence adding support for this is truly trivial.
    
    Since direct descriptors are only usable within io_uring itself, it can
    be useful to turn them into real file descriptors if they ever need to
    be accessed via normal syscalls. This can either be a transitory thing,
    or just a permanent transition for a given direct descriptor.
    
    By default, new fds are installed with O_CLOEXEC set. The application
    can disable O_CLOEXEC by setting IORING_FIXED_FD_NO_CLOEXEC in the
    sqe->install_fd_flags member.
    
    Suggested-by: Christian Brauner <brauner@kernel.org>
    Reviewed-by: Christian Brauner <brauner@kernel.org>
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-07-02 14:33:35 -04:00
Jeff Moyer 6625cdcc16 file: remove pointless wrapper
JIRA: https://issues.redhat.com/browse/RHEL-27755
Conflicts: RHEL is missing commit ed192c59f869 ("file: mostly
eliminate spurious relocking in __range_close"), which causes some
context differences.

commit 24fa3ae9467f49dd9698fd884f2c6b13cc8ea12d
Author: Christian Brauner <brauner@kernel.org>
Date:   Thu Nov 30 13:49:08 2023 +0100

    file: remove pointless wrapper
    
    Only io_uring uses __close_fd_get_file(). All it does is hide
    current->files but io_uring accesses files_struct directly right now
    anyway so it's a bit pointless. Just rename pick_file() to
    file_close_fd_locked() and let io_uring use it. Add a lockdep assert in
    there that we expect the caller to hold file_lock while we're at it.
    
    Link: https://lore.kernel.org/r/20231130-vfs-files-fixes-v1-2-e73ca6f4ea83@kernel.org
    Reviewed-by: Jens Axboe <axboe@kernel.dk>
    Reviewed-by: Jan Kara <jack@suse.cz>
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-07-02 10:12:34 -04:00
Jeff Moyer 7cc402a020 io_uring: use files_lookup_fd_locked()
JIRA: https://issues.redhat.com/browse/RHEL-27755

commit 50d910d27362d6809a0668f0f1cb5220bc7dc6a0
Author: Christian Brauner <brauner@kernel.org>
Date:   Tue Oct 10 10:23:26 2023 +0200

    io_uring: use files_lookup_fd_locked()
    
    While valid we don't need to open-code rcu dereferences if we're
    acquiring file_lock anyway.
    
    Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
    Link: https://lore.kernel.org/r/20231010030615.GO800259@ZenIV
    Signed-off-by: Christian Brauner <brauner@kernel.org>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2024-07-02 09:52:34 -04:00
Jeff Moyer 626dd4d929 io_uring: correct check for O_TMPFILE
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 72dbde0f2afbe4af8e8595a89c650ae6b9d9c36f
Author: Aleksa Sarai <cyphar@cyphar.com>
Date:   Mon Aug 7 12:24:15 2023 +1000

    io_uring: correct check for O_TMPFILE
    
    O_TMPFILE is actually __O_TMPFILE|O_DIRECTORY. This means that the old
    check for whether RESOLVE_CACHED can be used would incorrectly think
    that O_DIRECTORY could not be used with RESOLVE_CACHED.
    
    Cc: stable@vger.kernel.org # v5.12+
    Fixes: 3a81fd0204 ("io_uring: enable LOOKUP_CACHED path resolution for filename lookups")
    Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
    Link: https://lore.kernel.org/r/20230807-resolve_cached-o_tmpfile-v3-1-e49323e1ef6f@cyphar.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:57 -04:00
Jeff Moyer da5eea0749 fsnotify: move fsnotify_open() hook into do_dentry_open()
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 7b8c9d7bb4570ee4800642009c8f2d9756004552
Author: Amir Goldstein <amir73il@gmail.com>
Date:   Sun Jun 11 15:24:29 2023 +0300

    fsnotify: move fsnotify_open() hook into do_dentry_open()
    
    fsnotify_open() hook is called only from high level system calls
    context and not called for the very many helpers to open files.
    
    This may makes sense for many of the special file open cases, but it is
    inconsistent with fsnotify_close() hook that is called for every last
    fput() of on a file object with FMODE_OPENED.
    
    As a result, it is possible to observe ACCESS, MODIFY and CLOSE events
    without ever observing an OPEN event.
    
    Fix this inconsistency by replacing all the fsnotify_open() hooks with
    a single hook inside do_dentry_open().
    
    If there are special cases that would like to opt-out of the possible
    overhead of fsnotify() call in fsnotify_open(), they would probably also
    want to avoid the overhead of fsnotify() call in the rest of the fsnotify
    hooks, so they should be opening that file with the __FMODE_NONOTIFY flag.
    
    However, in the majority of those cases, the s_fsnotify_connectors
    optimization in fsnotify_parent() would be sufficient to avoid the
    overhead of fsnotify() call anyway.
    
    Signed-off-by: Amir Goldstein <amir73il@gmail.com>
    Signed-off-by: Jan Kara <jack@suse.cz>
    Message-Id: <20230611122429.1499617-1-amir73il@gmail.com>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:54 -04:00
Jeff Moyer 8133c1b6cd io_uring: always go async for unsupported open flags
JIRA: https://issues.redhat.com/browse/RHEL-12076

commit 0ffae640ad83de46865c6b8dc3fda370823e4f1d
Author: Dylan Yudaken <dylany@meta.com>
Date:   Fri Jan 27 05:52:27 2023 -0800

    io_uring: always go async for unsupported open flags
    
    No point in issuing -> return -EAGAIN -> go async, when it can be done upfront.
    
    Signed-off-by: Dylan Yudaken <dylany@meta.com>
    Link: https://lore.kernel.org/r/20230127135227.3646353-5-dylany@meta.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-11-02 15:31:11 -04:00
Jeff Moyer 95438cbb8c io_uring: make io_kiocb_to_cmd() typesafe
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit f2ccb5aed7bce1d8b3ed5b3385759a5509663028
Author: Stefan Metzmacher <metze@samba.org>
Date:   Thu Aug 11 09:11:15 2022 +0200

    io_uring: make io_kiocb_to_cmd() typesafe
    
    We need to make sure (at build time) that struct io_cmd_data is not
    casted to a structure that's larger.
    
    Signed-off-by: Stefan Metzmacher <metze@samba.org>
    Link: https://lore.kernel.org/r/c024cdf25ae19fc0319d4180e2298bade8ed17b8.1660201408.git.metze@samba.org
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 08:43:02 -04:00
Jeff Moyer 3f0281207a io_uring: split out fixed file installation and removal
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit f110ed8498afa6ff8e9a8c08fb26880e02117616
Author: Jens Axboe <axboe@kernel.dk>
Date:   Mon Jun 13 04:42:56 2022 -0600

    io_uring: split out fixed file installation and removal
    
    Put it with the filetable code, which is where it belongs. While doing
    so, have the helpers take a ctx rather than an io_kiocb. It doesn't make
    sense to use a request, as it's not an operation on the request itself.
    It applies to the ring itself.
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 07:06:02 -04:00
Jeff Moyer 8034d812f4 io_uring: kill extra io_uring_types.h includes
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 27a9d66fec77cff0e32d2ecd5d0ac7ef878a7bb0
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Thu Jun 16 13:57:18 2022 +0100

    io_uring: kill extra io_uring_types.h includes
    
    io_uring/io_uring.h already includes io_uring_types.h, no need to
    include it every time. Kill it in a bunch of places, it prepares us for
    following patches.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/94d8c943fbe0ef949981c508ddcee7fc1c18850f.1655384063.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 06:19:02 -04:00
Jeff Moyer 35319b7b26 io_uring: move rsrc related data, core, and commands
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit 73572984481907d92673255b494c0ff4f77c8ed4
Author: Jens Axboe <axboe@kernel.dk>
Date:   Mon Jun 13 07:12:45 2022 -0600

    io_uring: move rsrc related data, core, and commands
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 05:39:02 -04:00
Jeff Moyer 83351dc041 io_uring: split out open/close operations
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2068237

commit cd40cae29ef815de6f7e72207b677c78f43f4688
Author: Jens Axboe <axboe@kernel.dk>
Date:   Tue May 24 21:54:43 2022 -0600

    io_uring: split out open/close operations
    
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
2023-04-29 05:21:02 -04:00