[Devel] [PATCH vz7] x86,ia32: Restore 32bit personality

Dmitry Safonov 0x7f454c46 at gmail.com
Fri Nov 10 19:04:01 MSK 2017


Hi Cyrill,

2017-11-10 15:25 GMT+00:00 Cyrill Gorcunov <gorcunov at virtuozzo.com>:
> When restoring compatible applications (ie running in ia32
> mode) we have to restore thread flags and mm context at
> least otherwise compat_alloc_user_space may allocate
> values from old_rsp remembered at last 64 bit syscall
> leading to EFAULT.
>
> Note the vanilla kernel already switched to pt_regs::sp
> for this sake but backporting the patch is not an
> option due to its size.
>
> In the patch we simply make sure that the task is in
> container and has no TIF_IA32 before thus when CRIU
> call for rt_sigreturn via int80 gate we adjust the
> flags needed.
>
>  | [root at pcs7 ~]# vzctl exec b3a8161f-50e2-4072-ab0a-93baa9ac20d4 cat /home/criu/test/zdtm/static/aio01.out
>  | 15:08:15.525:   201: tail=2, head=128, nr=255
>  | 15:08:26.424:   201: tail=2, head=128, nr=255
>  | 15:08:26.425:   201: tail=3, head=128, nr=255
>  | 15:08:26.425:   201: PASS
>
> Previously this test failed because after the
> restore we call for io_submit in the test and
> kernel tries to allocate helper structure to
> convert arguments from compat to native mode
> with compat_alloc_user_space and failed.
>
> https://jira.sw.ru/browse/PSBM-76965
>
> CC: Andrei Vagin <avagin at openvz.org>
> CC: Dmitry Safonov <0x7f454c46 at gmail.com>
> CC: Pavel Emelyanov <xemul at virtuozzo.com>
> CC: Kirill Tkhai <ktkhai at virtuozzo.com>
> CC: Konstantin Khorenko <khorenko at virtuozzo.com>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  arch/x86/ia32/ia32_signal.c |   53 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
[..]
> +       /*
> +        * TIF_IA32 flag is used by the kernel to figure out
> +        * the task address space at least but more importantly
> +        * in compat_alloc_user_space when an application is
> +        * doing syscalls like io_submit and etc. So when
> +        * we restore such process via rt_sigreturn syscall
> +        * from inside of native mode with int80 gate help
> +        * we have to restore the TIF_IA32 and ia32_compat
> +        * at least.
> +        *
> +        * NOTE 1: this applies to applications running inside
> +        * VE only. The vanilla kernel alreasy throwing off
> +        * old_rsp symbol but the patch is too big to merge
> +        * inside.
> +        *
> +        * NOTE 2: this is pretty valid to call int80 on
> +        * regular x86-64 bit application with rt_sigreturn
> +        * as syscall number, but it's rather an exception
> +        * than common practice (except CRIU of course).
> +        */
> +       if (regs->cs == __USER32_CS) {
> +               /*
> +                * It's close to set_personality_ia32
> +                * but we don't want to change orig_ax.
> +                */
> +               set_thread_flag(TIF_ADDR32);
> +               set_thread_flag(TIF_IA32);
> +               clear_thread_flag(TIF_X32);
> +               current->personality |= force_personality32;
> +               current_thread_info()->status |= TS_COMPAT;
> +               if (current->mm)
> +                       current->mm->context.ia32_compat = TIF_IA32;
> +       }

I see. The thing is that setting this thread-flag may be considered
racy from the kernel side.
So, the way mainstream accepted ia32 C/R is that this TIF_IA32
will not be switched from userspace. Instead, this flag is considered
for removing. And the task from kernel perspective shouldn't differ
with exception for which syscall they are doing (ia32/x32/64-bit).
While I've removed the major users (like signal ABI format delivery,
ptrace and etc), there are a couple of minor users left like oprofile,
uprobes - and the way they use this flag is not critical for their work.

So, it looks like this difference between vz and ms has slipped my
mind. I don't mind your change, but have you tried something less
intrusive? Something like the attached patch.

Thanks,
Dima
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-x86-compat-Throw-away-TIF_IA32-in-arch_compat_alloc_.patch
Type: text/x-patch
Size: 2131 bytes
Desc: not available
URL: <http://lists.openvz.org/pipermail/devel/attachments/20171110/81cbeb33/attachment.bin>


More information about the Devel mailing list