All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Safonov <dsafonov@virtuozzo.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Dmitry Safonov" <0x7f454c46@gmail.com>,
	Andrew Lutomirski <luto@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	X86 ML <x86@kernel.org>, Cyrill Gorcunov <gorcunov@openvz.org>,
	Pavel Emelyanov <xemul@virtuozzo.com>
Subject: Re: [PATCHv3 3/6] x86/arch_prctl/vdso: add ARCH_MAP_VDSO_*
Date: Wed, 31 Aug 2016 18:46:24 +0300	[thread overview]
Message-ID: <e8bbe0bd-e6f4-54cb-c929-88e33e28b653@virtuozzo.com> (raw)
In-Reply-To: <CALCETrWLPbbXXMa+1hMg1hduF60sB_+MnBXMvyVMPUepWc1PpQ@mail.gmail.com>

On 08/31/2016 06:42 PM, Andy Lutomirski wrote:
> On Wed, Aug 31, 2016 at 8:30 AM, Dmitry Safonov <dsafonov@virtuozzo.com> wrote:
>> On 08/31/2016 06:00 PM, Andy Lutomirski wrote:
>>>
>>> On Fri, Aug 26, 2016 at 10:13 AM, Dmitry Safonov <dsafonov@virtuozzo.com>
>>> wrote:
>>>>
>>>> Add API to change vdso blob type with arch_prctl.
>>>> As this is usefull only by needs of CRIU, expose
>>>> this interface under CONFIG_CHECKPOINT_RESTORE.
>>>>
>>>> Cc: Andy Lutomirski <luto@kernel.org>
>>>> Cc: Oleg Nesterov <oleg@redhat.com>
>>>> Cc: Thomas Gleixner <tglx@linutronix.de>
>>>> Cc: "H. Peter Anvin" <hpa@zytor.com>
>>>> Cc: Ingo Molnar <mingo@redhat.com>
>>>> Cc: linux-mm@kvack.org
>>>> Cc: x86@kernel.org
>>>> Cc: Cyrill Gorcunov <gorcunov@openvz.org>
>>>> Cc: Pavel Emelyanov <xemul@virtuozzo.com>
>>>> Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
>>>> ---
>>>>  arch/x86/entry/vdso/vma.c         | 45
>>>> ++++++++++++++++++++++++++++++---------
>>>>  arch/x86/include/asm/vdso.h       |  2 ++
>>>>  arch/x86/include/uapi/asm/prctl.h |  6 ++++++
>>>>  arch/x86/kernel/process_64.c      | 25 ++++++++++++++++++++++
>>>>  4 files changed, 68 insertions(+), 10 deletions(-)
>>>>
>>>> diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
>>>> index 5bcb25a9e573..dad2b2d8ff03 100644
>>>> --- a/arch/x86/entry/vdso/vma.c
>>>> +++ b/arch/x86/entry/vdso/vma.c
>>>> @@ -176,6 +176,16 @@ static int vvar_fault(const struct
>>>> vm_special_mapping *sm,
>>>>         return VM_FAULT_SIGBUS;
>>>>  }
>>>>
>>>> +static const struct vm_special_mapping vdso_mapping = {
>>>> +       .name = "[vdso]",
>>>> +       .fault = vdso_fault,
>>>> +       .mremap = vdso_mremap,
>>>> +};
>>>> +static const struct vm_special_mapping vvar_mapping = {
>>>> +       .name = "[vvar]",
>>>> +       .fault = vvar_fault,
>>>> +};
>>>> +
>>>>  /*
>>>>   * Add vdso and vvar mappings to current process.
>>>>   * @image          - blob to map
>>>> @@ -188,16 +198,6 @@ static int map_vdso(const struct vdso_image *image,
>>>> unsigned long addr)
>>>>         unsigned long text_start;
>>>>         int ret = 0;
>>>>
>>>> -       static const struct vm_special_mapping vdso_mapping = {
>>>> -               .name = "[vdso]",
>>>> -               .fault = vdso_fault,
>>>> -               .mremap = vdso_mremap,
>>>> -       };
>>>> -       static const struct vm_special_mapping vvar_mapping = {
>>>> -               .name = "[vvar]",
>>>> -               .fault = vvar_fault,
>>>> -       };
>>>> -
>>>>         if (down_write_killable(&mm->mmap_sem))
>>>>                 return -EINTR;
>>>>
>>>> @@ -256,6 +256,31 @@ static int map_vdso_randomized(const struct
>>>> vdso_image *image)
>>>>         return map_vdso(image, addr);
>>>>  }
>>>>
>>>> +int map_vdso_once(const struct vdso_image *image, unsigned long addr)
>>>> +{
>>>> +       struct mm_struct *mm = current->mm;
>>>> +       struct vm_area_struct *vma;
>>>> +
>>>> +       down_write(&mm->mmap_sem);
>>>> +       /*
>>>> +        * Check if we have already mapped vdso blob - fail to prevent
>>>> +        * abusing from userspace install_speciall_mapping, which may
>>>> +        * not do accounting and rlimit right.
>>>> +        * We could search vma near context.vdso, but it's a slowpath,
>>>> +        * so let's explicitely check all VMAs to be completely sure.
>>>> +        */
>>>> +       for (vma = mm->mmap; vma; vma = vma->vm_next) {
>>>> +               if (vma->vm_private_data == &vdso_mapping ||
>>>> +                               vma->vm_private_data == &vvar_mapping) {
>>>
>>>
>>> Should probably also check that vm_ops == &special_mapping_vmops,
>>> which means that maybe there should be a:
>>>
>>> static inline bool vma_is_special_mapping(const struct vm_area_struct
>>> *vma, const struct vm_special_mapping &sm);
>>
>>
>> Oh, I remember why I didn't do it also (except header changes):
>> uprobes uses &special_mapping_vmops in inserted XOL area.
>>
>
> That's fine.  I think you should check *both* vm_ops and
> vm_private_data to avoid (unlikely) confusion with some other VMA.

Oh, I thought you suggest to check either of them.
*Both* makes sence, since AFAIU, vm_private_data may be uninitialized on
other VMAs, will do.

-- 
              Dmitry

WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Safonov <dsafonov@virtuozzo.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	Andrew Lutomirski <luto@kernel.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	X86 ML <x86@kernel.org>, Cyrill Gorcunov <gorcunov@openvz.org>,
	Pavel Emelyanov <xemul@virtuozzo.com>
Subject: Re: [PATCHv3 3/6] x86/arch_prctl/vdso: add ARCH_MAP_VDSO_*
Date: Wed, 31 Aug 2016 18:46:24 +0300	[thread overview]
Message-ID: <e8bbe0bd-e6f4-54cb-c929-88e33e28b653@virtuozzo.com> (raw)
In-Reply-To: <CALCETrWLPbbXXMa+1hMg1hduF60sB_+MnBXMvyVMPUepWc1PpQ@mail.gmail.com>

On 08/31/2016 06:42 PM, Andy Lutomirski wrote:
> On Wed, Aug 31, 2016 at 8:30 AM, Dmitry Safonov <dsafonov@virtuozzo.com> wrote:
>> On 08/31/2016 06:00 PM, Andy Lutomirski wrote:
>>>
>>> On Fri, Aug 26, 2016 at 10:13 AM, Dmitry Safonov <dsafonov@virtuozzo.com>
>>> wrote:
>>>>
>>>> Add API to change vdso blob type with arch_prctl.
>>>> As this is usefull only by needs of CRIU, expose
>>>> this interface under CONFIG_CHECKPOINT_RESTORE.
>>>>
>>>> Cc: Andy Lutomirski <luto@kernel.org>
>>>> Cc: Oleg Nesterov <oleg@redhat.com>
>>>> Cc: Thomas Gleixner <tglx@linutronix.de>
>>>> Cc: "H. Peter Anvin" <hpa@zytor.com>
>>>> Cc: Ingo Molnar <mingo@redhat.com>
>>>> Cc: linux-mm@kvack.org
>>>> Cc: x86@kernel.org
>>>> Cc: Cyrill Gorcunov <gorcunov@openvz.org>
>>>> Cc: Pavel Emelyanov <xemul@virtuozzo.com>
>>>> Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
>>>> ---
>>>>  arch/x86/entry/vdso/vma.c         | 45
>>>> ++++++++++++++++++++++++++++++---------
>>>>  arch/x86/include/asm/vdso.h       |  2 ++
>>>>  arch/x86/include/uapi/asm/prctl.h |  6 ++++++
>>>>  arch/x86/kernel/process_64.c      | 25 ++++++++++++++++++++++
>>>>  4 files changed, 68 insertions(+), 10 deletions(-)
>>>>
>>>> diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c
>>>> index 5bcb25a9e573..dad2b2d8ff03 100644
>>>> --- a/arch/x86/entry/vdso/vma.c
>>>> +++ b/arch/x86/entry/vdso/vma.c
>>>> @@ -176,6 +176,16 @@ static int vvar_fault(const struct
>>>> vm_special_mapping *sm,
>>>>         return VM_FAULT_SIGBUS;
>>>>  }
>>>>
>>>> +static const struct vm_special_mapping vdso_mapping = {
>>>> +       .name = "[vdso]",
>>>> +       .fault = vdso_fault,
>>>> +       .mremap = vdso_mremap,
>>>> +};
>>>> +static const struct vm_special_mapping vvar_mapping = {
>>>> +       .name = "[vvar]",
>>>> +       .fault = vvar_fault,
>>>> +};
>>>> +
>>>>  /*
>>>>   * Add vdso and vvar mappings to current process.
>>>>   * @image          - blob to map
>>>> @@ -188,16 +198,6 @@ static int map_vdso(const struct vdso_image *image,
>>>> unsigned long addr)
>>>>         unsigned long text_start;
>>>>         int ret = 0;
>>>>
>>>> -       static const struct vm_special_mapping vdso_mapping = {
>>>> -               .name = "[vdso]",
>>>> -               .fault = vdso_fault,
>>>> -               .mremap = vdso_mremap,
>>>> -       };
>>>> -       static const struct vm_special_mapping vvar_mapping = {
>>>> -               .name = "[vvar]",
>>>> -               .fault = vvar_fault,
>>>> -       };
>>>> -
>>>>         if (down_write_killable(&mm->mmap_sem))
>>>>                 return -EINTR;
>>>>
>>>> @@ -256,6 +256,31 @@ static int map_vdso_randomized(const struct
>>>> vdso_image *image)
>>>>         return map_vdso(image, addr);
>>>>  }
>>>>
>>>> +int map_vdso_once(const struct vdso_image *image, unsigned long addr)
>>>> +{
>>>> +       struct mm_struct *mm = current->mm;
>>>> +       struct vm_area_struct *vma;
>>>> +
>>>> +       down_write(&mm->mmap_sem);
>>>> +       /*
>>>> +        * Check if we have already mapped vdso blob - fail to prevent
>>>> +        * abusing from userspace install_speciall_mapping, which may
>>>> +        * not do accounting and rlimit right.
>>>> +        * We could search vma near context.vdso, but it's a slowpath,
>>>> +        * so let's explicitely check all VMAs to be completely sure.
>>>> +        */
>>>> +       for (vma = mm->mmap; vma; vma = vma->vm_next) {
>>>> +               if (vma->vm_private_data == &vdso_mapping ||
>>>> +                               vma->vm_private_data == &vvar_mapping) {
>>>
>>>
>>> Should probably also check that vm_ops == &special_mapping_vmops,
>>> which means that maybe there should be a:
>>>
>>> static inline bool vma_is_special_mapping(const struct vm_area_struct
>>> *vma, const struct vm_special_mapping &sm);
>>
>>
>> Oh, I remember why I didn't do it also (except header changes):
>> uprobes uses &special_mapping_vmops in inserted XOL area.
>>
>
> That's fine.  I think you should check *both* vm_ops and
> vm_private_data to avoid (unlikely) confusion with some other VMA.

Oh, I thought you suggest to check either of them.
*Both* makes sence, since AFAIU, vm_private_data may be uninitialized on
other VMAs, will do.

-- 
              Dmitry

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2016-08-31 17:22 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-26 17:13 [PATCHv3 0/6] x86: 32-bit compatible C/R on x86_64 Dmitry Safonov
2016-08-26 17:13 ` Dmitry Safonov
2016-08-26 17:13 ` [PATCHv3 1/6] x86/vdso: unmap vdso blob on vvar mapping failure Dmitry Safonov
2016-08-26 17:13   ` Dmitry Safonov
2016-08-26 17:13 ` [PATCHv3 2/6] x86/vdso: replace calculate_addr in map_vdso() with addr Dmitry Safonov
2016-08-26 17:13   ` Dmitry Safonov
2016-08-31 15:09   ` Andy Lutomirski
2016-08-31 15:09     ` Andy Lutomirski
2016-08-26 17:13 ` [PATCHv3 3/6] x86/arch_prctl/vdso: add ARCH_MAP_VDSO_* Dmitry Safonov
2016-08-26 17:13   ` Dmitry Safonov
2016-08-27 18:09   ` kbuild test robot
2016-08-27 18:09     ` kbuild test robot
2016-08-29 11:12     ` Dmitry Safonov
2016-08-29 11:12       ` Dmitry Safonov
2016-08-31 15:00   ` Andy Lutomirski
2016-08-31 15:00     ` Andy Lutomirski
2016-08-31 15:09     ` Dmitry Safonov
2016-08-31 15:09       ` Dmitry Safonov
2016-08-31 15:30     ` Dmitry Safonov
2016-08-31 15:30       ` Dmitry Safonov
2016-08-31 15:42       ` Andy Lutomirski
2016-08-31 15:42         ` Andy Lutomirski
2016-08-31 15:46         ` Dmitry Safonov [this message]
2016-08-31 15:46           ` Dmitry Safonov
2016-08-26 17:13 ` [PATCHv3 4/6] x86/coredump: use pr_reg size, rather that TIF_IA32 flag Dmitry Safonov
2016-08-26 17:13   ` Dmitry Safonov
2016-08-26 17:13 ` [PATCHv3 5/6] x86/ptrace: down with test_thread_flag(TIF_IA32) Dmitry Safonov
2016-08-26 17:13   ` Dmitry Safonov
2016-08-26 17:13 ` [PATCHv3 6/6] x86/signal: add SA_{X32,IA32}_ABI sa_flags Dmitry Safonov
2016-08-26 17:13   ` Dmitry Safonov
2016-08-26 17:16   ` Dmitry Safonov
2016-08-26 17:16     ` Dmitry Safonov

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=e8bbe0bd-e6f4-54cb-c929-88e33e28b653@virtuozzo.com \
    --to=dsafonov@virtuozzo.com \
    --cc=0x7f454c46@gmail.com \
    --cc=gorcunov@openvz.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=xemul@virtuozzo.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.