From: Dmitry Safonov <dsafonov@virtuozzo.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: <linux-kernel@vger.kernel.org>, <0x7f454c46@gmail.com>,
Adam Borowski <kilobyte@angband.pl>, <linux-mm@kvack.org>,
Andrei Vagin <avagin@gmail.com>,
Cyrill Gorcunov <gorcunov@openvz.org>,
Borislav Petkov <bp@suse.de>,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
<x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>,
Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCHv3] x86/mm: set x32 syscall bit in SET_PERSONALITY()
Date: Tue, 28 Mar 2017 15:59:00 +0300 [thread overview]
Message-ID: <66372d92-8fc1-301e-df21-7020514d7dbb@virtuozzo.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1703281449070.3616@nanos>
On 03/28/2017 03:51 PM, Thomas Gleixner wrote:
> On Tue, 28 Mar 2017, Dmitry Safonov wrote:
>> On 03/22/2017 01:21 AM, Thomas Gleixner wrote:
>>> On Tue, 21 Mar 2017, Dmitry Safonov wrote:
>>>> v3:
>>>> - clear x32 syscall flag during x32 -> x86-64 exec() (thanks, HPA).
>>>
>>> For correctness sake, this wants to be cleared in the IA32 path as
>>> well. It's not causing any harm, but ....
>>>
>>> I'll amend the patch.
>>
>> So, just a gentle reminder about this problem.
>> Should I resend v4 with clearing x32 bit in ia32 path?
>> Or should I resend with this fixup:
>> https://lkml.org/lkml/2017/3/22/343
>>
>> The fixup doesn't look as simple as clearing x32 syscall bit, but I may
>> be wrong.
>
> Something like the below should set it correctly for all possible
> scenarios.
Ok, I'll check the ifdeffery, define __NR_{x32_,ia32_}execve,
test it and resend v4 today or tomorrow.
Thanks.
>
> Thanks,
>
> tglx
>
> 8<------------------
>
> arch/x86/kernel/process_64.c | 63 ++++++++++++++++++++++++++++---------------
> 1 file changed, 42 insertions(+), 21 deletions(-)
>
> --- a/arch/x86/kernel/process_64.c
> +++ b/arch/x86/kernel/process_64.c
> @@ -494,6 +494,8 @@ void set_personality_64bit(void)
> clear_thread_flag(TIF_IA32);
> clear_thread_flag(TIF_ADDR32);
> clear_thread_flag(TIF_X32);
> + /* Pretend that this comes from a 64bit execve */
> + task_pt_regs(current)->orig_ax = __NR_execve;
>
> /* Ensure the corresponding mm is not marked. */
> if (current->mm)
> @@ -506,32 +508,51 @@ void set_personality_64bit(void)
> current->personality &= ~READ_IMPLIES_EXEC;
> }
>
> -void set_personality_ia32(bool x32)
> +static void __set_personality_x32(void)
> +{
> +#ifdef CONFIG_X86_X32
> + clear_thread_flag(TIF_IA32);
> + set_thread_flag(TIF_X32);
> + if (current->mm)
> + current->mm->context.ia32_compat = TIF_X32;
> + current->personality &= ~READ_IMPLIES_EXEC;
> + /*
> + * in_compat_syscall() uses the presence of the x32
> + * syscall bit flag to determine compat status.
> + * The x86 mmap() code relies on the syscall bitness
> + * so set x32 syscall bit right here to make
> + * in_compat_syscall() work during exec().
> + *
> + * Pretend to come from a x32 execve.
> + */
> + task_pt_regs(current)->orig_ax = __NR_x32_execve | __X32_SYSCALL_BIT;
> + current->thread.status &= ~TS_COMPAT;
> +#endif
> +}
> +
> +static void __set_personality_ia32(void)
> {
> - /* inherit personality from parent */
> +#ifdef CONFIG_COMPAT_32
> + set_thread_flag(TIF_IA32);
> + clear_thread_flag(TIF_X32);
> + if (current->mm)
> + current->mm->context.ia32_compat = TIF_IA32;
> + current->personality |= force_personality32;
> + /* Prepare the first "return" to user space */
> + task_pt_regs(current)->orig_ax = __NR_ia32_execve;
> + current->thread.status |= TS_COMPAT;
> +#endif
> +}
>
> +void set_personality_ia32(bool x32)
> +{
> /* Make sure to be in 32bit mode */
> set_thread_flag(TIF_ADDR32);
>
> - /* Mark the associated mm as containing 32-bit tasks. */
> - if (x32) {
> - clear_thread_flag(TIF_IA32);
> - set_thread_flag(TIF_X32);
> - if (current->mm)
> - current->mm->context.ia32_compat = TIF_X32;
> - current->personality &= ~READ_IMPLIES_EXEC;
> - /* in_compat_syscall() uses the presence of the x32
> - syscall bit flag to determine compat status */
> - current->thread.status &= ~TS_COMPAT;
> - } else {
> - set_thread_flag(TIF_IA32);
> - clear_thread_flag(TIF_X32);
> - if (current->mm)
> - current->mm->context.ia32_compat = TIF_IA32;
> - current->personality |= force_personality32;
> - /* Prepare the first "return" to user space */
> - current->thread.status |= TS_COMPAT;
> - }
> + if (x32)
> + __set_personality_x32();
> + else
> + __set_personality_ia32();
> }
> EXPORT_SYMBOL_GPL(set_personality_ia32);
>
>
--
Dmitry
prev parent reply other threads:[~2017-03-28 13:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-21 17:47 Dmitry Safonov
2017-03-21 21:16 ` Adam Borowski
2017-03-21 21:23 ` hpa
2017-03-21 22:07 ` Dmitry Safonov
2017-03-21 22:21 ` Thomas Gleixner
2017-03-21 22:25 ` hpa
2017-03-21 22:34 ` Thomas Gleixner
2017-03-22 13:40 ` Dmitry Safonov
2017-03-28 11:37 ` Dmitry Safonov
2017-03-28 12:51 ` Thomas Gleixner
2017-03-28 12:59 ` Dmitry Safonov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=66372d92-8fc1-301e-df21-7020514d7dbb@virtuozzo.com \
--to=dsafonov@virtuozzo.com \
--cc=0x7f454c46@gmail.com \
--cc=avagin@gmail.com \
--cc=bp@suse.de \
--cc=gorcunov@openvz.org \
--cc=hpa@zytor.com \
--cc=kilobyte@angband.pl \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®