aio: Fix io_pgetevents() struct __compat_aio_sigset layout
PATCH 1/1 aio: Fix io_pgetevents() struct __compat_aio_sigset layout
This type is used to pass the sigset_t from userland to the kernel, but it was using the kernel native pointer type for the member representing the compat userland pointer to the userland sigset_t.
This messes up the layout, and makes the kernel eat up both the userland pointer and the size members into the kernel pointer, and then reads garbage into the kernel sigsetsize. Which makes the sigset_t size consistency check fail, and consequently the syscall always returns -EINVAL.
This breaks both libaio and strace on 32-bit userland running on 64-bit kernels. And there are apparently no users in the wild of the current broken layout (at least according to codesearch.debian.org and a brief check over github.com search). So it looks safe to fix this directly in the kernel, instead of either letting userland deal with this permanently with the additional overhead or trying to make the syscall infer what layout userland used, even though this is also being worked around in libaio to temporarily cope with kernels that have not yet been fixed.
We use a proper compat_uptr_t instead of a compat_sigset_t pointer.
--- fs/aio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/aio.c +3 -3
@@ -2179,7 +2179,7 @@ SYSCALL_DEFINE5(io_getevents_time32, __u32, ctx_id,#ifdef CONFIG_COMPAT struct __compat_aio_sigset { -compat_sigset_t __user *sigmask; +compat_uptr_t sigmask;compat_size_t sigsetsize; };
@@ -2204,7 +2204,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,if (usig &©_from_user (&ksig, usig,sizeof (ksig)))return -EFAULT ; - ret =set_compat_user_sigmask (ksig.sigmask, ksig.sigsetsize); + ret =set_compat_user_sigmask (compat_ptr (ksig.sigmask), ksig.sigsetsize);if (ret)return ret;
@@ -2239,7 +2239,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,if (usig &©_from_user (&ksig, usig,sizeof (ksig)))return -EFAULT ; - ret =set_compat_user_sigmask (ksig.sigmask, ksig.sigsetsize); + ret =set_compat_user_sigmask (compat_ptr (ksig.sigmask), ksig.sigsetsize);if (ret)return ret;
Signature · 1 line
2.23.0
Quoted 20 lines · Guillem Jover
This type is used to pass the
sigset_tfrom userland to the kernel, but it was using the kernel native pointer type for the member representing the compat userland pointer to the userlandsigset_t.This messes up the layout, and makes the kernel eat up both the userland pointer and the size members into the kernel pointer, and then reads garbage into the kernel sigsetsize. Which makes the
sigset_tsize consistency check fail, and consequently the syscall always returns-EINVAL.This breaks both libaio and strace on 32-bit userland running on 64-bit kernels. And there are apparently no users in the wild of the current broken layout (at least according to codesearch.debian.org and a brief check over github.com search). So it looks safe to fix this directly in the kernel, instead of either letting userland deal with this permanently with the additional overhead or trying to make the syscall infer what layout userland used, even though this is also being worked around in libaio to temporarily cope with kernels that have not yet been fixed.
Quoted 4 lines
We use a proper
compat_uptr_tinstead of acompat_sigset_tpointer.Fixes 7a074e96 ("aio: implement io_pgetevents")Signed-off-by Guillem Jover <[email protected]>
Looks good,
Quoted 20 lines · Guillem Jover
This type is used to pass the
sigset_tfrom userland to the kernel, but it was using the kernel native pointer type for the member representing the compat userland pointer to the userlandsigset_t.This messes up the layout, and makes the kernel eat up both the userland pointer and the size members into the kernel pointer, and then reads garbage into the kernel sigsetsize. Which makes the
sigset_tsize consistency check fail, and consequently the syscall always returns-EINVAL.This breaks both libaio and strace on 32-bit userland running on 64-bit kernels. And there are apparently no users in the wild of the current broken layout (at least according to codesearch.debian.org and a brief check over github.com search). So it looks safe to fix this directly in the kernel, instead of either letting userland deal with this permanently with the additional overhead or trying to make the syscall infer what layout userland used, even though this is also being worked around in libaio to temporarily cope with kernels that have not yet been fixed.
Quoted 4 lines
We use a proper
compat_uptr_tinstead of acompat_sigset_tpointer.Fixes 7a074e96 ("aio: implement io_pgetevents")Signed-off-by Guillem Jover <[email protected]>
Looks good, thanks for finding and fixing this!
Quoted 34 lines
--- fs/aio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/aio.c +3
-3@@ -2179,7 +2179,7 @@ SYSCALL_DEFINE5(io_getevents_time32, __u32, ctx_id,#ifdef CONFIG_COMPAT struct __compat_aio_sigset { -compat_sigset_t __user *sigmask; +compat_uptr_t sigmask;compat_size_t sigsetsize; };@@ -2204,7 +2204,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,if (usig &©_from_user (&ksig, usig,sizeof (ksig)))return -EFAULT ; - ret =set_compat_user_sigmask (ksig.sigmask, ksig.sigsetsize); + ret =set_compat_user_sigmask (compat_ptr (ksig.sigmask), ksig.sigsetsize);if (ret)return ret;@@ -2239,7 +2239,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,if (usig &©_from_user (&ksig, usig,sizeof (ksig)))return -EFAULT ; - ret =set_compat_user_sigmask (ksig.sigmask, ksig.sigsetsize); + ret =set_compat_user_sigmask (compat_ptr (ksig.sigmask), ksig.sigsetsize);if (ret)return ret;
Jan Kara
reviewerQuoted 20 lines · Guillem Jover
This type is used to pass the
sigset_tfrom userland to the kernel, but it was using the kernel native pointer type for the member representing the compat userland pointer to the userlandsigset_t.This messes up the layout, and makes the kernel eat up both the userland pointer and the size members into the kernel pointer, and then reads garbage into the kernel sigsetsize. Which makes the
sigset_tsize consistency check fail, and consequently the syscall always returns-EINVAL.This breaks both libaio and strace on 32-bit userland running on 64-bit kernels. And there are apparently no users in the wild of the current broken layout (at least according to codesearch.debian.org and a brief check over github.com search). So it looks safe to fix this directly in the kernel, instead of either letting userland deal with this permanently with the additional overhead or trying to make the syscall infer what layout userland used, even though this is also being worked around in libaio to temporarily cope with kernels that have not yet been fixed.
Quoted 4 lines
We use a proper
compat_uptr_tinstead of acompat_sigset_tpointer.Fixes 7a074e96 ("aio: implement io_pgetevents")Signed-off-by Guillem Jover <[email protected]>
This patch seems to have fallen through the cracks. Al?
Honza
Quoted 38 lines
--- fs/aio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/aio.c +3
-3@@ -2179,7 +2179,7 @@ SYSCALL_DEFINE5(io_getevents_time32, __u32, ctx_id,#ifdef CONFIG_COMPAT struct __compat_aio_sigset { -compat_sigset_t __user *sigmask; +compat_uptr_t sigmask;compat_size_t sigsetsize; };@@ -2204,7 +2204,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,if (usig &©_from_user (&ksig, usig,sizeof (ksig)))return -EFAULT ; - ret =set_compat_user_sigmask (ksig.sigmask, ksig.sigsetsize); + ret =set_compat_user_sigmask (compat_ptr (ksig.sigmask), ksig.sigsetsize);if (ret)return ret;@@ -2239,7 +2239,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,if (usig &©_from_user (&ksig, usig,sizeof (ksig)))return -EFAULT ; - ret =set_compat_user_sigmask (ksig.sigmask, ksig.sigsetsize); + ret =set_compat_user_sigmask (compat_ptr (ksig.sigmask), ksig.sigsetsize);if (ret)return ret;Signature · 1 line
2.23.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Al Viro
maintainerQuoted 21 lines · Jan Kara
Quoted 20 lines · Guillem Jover
This type is used to pass the
sigset_tfrom userland to the kernel, but it was using the kernel native pointer type for the member representing the compat userland pointer to the userlandsigset_t.This messes up the layout, and makes the kernel eat up both the userland pointer and the size members into the kernel pointer, and then reads garbage into the kernel sigsetsize. Which makes the
sigset_tsize consistency check fail, and consequently the syscall always returns-EINVAL.This breaks both libaio and strace on 32-bit userland running on 64-bit kernels. And there are apparently no users in the wild of the current broken layout (at least according to codesearch.debian.org and a brief check over github.com search). So it looks safe to fix this directly in the kernel, instead of either letting userland deal with this permanently with the additional overhead or trying to make the syscall infer what layout userland used, even though this is also being worked around in libaio to temporarily cope with kernels that have not yet been fixed.
Quoted 6 lines
Quoted 4 lines
We use a proper
compat_uptr_tinstead of acompat_sigset_tpointer.Fixes 7a074e96 ("aio: implement io_pgetevents")Signed-off-by Guillem Jover <[email protected]>This patch seems to have fallen through the cracks. Al?
Looks like - back then I assumed that Jens would've picked it... Applied to #fixes...
PATCH v2 1/1 aio: Fix io_pgetevents() struct __compat_aio_sigset layout
This type is used to pass the sigset_t from userland to the kernel, but it was using the kernel native pointer type for the member representing the compat userland pointer to the userland sigset_t.
This messes up the layout, and makes the kernel eat up both the userland pointer and the size into the kernel pointer, and then reads garbage into the kernel sigsetsize. Which makes the sigset_t size consistency check fail, and consequently the syscall always returns -EINVAL.
This breaks both libaio and strace on 32-bit userland running on 64-bit kernels. And there are apparently no users in the wild of the current broken layout (at least according to codesearch.debian.org and a brief check over github.com search). So it looks safe to fix this directly in the kernel, instead of either letting userland deal with this permanently with the additional overhead or trying to make the syscall infer what layout userland used, even though this is also being worked around in libaio to temporarily cope with kernels that have not yet been fixed.
We use a proper compat_uptr_t instead of a compat_sigset_t pointer.
--- fs/aio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/aio.c +5 -5
@@ -2179,7 +2179,7 @@ SYSCALL_DEFINE5(io_getevents_time32, __u32, ctx_id,#ifdef CONFIG_COMPAT struct __compat_aio_sigset { -compat_sigset_t __user *sigmask; +compat_uptr_t sigmask;compat_size_t sigsetsize; };
@@ -2193,7 +2193,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents, struct old_timespec32 __user *, timeout, const struct __compat_aio_sigset __user *, usig) { - struct __compat_aio_sigset ksig = { NULL, }; + struct __compat_aio_sigset ksig = { 0, };struct timespec64 t;bool interrupted;int ret;
@@ -2204,7 +2204,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents,if (usig &©_from_user (&ksig, usig,sizeof (ksig)))return -EFAULT ; - ret =set_compat_user_sigmask (ksig.sigmask, ksig.sigsetsize); + ret =set_compat_user_sigmask (compat_ptr (ksig.sigmask), ksig.sigsetsize);if (ret)return ret;
@@ -2228,7 +2228,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64, struct __kernel_timespec __user *, timeout, const struct __compat_aio_sigset __user *, usig) { - struct __compat_aio_sigset ksig = { NULL, }; + struct __compat_aio_sigset ksig = { 0, };struct timespec64 t;bool interrupted;int ret;
@@ -2239,7 +2239,7 @@ COMPAT_SYSCALL_DEFINE6(io_pgetevents_time64,if (usig &©_from_user (&ksig, usig,sizeof (ksig)))return -EFAULT ; - ret =set_compat_user_sigmask (ksig.sigmask, ksig.sigsetsize); + ret =set_compat_user_sigmask (compat_ptr (ksig.sigmask), ksig.sigsetsize);if (ret)return ret;
Signature · 1 line
2.24.0.rc0.303.g954a862665
Quoted 21 lines · Guillem Jover
This type is used to pass the
sigset_tfrom userland to the kernel, but it was using the kernel native pointer type for the member representing the compat userland pointer to the userlandsigset_t.This messes up the layout, and makes the kernel eat up both the userland pointer and the size into the kernel pointer, and then reads garbage into the kernel sigsetsize. Which makes the
sigset_tsize consistency check fail, and consequently the syscall always returns-EINVAL.This breaks both libaio and strace on 32-bit userland running on 64-bit kernels. And there are apparently no users in the wild of the current broken layout (at least according to codesearch.debian.org and a brief check over github.com search). So it looks safe to fix this directly in the kernel, instead of either letting userland deal with this permanently with the additional overhead or trying to make the syscall infer what layout userland used, even though this is also being worked around in libaio to temporarily cope with kernels that have not yet been fixed.
Quoted 4 lines
We use a proper
compat_uptr_tinstead of acompat_sigset_tpointer.Fixes 7a074e96dee6 ("aio: implement io_pgetevents")Signed-off-by Guillem Jover <[email protected]>
When resending a patch that has already been reviewed, please add the tags you received so they get picked up into the final changeset as well:
Let's make sure this also gets added to stable kernels
Finally (if you like)
Arnd