2016-04-21 06:27:11

by Jan Beulich

[permalink] [raw]
Subject: [PATCH] x86/xen: suppress hugetlbfs in PV guests

Huge pages are not normally available to PV guests. Not suppressing
hugetlbfs use results in an endless loop of page faults when user mode
code tries to access a hugetlbfs mapped area (since the hypervisor
denies such PTEs to be created, but error indications can't be
propagated out of xen_set_pte_at(), just like for various of its
siblings), and - once killed in an oops like this:

kernel BUG at .../fs/hugetlbfs/inode.c:428!
invalid opcode: 0000 [#1] SMP
Modules linked in: ...
Supported: Yes
CPU: 2 PID: 6088 Comm: hugetlbfs Tainted: G W 4.4.0-2016-01-20-pv #2
Hardware name: ...
task: ffff8808059205c0 ti: ffff880803c84000 task.ti: ffff880803c84000
RIP: e030:[<ffffffff811c333b>] [<ffffffff811c333b>] remove_inode_hugepages+0x25b/0x320
RSP: e02b:ffff880803c879a8 EFLAGS: 00010202
RAX: 000000000077a4db RBX: ffffea001acff000 RCX: 0000000078417d38
RDX: 0000000000000000 RSI: 000000007e154fa7 RDI: ffff880805d70960
RBP: 0000000000000960 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000001 R12: 0000000000000000
R13: ffff880807486018 R14: 0000000000000000 R15: ffff880803c87af0
FS: 00007f85fa8b8700(0000) GS:ffff88080b640000(0000) knlGS:0000000000000000
CS: e033 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 00007f85fa000000 CR3: 0000000001a0a000 CR4: 0000000000040660
Stack:
ffff880000000fb0 ffff880803c87a18 ffff880803c87ae8 ffff8808059205c0
ffff880803c87af0 ffff880803c87ae8 ffff880807486018 0000000000000000
ffffffff81bf6e60 ffff880807486168 000003ffffffffff 0000000003c87758
Call Trace:
[<ffffffff811c3415>] hugetlbfs_evict_inode+0x15/0x40
[<ffffffff81167b3d>] evict+0xbd/0x1b0
[<ffffffff8116514a>] __dentry_kill+0x19a/0x1f0
[<ffffffff81165b0e>] dput+0x1fe/0x220
[<ffffffff81150535>] __fput+0x155/0x200
[<ffffffff81079fc0>] task_work_run+0x60/0xa0
[<ffffffff81063510>] do_exit+0x160/0x400
[<ffffffff810637eb>] do_group_exit+0x3b/0xa0
[<ffffffff8106e8bd>] get_signal+0x1ed/0x470
[<ffffffff8100f854>] do_signal+0x14/0x110
[<ffffffff810030e9>] prepare_exit_to_usermode+0xe9/0xf0
[<ffffffff814178a5>] retint_user+0x8/0x13

This is CVE-2016-3961 / XSA-174.

Reported-by: Vitaly Kuznetsov <[email protected]>
Signed-off-by: Jan Beulich <[email protected]>
Cc: [email protected]
---
arch/x86/include/asm/hugetlb.h | 1 +
1 file changed, 1 insertion(+)

--- 4.6-rc4/arch/x86/include/asm/hugetlb.h
+++ 4.6-rc4-xsa174/arch/x86/include/asm/hugetlb.h
@@ -4,6 +4,7 @@
#include <asm/page.h>
#include <asm-generic/hugetlb.h>

+#define hugepages_supported() cpu_has_pse

static inline int is_hugepage_only_range(struct mm_struct *mm,
unsigned long addr,




Subject: [tip:x86/asm] x86/mm/xen: Suppress hugetlbfs in PV guests

Commit-ID: 103f6112f253017d7062cd74d17f4a514ed4485c
Gitweb: http://git.kernel.org/tip/103f6112f253017d7062cd74d17f4a514ed4485c
Author: Jan Beulich <[email protected]>
AuthorDate: Thu, 21 Apr 2016 00:27:04 -0600
Committer: Ingo Molnar <[email protected]>
CommitDate: Fri, 22 Apr 2016 10:05:00 +0200

x86/mm/xen: Suppress hugetlbfs in PV guests

Huge pages are not normally available to PV guests. Not suppressing
hugetlbfs use results in an endless loop of page faults when user mode
code tries to access a hugetlbfs mapped area (since the hypervisor
denies such PTEs to be created, but error indications can't be
propagated out of xen_set_pte_at(), just like for various of its
siblings), and - once killed in an oops like this:

kernel BUG at .../fs/hugetlbfs/inode.c:428!
invalid opcode: 0000 [#1] SMP
...
RIP: e030:[<ffffffff811c333b>] [<ffffffff811c333b>] remove_inode_hugepages+0x25b/0x320
...
Call Trace:
[<ffffffff811c3415>] hugetlbfs_evict_inode+0x15/0x40
[<ffffffff81167b3d>] evict+0xbd/0x1b0
[<ffffffff8116514a>] __dentry_kill+0x19a/0x1f0
[<ffffffff81165b0e>] dput+0x1fe/0x220
[<ffffffff81150535>] __fput+0x155/0x200
[<ffffffff81079fc0>] task_work_run+0x60/0xa0
[<ffffffff81063510>] do_exit+0x160/0x400
[<ffffffff810637eb>] do_group_exit+0x3b/0xa0
[<ffffffff8106e8bd>] get_signal+0x1ed/0x470
[<ffffffff8100f854>] do_signal+0x14/0x110
[<ffffffff810030e9>] prepare_exit_to_usermode+0xe9/0xf0
[<ffffffff814178a5>] retint_user+0x8/0x13

This is CVE-2016-3961 / XSA-174.

Reported-by: Vitaly Kuznetsov <[email protected]>
Signed-off-by: Jan Beulich <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Brian Gerst <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Denys Vlasenko <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Luis R. Rodriguez <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Toshi Kani <[email protected]>
Cc: [email protected]
Cc: xen-devel <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
---
arch/x86/include/asm/hugetlb.h | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/x86/include/asm/hugetlb.h b/arch/x86/include/asm/hugetlb.h
index f8a29d2..e6a8613 100644
--- a/arch/x86/include/asm/hugetlb.h
+++ b/arch/x86/include/asm/hugetlb.h
@@ -4,6 +4,7 @@
#include <asm/page.h>
#include <asm-generic/hugetlb.h>

+#define hugepages_supported() cpu_has_pse

static inline int is_hugepage_only_range(struct mm_struct *mm,
unsigned long addr,

2016-04-22 18:05:50

by H. Peter Anvin

[permalink] [raw]
Subject: Re: [tip:x86/asm] x86/mm/xen: Suppress hugetlbfs in PV guests

On 04/22/2016 02:47 AM, tip-bot for Jan Beulich wrote:
> Commit-ID: 103f6112f253017d7062cd74d17f4a514ed4485c
> Gitweb: http://git.kernel.org/tip/103f6112f253017d7062cd74d17f4a514ed4485c
> Author: Jan Beulich <[email protected]>
> AuthorDate: Thu, 21 Apr 2016 00:27:04 -0600
> Committer: Ingo Molnar <[email protected]>
> CommitDate: Fri, 22 Apr 2016 10:05:00 +0200
>
>
> diff --git a/arch/x86/include/asm/hugetlb.h b/arch/x86/include/asm/hugetlb.h
> index f8a29d2..e6a8613 100644
> --- a/arch/x86/include/asm/hugetlb.h
> +++ b/arch/x86/include/asm/hugetlb.h
> @@ -4,6 +4,7 @@
> #include <asm/page.h>
> #include <asm-generic/hugetlb.h>
>
> +#define hugepages_supported() cpu_has_pse
>

Please don't use the cpu_has_* macros anymore, they are going away soon.

In this case it should be static_cpu_has(X86_FEATURE_PSE).

-hpa


2016-04-22 18:17:08

by Borislav Petkov

[permalink] [raw]
Subject: Re: [tip:x86/asm] x86/mm/xen: Suppress hugetlbfs in PV guests

On Fri, Apr 22, 2016 at 11:03:53AM -0700, H. Peter Anvin wrote:
> Please don't use the cpu_has_* macros anymore, they are going away soon.
>
> In this case it should be static_cpu_has(X86_FEATURE_PSE).

Ingo fixed this up while merging:

b2eafe890d4a ("Merge branch 'x86/urgent' into x86/asm, to fix semantic conflict")

The cpu_has_* things are gone now in tip! \o/

:-)

--
Regards/Gruss,
Boris.

ECO tip #101: Trim your mails when you reply.

2016-04-25 07:37:53

by Jan Beulich

[permalink] [raw]
Subject: Re: [tip:x86/asm] x86/mm/xen: Suppress hugetlbfs in PV guests

>>> On 22.04.16 at 20:03, <[email protected]> wrote:
> On 04/22/2016 02:47 AM, tip-bot for Jan Beulich wrote:
>> Commit-ID: 103f6112f253017d7062cd74d17f4a514ed4485c
>> Gitweb:
> http://git.kernel.org/tip/103f6112f253017d7062cd74d17f4a514ed4485c
>> Author: Jan Beulich <[email protected]>
>> AuthorDate: Thu, 21 Apr 2016 00:27:04 -0600
>> Committer: Ingo Molnar <[email protected]>
>> CommitDate: Fri, 22 Apr 2016 10:05:00 +0200
>>
>>
>> diff --git a/arch/x86/include/asm/hugetlb.h b/arch/x86/include/asm/hugetlb.h
>> index f8a29d2..e6a8613 100644
>> --- a/arch/x86/include/asm/hugetlb.h
>> +++ b/arch/x86/include/asm/hugetlb.h
>> @@ -4,6 +4,7 @@
>> #include <asm/page.h>
>> #include <asm-generic/hugetlb.h>
>>
>> +#define hugepages_supported() cpu_has_pse
>>
>
> Please don't use the cpu_has_* macros anymore, they are going away soon.
>
> In this case it should be static_cpu_has(X86_FEATURE_PSE).

I can certainly do that, but this
- will (mildly) harm backportability
- imo should have been requested much earlier (when the patch was
still under discussion)

Jan

2016-04-25 07:54:42

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [tip:x86/asm] x86/mm/xen: Suppress hugetlbfs in PV guests

On Mon, 25 Apr 2016, Jan Beulich wrote:
> >>> On 22.04.16 at 20:03, <[email protected]> wrote:
> >> +#define hugepages_supported() cpu_has_pse
> >>
> >
> > Please don't use the cpu_has_* macros anymore, they are going away soon.
> >
> > In this case it should be static_cpu_has(X86_FEATURE_PSE).
>
> I can certainly do that, but this
> - will (mildly) harm backportability
> - imo should have been requested much earlier (when the patch was
> still under discussion)

It's requested now as cpu_has_* is going away. So instead of making silly
arguments you should have sent a delta patch fixing this.

Thanks,

tglx

2016-04-25 12:39:42

by David Vrabel

[permalink] [raw]
Subject: Re: [Xen-devel] [tip:x86/asm] x86/mm/xen: Suppress hugetlbfs in PV guests

On 25/04/16 08:52, Thomas Gleixner wrote:
> On Mon, 25 Apr 2016, Jan Beulich wrote:
>>>>> On 22.04.16 at 20:03, <[email protected]> wrote:
>>>> +#define hugepages_supported() cpu_has_pse
>>>>
>>>
>>> Please don't use the cpu_has_* macros anymore, they are going away soon.
>>>
>>> In this case it should be static_cpu_has(X86_FEATURE_PSE).
>>
>> I can certainly do that, but this
>> - will (mildly) harm backportability
>> - imo should have been requested much earlier (when the patch was
>> still under discussion)
>
> It's requested now as cpu_has_* is going away. So instead of making silly
> arguments you should have sent a delta patch fixing this.

Ingo fixed this up in the x86/asm branch[1] so I assumed this patch
didn't need updating.

David

[1]
https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?h=x86/asm&id=b2eafe890d4a09bfa63ab31ff018d7d6bb8cfefc