Prevent linker issues in lapi/io_uring.h
PATCH 1/4 Prevent linker issues in lapi/io_uring.h
Fallback io_uring syscall wrappers were not defined as static inline. This will lead to linker issues when safe function variants get added to LTP library.
Also add check for <linux/io_uring.h> to configure script and #include it in the LAPI header if it's available.
Signed-off-by Martin Doucha <[email protected]>
--- configure.ac | 1 + include/lapi/io_uring.h | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-)
configure.ac +1 -0
@@ -49,6 +49,7 @@ AC_CHECK_HEADERS_ONCE([ \ linux/if_alg.h \ linux/if_ether.h \ linux/if_packet.h \ + linux/io_uring.h \ linux/keyctl.h \ linux/mempolicy.h \ linux/module.h \
include/lapi/io_uring.h +11 -6
@@ -18,6 +18,10 @@#include "lapi/syscalls.h" +#ifdef HAVE_LINUX_IO_URING_H +#include <linux/io_uring.h> +#endif +#ifndef IOSQE_FIXED_FILE #ifndef __kernel_rwf_t
@@ -260,8 +264,8 @@ struct io_uring_probe {#ifndef HAVE_IO_URING_REGISTER -int io_uring_register (int fd,unsigned int opcode,void *arg, -unsigned int nr_args) +static inline int io_uring_register (int fd,unsigned int opcode,void *arg, +unsigned int nr_args) {return tst_syscall (__NR_io_uring_register, fd, opcode, arg, nr_args); }
@@ -269,22 +273,23 @@ int io_uring_register(int fd, unsigned int opcode, void *arg,#ifndef HAVE_IO_URING_SETUP -int io_uring_setup (unsigned int entries,struct io_uring_params *p) +static inline int io_uring_setup (unsigned int entries, +struct io_uring_params *p) {return tst_syscall (__NR_io_uring_setup, entries, p); }#endif /* HAVE_IO_URING_SETUP */ #ifndef HAVE_IO_URING_ENTER -int io_uring_enter (int fd,unsigned int to_submit,unsigned int min_complete, -unsigned int flags,sigset_t *sig) +static inline int io_uring_enter (int fd,unsigned int to_submit, +unsigned int min_complete,unsigned int flags,sigset_t *sig) {return tst_syscall (__NR_io_uring_enter, fd, to_submit, min_complete, flags, sig, _NSIG /8 ); }#endif /* HAVE_IO_URING_ENTER */ -void io_uring_setup_supported_by_kernel (void ) +static inline void io_uring_setup_supported_by_kernel (void ) {if ((tst_kvercmp (5 ,1 ,0 )) <0 ) {TEST (syscall (__NR_io_uring_setup,NULL ,0 ));
Signature · 1 line
2.30.0
PATCH 2/4 Add safe functions for io_uring to LTP library
Signed-off-by Martin Doucha <[email protected]>
--- include/tst_safe_io_uring.h | 63 +++++++++++++++++++++ lib/tst_safe_io_uring.c | 108 ++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 include/tst_safe_io_uring.h create mode 100644 lib/tst_safe_io_uring.c
include/tst_safe_io_uring.h new file +63 -0
@@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (c) Linux Test Project, 2021 +*/ + +#ifndef TST_IO_URING_H__ +#define TST_IO_URING_H__ + +#include "config.h" +#include "lapi/io_uring.h" + +struct tst_io_uring { +int fd; +void *sqr_base, *cqr_base; +/* buffer sizes in bytes for unmapping */ +size_t sqr_mapsize, cqr_mapsize; + +/* Number of entries in the ring buffers */ +uint32_t sqr_size, cqr_size; + +/* Submission queue pointers */ +struct io_uring_sqe *sqr_entries; +const uint32_t *sqr_head, *sqr_mask, *sqr_flags, *sqr_dropped; +uint32_t *sqr_tail, *sqr_array; + +/* Completion queue pointers */ +const struct io_uring_cqe *cqr_entries; +const uint32_t *cqr_tail, *cqr_mask, *cqr_overflow; +uint32_t *cqr_head; + +}; + +/* +* Call io_uring_setup() with given arguments and prepare memory mappings +* into the tst_io_uring structure passed in the third argument. +*/ +#define SAFE_IO_URING_INIT (entries, params, uring) \ + safe_io_uring_init(__FILE__, __LINE__, (entries), (params), (uring)) +int safe_io_uring_init (const char *file,const int lineno, +unsigned int entries,struct io_uring_params *params, +struct tst_io_uring *uring); + +/* +* Release io_uring mappings and close the file descriptor. uring->fd will +* be set to -1 after close. +*/ +#define SAFE_IO_URING_CLOSE (uring) \ + safe_io_uring_close(__FILE__, __LINE__, (uring)) +int safe_io_uring_close (const char *file,const int lineno, +struct tst_io_uring *uring); + +/* +* Call io_uring_enter() and check for errors. The "strict" argument controls +* pedantic check whether return value is equal to "to_submit" argument. +*/ +#define SAFE_IO_URING_ENTER (strict, fd, to_submit, min_complete, flags, sig) \ + safe_io_uring_enter(__FILE__, __LINE__, (strict), (fd), (to_submit), \ + (min_complete), (flags), (sig)) +int safe_io_uring_enter (const char *file,const int lineno,int strict, +int fd,unsigned int to_submit,unsigned int min_complete, +unsigned int flags,sigset_t *sig); + +#endif /* TST_IO_URING_H__ */
lib/tst_safe_io_uring.c new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.30.0
PATCH 3/4 Add CAP_SYS_CHROOT to lapi/capability.h
In reply to Martin DouchaSigned-off-by Martin Doucha <[email protected]>
--- include/lapi/capability.h | 4 ++++ 1 file changed, 4 insertions(+)
include/lapi/capability.h +4 -0
@@ -24,6 +24,10 @@# define CAP_NET_RAW 13#endif +#ifndef CAP_SYS_CHROOT +# define CAP_SYS_CHROOT 18 +#endif +#ifndef CAP_SYS_ADMIN # define CAP_SYS_ADMIN 21#endif
Signature · 1 line
2.30.0
PATCH 4/4 Add test for CVE 2020-29373
In reply to Martin DouchaFixes #770
Signed-off-by Martin Doucha <[email protected]>
--- runtest/cve | 1 + runtest/syscalls | 1 + .../kernel/syscalls/io_uring/io_uring02.c | 197 ++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 testcases/kernel/syscalls/io_uring/io_uring02.c
runtest/cve +1 -0
@@ -60,3 +60,4 @@ cve-2019-8912 af_alg07 cve-2020-11494 pty04 cve-2020-14386 sendto03 cve-2020-14416 pty03 +cve-2020-29373 io_uring02
runtest/syscalls +1 -0
@@ -1712,3 +1712,4 @@ statx07 statx07 membarrier01 membarrier01 io_uring01 io_uring01 +io_uring02 io_uring02
testcases/kernel/syscalls/io_uring/io_uring02.c new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
2.30.0