let import_iovec deal with compat_iovecs as well
Subsystems (25)
Hi Al,
this series changes import_iovec to transparently deal with comat iovec structures, and then cleanups up a lot of code dupliation. But to get there it first has to fix the pre-existing bug that io_uring compat contexts don't trigger the in_compat_syscall() check. This has so far been relatively harmless as very little code callable from io_uring used the check, and even that code that could be called usually wasn't.
Diffstat
arch/arm64/include/asm/unistd32.h | 10 arch/mips/kernel/syscalls/syscall_n32.tbl | 10 arch/mips/kernel/syscalls/syscall_o32.tbl | 10 arch/parisc/kernel/syscalls/syscall.tbl | 10 arch/powerpc/kernel/syscalls/syscall.tbl | 10 arch/s390/kernel/syscalls/syscall.tbl | 10 arch/sparc/include/asm/compat.h | 3 arch/sparc/kernel/syscalls/syscall.tbl | 10 arch/x86/entry/syscall_x32.c | 5 arch/x86/entry/syscalls/syscall_32.tbl | 10 arch/x86/entry/syscalls/syscall_64.tbl | 10 arch/x86/include/asm/compat.h | 2 block/scsi_ioctl.c | 12 drivers/scsi/sg.c | 9 fs/aio.c | 38 -- fs/io_uring.c | 21 - fs/read_write.c | 307 ++++----------------- fs/splice.c | 57 --- include/linux/compat.h | 29 - include/linux/fs.h | 7 include/linux/sched.h | 1 include/linux/uio.h | 7 include/uapi/asm-generic/unistd.h | 12 lib/iov_iter.c | 30 -- mm/process_vm_access.c | 69 ---- net/compat.c | 4 security/keys/compat.c | 37 -- security/keys/internal.h | 5 security/keys/keyctl.c | 2 tools/include/uapi/asm-generic/unistd.h | 12 tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 10 tools/perf/arch/s390/entry/syscalls/syscall.tbl | 10 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 10 33 files changed, 207 insertions(+), 582 deletions(-)
PATCH 1/9 kernel: add a PF_FORCE_COMPAT flag
Add a flag to force processing a syscall as a compat syscall. This is required so that in_compat_syscall() works for I/O submitted by io_uring helper threads on behalf of compat syscalls.
--- arch/sparc/include/asm/compat.h | 3 ++- arch/x86/include/asm/compat.h | 2 +- fs/io_uring.c | 9 +++++++++ include/linux/compat.h | 5 ++++- include/linux/sched.h | 1 + 5 files changed, 17 insertions(+), 3 deletions(-)
arch/sparc/include/asm/compat.h +2 -1
@@ -211,7 +211,8 @@ static inline int is_compat_task(void)static inline bool in_compat_syscall (void ) {/* Vector 0x110 is LINUX_32BIT_SYSCALL_TRAP */ -return pt_regs_trap_type (current_pt_regs ()) =0x110 ; +return pt_regs_trap_type (current_pt_regs ()) =0x110 || + (current->flags &PF_FORCE_COMPAT ); }#define in_compat_syscall in_compat_syscall#endif
arch/x86/include/asm/compat.h +1 -1
@@ -208,7 +208,7 @@ static inline bool in_32bit_syscall(void)#ifdef CONFIG_COMPAT static inline bool in_compat_syscall (void ) { -return in_32bit_syscall (); +return in_32bit_syscall () || (current->flags &PF_FORCE_COMPAT ); }#define in_compat_syscall in_compat_syscall/* override the generic impl */ #endif
fs/io_uring.c +9 -0
@@ -5449,6 +5449,9 @@ static int io_req_defer_prep(struct io_kiocb *req,if (unlikely (ret))return ret; +if (req->ctx->compat) + current->flags |=PF_FORCE_COMPAT ; +switch (req->opcode) {case IORING_OP_NOP :break ;
@@ -5546,6 +5549,7 @@ static int io_req_defer_prep(struct io_kiocb *req,break ; } + current->flags &= ~PF_FORCE_COMPAT ;return ret; }
@@ -5669,6 +5673,9 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,struct io_ring_ctx *ctx = req->ctx;int ret; +if (ctx->compat) + current->flags |=PF_FORCE_COMPAT ; +switch (req->opcode) {case IORING_OP_NOP : ret =io_nop (req, cs);
@@ -5898,6 +5905,8 @@ static int io_issue_sqe(struct io_kiocb *req, const struct io_uring_sqe *sqe,break ; } + current->flags &= ~PF_FORCE_COMPAT ; +if (ret)return ret;
include/linux/compat.h +4 -1
@@ -891,7 +891,10 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args);*/ #ifndef in_compat_syscall -static inline bool in_compat_syscall (void ) {return is_compat_task (); } +static inline bool in_compat_syscall (void ) +{ +return is_compat_task () || (current->flags &PF_FORCE_COMPAT ); +}#endif /**
include/linux/sched.h +1 -0
@@ -1491,6 +1491,7 @@ extern struct pid *cad_pid;*/ #define PF_IDLE 0x00000002/* I am an IDLE thread */ #define PF_EXITING 0x00000004/* Getting shut down */ +#define PF_FORCE_COMPAT 0x00000008/* acting as compat task */ #define PF_VCPU 0x00000010/* I'm a virtual CPU */ #define PF_WQ_WORKER 0x00000020/* I'm a workqueue worker */ #define PF_FORKNOEXEC 0x00000040/* Forked but didn't exec */
Signature · 1 line
2.28.0
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 18 lines · Christoph Hellwig
Add a flag to force processing a syscall as a compat syscall. This is required so that
in_compat_syscall()works for I/O submitted byio_uringhelper threads on behalf of compat syscalls.Signed-off-by Christoph Hellwig <[email protected]>--- arch/sparc/include/asm/compat.h | 3 ++- arch/x86/include/asm/compat.h | 2 +- fs/io_uring.c | 9 +++++++++ include/linux/compat.h | 5 ++++- include/linux/sched.h | 1 + 5 files changed, 17 insertions(+), 3 deletions(-)arch/sparc/include/asm/compat.h +0
-0
arch/sparc/include/asm/compat.h static inline int is_compat_task(void) · line 215
Quoted 6 lines
arch/sparc/include/asm/compat.h +2
-1@@ -211,7 +211,8 @@ static inline int is_compat_task(void)static inline bool in_compat_syscall (void ) {/* Vector 0x110 is LINUX_32BIT_SYSCALL_TRAP */ -return pt_regs_trap_type (current_pt_regs ()) =0x110 ; +return pt_regs_trap_type (current_pt_regs ()) =0x110 || + (current->flags &PF_FORCE_COMPAT );
Can't say I like that approach ;-/ Reasoning about the behaviour is much harder when it's controlled like that - witness set_fs() shite...
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 7 lines · Al Viro
arch/sparc/include/asm/compat.h static inline int is_compat_task(void) · line 215
Quoted 4 lines
arch/sparc/include/asm/compat.h +2
-1/* Vector 0x110 is LINUX_32BIT_SYSCALL_TRAP */ -return pt_regs_trap_type (current_pt_regs ()) =0x110 ; +return pt_regs_trap_type (current_pt_regs ()) =0x110 || + (current->flags &PF_FORCE_COMPAT );Can't say I like that approach ;-/ Reasoning about the behaviour is much harder when it's controlled like that - witness
set_fs()shite...
I don't particularly like it either. But do you have a better idea how to deal with io_uring vs compat tasks?
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 11 lines · Christoph Hellwig
Quoted 7 lines · Al Viro
arch/sparc/include/asm/compat.h static inline int is_compat_task(void) · line 215
Quoted 4 lines
arch/sparc/include/asm/compat.h +2
-1/* Vector 0x110 is LINUX_32BIT_SYSCALL_TRAP */ -return pt_regs_trap_type (current_pt_regs ()) =0x110 ; +return pt_regs_trap_type (current_pt_regs ()) =0x110 || + (current->flags &PF_FORCE_COMPAT );Can't say I like that approach ;-/ Reasoning about the behaviour is much harder when it's controlled like that - witness
set_fs()shite...I don't particularly like it either. But do you have a better idea how to deal with
io_uringvs compat tasks?
<wry> git rm fs/io_uring.c would make a good starting point </wry> Yes, I know it's not going to happen, but one can dream...
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass in_compat_syscall() to that...
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...
That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when io_uring is used to access read or write methods that use in_compat_syscall(). One example that I recently ran into is drivers/scsi/sg.c.
Andy Lutomirski
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.
Aside from the potentially nasty use of per-task variables, one thing I don't like about PF_FORCE_COMPAT is that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?
Arnd Bergmann
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 10 lines · Andy Lutomirski
Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.
Ah, so reading /dev/input/event* would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to use io_uring to read /dev/input/event on x32...
For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?
The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
Arnd
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 26 lines · Arnd Bergmann
Quoted 10 lines · Andy Lutomirski
Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.Ah, so reading
/dev/input/event*would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to useio_uringto read/dev/input/eventon x32...For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?
Quoted 4 lines
The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
Quite possibly. The ext4 vs. compat getdents bug is still unresolved. Please see,
https://lore.kernel.org/lkml/CAFEAcA9W+JK7_TrtTnL1P2ES1knNPJX9wcUvhfLwxLq9augq1w@mail.gmail.com/
Quoted 2 lines
Arnd
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Arnd BergmannQuoted 29 lines · Arnd Bergmann
Quoted 10 lines · Andy Lutomirski
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.Ah, so reading
/dev/input/event*would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to useio_uringto read/dev/input/eventon x32...For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?
Quoted 4 lines
The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
I can certainly imagine needing to force x32 mode from a kernel thread.
As for the other direction: what exactly are the desired bitness/arch semantics of io_uring? Is the operation bitness chosen by the io_uring creation or by the io_uring_enter() bitness?
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 29 lines · Andy Lutomirski
Quoted 29 lines · Arnd Bergmann
Quoted 10 lines · Andy Lutomirski
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.Ah, so reading
/dev/input/event*would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to useio_uringto read/dev/input/eventon x32...For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?
Quoted 8 lines
Quoted 4 lines
The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
I can certainly imagine needing to force x32 mode from a kernel thread.
As for the other direction: what exactly are the desired bitness/arch semantics of
io_uring? Is the operation bitness chosen by theio_uringcreation or by theio_uring_enter()bitness?
It's rather the second one. Even though AFAIR it wasn't discussed specifically, that how it works now (_partially_).
Signature · 1 line
Pavel Begunkov
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 35 lines · Pavel Begunkov
Quoted 34 lines · Andy Lutomirski
Quoted 33 lines · Arnd Bergmann
Quoted 10 lines · Andy Lutomirski
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.Ah, so reading
/dev/input/event*would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to useio_uringto read/dev/input/eventon x32...For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
Quoted 6 lines
Quoted 3 lines
I can certainly imagine needing to force x32 mode from a kernel thread.
As for the other direction: what exactly are the desired bitness/arch semantics of
io_uring? Is the operation bitness chosen by theio_uringcreation or by theio_uring_enter()bitness?It's rather the second one. Even though AFAIR it wasn't discussed specifically, that how it works now (_partially_).
Double checked -- I'm wrong, that's the former one. Most of it is based on a flag that was set an creation.
Signature · 1 line
Pavel Begunkov
Andy Lutomirski
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 39 lines · Pavel Begunkov
Quoted 37 lines · Pavel Begunkov
Quoted 36 lines · Andy Lutomirski
Quoted 29 lines · Arnd Bergmann
Quoted 10 lines · Andy Lutomirski
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.Ah, so reading
/dev/input/event*would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to useio_uringto read/dev/input/eventon x32...For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?Quoted 4 lines
The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
I can certainly imagine needing to force x32 mode from a kernel thread.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
As for the other direction: what exactly are the desired bitness/arch semantics of
io_uring? Is the operation bitness chosen by theio_uringcreation or by theio_uring_enter()bitness?It's rather the second one. Even though AFAIR it wasn't discussed specifically, that how it works now (_partially_).
Double checked -- I'm wrong, that's the former one. Most of it is based on a flag that was set an creation.
Could we get away with making io_uring_enter() return -EINVAL (or maybe -ENOTTY?) if you try to do it with bitness that doesn't match the io_uring? And disable SQPOLL in compat mode?
--Andy
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 45 lines · Andy Lutomirski
Quoted 44 lines · Pavel Begunkov
Quoted 41 lines · Pavel Begunkov
Quoted 29 lines · Andy Lutomirski
Quoted 29 lines · Arnd Bergmann
Quoted 10 lines · Andy Lutomirski
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.Ah, so reading
/dev/input/event*would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to useio_uringto read/dev/input/eventon x32...For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?Quoted 8 lines
Quoted 4 lines
The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
I can certainly imagine needing to force x32 mode from a kernel thread.
As for the other direction: what exactly are the desired bitness/arch semantics of
io_uring? Is the operation bitness chosen by theio_uringcreation or by theio_uring_enter()bitness?It's rather the second one. Even though AFAIR it wasn't discussed specifically, that how it works now (_partially_).
Quoted 7 lines
Quoted 3 lines
Double checked -- I'm wrong, that's the former one. Most of it is based on a flag that was set an creation.
Could we get away with making
io_uring_enter()return-EINVAL(or maybe-ENOTTY?) if you try to do it with bitness that doesn't match theio_uring? And disable SQPOLL in compat mode?
Something like below. If PF_FORCE_COMPAT or any other solution doesn't lend by the time, I'll take a look whether other io_uring's syscalls need similar checks, etc.
fs/io_uring.c +8 -0
@@ -8671,6 +8671,10 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,if (ctx->flags &IORING_SETUP_R_DISABLED ) goto out; + ret = -EINVAl; +if (ctx->compat !=in_compat_syscall ()) + goto out; +/* * For SQ polling, the thread will do all submissions and completions. * Just return the requested submit count, and wake the thread if
@@ -9006,6 +9010,10 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,if (ret) goto err; + ret = -EINVAL ; +if (ctx->compat) + goto err; +/* Only gets the ring fd, doesn't install it in the file table */ fd =io_uring_get_fd (ctx, &file);if (fd <0 ) {
Signature · 1 line
Pavel Begunkov
Andy Lutomirski
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 67 lines · Pavel Begunkov
Quoted 45 lines · Andy Lutomirski
Quoted 44 lines · Pavel Begunkov
Quoted 41 lines · Pavel Begunkov
Quoted 29 lines · Andy Lutomirski
Quoted 29 lines · Arnd Bergmann
Quoted 10 lines · Andy Lutomirski
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.Ah, so reading
/dev/input/event*would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to useio_uringto read/dev/input/eventon x32...For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?Quoted 8 lines
Quoted 4 lines
The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
I can certainly imagine needing to force x32 mode from a kernel thread.
As for the other direction: what exactly are the desired bitness/arch semantics of
io_uring? Is the operation bitness chosen by theio_uringcreation or by theio_uring_enter()bitness?It's rather the second one. Even though AFAIR it wasn't discussed specifically, that how it works now (_partially_).
Quoted 7 lines
Quoted 3 lines
Double checked -- I'm wrong, that's the former one. Most of it is based on a flag that was set an creation.
Could we get away with making
io_uring_enter()return-EINVAL(or maybe-ENOTTY?) if you try to do it with bitness that doesn't match theio_uring? And disable SQPOLL in compat mode?Something like below. If
PF_FORCE_COMPATor any other solution doesn't lend by the time, I'll take a look whether other io_uring's syscalls need similar checks, etc.fs/io_uring.c +0
-0
fs/io_uring.c SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, · line 8677
Quoted 7 lines
fs/io_uring.c +4
-0@@ -8671,6 +8671,10 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,if (ctx->flags &IORING_SETUP_R_DISABLED ) goto out; + ret = -EINVAl; +if (ctx->compat !=in_compat_syscall ()) + goto out; +
This seems entirely reasonable to me. Sharing an io_uring ring between programs with different ABIs seems a bit nutty.
fs/io_uring.c static int io_uring_create(unsigned entries, struct io_uring_params *p, · line 9016
Quoted 11 lines
fs/io_uring.c +4
-0/* * For SQ polling, the thread will do all submissions and completions. * Just return the requested submit count, and wake the thread if @@ -9006,6 +9010,10 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,if (ret) goto err; + ret = -EINVAL ; +if (ctx->compat) + goto err; +
I may be looking at a different kernel than you, but aren't you preventing creating an io_uring regardless of whether SQPOLL is requested?
Quoted 5 lines
fs/io_uring.c +0
-1/* Only gets the ring fd, doesn't install it in the file table */ fd =io_uring_get_fd (ctx, &file);if (fd <0 ) { --Pavel Begunkov
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 63 lines · Andy Lutomirski
Quoted 44 lines · Pavel Begunkov
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
Ah, so reading
/dev/input/event*would suffer from the same issue, and that one would in fact be broken by your patch in the hypothetical case that someone tried to useio_uringto read/dev/input/eventon x32...For reference, I checked the socket timestamp handling that has a number of corner cases with time32/time64 formats in compat mode, but none of those appear to be affected by the problem.
Quoted 5 lines
Aside from the potentially nasty use of per-task variables, one thing I don't like about
PF_FORCE_COMPATis that it's one-way. If we're going to have a generic mechanism for this, shouldn't we allow a full override of the syscall arch instead of just allowing forcing compat so that a compat syscall can do a non-compat operation?Quoted 8 lines
Quoted 4 lines
The only reason it's needed here is that the caller is in a kernel thread rather than a system call. Are there any possible scenarios where one would actually need the opposite?
I can certainly imagine needing to force x32 mode from a kernel thread.
As for the other direction: what exactly are the desired bitness/arch semantics of
io_uring? Is the operation bitness chosen by theio_uringcreation or by theio_uring_enter()bitness?It's rather the second one. Even though AFAIR it wasn't discussed specifically, that how it works now (_partially_).
Quoted 7 lines
Quoted 3 lines
Double checked -- I'm wrong, that's the former one. Most of it is based on a flag that was set an creation.
Could we get away with making
io_uring_enter()return-EINVAL(or maybe-ENOTTY?) if you try to do it with bitness that doesn't match theio_uring? And disable SQPOLL in compat mode?Something like below. If
PF_FORCE_COMPATor any other solution doesn't lend by the time, I'll take a look whether other io_uring's syscalls need similar checks, etc.fs/io_uring.c +0
-0fs/io_uring.c SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit, · line 8677
Quoted 7 lines
fs/io_uring.c +4
-0@@ -8671,6 +8671,10 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,if (ctx->flags &IORING_SETUP_R_DISABLED ) goto out; + ret = -EINVAl; +if (ctx->compat !=in_compat_syscall ()) + goto out; +This seems entirely reasonable to me. Sharing an
io_uringring between programs with different ABIs seems a bit nutty.Quoted 7 lines
fs/io_uring.c +0
-0/* * For SQ polling, the thread will do all submissions and completions. * Just return the requested submit count, and wake the thread if @@ -9006,6 +9010,10 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p,if (ret) goto err;
Quoted 8 lines
fs/io_uring.c static int io_uring_create(unsigned entries, struct io_uring_params *p, · line 9016
Quoted 4 lines
fs/io_uring.c +4
-0+ ret = -EINVAL ; +if (ctx->compat) + goto err; +I may be looking at a different kernel than you, but aren't you preventing creating an
io_uringregardless of whether SQPOLL is requested?
I diffed a not-saved file on a sleepy head, thanks for noticing. As you said, there should be an SQPOLL check.
...
if (ctx->compat && (p->flags & IORING_SETUP_SQPOLL))
goto err;
Signature · 1 line
Pavel Begunkov
Arnd Bergmann
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 6 lines · Pavel Begunkov
Quoted 4 lines · Andy Lutomirski
On Mon, Sep 21, 2020 at 5:24 PM Pavel Begunkov <[email protected]> wrote:
I may be looking at a different kernel than you, but aren't you preventing creating anio_uringregardless of whether SQPOLL is requested?
Quoted 6 lines
I diffed a not-saved file on a sleepy head, thanks for noticing. As you said, there should be an SQPOLL check.
...
if (ctx->compat&& (p->flags&IORING_SETUP_SQPOLL))goto err;
Wouldn't that mean that now 32-bit containers behave differently between compat and native execution?
I think if you want to prevent 32-bit applications from using SQPOLL, it needs to be done the same way on both to be consistent:
if ((!IS_ENABLED(CONFIG_64BIT) || ctx->compat) &&
(p->flags & IORING_SETUP_SQPOLL))
goto err;I don't really see how taking away SQPOLL from 32-bit tasks is any better than just preventing access to the known-broken files as Al suggested, or adding the hack to make it work as in Christoph's original patch.
Can we expect all existing and future user space to have a sane fallback when IORING_SETUP_SQPOLL fails?
Arnd
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 14 lines · Arnd Bergmann
Quoted 6 lines · Pavel Begunkov
Quoted 4 lines · Andy Lutomirski
On Mon, Sep 21, 2020 at 5:24 PM Pavel Begunkov <[email protected]> wrote:
I may be looking at a different kernel than you, but aren't you preventing creating anio_uringregardless of whether SQPOLL is requested?Quoted 6 lines
I diffed a not-saved file on a sleepy head, thanks for noticing. As you said, there should be an SQPOLL check.
...
if (ctx->compat&& (p->flags&IORING_SETUP_SQPOLL))goto err;
Quoted 5 lines
Wouldn't that mean that now 32-bit containers behave differently between compat and native execution?
I think if you want to prevent 32-bit applications from using SQPOLL, it needs to be done the same way on both to be consistent:
The intention was to disable only compat not native 32-bit.
Quoted 9 lines
if ((!IS_ENABLED(CONFIG_64BIT) || ctx->compat) && (p->flags & IORING_SETUP_SQPOLL)) goto err;I don't really see how taking away SQPOLL from 32-bit tasks is any better than just preventing access to the known-broken files as Al suggested, or adding the hack to make it work as in Christoph's original patch.
That's why I'm hoping that Christoph's work and the discussion will reach consensus, but the bug should be patched in the end. IMHO, it's a good and easy enough fallback option (temporal?).
Quoted 3 lines
Can we expect all existing and future user space to have a sane fallback when
IORING_SETUP_SQPOLLfails?
SQPOLL has a few differences with non-SQPOLL modes, but it's easy to convert between them. Anyway, SQPOLL is a privileged special case that's here for performance/latency reasons, I don't think there will be any non-accidental users of it.
Signature · 1 line
Pavel Begunkov
Arnd Bergmann
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 15 lines · Pavel Begunkov
Quoted 14 lines · Arnd Bergmann
Quoted 12 lines · Pavel Begunkov
Quoted 4 lines · Andy Lutomirski
On Mon, Sep 21, 2020 at 5:24 PM Pavel Begunkov <[email protected]> wrote:
I may be looking at a different kernel than you, but aren't you preventing creating anio_uringregardless of whether SQPOLL is requested?I diffed a not-saved file on a sleepy head, thanks for noticing. As you said, there should be an SQPOLL check.
...
if (ctx->compat&& (p->flags&IORING_SETUP_SQPOLL))goto err;
Quoted 7 lines
Quoted 5 lines
Wouldn't that mean that now 32-bit containers behave differently between compat and native execution?
I think if you want to prevent 32-bit applications from using SQPOLL, it needs to be done the same way on both to be consistent:
The intention was to disable only compat not native 32-bit.
I'm not following why that would be considered a valid option, as that clearly breaks existing users that update from a 32-bit kernel to a 64-bit one.
Taking away the features from users that are still on 32-bit kernels already seems questionable to me, but being inconsistent about it seems much worse, in particular when the regression is on the upgrade path.
Quoted 7 lines
Quoted 2 lines
Can we expect all existing and future user space to have a sane fallback when
IORING_SETUP_SQPOLLfails?SQPOLL has a few differences with non-SQPOLL modes, but it's easy to convert between them. Anyway, SQPOLL is a privileged special case that's here for performance/latency reasons, I don't think there will be any non-accidental users of it.
Ok, so the behavior of 32-bit tasks would be the same as running the same application as unprivileged 64-bit tasks, with applications already having to implement that fallback, right?
Arnd
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 40 lines · Arnd Bergmann
Quoted 15 lines · Pavel Begunkov
Quoted 15 lines · Arnd Bergmann
Quoted 12 lines · Pavel Begunkov
Quoted 4 lines · Andy Lutomirski
On Mon, Sep 21, 2020 at 5:24 PM Pavel Begunkov <[email protected]> wrote:
I may be looking at a different kernel than you, but aren't you preventing creating anio_uringregardless of whether SQPOLL is requested?I diffed a not-saved file on a sleepy head, thanks for noticing. As you said, there should be an SQPOLL check.
...
if (ctx->compat&& (p->flags&IORING_SETUP_SQPOLL))goto err;Quoted 7 lines
Quoted 5 lines
Wouldn't that mean that now 32-bit containers behave differently between compat and native execution?
I think if you want to prevent 32-bit applications from using SQPOLL, it needs to be done the same way on both to be consistent:
The intention was to disable only compat not native 32-bit.
I'm not following why that would be considered a valid option, as that clearly breaks existing users that update from a 32-bit kernel to a 64-bit one.
Taking away the features from users that are still on 32-bit kernels already seems questionable to me, but being inconsistent about it seems much worse, in particular when the regression is on the upgrade path.
Quoted 3 lines
Quoted 2 lines
Can we expect all existing and future user space to have a sane fallback when
IORING_SETUP_SQPOLLfails?
Quoted 10 lines
Quoted 4 lines
SQPOLL has a few differences with non-SQPOLL modes, but it's easy to convert between them. Anyway, SQPOLL is a privileged special case that's here for performance/latency reasons, I don't think there will be any non-accidental users of it.
Ok, so the behavior of 32-bit tasks would be the same as running the same application as unprivileged 64-bit tasks, with applications already having to implement that fallback, right?
I don’t have any real preference wrt SQPOLL, and it may be that we have a problem even without SQPOLL when IO gets punted without one of the fixes discussed.
But banning the mismatched io_uring and io_uring_enter seems like it may be worthwhile regardless.
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Arnd BergmannQuoted 19 lines · Arnd Bergmann
Quoted 18 lines · Pavel Begunkov
Quoted 17 lines · Arnd Bergmann
Quoted 6 lines · Pavel Begunkov
Quoted 4 lines · Andy Lutomirski
On Mon, Sep 21, 2020 at 5:24 PM Pavel Begunkov <[email protected]> wrote:
I may be looking at a different kernel than you, but aren't you preventing creating anio_uringregardless of whether SQPOLL is requested?Quoted 6 lines
I diffed a not-saved file on a sleepy head, thanks for noticing. As you said, there should be an SQPOLL check.
...
if (ctx->compat&& (p->flags&IORING_SETUP_SQPOLL))goto err;Wouldn't that mean that now 32-bit containers behave differently between compat and native execution?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I think if you want to prevent 32-bit applications from using SQPOLL, it needs to be done the same way on both to be consistent:
The intention was to disable only compat not native 32-bit.
I'm not following why that would be considered a valid option, as that clearly breaks existing users that update from a 32-bit kernel to a 64-bit one.
Do you mean users who move 32-bit binaries (without recompiling) to a new x64 kernel? Does the kernel guarantees that to work? I'd personally care more native-bitness apps.
Quoted 5 lines
Taking away the features from users that are still on 32-bit kernels already seems questionable to me, but being inconsistent about it seems much worse, in particular when the regression is on the upgrade path.
TBH, this won't fix that entirely (e.g. passing non-compat io_uring to a compat process should yield the same problem). So, let's put it aside for now until this bikeshedding would be relevant.
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
Can we expect all existing and future user space to have a sane fallback when
IORING_SETUP_SQPOLLfails?SQPOLL has a few differences with non-SQPOLL modes, but it's easy to convert between them. Anyway, SQPOLL is a privileged special case that's here for performance/latency reasons, I don't think there will be any non-accidental users of it.
Ok, so the behavior of 32-bit tasks would be the same as running the same application as unprivileged 64-bit tasks, with applications
Yes, something like that, but that's not automatic and in some (hopefully rare) cases there may be pitfalls. That's in short, I can expand the idea a bit if anyone would be interested.
Quoted 1 line
already having to implement that fallback, right?
Well, not everyone _have_ to implement such a fallback, e.g. applications working only whilst privileged may use SQPOLL only.
Signature · 1 line
Pavel Begunkov
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 6 lines · Pavel Begunkov
Quoted 3 lines
I'm not following why that would be considered a valid option, as that clearly breaks existing users that update from a 32-bit kernel to a 64-bit one.
Do you mean users who move 32-bit binaries (without recompiling) to a new x64 kernel? Does the kernel guarantees that to work?
Yes.
No further (printable) comments for now...
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Christoph HellwigQuoted 9 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.
So screw such read/write methods - don't use them with io_uring. That, BTW, is one of the reasons I'm sceptical about burying the decisions deep into the callchain - we don't _want_ different data layouts on read/write depending upon the 32bit vs. 64bit caller, let alone the pointer-chasing garbage that is /dev/sg.
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 14 lines · Al Viro
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.
Quoted 5 lines
So screw such read/write methods - don't use them with
io_uring. That, BTW, is one of the reasons I'm sceptical about burying the decisions deep into the callchain - we don't _want_ different data layouts on read/write depending upon the 32bit vs. 64bit caller, let alone the pointer-chasing garbage that is/dev/sg.
Well, we could remove in_compat_syscall(), etc and instead have an implicit parameter in DEFINE_SYSCALL. Then everything would have to be explicit. This would probably be a win, although it could be quite a bit of work.
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 14 lines · Andy Lutomirski
Quoted 14 lines · Al Viro
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.
Quoted 7 lines
Quoted 5 lines
So screw such read/write methods - don't use them with
io_uring. That, BTW, is one of the reasons I'm sceptical about burying the decisions deep into the callchain - we don't _want_ different data layouts on read/write depending upon the 32bit vs. 64bit caller, let alone the pointer-chasing garbage that is/dev/sg.Well, we could remove
in_compat_syscall(), etc and instead have an implicit parameter inDEFINE_SYSCALL. Then everything would have to be explicit. This would probably be a win, although it could be quite a bit of work.
It would not be a win - most of the syscalls don't give a damn about 32bit vs. 64bit...
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 25 lines · Al Viro
Quoted 20 lines · Andy Lutomirski
Quoted 19 lines
Quoted 2 lines · Al Viro
Quoted 9 lines · Christoph Hellwig
Quoted 4 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.So screw such read/write methods - don't use them with
io_uring. That, BTW, is one of the reasons I'm sceptical about burying the decisions deep into the callchain - we don't _want_ different data layouts on read/write depending upon the 32bit vs. 64bit caller, let alone the pointer-chasing garbage that is/dev/sg.
Quoted 4 lines
Quoted 1 line
Well, we could remove
in_compat_syscall(), etc and instead have an implicit parameter inDEFINE_SYSCALL. Then everything would have to be explicit. This would probably be a win, although it could be quite a bit of work.It would not be a win - most of the syscalls don't give a damn about 32bit vs. 64bit...
Any reasonable implementation would optimize it out for syscalls that don’t care. Or it could be explicit:
DEFINE_MULTIARCH_SYSCALL(...)
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 6 lines · Andy Lutomirski
Quoted 2 lines
It would not be a win - most of the syscalls don't give a damn about 32bit vs. 64bit...
Any reasonable implementation would optimize it out for syscalls that don’t care. Or it could be explicit:
DEFINE_MULTIARCH_SYSCALL(...)
1) what would that look like?
2) have you counted the syscalls that do and do not need that?
3) how many of those realistically *can* be unified with their compat counterparts? [hint: ioctl(2) cannot]
Andy Lutomirski
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 11 lines · Al Viro
Quoted 6 lines · Andy Lutomirski
Quoted 2 lines
It would not be a win - most of the syscalls don't give a damn about 32bit vs. 64bit...
Any reasonable implementation would optimize it out for syscalls that don’t care. Or it could be explicit:
DEFINE_MULTIARCH_SYSCALL(...)1) what would that look like?
In effect, it would work like this:
/* Arch-specific, but there's a generic case for sane architectures. */ enum syscall_arch {
SYSCALL_NATIVE,
SYSCALL_COMPAT,
SYSCALL_X32,
};
DEFINE_MULTIARCH_SYSCALLn(args, arch)
{
args are the args here, and arch is the arch.
}
Quoted 1 line
2) have you counted the syscalls that do and do not need that?
No.
Quoted 2 lines
3) how many of those realistically *can* be unified with their compat counterparts? [hint: ioctl(2) cannot]
There would be no requirement to unify anything. The idea is that we'd get rid of all the global state flags.
For ioctl, we'd have a new file_operation:
long ioctl(struct file *, unsigned int, unsigned long, enum syscall_arch);
I'm not saying this is easy, but I think it's possible and the result would be more obviously correct than what we have now.
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 3 lines · Andy Lutomirski
Quoted 1 line
2) have you counted the syscalls that do and do not need that?
No.
Might be illuminating...
Quoted 5 lines
Quoted 2 lines
3) how many of those realistically *can* be unified with their compat counterparts? [hint: ioctl(2) cannot]
There would be no requirement to unify anything. The idea is that we'd get rid of all the global state flags.
_What_ global state flags? When you have separate SYSCALL_DEFINE3(ioctl...) and COMPAT_SYSCALL_DEFINE3(ioctl...), there's no flags at all, global or local. They only come into the play when you try to share the same function for both, right on the top level.
Quoted 6 lines
For ioctl, we'd have a new
file_operation:long
ioctl(struct file *, unsigned int, unsigned long, enum syscall_arch);I'm not saying this is easy, but I think it's possible and the result would be more obviously correct than what we have now.
No, it would not. Seriously, from time to time a bit of RTFS before grand proposals turns out to be useful.
Andy Lutomirski
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 19 lines · Al Viro
Quoted 3 lines · Andy Lutomirski
Quoted 1 line
2) have you counted the syscalls that do and do not need that?
No.
Might be illuminating...
Quoted 5 lines
Quoted 2 lines
3) how many of those realistically *can* be unified with their compat counterparts? [hint: ioctl(2) cannot]
There would be no requirement to unify anything. The idea is that we'd get rid of all the global state flags.
_What_ global state flags? When you have separate
SYSCALL_DEFINE3(ioctl...)andCOMPAT_SYSCALL_DEFINE3(ioctl...), there's no flags at all, global or local. They only come into the play when you try to share the same function for both, right on the top level.
...
Quoted 10 lines
Quoted 7 lines
For ioctl, we'd have a new
file_operation:long
ioctl(struct file *, unsigned int, unsigned long, enum syscall_arch);I'm not saying this is easy, but I think it's possible and the result would be more obviously correct than what we have now.
No, it would not. Seriously, from time to time a bit of RTFS before grand proposals turns out to be useful.
As one example, look at __sys_setsockopt(). It's called for the native and compat versions, and it contains an in_compat_syscall() check. (This particularly check looks dubious to me, but that's another story.) If this were to be done with equivalent semantics without a separate COMPAT_DEFINE_SYSCALL and without in_compat_syscall(), there would need to be some indication as to whether this is compat or native setsockopt. There are other setsockopt implementations in the net stack with more legitimate-seeming uses of in_compat_syscall() that would need some other mechanism if in_compat_syscall() were to go away.
setsockopt is (I hope!) out of scope for io_uring, but the situation isn't fundamentally different from read and write.
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 11 lines · Andy Lutomirski
As one example, look at
__sys_setsockopt(). It's called for the native and compat versions, and it contains anin_compat_syscall()check. (This particularly check looks dubious to me, but that's another story.) If this were to be done with equivalent semantics without a separateCOMPAT_DEFINE_SYSCALLand withoutin_compat_syscall(), there would need to be some indication as to whether this is compat or native setsockopt. There are other setsockopt implementations in the net stack with more legitimate-seeming uses ofin_compat_syscall()that would need some other mechanism ifin_compat_syscall()were to go away.
Quoted 2 lines
setsockopt is (I hope!) out of scope for
io_uring, but the situation isn't fundamentally different from read and write.
Except that setsockopt() had that crap very widespread; for read()
and write() those are very rare exceptions.
Andy, please RTFS. Or dig through archives. The situation
with setsockopt() is *NOT* a good thing - it's (probably) the least of the evils. The last thing we need is making that the norm.
Arnd Bergmann
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Al ViroQuoted 11 lines · Al Viro
Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.
Quoted 5 lines
So screw such read/write methods - don't use them with
io_uring. That, BTW, is one of the reasons I'm sceptical about burying the decisions deep into the callchain - we don't _want_ different data layouts on read/write depending upon the 32bit vs. 64bit caller, let alone the pointer-chasing garbage that is/dev/sg.
Would it be too late to limit what kind of file descriptors we allow io_uring to read/write on?
If io_uring can get changed to return -EINVAL on trying to read/write something other than S_IFREG file descriptors, that particular problem space gets a lot simpler, but this is of course only possible if nobody actually relies on it yet.
Arnd
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 18 lines · Arnd Bergmann
Quoted 11 lines · Al Viro
Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Al Viro
Said that, why not provide a variant that would take an explicit "is it compat" argument and use it there? And have the normal one pass
in_compat_syscall()to that...That would help to not introduce a regression with this series yes. But it wouldn't fix existing bugs when
io_uringis used to access read or write methods that usein_compat_syscall(). One example that I recently ran into isdrivers/scsi/sg.c.Quoted 5 lines
So screw such read/write methods - don't use them with
io_uring. That, BTW, is one of the reasons I'm sceptical about burying the decisions deep into the callchain - we don't _want_ different data layouts on read/write depending upon the 32bit vs. 64bit caller, let alone the pointer-chasing garbage that is/dev/sg.
Quoted 7 lines
Would it be too late to limit what kind of file descriptors we allow
io_uringto read/write on?If
io_uringcan get changed to return-EINVALon trying to read/write something other thanS_IFREGfile descriptors, that particular problem space gets a lot simpler, but this is of course only possible if nobody actually relies on it yet.
S_IFREG is almost certainly too heavy as a restriction. Looking through the stuff sensitive to 32bit/64bit, we seem to have
* /dev/sg - pointer-chasing horror
* sysfs files for efivar - different layouts for compat and native,
shitty userland ABI design (
struct efi_variable {
efi_char16_t VariableName[EFI_VAR_NAME_LEN/sizeof(efi_char16_t)];
efi_guid_t VendorGuid;
unsigned long DataSize;
__u8 Data[1024];
efi_status_t Status;
__u32 Attributes;
} __attribute__((packed));) is the piece of crap in question; 'DataSize' is where the headache comes from. Regular files, BTW...
* uhid - character device, milder pointer-chasing horror. Trouble
comes from this:
/* Obsolete! Use UHID_CREATE2. */
struct uhid_create_req {
__u8 name[128];
__u8 phys[64];
__u8 uniq[64];
__u8 __user *rd_data;
__u16 rd_size;
__u16 bus;
__u32 vendor;
__u32 product;
__u32 version;
__u32 country;
} __attribute__((__packed__));and suggested replacement doesn't do any pointer-chasing (rd_data is an embedded array in the end of struct uhid_create2_req).
* evdev, uinput - bitness-sensitive layout, due to timestamps
* /proc/bus/input/devices - weird crap with printing bitmap, different
_text_ layouts seen by 32bit and 64bit readers. Binary structures are PITA, but with sufficient effort you can screw the text just as hard... Oh, and it's a regular file.
* similar in sysfs analogue
And AFAICS, that's it for read/write-related method instances.
RE: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Al ViroFrom: Al Viro
Quoted 12 lines
Sent: 18 September 2020 14:58
Quoted 9 lines · Christoph Hellwig
Quoted 7 lines · Al Viro
arch/sparc/include/asm/compat.h static inline int is_compat_task(void) · line 215
Quoted 4 lines
arch/sparc/include/asm/compat.h +2
-1/* Vector 0x110 is LINUX_32BIT_SYSCALL_TRAP */ -return pt_regs_trap_type (current_pt_regs ()) =0x110 ; +return pt_regs_trap_type (current_pt_regs ()) =0x110 || + (current->flags &PF_FORCE_COMPAT );Can't say I like that approach ;-/ Reasoning about the behaviour is much harder when it's controlled like that - witness
set_fs()shite...
Quoted 5 lines
Quoted 2 lines
I don't particularly like it either. But do you have a better idea how to deal with
io_uringvs compat tasks?<wry> git rm
fs/io_uring.cwould make a good starting point </wry> Yes, I know it's not going to happen, but one can dream...
Maybe the io_uring code needs some changes to make it vaguely safe.
- No support for 32-bit compat mixed working (or at all?). Plausibly a special worker could do 32bit work.
- ring structure (I'm assuming mapped by mmap()) never mapped in more than one process (not cloned by fork()).
- No implicit handover of files to another process. Would need an munmap, handover, mmap sequence.
In any case the io_ring rather abuses the import_iovec() interface.
The canonical sequence is (types from memory):
struct iovec cache[8], *iov = cache; struct iter iter; ... rval = import_iovec(..., &iov, 8, &iter); // Do read/write user using 'iter' free(iov);
I don't think there is any strict requirement that iter.iov is set to either 'cache' or 'iov' (it probably must point into one of them.)
But the io_uring code will make that assumption because the actual copies can be done much later and it doesn't save 'iter'. It gets itself in a right mess because it doesn't separate the 'address I need to free' from 'the iov[] for any transfers'.
io_uring is also the only code that relies on import_iovec() returning the iter.count on success.
It would be much better to have:
iov = import_iovec(..., &cache, ...); free(iov);
and use ERR_PTR() et al for error detectoion.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Arnd Bergmann
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Christoph HellwigQuoted 7 lines · Christoph Hellwig
Quoted 5 lines · Al Viro
Quoted 4 lines
/* Vector 0x110 is LINUX_32BIT_SYSCALL_TRAP */arch/sparc/include/asm/compat.h +2
-1-return pt_regs_trap_type (current_pt_regs ()) =0x110 ; +return pt_regs_trap_type (current_pt_regs ()) =0x110 || + (current->flags &PF_FORCE_COMPAT );
Quoted 5 lines
Quoted 2 lines
Can't say I like that approach ;-/ Reasoning about the behaviour is much harder when it's controlled like that - witness
set_fs()shite...I don't particularly like it either. But do you have a better idea how to deal with
io_uringvs compat tasks?
Do we need to worry about something other than the compat_iovec struct for now? Regarding the code in io_import_iovec(), it would seem that can easily be handled by exposing an internal helper. Instead of
#ifdef CONFIG_COMPAT
if (req->ctx->compat)
return compat_import_iovec(rw, buf, sqe_len, UIO_FASTIOV,
iovec, iter);
#endif
return import_iovec(rw, buf, sqe_len, UIO_FASTIOV, iovec, iter);This could do
__import_iovec(rw, buf, sqe_len, UIO_FASTIOV, iovec,
iter, req->ctx->compat);
With the normal import_iovec() becoming a trivial wrapper around the same thing:
ssize_t import_iovec(int type, const struct iovec __user * uvector,
unsigned nr_segs, unsigned fast_segs, struct iovec **iov, struct iov_iter *i)
{
return __import_iovec(type, uvector, nr_segs, fast_segs, iov,
i, in_compat_syscall());
}
Arnd
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Christoph HellwigQuoted 3 lines · Christoph Hellwig
Add a flag to force processing a syscall as a compat syscall. This is required so that
in_compat_syscall()works for I/O submitted byio_uringhelper threads on behalf of compat syscalls.
Al doesn't like this much, but my suggestion is to introduce two new opcodes -- IORING_OP_READV32 and IORING_OP_WRITEV32. The compat code can translate IORING_OP_READV to IORING_OP_READV32 and then the core code can know what that user pointer is pointing to.
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
I really like that as it’s self-documenting and anyone debugging it can see what is actually being used at a glance.
Quoted 11 lines · Matthew Wilcox
Quoted 3 lines · Christoph Hellwig
Add a flag to force processing a syscall as a compat syscall. This is required so that
in_compat_syscall()works for I/O submitted byio_uringhelper threads on behalf of compat syscalls.Al doesn't like this much, but my suggestion is to introduce two new opcodes --
IORING_OP_READV32andIORING_OP_WRITEV32. The compat code can translateIORING_OP_READVtoIORING_OP_READV32and then the core code can know what that user pointer is pointing to.
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 1 line · William Kucharski
I really like that as it’s self-documenting and anyone debugging it can see what is actually being used at a glance.
Also creates special cases for things that few people care about, and makes it a pain for cross-platform (cross-bitness) development.
Quoted 12 lines
Quoted 12 lines · Matthew Wilcox
Quoted 3 lines · Christoph Hellwig
Add a flag to force processing a syscall as a compat syscall. This is required so that
in_compat_syscall()works for I/O submitted byio_uringhelper threads on behalf of compat syscalls.Al doesn't like this much, but my suggestion is to introduce two new opcodes --
IORING_OP_READV32andIORING_OP_WRITEV32. The compat code can translateIORING_OP_READVtoIORING_OP_READV32and then the core code can know what that user pointer is pointing to.
Signature · 1 line
Pavel Begunkov
Arnd Bergmann
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Matthew WilcoxQuoted 10 lines · Matthew Wilcox
Quoted 3 lines · Christoph Hellwig
Add a flag to force processing a syscall as a compat syscall. This is required so that
in_compat_syscall()works for I/O submitted byio_uringhelper threads on behalf of compat syscalls.Al doesn't like this much, but my suggestion is to introduce two new opcodes --
IORING_OP_READV32andIORING_OP_WRITEV32. The compat code can translateIORING_OP_READVtoIORING_OP_READV32and then the core code can know what that user pointer is pointing to.
How is that different from the current approach of storing the ABI as a flag in ctx->compat?
Arnd
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Matthew WilcoxQuoted 9 lines · Matthew Wilcox
Quoted 3 lines · Christoph Hellwig
Add a flag to force processing a syscall as a compat syscall. This is required so that
in_compat_syscall()works for I/O submitted byio_uringhelper threads on behalf of compat syscalls.Al doesn't like this much, but my suggestion is to introduce two new opcodes --
IORING_OP_READV32andIORING_OP_WRITEV32. The compat code can translateIORING_OP_READVtoIORING_OP_READV32and then the core code can know what that user pointer is pointing to.
Let's separate two issues:
1) compat syscalls want 32bit iovecs. Nothing to do with the
drivers, dealt with just fine.
2) a few drivers are really fucked in head. They use different
*DATA* layouts for reads/writes, depending upon the calling process. IOW, if you fork/exec a 32bit binary and your stdin is one of those, reads from stdin in parent and child will yield different data layouts. On the same struct file.
That's what Christoph worries about (/dev/sg he'd mentioned is
one of those).
IMO we should simply have that dozen or so of pathological files
marked with FMODE_SHITTY_ABI; it's not about how they'd been opened - it describes the userland ABI provided by those. And it's cast in stone.
Any in_compat_syscall() in ->read()/->write() instances is an ABI
bug, plain and simple. Some are unfixable for compatibility reasons, but any new caller like that should be a big red flag.
How we import iovec array is none of the drivers' concern; we do
not need to mess with in_compat_syscall() reporting the matching value, etc. for that. It's about the instances that want in_compat_syscall() to decide between the 32bit and 64bit data layouts. And I believe that we should simply have them marked as such and rejected by io_uring. With any new occurences getting slapped down hard.
Current list of those turds:/dev/sg (pointer-chasing, generally insane) /sys/firmware/efi/vars/*/raw_var (fucked binary structure) /sys/firmware/efi/vars/new_var (fucked binary structure) /sys/firmware/efi/vars/del_var (fucked binary structure)/dev/uhid (pointer-chasing for one obsolete command)/dev/input/event* (timestamps)/dev/uinput (timestamps)/proc/bus/input/devices (fucked bitmap-to-text representation) /sys/class/input/*/capabilities/* (fucked bitmap-to-text representation)
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 1 line · Al Viro
/proc/bus/input/devices(fucked bitmap-to-text representation)
To illustrate the, er, beauty of that stuff:
; cat32 /proc/bus/input/devices >/tmp/a
; cat /proc/bus/input/devices >/tmp/b
; diff -u /tmp/a /tmp/b|grep '^[-+]'
--- /tmp/a 2020-09-20 14:28:43.442560691 -0400
+++ /tmp/b 2020-09-20 14:28:49.018543230 -0400
-B: KEY00f 2902000 8380307c f910f001 feffffdf ffefffff ffffffff fffffffe +B: KEY00f02902000 8380307cf910f001 feffffdfffefffff fffffffffffffffe -B: KEYp000 0 0 0 0 0 0 0 0
+B: KEYp000 0 0 0 0
-B: KEYB0 0 70000 0 0 0 0 0 0 0 0
+B: KEYB0 70000 0 0 0 0
-B: KEY0000 0 0 0
+B: KEY000000000000 0
-B: KEY@00 0 0 0 0
+B: KEY@00 0 0
-B: KEY€00 0 0 0 0 0 1100b 800 2 200000 0 0 0 0
+B: KEY€0000000000 0 0 1100b00000800 200200000 0 0
-B: KEY>000b 0 0 0 0 0 0 0
+B: KEY>000b00000000 0 0 0
-B: KEY˙ffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe +B: KEY˙ffffffffffffff ffffffffffffffff ffffffffffffffff fffffffffffffffe ;
(cat32 being a 32bit binary of cat)
All the differences are due to homegrown bitmap-to-text conversion.
Note that feeding that into a pipe leaves the recepient with a lovely problem - you can't go by the width of words (they are not zero-padded) and you can't go by the number of words either - it varies from device to device.
And there's nothing we can do with that - it's a userland ABI, can't be changed without breaking stuff. I would prefer to avoid additional examples like that, TYVM...
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Al ViroQuoted 8 lines · Al Viro
2) a few drivers are really fucked in head. They use different
*DATA* layouts for reads/writes, depending upon the calling process. IOW, if you fork/exec a 32bit binary and your stdin is one of those, reads from stdin in parent and child will yield different data layouts. On the same struct file.
That's what Christoph worries about (/dev/sghe'd mentioned is
one of those).
Quoted 7 lines
IMO we should simply have that dozen or so of pathological files
marked withFMODE_SHITTY_ABI; it's not about how they'd been opened - it describes the userland ABI provided by those. And it's cast in stone.Any in_compat_syscall() in ->read()/->write() instances is an ABIbug, plain and simple. Some are unfixable for compatibility reasons, but any new caller like that should be a big red flag.
So an IOCB_COMPAT flag would let us know whether the caller is expecting a 32-bit or 64-bit layout? And io_uring could set it based on the ctx->compat flag.
Quoted 10 lines
Current list of those turds:
/dev/sg(pointer-chasing, generally insane)/sys/firmware/efi/vars/*/raw_var(fucked binary structure)/sys/firmware/efi/vars/new_var(fucked binary structure)/sys/firmware/efi/vars/del_var(fucked binary structure)/dev/uhid(pointer-chasing for one obsolete command)/dev/input/event*(timestamps)/dev/uinput(timestamps)/proc/bus/input/devices(fucked bitmap-to-text representation)/sys/class/input/*/capabilities/*(fucked bitmap-to-text representation)
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 13 lines · Matthew Wilcox
Quoted 12 lines · Al Viro
2) a few drivers are really fucked in head. They use different
*DATA* layouts for reads/writes, depending upon the calling process. IOW, if you fork/exec a 32bit binary and your stdin is one of those, reads from stdin in parent and child will yield different data layouts. On the same struct file.
That's what Christoph worries about (/dev/sghe'd mentioned is
one of those).IMO we should simply have that dozen or so of pathological files
marked withFMODE_SHITTY_ABI; it's not about how they'd been opened - it describes the userland ABI provided by those. And it's cast in stone.
Quoted 7 lines
Quoted 3 lines
Any in_compat_syscall() in ->read()/->write() instances is an ABIbug, plain and simple. Some are unfixable for compatibility reasons, but any new caller like that should be a big red flag.
So an
IOCB_COMPATflag would let us know whether the caller is expecting a 32-bit or 64-bit layout? Andio_uringcould set it based on thectx->compatflag.
So you want to convert all that crap to a form that would see iocb (IOW, ->read_iter()/->write_iter())? And, since quite a few are sysfs attributes, propagate that through sysfs, changing the method signatures to match that and either modifying fuckloads of instances or introducing new special methods for the ones that are sensitive to that crap?
IMO it's much saner to mark those and refuse to touch them from io_uring...
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 1 line · Al Viro
IMO it's much saner to mark those and refuse to touch them from
io_uring...
Simpler solution is to remove io_uring from the 32-bit syscall list. If you're a 32-bit process, you don't get to use io_uring. Would any real users actually care about that?
Andy Lutomirski
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 7 lines · Matthew Wilcox
Quoted 1 line · Al Viro
IMO it's much saner to mark those and refuse to touch them from
io_uring...Simpler solution is to remove
io_uringfrom the 32-bit syscall list. If you're a 32-bit process, you don't get to useio_uring. Would any real users actually care about that?
We could go one step farther and declare that we're done adding *any* new compat syscalls :)
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Arnd Bergmann
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 11 lines · Andy Lutomirski
Quoted 7 lines · Matthew Wilcox
Quoted 1 line · Al Viro
IMO it's much saner to mark those and refuse to touch them from
io_uring...Simpler solution is to remove
io_uringfrom the 32-bit syscall list. If you're a 32-bit process, you don't get to useio_uring. Would any real users actually care about that?We could go one step farther and declare that we're done adding *any* new compat syscalls :)
Would you also stop adding system calls to native 32-bit systems then?
On memory constrained systems (less than 2GB a.t.m.), there is still a strong demand for running 32-bit user space, but all of the recent Arm cores (after Cortex-A55) dropped the ability to run 32-bit kernels, so that compat mode may eventually become the primary way to run Linux on cheap embedded systems.
I don't think there is any chance we can realistically take away io_uring from the 32-bit ABI any more now.
Arnd
RE: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
RnJvbTogQXJuZCBCZXJnbWFubg0KPiBTZW50OiAyMCBTZXB0ZW1iZXIgMjAyMCAyMTo0OQ0KPiAN Cj4gT24gU3VuLCBTZXAgMjAsIDIwMjAgYXQgOToyOCBQTSBBbmR5IEx1dG9taXJza2kgPGx1dG9A a2VybmVsLm9yZz4gd3JvdGU6DQo+ID4gT24gU3VuLCBTZXAgMjAsIDIwMjAgYXQgMTI6MjMgUE0g TWF0dGhldyBXaWxjb3ggPHdpbGx5QGluZnJhZGVhZC5vcmc+IHdyb3RlOg0KPiA+ID4NCj4gPiA+ IE9uIFN1biwgU2VwIDIwLCAyMDIwIGF0IDA4OjEwOjMxUE0gKzAxMDAsIEFsIFZpcm8gd3JvdGU6 DQo+ID4gPiA+IElNTyBpdCdzIG11Y2ggc2FuZXIgdG8gbWFyayB0aG9zZSBhbmQgcmVmdXNlIHRv IHRvdWNoIHRoZW0gZnJvbSBpb191cmluZy4uLg0KPiA+ID4NCj4gPiA+IFNpbXBsZXIgc29sdXRp b24gaXMgdG8gcmVtb3ZlIGlvX3VyaW5nIGZyb20gdGhlIDMyLWJpdCBzeXNjYWxsIGxpc3QuDQo+ ID4gPiBJZiB5b3UncmUgYSAzMi1iaXQgcHJvY2VzcywgeW91IGRvbid0IGdldCB0byB1c2UgaW9f dXJpbmcuICBXb3VsZA0KPiA+ID4gYW55IHJlYWwgdXNlcnMgYWN0dWFsbHkgY2FyZSBhYm91dCB0 aGF0Pw0KPiA+DQo+ID4gV2UgY291bGQgZ28gb25lIHN0ZXAgZmFydGhlciBhbmQgZGVjbGFyZSB0 aGF0IHdlJ3JlIGRvbmUgYWRkaW5nICphbnkqDQo+ID4gbmV3IGNvbXBhdCBzeXNjYWxscyA6KQ0K PiANCj4gV291bGQgeW91IGFsc28gc3RvcCBhZGRpbmcgc3lzdGVtIGNhbGxzIHRvIG5hdGl2ZSAz Mi1iaXQgc3lzdGVtcyB0aGVuPw0KPiANCj4gT24gbWVtb3J5IGNvbnN0cmFpbmVkIHN5c3RlbXMg KGxlc3MgdGhhbiAyR0IgYS50Lm0uKSwgdGhlcmUgaXMgc3RpbGwgYQ0KPiBzdHJvbmcgZGVtYW5k IGZvciBydW5uaW5nIDMyLWJpdCB1c2VyIHNwYWNlLCBidXQgYWxsIG9mIHRoZSByZWNlbnQgQXJt DQo+IGNvcmVzIChhZnRlciBDb3J0ZXgtQTU1KSBkcm9wcGVkIHRoZSBhYmlsaXR5IHRvIHJ1biAz Mi1iaXQga2VybmVscywgc28NCj4gdGhhdCBjb21wYXQgbW9kZSBtYXkgZXZlbnR1YWxseSBiZWNv bWUgdGhlIHByaW1hcnkgd2F5IHRvIHJ1bg0KPiBMaW51eCBvbiBjaGVhcCBlbWJlZGRlZCBzeXN0 ZW1zLg0KPiANCj4gSSBkb24ndCB0aGluayB0aGVyZSBpcyBhbnkgY2hhbmNlIHdlIGNhbiByZWFs aXN0aWNhbGx5IHRha2UgYXdheSBpb191cmluZw0KPiBmcm9tIHRoZSAzMi1iaXQgQUJJIGFueSBt b3JlIG5vdy4NCg0KQ2FuJ3QgaXQganVzdCBydW4gcmVxdWVzdHMgZnJvbSAzMmJpdCBhcHBzIGlu IGEga2VybmVsIHRocmVhZCB0aGF0IGhhcw0KdGhlICdpbl9jb21wYXRfc3lzY2FsbCcgZmxhZyBz ZXQ/DQpOb3QgdGhhdCBpIHJlY2FsbCBzZWVpbmcgdGhlIGNvZGUgd2hlcmUgaXQgc2F2ZXMgdGhl ICdjb21wYXQnIG5hdHVyZQ0Kb2YgYW55IHJlcXVlc3RzLg0KDQpJdCBpcyBhbHJlYWR5IGNvbXBs ZXRlbHkgZipja2VkIGlmIHlvdSB0cnkgdG8gcGFzcyB0aGUgY29tbWFuZCByaW5nDQp0byBhIGNo aWxkIHByb2Nlc3MgLSBpdCB1c2VzIHRoZSB3cm9uZyAnbW0nLg0KSSBzdXNwZWN0IHRoZXJlIGFy ZSBzb21lIHJlYWxseSBob3JyaWQgc2VjdXJpdHkgaG9sZXMgaW4gdGhhdCBhcmVhLg0KDQoJRGF2 aWQuDQoNCi0NClJlZ2lzdGVyZWQgQWRkcmVzcyBMYWtlc2lkZSwgQnJhbWxleSBSb2FkLCBNb3Vu dCBGYXJtLCBNaWx0b24gS2V5bmVzLCBNSzEgMVBULCBVSw0KUmVnaXN0cmF0aW9uIE5vOiAxMzk3 Mzg2IChXYWxlcykNCg=
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 27 lines · David Laight
From: Arnd Bergmann
Quoted 17 lines
Sent: 20 September 2020 21:49
Quoted 11 lines · Andy Lutomirski
Quoted 7 lines · Matthew Wilcox
Quoted 1 line · Al Viro
IMO it's much saner to mark those and refuse to touch them from
io_uring...Simpler solution is to remove
io_uringfrom the 32-bit syscall list. If you're a 32-bit process, you don't get to useio_uring. Would any real users actually care about that?We could go one step farther and declare that we're done adding *any* new compat syscalls :)
Would you also stop adding system calls to native 32-bit systems then?
Quoted 8 lines
On memory constrained systems (less than 2GB a.t.m.), there is still a strong demand for running 32-bit user space, but all of the recent Arm cores (after Cortex-A55) dropped the ability to run 32-bit kernels, so that compat mode may eventually become the primary way to run Linux on cheap embedded systems.
I don't think there is any chance we can realistically take away
io_uringfrom the 32-bit ABI any more now.
Quoted 7 lines
Can't it just run requests from 32bit apps in a kernel thread that has the '
in_compat_syscall' flag set?
Not that i recall seeing the code where it saves the 'compat' nature of any requests.It is already completely f*cked if you try to pass the command ring to a child process - it uses the wrong 'mm'.
And how so? io_uring uses mm of a submitter. The exception is SQPOLL mode, but it requires CAP_SYS_ADMIN or CAP_SYS_NICE anyway.
Quoted 8 lines
I suspect there are some really horrid security holes in that area.
David.
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Signature · 1 line
Pavel Begunkov
Al Viro
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Matthew WilcoxQuoted 6 lines · Matthew Wilcox
Quoted 1 line · Al Viro
IMO it's much saner to mark those and refuse to touch them from
io_uring...Simpler solution is to remove
io_uringfrom the 32-bit syscall list. If you're a 32-bit process, you don't get to useio_uring. Would any real users actually care about that?
What for? I mean, is there any reason to try and keep those bugs as first-class citizens? IDGI... Yes, we have several special files (out of thousands) that have read()/write() user-visible semantics broken wrt 32bit/64bit. And we have to keep them working that way for existing syscalls. Why would we want to pretend that their behaviour is normal and isn't an ABI bug, not to be repeated for anything new?
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Matthew WilcoxQuoted 6 lines · Matthew Wilcox
Quoted 1 line · Al Viro
IMO it's much saner to mark those and refuse to touch them from
io_uring...Simpler solution is to remove
io_uringfrom the 32-bit syscall list. If you're a 32-bit process, you don't get to useio_uring. Would any real users actually care about that?
There were .net and\or wine (which AFAIK often works in compat) guys experimenting with io_uring, they might want it.
Signature · 1 line
Pavel Begunkov
Andy Lutomirski
maintainerRe: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
In reply to Al ViroQuoted 23 lines · Al Viro
Quoted 9 lines · Matthew Wilcox
Quoted 3 lines · Christoph Hellwig
Add a flag to force processing a syscall as a compat syscall. This is required so that
in_compat_syscall()works for I/O submitted byio_uringhelper threads on behalf of compat syscalls.Al doesn't like this much, but my suggestion is to introduce two new opcodes --
IORING_OP_READV32andIORING_OP_WRITEV32. The compat code can translateIORING_OP_READVtoIORING_OP_READV32and then the core code can know what that user pointer is pointing to.Let's separate two issues:
1) compat syscalls want 32bit iovecs. Nothing to do with the
drivers, dealt with just fine.
2) a few drivers are really fucked in head. They use different
*DATA* layouts for reads/writes, depending upon the calling process. IOW, if you fork/exec a 32bit binary and your stdin is one of those, reads from stdin in parent and child will yield different data layouts. On the same struct file.
That's what Christoph worries about (/dev/sghe'd mentioned is
one of those).
Quoted 4 lines
IMO we should simply have that dozen or so of pathological files
marked withFMODE_SHITTY_ABI; it's not about how they'd been opened - it describes the userland ABI provided by those. And it's cast in stone.
I wonder if this is really quite cast in stone. We could also have FMODE_SHITTY_COMPAT and set that when a file like this is *opened* in compat mode. Then that particular struct file would be read and written using the compat data format. The change would be user-visible, but the user that would see it would be very strange indeed.
I don't have a strong opinion as to whether that is better or worse than denying io_uring access to these things, but at least it moves the special case out of io_uring.
--Andy
Re: [PATCH 1/9] kernel: add a PF_FORCE_COMPAT flag
Quoted 10 lines · Andy Lutomirski
I wonder if this is really quite cast in stone. We could also have
FMODE_SHITTY_COMPATand set that when a file like this is *opened* in compat mode. Then that particular struct file would be read and written using the compat data format. The change would be user-visible, but the user that would see it would be very strange indeed.I don't have a strong opinion as to whether that is better or worse than denying
io_uringaccess to these things, but at least it moves the special case out ofio_uring.
open could have happened through an io_uring thread a well, so I don't see how this would do anything but move the problem to a different place.
Quoted 2 lines
--Andy
---end quoted text---
PATCH 2/9 compat.h: fix a spelling error in <linux/compat.h>
In reply to Christoph HellwigWe only have not compat_sys_readv64v2 syscall, only a compat_sys_preadv64v2 syscall one. This probably worked given that the syscall was not referenced from anywhere but the x86 syscall table.
--- include/linux/compat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/compat.h +1 -1
@@ -812,7 +812,7 @@ asmlinkage ssize_t compat_sys_pwritev2(compat_ulong_t fd,const struct compat_iovec __user *vec, compat_ulong_t vlen, u32 pos_low, u32 pos_high, rwf_t flags);#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2 -asmlinkage long compat_sys_readv64v2 (unsigned long fd, +asmlinkage long compat_sys_preadv64v2 (unsigned long fd,const struct compat_iovec __user *vec,unsigned long vlen,loff_t pos,rwf_t flags);#endif
Signature · 1 line
2.28.0
Re: [PATCH 2/9] compat.h: fix a spelling error in <linux/compat.h>
Quoted 1 line · Christoph Hellwig
We only have not
compat_sys_readv64v2syscall, only a
We have no?
PATCH 3/9 fs: explicitly check for CHECK_IOVEC_ONLY in rw_copy_check_uvector
In reply to Christoph HellwigExplicitly check for the magic value insted of implicitly relying on its number representation.
--- fs/read_write.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/read_write.c +2 -3
@@ -840,8 +840,7 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, ret = -EINVAL ; goto out; } -if (type >=0 - &&unlikely (!access_ok (buf, len))) { +if (type !=CHECK_IOVEC_ONLY &&unlikely (!access_ok (buf, len))) { ret = -EFAULT ; goto out; }
@@ -911,7 +910,7 @@ ssize_t compat_rw_copy_check_uvector(int type, }if (len <0 )/* size_t not fitting in compat_ssize_t .. */ goto out; -if (type >=0 && +if (type !=CHECK_IOVEC_ONLY && !access_ok (compat_ptr (buf), len)) { ret = -EFAULT ; goto out;
Signature · 1 line
2.28.0
Re: [PATCH 3/9] fs: explicitly check for CHECK_IOVEC_ONLY in rw_copy_check_uvector
fs/read_write.c ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, · line 843
Quoted 4 lines · Christoph Hellwig
fs/read_write.c +1
-2} -if (type >=0 - &&unlikely (!access_ok (buf, len))) { +if (type !=CHECK_IOVEC_ONLY &&unlikely (!access_ok (buf, len))) {
drop the unlikely() at the same time? if it's really advantageous, that should be embedded in the access_ok macro.
Re: [PATCH 3/9] fs: explicitly check for CHECK_IOVEC_ONLY in rw_copy_check_uvector
In reply to Christoph HellwigLooks good,
PATCH 4/9 fs: handle the compat case in import_iovec
In reply to Christoph HellwigUse in compat_syscall to import either native or the compat iovecs, and remove the now superflous compat_import_iovec.
--- block/scsi_ioctl.c | 12 +--- drivers/scsi/sg.c | 9 +-- fs/aio.c | 38 +++++------- fs/io_uring.c | 12 +--- fs/read_write.c | 127 +++++++++++++++-------------------------- fs/splice.c | 2 +- include/linux/compat.h | 6 -- include/linux/fs.h | 7 +-- include/linux/uio.h | 7 --- lib/iov_iter.c | 30 +--------- mm/process_vm_access.c | 9 +-- net/compat.c | 4 +- security/keys/compat.c | 5 +- 13 files changed, 83 insertions(+), 185 deletions(-)
block/scsi_ioctl.c +2 -10
@@ -333,16 +333,8 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,struct iov_iter i;struct iovec *iov =NULL ; -#ifdef CONFIG_COMPAT -if (in_compat_syscall ()) - ret =compat_import_iovec (rq_data_dir (rq), - hdr->dxferp, hdr->iovec_count, -0 , &iov, &i); - else -#endif - ret =import_iovec (rq_data_dir (rq), - hdr->dxferp, hdr->iovec_count, -0 , &iov, &i); + ret =import_iovec (rq_data_dir (rq), hdr->dxferp, + hdr->iovec_count,0 , &iov, &i);if (ret <0 ) goto out_free_cdb;
drivers/scsi/sg.c +1 -8
@@ -1820,14 +1820,7 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)struct iovec *iov =NULL ;struct iov_iter i; -#ifdef CONFIG_COMPAT -if (in_compat_syscall ()) - res =compat_import_iovec (rw, hp->dxferp, iov_count, -0 , &iov, &i); - else -#endif - res =import_iovec (rw, hp->dxferp, iov_count, -0 , &iov, &i); + res =import_iovec (rw, hp->dxferp, iov_count,0 , &iov, &i);if (res <0 )return res;
fs/aio.c +14 -24
@@ -1478,8 +1478,7 @@ static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb) }static ssize_t aio_setup_rw (int rw,const struct iocb *iocb, -struct iovec **iovec,bool vectored,bool compat, -struct iov_iter *iter) +struct iovec **iovec,bool vectored,struct iov_iter *iter) {void __user *buf = (void __user *)(uintptr_t )iocb->aio_buf;size_t len = iocb->aio_nbytes;
@@ -1489,11 +1488,6 @@ static ssize_t aio_setup_rw(int rw, const struct iocb *iocb, *iovec =NULL ;return ret; } -#ifdef CONFIG_COMPAT -if (compat) -return compat_import_iovec (rw, buf, len,UIO_FASTIOV , iovec, - iter); -#endif return import_iovec (rw, buf, len,UIO_FASTIOV , iovec, iter); }
@@ -1517,8 +1511,7 @@ static inline void aio_rw_done(struct kiocb *req, ssize_t ret) } } -static int aio_read (struct kiocb *req,const struct iocb *iocb, -bool vectored,bool compat) +static int aio_read (struct kiocb *req,const struct iocb *iocb,bool vectored) {struct iovec inline_vecs[UIO_FASTIOV ], *iovec = inline_vecs;struct iov_iter iter;
@@ -1535,7 +1528,7 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb,if (unlikely (!file->f_op->read_iter))return -EINVAL ; - ret =aio_setup_rw (READ , iocb, &iovec, vectored, compat, &iter); + ret =aio_setup_rw (READ , iocb, &iovec, vectored, &iter);if (ret <0 )return ret; ret =rw_verify_area (READ , file, &req->ki_pos,iov_iter_count (&iter));
@@ -1545,8 +1538,7 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb,return ret; } -static int aio_write (struct kiocb *req,const struct iocb *iocb, -bool vectored,bool compat) +static int aio_write (struct kiocb *req,const struct iocb *iocb,bool vectored) {struct iovec inline_vecs[UIO_FASTIOV ], *iovec = inline_vecs;struct iov_iter iter;
@@ -1563,7 +1555,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,if (unlikely (!file->f_op->write_iter))return -EINVAL ; - ret =aio_setup_rw (WRITE , iocb, &iovec, vectored, compat, &iter); + ret =aio_setup_rw (WRITE , iocb, &iovec, vectored, &iter);if (ret <0 )return ret; ret =rw_verify_area (WRITE , file, &req->ki_pos,iov_iter_count (&iter));
@@ -1799,8 +1791,7 @@ static int aio_poll(struct aio_kiocb *aiocb, const struct iocb *iocb) }static int __io_submit_one (struct kioctx *ctx,const struct iocb *iocb, -struct iocb __user *user_iocb,struct aio_kiocb *req, -bool compat) +struct iocb __user *user_iocb,struct aio_kiocb *req) { req->ki_filp =fget (iocb->aio_fildes);if (unlikely (!req->ki_filp))
@@ -1833,13 +1824,13 @@ static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb,switch (iocb->aio_lio_opcode) {case IOCB_CMD_PREAD : -return aio_read (&req->rw, iocb, false, compat); +return aio_read (&req->rw, iocb, false);case IOCB_CMD_PWRITE : -return aio_write (&req->rw, iocb, false, compat); +return aio_write (&req->rw, iocb, false);case IOCB_CMD_PREADV : -return aio_read (&req->rw, iocb, true, compat); +return aio_read (&req->rw, iocb, true);case IOCB_CMD_PWRITEV : -return aio_write (&req->rw, iocb, true, compat); +return aio_write (&req->rw, iocb, true);case IOCB_CMD_FSYNC :return aio_fsync (&req->fsync, iocb, false);case IOCB_CMD_FDSYNC :
@@ -1852,8 +1843,7 @@ static int __io_submit_one(struct kioctx *ctx, const struct iocb *iocb, } } -static int io_submit_one (struct kioctx *ctx,struct iocb __user *user_iocb, -bool compat) +static int io_submit_one (struct kioctx *ctx,struct iocb __user *user_iocb) {struct aio_kiocb *req;struct iocb iocb;
@@ -1882,7 +1872,7 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,if (unlikely (!req))return -EAGAIN ; - err =__io_submit_one (ctx, &iocb, user_iocb, req, compat); + err =__io_submit_one (ctx, &iocb, user_iocb, req);/* Done with the synchronous reference */ iocb_put (req);
@@ -1941,7 +1931,7 @@ SYSCALL_DEFINE3(io_submit, aio_context_t, ctx_id, long, nr,break ; } - ret =io_submit_one (ctx, user_iocb, false); + ret =io_submit_one (ctx, user_iocb);if (ret)break ; }
@@ -1983,7 +1973,7 @@ COMPAT_SYSCALL_DEFINE3(io_submit, compat_aio_context_t, ctx_id,break ; } - ret =io_submit_one (ctx,compat_ptr (user_iocb), true); + ret =io_submit_one (ctx,compat_ptr (user_iocb));if (ret)break ; }
fs/io_uring.c +3 -9
@@ -2837,12 +2837,6 @@ static ssize_t __io_import_iovec(int rw, struct io_kiocb *req,return ret; } -#ifdef CONFIG_COMPAT -if (req->ctx->compat) -return compat_import_iovec (rw, buf, sqe_len,UIO_FASTIOV , - iovec, iter); -#endif -return import_iovec (rw, buf, sqe_len,UIO_FASTIOV , iovec, iter); }
@@ -4220,9 +4214,9 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req, sr->len = iomsg->iov[0 ].iov_len; iomsg->iov =NULL ; }else { - ret =compat_import_iovec (READ , uiov, len,UIO_FASTIOV , - &iomsg->iov, - &iomsg->msg.msg_iter); + ret =import_iovec (READ , (struct iovec __user *)uiov, len, +UIO_FASTIOV , &iomsg->iov, + &iomsg->msg.msg_iter);if (ret <0 )return ret; }
fs/read_write.c +46 -80
162 lines not on this page · raw message
fs/splice.c +1 -1
@@ -1387,7 +1387,7 @@ COMPAT_SYSCALL_DEFINE4(vmsplice, int, fd, const struct compat_iovec __user *, ioif (error)return error; - error =compat_import_iovec (type, iov32, nr_segs, + error =import_iovec (type, (struct iovec __user *)iov32, nr_segs,ARRAY_SIZE (iovstack), &iov, &iter);if (error >=0 ) { error =do_vmsplice (f.file, &iter, flags);
include/linux/compat.h +0 -6
@@ -451,12 +451,6 @@ extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,struct epoll_event ;/* fortunately, this one is fixed-layout */ -extern ssize_t compat_rw_copy_check_uvector (int type, -const struct compat_iovec __user *uvector, -unsigned long nr_segs, -unsigned long fast_segs,struct iovec *fast_pointer, -struct iovec **ret_pointer); -extern void __user *compat_alloc_user_space (unsigned long len);int compat_restore_altstack (const compat_stack_t __user *uss);
include/linux/fs.h +3 -4
@@ -179,10 +179,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,#define FMODE_BUF_RASYNC ((__force fmode_t)0x40000000)/* -* Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector -* that indicates that they should check the contents of the iovec are -* valid, but not check the memory that the iovec elements -* points too. +* Flag for rw_copy_check_uvector that indicates that they should check the +* contents of the iovec are valid, but not check the memory that the iovec +* elements points too. */ #define CHECK_IOVEC_ONLY -1
include/linux/uio.h +0 -7
@@ -270,13 +270,6 @@ ssize_t import_iovec(int type, const struct iovec __user * uvector, unsigned nr_segs, unsigned fast_segs, struct iovec **iov, struct iov_iter *i); -#ifdef CONFIG_COMPAT -struct compat_iovec ; -ssize_t compat_import_iovec (int type,const struct compat_iovec __user * uvector, -unsigned nr_segs,unsigned fast_segs, -struct iovec **iov,struct iov_iter *i); -#endif -int import_single_range (int type,void __user *buf,size_t len,struct iovec *iov,struct iov_iter *i);
lib/iov_iter.c +3 -27
@@ -10,6 +10,7 @@#include <net/checksum.h> #include <linux/scatterlist.h> #include <linux/instrumented.h> +#include <linux/compat.h> #define PIPE_PARANOIA /* for now */
@@ -1678,32 +1679,8 @@ ssize_t import_iovec(int type, const struct iovec __user * uvector, {ssize_t n;struct iovec *p; - n =rw_copy_check_uvector (type, uvector, nr_segs, fast_segs, - *iov, &p); -if (n <0 ) { -if (p != *iov) -kfree (p); - *iov =NULL ; -return n; - } -iov_iter_init (i, type, p, nr_segs, n); - *iov = p = *iov ?NULL : p; -return n; -} -EXPORT_SYMBOL (import_iovec); -#ifdef CONFIG_COMPAT -#include <linux/compat.h> - -ssize_t compat_import_iovec (int type, -const struct compat_iovec __user * uvector, -unsigned nr_segs,unsigned fast_segs, -struct iovec **iov,struct iov_iter *i) -{ -ssize_t n; -struct iovec *p; - n =compat_rw_copy_check_uvector (type, uvector, nr_segs, fast_segs, - *iov, &p); + n =rw_copy_check_uvector (type, uvector, nr_segs, fast_segs, *iov, &p);if (n <0 ) {if (p != *iov)kfree (p);
@@ -1714,8 +1691,7 @@ ssize_t compat_import_iovec(int type, *iov = p = *iov ?NULL : p;return n; } -EXPORT_SYMBOL (compat_import_iovec); -#endif +EXPORT_SYMBOL (import_iovec);int import_single_range (int rw,void __user *buf,size_t len,struct iovec *iov,struct iov_iter *i)
mm/process_vm_access.c +5 -4
@@ -329,14 +329,15 @@ compat_process_vm_rw(compat_pid_t pid,if (flags !=0 )return -EINVAL ; - rc =compat_import_iovec (dir, lvec, liovcnt,UIO_FASTIOV , &iov_l, &iter); + rc =import_iovec (dir, (const struct iovec __user *)lvec, liovcnt, +UIO_FASTIOV , &iov_l, &iter);if (rc <0 )return rc;if (!iov_iter_count (&iter)) goto free_iovecs; - rc =compat_rw_copy_check_uvector (CHECK_IOVEC_ONLY , rvec, riovcnt, -UIO_FASTIOV , iovstack_r, - &iov_r); + rc =rw_copy_check_uvector (CHECK_IOVEC_ONLY , + (const struct iovec __user *)rvec, riovcnt, +UIO_FASTIOV , iovstack_r, &iov_r);if (rc <=0 ) goto free_iovecs;
net/compat.c +2 -2
@@ -98,8 +98,8 @@ int get_compat_msghdr(struct msghdr *kmsg,if (err)return err; - err =compat_import_iovec (save_addr ?READ :WRITE ,compat_ptr (ptr), - len,UIO_FASTIOV , iov, &kmsg->msg_iter); + err =import_iovec (save_addr ?READ :WRITE ,compat_ptr (ptr), len, +UIO_FASTIOV , iov, &kmsg->msg_iter);return err <0 ? err :0 ; }
security/keys/compat.c +2 -3
@@ -33,9 +33,8 @@ static long compat_keyctl_instantiate_key_iov(if (!_payload_iov) ioc =0 ; - ret =compat_import_iovec (WRITE , _payload_iov, ioc, -ARRAY_SIZE (iovstack), &iov, - &from); + ret =import_iovec (WRITE , (const struct iovec __user *)_payload_iov, + ioc,ARRAY_SIZE (iovstack), &iov, &from);if (ret <0 )return ret;
Signature · 1 line
2.28.0
PATCH 5/9 fs: remove various compat readv/writev helpers
In reply to Christoph HellwigNow that import_iovec handles compat iovecs as well, all the duplicated code in the compat readv/writev helpers is not needed. Remove them and switch the compat syscall handlers to use the native helpers.
--- fs/read_write.c | 179 ++++++++---------------------------------------- 1 file changed, 30 insertions(+), 149 deletions(-)
fs/read_write.c +30 -149
@@ -1211,226 +1211,107 @@ SYSCALL_DEFINE6(pwritev2, unsigned long, fd, const struct iovec __user *, vec,return do_pwritev (fd, vec, vlen, pos, flags); } +/* +* Various compat syscalls. Note that they all pretend to take a native +* iovec - import_iovec will properly treat those as compat_iovecs based on +* in_compat_syscall(). +*/ #ifdef CONFIG_COMPAT -static size_t compat_readv (struct file *file, -const struct compat_iovec __user *vec, -unsigned long vlen,loff_t *pos,rwf_t flags) -{ -struct iovec iovstack[UIO_FASTIOV ]; -struct iovec *iov = iovstack; -struct iov_iter iter; -ssize_t ret; - - ret =import_iovec (READ , (const struct iovec __user *)vec, vlen, -UIO_FASTIOV , &iov, &iter); -if (ret >=0 ) { - ret =do_iter_read (file, &iter, pos, flags); -kfree (iov); - } -if (ret >0 ) -add_rchar (current, ret); -inc_syscr (current); -return ret; -} - -static size_t do_compat_readv (compat_ulong_t fd, -const struct compat_iovec __user *vec, -compat_ulong_t vlen,rwf_t flags) -{ -struct fd f =fdget_pos (fd); -ssize_t ret; -loff_t pos; - -if (!f.file) -return -EBADF ; - pos = f.file->f_pos; - ret =compat_readv (f.file, vec, vlen, &pos, flags); -if (ret >=0 ) - f.file->f_pos = pos; -fdput_pos (f); -return ret; - -} -COMPAT_SYSCALL_DEFINE3 (readv, compat_ulong_t, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *, vec, compat_ulong_t, vlen) { -return do_compat_readv (fd, vec, vlen,0 ); -} - -static long do_compat_preadv64 (unsigned long fd, -const struct compat_iovec __user *vec, -unsigned long vlen,loff_t pos,rwf_t flags) -{ -struct fd f; -ssize_t ret; - -if (pos <0 ) -return -EINVAL ; - f =fdget (fd); -if (!f.file) -return -EBADF ; - ret = -ESPIPE ; -if (f.file->f_mode &FMODE_PREAD ) - ret =compat_readv (f.file, vec, vlen, &pos, flags); -fdput (f); -return ret; +return do_readv (fd, vec, vlen,0 ); }#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64 COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *, vec, unsigned long, vlen, loff_t, pos) { -return do_compat_preadv64 (fd, vec, vlen, pos,0 ); +return do_preadv (fd, vec, vlen, pos,0 ); }#endif COMPAT_SYSCALL_DEFINE5 (preadv, compat_ulong_t, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *, vec, compat_ulong_t, vlen, u32, pos_low, u32, pos_high) {loff_t pos = ((loff_t )pos_high <<32 ) | pos_low; -return do_compat_preadv64 (fd, vec, vlen, pos,0 ); +return do_preadv (fd, vec, vlen, pos,0 ); }#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64V2 COMPAT_SYSCALL_DEFINE5(preadv64v2, unsigned long, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *, vec, unsigned long, vlen, loff_t, pos, rwf_t, flags) {if (pos =-1 ) -return do_compat_readv (fd, vec, vlen, flags); - -return do_compat_preadv64 (fd, vec, vlen, pos, flags); +return do_readv (fd, vec, vlen, flags); +return do_preadv (fd, vec, vlen, pos, flags); }#endif COMPAT_SYSCALL_DEFINE6 (preadv2, compat_ulong_t, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *, vec, compat_ulong_t, vlen, u32, pos_low, u32, pos_high, rwf_t, flags) {loff_t pos = ((loff_t )pos_high <<32 ) | pos_low;if (pos =-1 ) -return do_compat_readv (fd, vec, vlen, flags); - -return do_compat_preadv64 (fd, vec, vlen, pos, flags); -} - -static size_t compat_writev (struct file *file, -const struct compat_iovec __user *vec, -unsigned long vlen,loff_t *pos,rwf_t flags) -{ -struct iovec iovstack[UIO_FASTIOV ]; -struct iovec *iov = iovstack; -struct iov_iter iter; -ssize_t ret; - - ret =import_iovec (WRITE , (const struct iovec __user *)vec, vlen, -UIO_FASTIOV , &iov, &iter); -if (ret >=0 ) { -file_start_write (file); - ret =do_iter_write (file, &iter, pos, flags); -file_end_write (file); -kfree (iov); - } -if (ret >0 ) -add_wchar (current, ret); -inc_syscw (current); -return ret; -} - -static size_t do_compat_writev (compat_ulong_t fd, -const struct compat_iovec __user * vec, -compat_ulong_t vlen,rwf_t flags) -{ -struct fd f =fdget_pos (fd); -ssize_t ret; -loff_t pos; - -if (!f.file) -return -EBADF ; - pos = f.file->f_pos; - ret =compat_writev (f.file, vec, vlen, &pos, flags); -if (ret >=0 ) - f.file->f_pos = pos; -fdput_pos (f); -return ret; +return do_readv (fd, vec, vlen, flags); +return do_preadv (fd, vec, vlen, pos, flags); }COMPAT_SYSCALL_DEFINE3 (writev, compat_ulong_t, fd, - const struct compat_iovec __user *, vec, + const struct iovec __user *, vec, compat_ulong_t, vlen) { -return do_compat_writev (fd, vec, vlen,0 ); -} - -static long do_compat_pwritev64 (unsigned long fd, -const struct compat_iovec __user *vec, -unsigned long vlen,loff_t pos,rwf_t flags) -{ -struct fd f; -ssize_t ret; - -if (pos <0 ) -return -EINVAL ; - f =fdget (fd); -if (!f.file) -return -EBADF ; - ret = -ESPIPE ; -if (f.file->f_mode &FMODE_PWRITE ) - ret =compat_writev (f.file, vec, vlen, &pos, flags); -fdput (f); -return ret; +return do_writev (fd, vec, vlen,0 ); }#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64 COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *, vec, unsigned long, vlen, loff_t, pos) { -return do_compat_pwritev64 (fd, vec, vlen, pos,0 ); +return do_pwritev (fd, vec, vlen, pos,0 ); }#endif COMPAT_SYSCALL_DEFINE5 (pwritev, compat_ulong_t, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *,vec, compat_ulong_t, vlen, u32, pos_low, u32, pos_high) {loff_t pos = ((loff_t )pos_high <<32 ) | pos_low; -return do_compat_pwritev64 (fd, vec, vlen, pos,0 ); +return do_pwritev (fd, vec, vlen, pos,0 ); }#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64V2 COMPAT_SYSCALL_DEFINE5(pwritev64v2, unsigned long, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *, vec, unsigned long, vlen, loff_t, pos, rwf_t, flags) {if (pos =-1 ) -return do_compat_writev (fd, vec, vlen, flags); - -return do_compat_pwritev64 (fd, vec, vlen, pos, flags); +return do_writev (fd, vec, vlen, flags); +return do_pwritev (fd, vec, vlen, pos, flags); }#endif COMPAT_SYSCALL_DEFINE6 (pwritev2, compat_ulong_t, fd, - const struct compat_iovec __user *,vec, + const struct iovec __user *,vec, compat_ulong_t, vlen, u32, pos_low, u32, pos_high, rwf_t, flags) {loff_t pos = ((loff_t )pos_high <<32 ) | pos_low;if (pos =-1 ) -return do_compat_writev (fd, vec, vlen, flags); - -return do_compat_pwritev64 (fd, vec, vlen, pos, flags); +return do_writev (fd, vec, vlen, flags); +return do_pwritev (fd, vec, vlen, pos, flags); } - -#endif +#endif /* CONFIG_COMPAT */ static ssize_t do_sendfile (int out_fd,int in_fd,loff_t *ppos,size_t count,loff_t max)
Signature · 1 line
2.28.0
PATCH 6/9 fs: remove the compat readv/writev syscalls
In reply to Christoph HellwigNow that import_iovec handles compat iovecs, the native readv and writev syscalls can be used for the compat case as well.
--- arch/arm64/include/asm/unistd32.h | 4 ++-- arch/mips/kernel/syscalls/syscall_n32.tbl | 4 ++-- arch/mips/kernel/syscalls/syscall_o32.tbl | 4 ++-- arch/parisc/kernel/syscalls/syscall.tbl | 4 ++-- arch/powerpc/kernel/syscalls/syscall.tbl | 4 ++-- arch/s390/kernel/syscalls/syscall.tbl | 4 ++-- arch/sparc/kernel/syscalls/syscall.tbl | 4 ++-- arch/x86/entry/syscall_x32.c | 2 ++ arch/x86/entry/syscalls/syscall_32.tbl | 4 ++-- arch/x86/entry/syscalls/syscall_64.tbl | 4 ++-- fs/read_write.c | 14 -------------- include/linux/compat.h | 4 ---- include/uapi/asm-generic/unistd.h | 4 ++-- tools/include/uapi/asm-generic/unistd.h | 4 ++-- tools/perf/arch/powerpc/entry/syscalls/syscall.tbl | 4 ++-- tools/perf/arch/s390/entry/syscalls/syscall.tbl | 4 ++-- tools/perf/arch/x86/entry/syscalls/syscall_64.tbl | 4 ++-- 17 files changed, 30 insertions(+), 46 deletions(-)
arch/arm64/include/asm/unistd32.h +2 -2
@@ -301,9 +301,9 @@ __SYSCALL(__NR_flock, sys_flock)#define __NR_msync 144 __SYSCALL(__NR_msync, sys_msync)#define __NR_readv 145 -__SYSCALL(__NR_readv, compat_sys_readv) +__SYSCALL(__NR_readv, sys_readv)#define __NR_writev 146 -__SYSCALL(__NR_writev, compat_sys_writev) +__SYSCALL(__NR_writev, sys_writev)#define __NR_getsid 147 __SYSCALL(__NR_getsid, sys_getsid)#define __NR_fdatasync 148
arch/mips/kernel/syscalls/syscall_n32.tbl +2 -2
@@ -25,8 +25,8 @@ 15 n32 ioctl compat_sys_ioctl 16 n32 pread64 sys_pread64 17 n32 pwrite64 sys_pwrite64 -18 n32 readv compat_sys_readv -19 n32 writev compat_sys_writev +18 n32 readv sys_readv +19 n32 writev sys_writev 20 n32 access sys_access 21 n32 pipe sysm_pipe 22 n32 _newselect compat_sys_select
arch/mips/kernel/syscalls/syscall_o32.tbl +2 -2
@@ -156,8 +156,8 @@ 142 o32 _newselect sys_select compat_sys_select 143 o32 flock sys_flock 144 o32 msync sys_msync -145 o32 readv sys_readv compat_sys_readv -146 o32 writev sys_writev compat_sys_writev +145 o32 readv sys_readv +146 o32 writev sys_writev 147 o32 cacheflush sys_cacheflush 148 o32 cachectl sys_cachectl 149 o32 sysmips __sys_sysmips
arch/parisc/kernel/syscalls/syscall.tbl +2 -2
@@ -159,8 +159,8 @@ 142 common _newselect sys_select compat_sys_select 143 common flock sys_flock 144 common msync sys_msync -145 common readv sys_readv compat_sys_readv -146 common writev sys_writev compat_sys_writev +145 common readv sys_readv +146 common writev sys_writev 147 common getsid sys_getsid 148 common fdatasync sys_fdatasync 149 common _sysctl sys_ni_syscall
arch/powerpc/kernel/syscalls/syscall.tbl +2 -2
@@ -193,8 +193,8 @@ 142 common _newselect sys_select compat_sys_select 143 common flock sys_flock 144 common msync sys_msync -145 common readv sys_readv compat_sys_readv -146 common writev sys_writev compat_sys_writev +145 common readv sys_readv +146 common writev sys_writev 147 common getsid sys_getsid 148 common fdatasync sys_fdatasync 149 nospu _sysctl sys_ni_syscall
arch/s390/kernel/syscalls/syscall.tbl +2 -2
@@ -134,8 +134,8 @@ 142 64 select sys_select - 143 common flock sys_flock sys_flock 144 common msync sys_msync sys_msync -145 common readv sys_readv compat_sys_readv -146 common writev sys_writev compat_sys_writev +145 common readv sys_readv sys_readv +146 common writev sys_writev sys_writev 147 common getsid sys_getsid sys_getsid 148 common fdatasync sys_fdatasync sys_fdatasync 149 common _sysctl - -
arch/sparc/kernel/syscalls/syscall.tbl +2 -2
@@ -149,8 +149,8 @@ 117 common getrusage sys_getrusage compat_sys_getrusage 118 common getsockopt sys_getsockopt sys_getsockopt 119 common getcwd sys_getcwd -120 common readv sys_readv compat_sys_readv -121 common writev sys_writev compat_sys_writev +120 common readv sys_readv +121 common writev sys_writev 122 common settimeofday sys_settimeofday compat_sys_settimeofday 123 32 fchown sys_fchown16 123 64 fchown sys_fchown
arch/x86/entry/syscall_x32.c +2 -0
@@ -12,6 +12,8 @@* Reuse the 64-bit entry points for the x32 versions that occupy different * slots in the syscall table. */ +#define __x32_sys_readv __x64_sys_readv +#define __x32_sys_writev __x64_sys_writev#define __x32_sys_getsockopt __x64_sys_getsockopt#define __x32_sys_setsockopt __x64_sys_setsockopt
arch/x86/entry/syscalls/syscall_32.tbl +2 -2
@@ -156,8 +156,8 @@ 142 i386 _newselect sys_select compat_sys_select 143 i386 flock sys_flock 144 i386 msync sys_msync -145 i386 readv sys_readv compat_sys_readv -146 i386 writev sys_writev compat_sys_writev +145 i386 readv sys_readv +146 i386 writev sys_writev 147 i386 getsid sys_getsid 148 i386 fdatasync sys_fdatasync 149 i386 _sysctl sys_ni_syscall
arch/x86/entry/syscalls/syscall_64.tbl +2 -2
@@ -371,8 +371,8 @@ 512 x32 rt_sigaction compat_sys_rt_sigaction 513 x32 rt_sigreturn compat_sys_x32_rt_sigreturn 514 x32 ioctl compat_sys_ioctl -515 x32 readv compat_sys_readv -516 x32 writev compat_sys_writev +515 x32 readv sys_readv +516 x32 writev sys_writev 517 x32 recvfrom compat_sys_recvfrom 518 x32 sendmsg compat_sys_sendmsg 519 x32 recvmsg compat_sys_recvmsg
fs/read_write.c +0 -14
@@ -1217,13 +1217,6 @@ SYSCALL_DEFINE6(pwritev2, unsigned long, fd, const struct iovec __user *, vec,* in_compat_syscall(). */ #ifdef CONFIG_COMPAT -COMPAT_SYSCALL_DEFINE3 (readv, compat_ulong_t, fd, - const struct iovec __user *, vec, - compat_ulong_t, vlen) -{ -return do_readv (fd, vec, vlen,0 ); -} -#ifdef __ARCH_WANT_COMPAT_SYS_PREADV64 COMPAT_SYSCALL_DEFINE4(preadv64, unsigned long, fd, const struct iovec __user *, vec,
@@ -1265,13 +1258,6 @@ COMPAT_SYSCALL_DEFINE6(preadv2, compat_ulong_t, fd,return do_preadv (fd, vec, vlen, pos, flags); } -COMPAT_SYSCALL_DEFINE3 (writev, compat_ulong_t, fd, - const struct iovec __user *, vec, - compat_ulong_t, vlen) -{ -return do_writev (fd, vec, vlen,0 ); -} -#ifdef __ARCH_WANT_COMPAT_SYS_PWRITEV64 COMPAT_SYSCALL_DEFINE4(pwritev64, unsigned long, fd, const struct iovec __user *, vec,
include/linux/compat.h +0 -4
@@ -545,10 +545,6 @@ asmlinkage long compat_sys_getdents(unsigned int fd,/* fs/read_write.c */ asmlinkage long compat_sys_lseek (unsigned int ,compat_off_t ,unsigned int ); -asmlinkage ssize_t compat_sys_readv(compat_ulong_t fd, -const struct compat_iovec __user *vec,compat_ulong_t vlen); -asmlinkage ssize_t compat_sys_writev(compat_ulong_t fd, -const struct compat_iovec __user *vec,compat_ulong_t vlen);/* No generic prototype for pread64 and pwrite64 */ asmlinkage ssize_t compat_sys_preadv(compat_ulong_t fd, const struct compat_iovec __user *vec,
include/uapi/asm-generic/unistd.h +2 -2
@@ -207,9 +207,9 @@ __SYSCALL(__NR_read, sys_read)#define __NR_write 64 __SYSCALL(__NR_write, sys_write)#define __NR_readv 65 -__SC_COMP(__NR_readv, sys_readv, compat_sys_readv) +__SC_COMP(__NR_readv, sys_readv, sys_readv)#define __NR_writev 66 -__SC_COMP(__NR_writev, sys_writev, compat_sys_writev) +__SC_COMP(__NR_writev, sys_writev, sys_writev)#define __NR_pread64 67 __SC_COMP(__NR_pread64, sys_pread64, compat_sys_pread64)#define __NR_pwrite64 68
tools/include/uapi/asm-generic/unistd.h +2 -2
@@ -207,9 +207,9 @@ __SYSCALL(__NR_read, sys_read)#define __NR_write 64 __SYSCALL(__NR_write, sys_write)#define __NR_readv 65 -__SC_COMP(__NR_readv, sys_readv, compat_sys_readv) +__SC_COMP(__NR_readv, sys_readv, sys_readv)#define __NR_writev 66 -__SC_COMP(__NR_writev, sys_writev, compat_sys_writev) +__SC_COMP(__NR_writev, sys_writev, sys_writev)#define __NR_pread64 67 __SC_COMP(__NR_pread64, sys_pread64, compat_sys_pread64)#define __NR_pwrite64 68
tools/perf/arch/powerpc/entry/syscalls/syscall.tbl +2 -2
@@ -189,8 +189,8 @@ 142 common _newselect sys_select compat_sys_select 143 common flock sys_flock 144 common msync sys_msync -145 common readv sys_readv compat_sys_readv -146 common writev sys_writev compat_sys_writev +145 common readv sys_readv +146 common writev sys_writev 147 common getsid sys_getsid 148 common fdatasync sys_fdatasync 149 nospu _sysctl sys_ni_syscall
tools/perf/arch/s390/entry/syscalls/syscall.tbl +2 -2
@@ -134,8 +134,8 @@ 142 64 select sys_select - 143 common flock sys_flock sys_flock 144 common msync sys_msync compat_sys_msync -145 common readv sys_readv compat_sys_readv -146 common writev sys_writev compat_sys_writev +145 common readv sys_readv +146 common writev sys_writev 147 common getsid sys_getsid sys_getsid 148 common fdatasync sys_fdatasync sys_fdatasync 149 common _sysctl - -
tools/perf/arch/x86/entry/syscalls/syscall_64.tbl +2 -2
@@ -371,8 +371,8 @@ 512 x32 rt_sigaction compat_sys_rt_sigaction 513 x32 rt_sigreturn compat_sys_x32_rt_sigreturn 514 x32 ioctl compat_sys_ioctl -515 x32 readv compat_sys_readv -516 x32 writev compat_sys_writev +515 x32 readv sys_readv +516 x32 writev sys_writev 517 x32 recvfrom compat_sys_recvfrom 518 x32 sendmsg compat_sys_sendmsg 519 x32 recvmsg compat_sys_recvmsg
Signature · 1 line
2.28.0
PATCH 7/9 fs: remove compat_sys_vmsplice
In reply to Christoph HellwigNow that import_iovec handles compat iovecs, the native vmsplice syscall can be used for the compat case as well.
--- arch/arm64/include/asm/unistd32.h | 2 +- arch/mips/kernel/syscalls/syscall_n32.tbl | 2 +- arch/mips/kernel/syscalls/syscall_o32.tbl | 2 +- arch/parisc/kernel/syscalls/syscall.tbl | 2 +- arch/powerpc/kernel/syscalls/syscall.tbl | 2 +- arch/s390/kernel/syscalls/syscall.tbl | 2 +- arch/sparc/kernel/syscalls/syscall.tbl | 2 +- arch/x86/entry/syscall_x32.c | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 2 +- arch/x86/entry/syscalls/syscall_64.tbl | 2 +- fs/splice.c | 57 +++++-------------- include/linux/compat.h | 4 -- include/uapi/asm-generic/unistd.h | 2 +- tools/include/uapi/asm-generic/unistd.h | 2 +- .../arch/powerpc/entry/syscalls/syscall.tbl | 2 +- .../perf/arch/s390/entry/syscalls/syscall.tbl | 2 +- .../arch/x86/entry/syscalls/syscall_64.tbl | 2 +- 17 files changed, 28 insertions(+), 62 deletions(-)
arch/arm64/include/asm/unistd32.h +1 -1
@@ -697,7 +697,7 @@ __SYSCALL(__NR_sync_file_range2, compat_sys_aarch32_sync_file_range2)#define __NR_tee 342 __SYSCALL(__NR_tee, sys_tee)#define __NR_vmsplice 343 -__SYSCALL(__NR_vmsplice, compat_sys_vmsplice) +__SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_move_pages 344 __SYSCALL(__NR_move_pages, compat_sys_move_pages)#define __NR_getcpu 345
arch/mips/kernel/syscalls/syscall_n32.tbl +1 -1
@@ -278,7 +278,7 @@ 267 n32 splice sys_splice 268 n32 sync_file_range sys_sync_file_range 269 n32 tee sys_tee -270 n32 vmsplice compat_sys_vmsplice +270 n32 vmsplice sys_vmsplice 271 n32 move_pages compat_sys_move_pages 272 n32 set_robust_list compat_sys_set_robust_list 273 n32 get_robust_list compat_sys_get_robust_list
arch/mips/kernel/syscalls/syscall_o32.tbl +1 -1
@@ -318,7 +318,7 @@ 304 o32 splice sys_splice 305 o32 sync_file_range sys_sync_file_range sys32_sync_file_range 306 o32 tee sys_tee -307 o32 vmsplice sys_vmsplice compat_sys_vmsplice +307 o32 vmsplice sys_vmsplice 308 o32 move_pages sys_move_pages compat_sys_move_pages 309 o32 set_robust_list sys_set_robust_list compat_sys_set_robust_list 310 o32 get_robust_list sys_get_robust_list compat_sys_get_robust_list
arch/parisc/kernel/syscalls/syscall.tbl +1 -1
@@ -330,7 +330,7 @@ 292 32 sync_file_range parisc_sync_file_range 292 64 sync_file_range sys_sync_file_range 293 common tee sys_tee -294 common vmsplice sys_vmsplice compat_sys_vmsplice +294 common vmsplice sys_vmsplice 295 common move_pages sys_move_pages compat_sys_move_pages 296 common getcpu sys_getcpu 297 common epoll_pwait sys_epoll_pwait compat_sys_epoll_pwait
arch/powerpc/kernel/syscalls/syscall.tbl +1 -1
@@ -369,7 +369,7 @@ 282 common unshare sys_unshare 283 common splice sys_splice 284 common tee sys_tee -285 common vmsplice sys_vmsplice compat_sys_vmsplice +285 common vmsplice sys_vmsplice 286 common openat sys_openat compat_sys_openat 287 common mkdirat sys_mkdirat 288 common mknodat sys_mknodat
arch/s390/kernel/syscalls/syscall.tbl +1 -1
@@ -316,7 +316,7 @@ 306 common splice sys_splice sys_splice 307 common sync_file_range sys_sync_file_range compat_sys_s390_sync_file_range 308 common tee sys_tee sys_tee -309 common vmsplice sys_vmsplice compat_sys_vmsplice +309 common vmsplice sys_vmsplice sys_vmsplice 310 common move_pages sys_move_pages compat_sys_move_pages 311 common getcpu sys_getcpu sys_getcpu 312 common epoll_pwait sys_epoll_pwait compat_sys_epoll_pwait
arch/sparc/kernel/syscalls/syscall.tbl +1 -1
@@ -38,7 +38,7 @@ 23 64 setuid sys_setuid 24 32 getuid sys_getuid16 24 64 getuid sys_getuid -25 common vmsplice sys_vmsplice compat_sys_vmsplice +25 common vmsplice sys_vmsplice 26 common ptrace sys_ptrace compat_sys_ptrace 27 common alarm sys_alarm 28 common sigaltstack sys_sigaltstack compat_sys_sigaltstack
arch/x86/entry/syscall_x32.c +1 -0
@@ -16,6 +16,7 @@#define __x32_sys_writev __x64_sys_writev#define __x32_sys_getsockopt __x64_sys_getsockopt#define __x32_sys_setsockopt __x64_sys_setsockopt +#define __x32_sys_vmsplice __x64_sys_vmsplice#define __SYSCALL_64 (nr, sym)
arch/x86/entry/syscalls/syscall_32.tbl +1 -1
@@ -327,7 +327,7 @@ 313 i386 splice sys_splice 314 i386 sync_file_range sys_ia32_sync_file_range 315 i386 tee sys_tee -316 i386 vmsplice sys_vmsplice compat_sys_vmsplice +316 i386 vmsplice sys_vmsplice 317 i386 move_pages sys_move_pages compat_sys_move_pages 318 i386 getcpu sys_getcpu 319 i386 epoll_pwait sys_epoll_pwait
arch/x86/entry/syscalls/syscall_64.tbl +1 -1
@@ -388,7 +388,7 @@ 529 x32 waitid compat_sys_waitid 530 x32 set_robust_list compat_sys_set_robust_list 531 x32 get_robust_list compat_sys_get_robust_list -532 x32 vmsplice compat_sys_vmsplice +532 x32 vmsplice sys_vmsplice 533 x32 move_pages compat_sys_move_pages 534 x32 preadv compat_sys_preadv64 535 x32 pwritev compat_sys_pwritev64
fs/splice.c +13 -44
86 lines not on this page · raw message
include/linux/compat.h +0 -4
@@ -597,10 +597,6 @@ asmlinkage long compat_sys_signalfd4(int ufd,const compat_sigset_t __user *sigmask, compat_size_t sigsetsize, int flags); -/* fs/splice.c */ -asmlinkage long compat_sys_vmsplice (int fd,const struct compat_iovec __user *, -unsigned int nr_segs,unsigned int flags); -/* fs/stat.c */ asmlinkage long compat_sys_newfstatat(unsigned int dfd, const char __user *filename,
include/uapi/asm-generic/unistd.h +1 -1
@@ -237,7 +237,7 @@ __SC_COMP(__NR_signalfd4, sys_signalfd4, compat_sys_signalfd4)/* fs/splice.c */ #define __NR_vmsplice 75 -__SC_COMP(__NR_vmsplice, sys_vmsplice, compat_sys_vmsplice) +__SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_splice 76 __SYSCALL(__NR_splice, sys_splice)#define __NR_tee 77
tools/include/uapi/asm-generic/unistd.h +1 -1
@@ -237,7 +237,7 @@ __SC_COMP(__NR_signalfd4, sys_signalfd4, compat_sys_signalfd4)/* fs/splice.c */ #define __NR_vmsplice 75 -__SC_COMP(__NR_vmsplice, sys_vmsplice, compat_sys_vmsplice) +__SYSCALL(__NR_vmsplice, sys_vmsplice)#define __NR_splice 76 __SYSCALL(__NR_splice, sys_splice)#define __NR_tee 77
tools/perf/arch/powerpc/entry/syscalls/syscall.tbl +1 -1
@@ -363,7 +363,7 @@ 282 common unshare sys_unshare 283 common splice sys_splice 284 common tee sys_tee -285 common vmsplice sys_vmsplice compat_sys_vmsplice +285 common vmsplice sys_vmsplice 286 common openat sys_openat compat_sys_openat 287 common mkdirat sys_mkdirat 288 common mknodat sys_mknodat
tools/perf/arch/s390/entry/syscalls/syscall.tbl +1 -1
@@ -316,7 +316,7 @@ 306 common splice sys_splice compat_sys_splice 307 common sync_file_range sys_sync_file_range compat_sys_s390_sync_file_range 308 common tee sys_tee compat_sys_tee -309 common vmsplice sys_vmsplice compat_sys_vmsplice +309 common vmsplice sys_vmsplice sys_vmsplice 310 common move_pages sys_move_pages compat_sys_move_pages 311 common getcpu sys_getcpu compat_sys_getcpu 312 common epoll_pwait sys_epoll_pwait compat_sys_epoll_pwait
tools/perf/arch/x86/entry/syscalls/syscall_64.tbl +1 -1
@@ -388,7 +388,7 @@ 529 x32 waitid compat_sys_waitid 530 x32 set_robust_list compat_sys_set_robust_list 531 x32 get_robust_list compat_sys_get_robust_list -532 x32 vmsplice compat_sys_vmsplice +532 x32 vmsplice sys_vmsplice 533 x32 move_pages compat_sys_move_pages 534 x32 preadv compat_sys_preadv64 535 x32 pwritev compat_sys_pwritev64
Signature · 1 line
2.28.0
PATCH 8/9 mm: remove compat_process_vm_{readv,writev}
In reply to Christoph HellwigNow that import_iovec handles compat iovecs, the native syscalls can be used for the compat case as well.
--- arch/arm64/include/asm/unistd32.h | 4 +- arch/mips/kernel/syscalls/syscall_n32.tbl | 4 +- arch/mips/kernel/syscalls/syscall_o32.tbl | 4 +- arch/parisc/kernel/syscalls/syscall.tbl | 4 +- arch/powerpc/kernel/syscalls/syscall.tbl | 4 +- arch/s390/kernel/syscalls/syscall.tbl | 4 +- arch/sparc/kernel/syscalls/syscall.tbl | 4 +- arch/x86/entry/syscall_x32.c | 2 + arch/x86/entry/syscalls/syscall_32.tbl | 4 +- arch/x86/entry/syscalls/syscall_64.tbl | 4 +- include/linux/compat.h | 8 --- include/uapi/asm-generic/unistd.h | 6 +- mm/process_vm_access.c | 70 ------------------- tools/include/uapi/asm-generic/unistd.h | 6 +- .../arch/powerpc/entry/syscalls/syscall.tbl | 4 +- .../perf/arch/s390/entry/syscalls/syscall.tbl | 4 +- .../arch/x86/entry/syscalls/syscall_64.tbl | 4 +- 17 files changed, 30 insertions(+), 110 deletions(-)
arch/arm64/include/asm/unistd32.h +2 -2
@@ -763,9 +763,9 @@ __SYSCALL(__NR_sendmmsg, compat_sys_sendmmsg)#define __NR_setns 375 __SYSCALL(__NR_setns, sys_setns)#define __NR_process_vm_readv 376 -__SYSCALL(__NR_process_vm_readv, compat_sys_process_vm_readv) +__SYSCALL(__NR_process_vm_readv, sys_process_vm_readv)#define __NR_process_vm_writev 377 -__SYSCALL(__NR_process_vm_writev, compat_sys_process_vm_writev) +__SYSCALL(__NR_process_vm_writev, sys_process_vm_writev)#define __NR_kcmp 378 __SYSCALL(__NR_kcmp, sys_kcmp)#define __NR_finit_module 379
arch/mips/kernel/syscalls/syscall_n32.tbl +2 -2
@@ -317,8 +317,8 @@ 306 n32 syncfs sys_syncfs 307 n32 sendmmsg compat_sys_sendmmsg 308 n32 setns sys_setns -309 n32 process_vm_readv compat_sys_process_vm_readv -310 n32 process_vm_writev compat_sys_process_vm_writev +309 n32 process_vm_readv sys_process_vm_readv +310 n32 process_vm_writev sys_process_vm_writev 311 n32 kcmp sys_kcmp 312 n32 finit_module sys_finit_module 313 n32 sched_setattr sys_sched_setattr
arch/mips/kernel/syscalls/syscall_o32.tbl +2 -2
@@ -356,8 +356,8 @@ 342 o32 syncfs sys_syncfs 343 o32 sendmmsg sys_sendmmsg compat_sys_sendmmsg 344 o32 setns sys_setns -345 o32 process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv -346 o32 process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev +345 o32 process_vm_readv sys_process_vm_readv +346 o32 process_vm_writev sys_process_vm_writev 347 o32 kcmp sys_kcmp 348 o32 finit_module sys_finit_module 349 o32 sched_setattr sys_sched_setattr
arch/parisc/kernel/syscalls/syscall.tbl +2 -2
@@ -372,8 +372,8 @@ 327 common syncfs sys_syncfs 328 common setns sys_setns 329 common sendmmsg sys_sendmmsg compat_sys_sendmmsg -330 common process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv -331 common process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev +330 common process_vm_readv sys_process_vm_readv +331 common process_vm_writev sys_process_vm_writev 332 common kcmp sys_kcmp 333 common finit_module sys_finit_module 334 common sched_setattr sys_sched_setattr
arch/powerpc/kernel/syscalls/syscall.tbl +2 -2
@@ -449,8 +449,8 @@ 348 common syncfs sys_syncfs 349 common sendmmsg sys_sendmmsg compat_sys_sendmmsg 350 common setns sys_setns -351 nospu process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv -352 nospu process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev +351 nospu process_vm_readv sys_process_vm_readv +352 nospu process_vm_writev sys_process_vm_writev 353 nospu finit_module sys_finit_module 354 nospu kcmp sys_kcmp 355 common sched_setattr sys_sched_setattr
arch/s390/kernel/syscalls/syscall.tbl +2 -2
@@ -347,8 +347,8 @@ 337 common clock_adjtime sys_clock_adjtime sys_clock_adjtime32 338 common syncfs sys_syncfs sys_syncfs 339 common setns sys_setns sys_setns -340 common process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv -341 common process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev +340 common process_vm_readv sys_process_vm_readv sys_process_vm_readv +341 common process_vm_writev sys_process_vm_writev sys_process_vm_writev 342 common s390_runtime_instr sys_s390_runtime_instr sys_s390_runtime_instr 343 common kcmp sys_kcmp sys_kcmp 344 common finit_module sys_finit_module sys_finit_module
arch/sparc/kernel/syscalls/syscall.tbl +2 -2
@@ -406,8 +406,8 @@ 335 common syncfs sys_syncfs 336 common sendmmsg sys_sendmmsg compat_sys_sendmmsg 337 common setns sys_setns -338 common process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv -339 common process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev +338 common process_vm_readv sys_process_vm_readv +339 common process_vm_writev sys_process_vm_writev 340 32 kern_features sys_ni_syscall sys_kern_features 340 64 kern_features sys_kern_features 341 common kcmp sys_kcmp
arch/x86/entry/syscall_x32.c +2 -0
@@ -17,6 +17,8 @@#define __x32_sys_getsockopt __x64_sys_getsockopt#define __x32_sys_setsockopt __x64_sys_setsockopt#define __x32_sys_vmsplice __x64_sys_vmsplice +#define __x32_sys_process_vm_readv __x64_sys_process_vm_readv +#define __x32_sys_process_vm_writev __x64_sys_process_vm_writev#define __SYSCALL_64 (nr, sym)
arch/x86/entry/syscalls/syscall_32.tbl +2 -2
@@ -358,8 +358,8 @@ 344 i386 syncfs sys_syncfs 345 i386 sendmmsg sys_sendmmsg compat_sys_sendmmsg 346 i386 setns sys_setns -347 i386 process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv -348 i386 process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev +347 i386 process_vm_readv sys_process_vm_readv +348 i386 process_vm_writev sys_process_vm_writev 349 i386 kcmp sys_kcmp 350 i386 finit_module sys_finit_module 351 i386 sched_setattr sys_sched_setattr
arch/x86/entry/syscalls/syscall_64.tbl +2 -2
@@ -395,8 +395,8 @@ 536 x32 rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo 537 x32 recvmmsg compat_sys_recvmmsg_time64 538 x32 sendmmsg compat_sys_sendmmsg -539 x32 process_vm_readv compat_sys_process_vm_readv -540 x32 process_vm_writev compat_sys_process_vm_writev +539 x32 process_vm_readv sys_process_vm_readv +540 x32 process_vm_writev sys_process_vm_writev 541 x32 setsockopt sys_setsockopt 542 x32 getsockopt sys_getsockopt 543 x32 io_setup compat_sys_io_setup
include/linux/compat.h +0 -8
@@ -780,14 +780,6 @@ asmlinkage long compat_sys_open_by_handle_at(int mountdirfd, int flags);asmlinkage long compat_sys_sendmmsg (int fd,struct compat_mmsghdr __user *mmsg,unsigned vlen,unsigned int flags); -asmlinkage ssize_t compat_sys_process_vm_readv(compat_pid_t pid, -const struct compat_iovec __user *lvec, -compat_ulong_t liovcnt,const struct compat_iovec __user *rvec, -compat_ulong_t riovcnt,compat_ulong_t flags); -asmlinkage ssize_t compat_sys_process_vm_writev(compat_pid_t pid, -const struct compat_iovec __user *lvec, -compat_ulong_t liovcnt,const struct compat_iovec __user *rvec, -compat_ulong_t riovcnt,compat_ulong_t flags);asmlinkage long compat_sys_execveat (int dfd,const char __user *filename,const compat_uptr_t __user *argv,const compat_uptr_t __user *envp,int flags);
include/uapi/asm-generic/unistd.h +2 -4
@@ -727,11 +727,9 @@ __SYSCALL(__NR_setns, sys_setns)#define __NR_sendmmsg 269 __SC_COMP(__NR_sendmmsg, sys_sendmmsg, compat_sys_sendmmsg)#define __NR_process_vm_readv 270 -__SC_COMP (__NR_process_vm_readv, sys_process_vm_readv, \ - compat_sys_process_vm_readv) +__SYSCALL(__NR_process_vm_readv, sys_process_vm_readv)#define __NR_process_vm_writev 271 -__SC_COMP (__NR_process_vm_writev, sys_process_vm_writev, \ - compat_sys_process_vm_writev) +__SYSCALL(__NR_process_vm_writev, sys_process_vm_writev)#define __NR_kcmp 272 __SYSCALL(__NR_kcmp, sys_kcmp)#define __NR_finit_module 273
mm/process_vm_access.c +0 -70
79 lines not on this page · raw message
tools/include/uapi/asm-generic/unistd.h +2 -4
@@ -727,11 +727,9 @@ __SYSCALL(__NR_setns, sys_setns)#define __NR_sendmmsg 269 __SC_COMP(__NR_sendmmsg, sys_sendmmsg, compat_sys_sendmmsg)#define __NR_process_vm_readv 270 -__SC_COMP (__NR_process_vm_readv, sys_process_vm_readv, \ - compat_sys_process_vm_readv) +__SYSCALL(__NR_process_vm_readv, sys_process_vm_readv)#define __NR_process_vm_writev 271 -__SC_COMP (__NR_process_vm_writev, sys_process_vm_writev, \ - compat_sys_process_vm_writev) +__SYSCALL(__NR_process_vm_writev, sys_process_vm_writev)#define __NR_kcmp 272 __SYSCALL(__NR_kcmp, sys_kcmp)#define __NR_finit_module 273
tools/perf/arch/powerpc/entry/syscalls/syscall.tbl +2 -2
@@ -443,8 +443,8 @@ 348 common syncfs sys_syncfs 349 common sendmmsg sys_sendmmsg compat_sys_sendmmsg 350 common setns sys_setns -351 nospu process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv -352 nospu process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev +351 nospu process_vm_readv sys_process_vm_readv +352 nospu process_vm_writev sys_process_vm_writev 353 nospu finit_module sys_finit_module 354 nospu kcmp sys_kcmp 355 common sched_setattr sys_sched_setattr
tools/perf/arch/s390/entry/syscalls/syscall.tbl +2 -2
@@ -347,8 +347,8 @@ 337 common clock_adjtime sys_clock_adjtime compat_sys_clock_adjtime 338 common syncfs sys_syncfs sys_syncfs 339 common setns sys_setns sys_setns -340 common process_vm_readv sys_process_vm_readv compat_sys_process_vm_readv -341 common process_vm_writev sys_process_vm_writev compat_sys_process_vm_writev +340 common process_vm_readv sys_process_vm_readv sys_process_vm_readv +341 common process_vm_writev sys_process_vm_writev sys_process_vm_writev 342 common s390_runtime_instr sys_s390_runtime_instr sys_s390_runtime_instr 343 common kcmp sys_kcmp compat_sys_kcmp 344 common finit_module sys_finit_module compat_sys_finit_module
tools/perf/arch/x86/entry/syscalls/syscall_64.tbl +2 -2
@@ -395,8 +395,8 @@ 536 x32 rt_tgsigqueueinfo compat_sys_rt_tgsigqueueinfo 537 x32 recvmmsg compat_sys_recvmmsg_time64 538 x32 sendmmsg compat_sys_sendmmsg -539 x32 process_vm_readv compat_sys_process_vm_readv -540 x32 process_vm_writev compat_sys_process_vm_writev +539 x32 process_vm_readv sys_process_vm_readv +540 x32 process_vm_writev sys_process_vm_writev 541 x32 setsockopt sys_setsockopt 542 x32 getsockopt sys_getsockopt 543 x32 io_setup compat_sys_io_setup
Signature · 1 line
2.28.0
Arnd Bergmann
maintainerRe: [PATCH 8/9] mm: remove compat_process_vm_{readv,writev}
Quoted 9 lines · Christoph Hellwig
Now that
import_iovechandles compat iovecs, the native syscalls can be used for the compat case as well.arch/x86/entry/syscall_x32.c +0
-0
arch/x86/entry/syscall_x32.c line 24
Quoted 8 lines
arch/x86/entry/syscall_x32.c +2
-0@@ -17,6 +17,8 @@#define __x32_sys_getsockopt __x64_sys_getsockopt#define __x32_sys_setsockopt __x64_sys_setsockopt#define __x32_sys_vmsplice __x64_sys_vmsplice +#define __x32_sys_process_vm_readv __x64_sys_process_vm_readv +#define __x32_sys_process_vm_writev __x64_sys_process_vm_writev#define __SYSCALL_64 (nr, sym)
I forgot this hack existed, and just sent a patch with subject "x86: add __X32_COND_SYSCALL() macro" instead.
If I understand this right, the macros above should no longer be needed once my patch gets merged.
Arnd
PATCH 9/9 security/keys: remove compat_keyctl_instantiate_key_iov
In reply to Christoph HellwigNow that import_iovec handles compat iovecs, the native version of keyctl_instantiate_key_iov can be used for the compat case as well.
--- security/keys/compat.c | 36 ++---------------------------------- security/keys/internal.h | 5 ----- security/keys/keyctl.c | 2 +- 3 files changed, 3 insertions(+), 40 deletions(-)
security/keys/compat.c +2 -34
@@ -11,38 +11,6 @@#include <linux/slab.h> #include "internal.h" -/* -* Instantiate a key with the specified compatibility multipart payload and -* link the key into the destination keyring if one is given. -* -* The caller must have the appropriate instantiation permit set for this to -* work (see keyctl_assume_authority). No other permissions are required. -* -* If successful, 0 will be returned. -*/ -static long compat_keyctl_instantiate_key_iov ( -key_serial_t id, -const struct compat_iovec __user *_payload_iov, -unsigned ioc, -key_serial_t ringid) -{ -struct iovec iovstack[UIO_FASTIOV ], *iov = iovstack; -struct iov_iter from; -long ret; - -if (!_payload_iov) - ioc =0 ; - - ret =import_iovec (WRITE , (const struct iovec __user *)_payload_iov, - ioc,ARRAY_SIZE (iovstack), &iov, &from); -if (ret <0 ) -return ret; - - ret =keyctl_instantiate_key_common (id, &from, ringid); -kfree (iov); -return ret; -} -/* * The key control system call, 32-bit compatibility version for 64-bit archs */
@@ -113,8 +81,8 @@ COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,return keyctl_reject_key (arg2, arg3, arg4, arg5);case KEYCTL_INSTANTIATE_IOV : -return compat_keyctl_instantiate_key_iov ( - arg2,compat_ptr (arg3), arg4, arg5); +return keyctl_instantiate_key_iov (arg2,compat_ptr (arg3), arg4, + arg5);case KEYCTL_INVALIDATE :return keyctl_invalidate_key (arg2);
security/keys/internal.h +0 -5
@@ -262,11 +262,6 @@ extern long keyctl_instantiate_key_iov(key_serial_t, const struct iovec __user *, unsigned, key_serial_t);extern long keyctl_invalidate_key (key_serial_t ); - -struct iov_iter ; -extern long keyctl_instantiate_key_common (key_serial_t , -struct iov_iter *, -key_serial_t );extern long keyctl_restrict_keyring (key_serial_t id,const char __user *_type,const char __user *_restriction);
security/keys/keyctl.c +1 -1
@@ -1164,7 +1164,7 @@ static int keyctl_change_reqkey_auth(struct key *key)* * If successful, 0 will be returned. */ -long keyctl_instantiate_key_common (key_serial_t id, +static long keyctl_instantiate_key_common (key_serial_t id,struct iov_iter *from,key_serial_t ringid) {
Signature · 1 line
2.28.0
From: Christoph Hellwig
Quoted 8 lines
Sent: 18 September 2020 13:45
this series changes
import_iovecto transparently deal with comat iovec structures, and then cleanups up a lot of code dupliation. But to get there it first has to fix the pre-existing bug thatio_uringcompat contexts don't trigger thein_compat_syscall()check. This has so far been relatively harmless as very little code callable fromio_uringused the check, and even that code that could be called usually wasn't.
I thought about that change while writing my import_iovec() => iovec_import() patch - and thought that the io_uring code would (as usual) cause grief.
Christoph - did you see those patches?
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 4 lines · David Laight
I thought about that change while writing my
import_iovec()=>iovec_import()patch - and thought that theio_uringcode would (as usual) cause grief.Christoph - did you see those patches?
No.
Quoted 5 lines · David Laight
Quoted 4 lines
I thought about that change while writing my
import_iovec()=>iovec_import()patch - and thought that theio_uringcode would (as usual) cause grief.Christoph - did you see those patches?
Link to cover email.
https://lkml.org/lkml/2020/9/15/661
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)