Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1312415 > unrolled thread
| Started by | Kees Cook <keescook@chromium.org> |
|---|---|
| First post | 2016-01-19 19:10 +0100 |
| Last post | 2016-01-20 04:00 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v4 8/8] x86, vdso: mark vDSO read-only after init Kees Cook <keescook@chromium.org> - 2016-01-19 19:10 +0100
Re: [PATCH v4 8/8] x86, vdso: mark vDSO read-only after init Andy Lutomirski <luto@amacapital.net> - 2016-01-19 20:10 +0100
Re: [PATCH v4 8/8] x86, vdso: mark vDSO read-only after init "H. Peter Anvin" <hpa@zytor.com> - 2016-01-20 04:00 +0100
Re: [PATCH v4 8/8] x86, vdso: mark vDSO read-only after init Andy Lutomirski <luto@amacapital.net> - 2016-01-20 04:00 +0100
| From | Kees Cook <keescook@chromium.org> |
|---|---|
| Date | 2016-01-19 19:10 +0100 |
| Subject | [PATCH v4 8/8] x86, vdso: mark vDSO read-only after init |
| Message-ID | <qSIT9-33H-29@gated-at.bofh.it> |
The vDSO does not need to be writable after __init, so mark it as
__ro_after_init. The result kills the exploit method of writing to the
vDSO from kernel space resulting in userspace executing the modified code,
as shown here to bypass SMEP restrictions: http://itszn.com/blog/?p=21
The memory map (with added vDSO address reporting) shows the vDSO moving
into read-only memory:
Before:
[ 0.143067] vDSO @ ffffffff82004000
[ 0.143551] vDSO @ ffffffff82006000
---[ High Kernel Mapping ]---
0xffffffff80000000-0xffffffff81000000 16M pmd
0xffffffff81000000-0xffffffff81800000 8M ro PSE GLB x pmd
0xffffffff81800000-0xffffffff819f3000 1996K ro GLB x pte
0xffffffff819f3000-0xffffffff81a00000 52K ro NX pte
0xffffffff81a00000-0xffffffff81e00000 4M ro PSE GLB NX pmd
0xffffffff81e00000-0xffffffff81e05000 20K ro GLB NX pte
0xffffffff81e05000-0xffffffff82000000 2028K ro NX pte
0xffffffff82000000-0xffffffff8214f000 1340K RW GLB NX pte
0xffffffff8214f000-0xffffffff82281000 1224K RW NX pte
0xffffffff82281000-0xffffffff82400000 1532K RW GLB NX pte
0xffffffff82400000-0xffffffff83200000 14M RW PSE GLB NX pmd
0xffffffff83200000-0xffffffffc0000000 974M pmd
After:
[ 0.145062] vDSO @ ffffffff81da1000
[ 0.146057] vDSO @ ffffffff81da4000
---[ High Kernel Mapping ]---
0xffffffff80000000-0xffffffff81000000 16M pmd
0xffffffff81000000-0xffffffff81800000 8M ro PSE GLB x pmd
0xffffffff81800000-0xffffffff819f3000 1996K ro GLB x pte
0xffffffff819f3000-0xffffffff81a00000 52K ro NX pte
0xffffffff81a00000-0xffffffff81e00000 4M ro PSE GLB NX pmd
0xffffffff81e00000-0xffffffff81e0b000 44K ro GLB NX pte
0xffffffff81e0b000-0xffffffff82000000 2004K ro NX pte
0xffffffff82000000-0xffffffff8214c000 1328K RW GLB NX pte
0xffffffff8214c000-0xffffffff8227e000 1224K RW NX pte
0xffffffff8227e000-0xffffffff82400000 1544K RW GLB NX pte
0xffffffff82400000-0xffffffff83200000 14M RW PSE GLB NX pmd
0xffffffff83200000-0xffffffffc0000000 974M pmd
Based on work by PaX Team and Brad Spengler.
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Andy Lutomirski <luto@kernel.org>
---
arch/x86/entry/vdso/vdso2c.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/entry/vdso/vdso2c.h b/arch/x86/entry/vdso/vdso2c.h
index 0224987556ce..eb93a3137ed2 100644
--- a/arch/x86/entry/vdso/vdso2c.h
+++ b/arch/x86/entry/vdso/vdso2c.h
@@ -140,7 +140,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
fprintf(outfile, "#include <asm/vdso.h>\n");
fprintf(outfile, "\n");
fprintf(outfile,
- "static unsigned char raw_data[%lu] __page_aligned_data = {",
+ "static unsigned char raw_data[%lu] __ro_after_init __aligned(PAGE_SIZE) = {",
mapping_size);
for (j = 0; j < stripped_len; j++) {
if (j % 10 == 0)
@@ -150,7 +150,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
}
fprintf(outfile, "\n};\n\n");
- fprintf(outfile, "static struct page *pages[%lu];\n\n",
+ fprintf(outfile, "static struct page *pages[%lu] __ro_after_init;\n\n",
mapping_size / 4096);
fprintf(outfile, "const struct vdso_image %s = {\n", name);
--
2.6.3
[toc] | [next] | [standalone]
| From | Andy Lutomirski <luto@amacapital.net> |
|---|---|
| Date | 2016-01-19 20:10 +0100 |
| Message-ID | <qSJPc-3EO-15@gated-at.bofh.it> |
| In reply to | #1312415 |
On Tue, Jan 19, 2016 at 10:08 AM, Kees Cook <keescook@chromium.org> wrote: > The vDSO does not need to be writable after __init, so mark it as > __ro_after_init. The result kills the exploit method of writing to the > vDSO from kernel space resulting in userspace executing the modified code, > as shown here to bypass SMEP restrictions: http://itszn.com/blog/?p=21 > > The memory map (with added vDSO address reporting) shows the vDSO moving > into read-only memory: Acked-by: Andy Lutomirski <luto@kernel.org>
[toc] | [prev] | [next] | [standalone]
| From | "H. Peter Anvin" <hpa@zytor.com> |
|---|---|
| Date | 2016-01-20 04:00 +0100 |
| Message-ID | <qSRa2-5e-9@gated-at.bofh.it> |
| In reply to | #1312415 |
On 01/19/16 10:08, Kees Cook wrote: > The vDSO does not need to be writable after __init, so mark it as > __ro_after_init. The result kills the exploit method of writing to the > vDSO from kernel space resulting in userspace executing the modified code, > as shown here to bypass SMEP restrictions: http://itszn.com/blog/?p=21 > > The memory map (with added vDSO address reporting) shows the vDSO moving > into read-only memory: > > Before: > [ 0.143067] vDSO @ ffffffff82004000 > [ 0.143551] vDSO @ ffffffff82006000 > ---[ High Kernel Mapping ]--- > 0xffffffff80000000-0xffffffff81000000 16M pmd > 0xffffffff81000000-0xffffffff81800000 8M ro PSE GLB x pmd > 0xffffffff81800000-0xffffffff819f3000 1996K ro GLB x pte > 0xffffffff819f3000-0xffffffff81a00000 52K ro NX pte > 0xffffffff81a00000-0xffffffff81e00000 4M ro PSE GLB NX pmd > 0xffffffff81e00000-0xffffffff81e05000 20K ro GLB NX pte > 0xffffffff81e05000-0xffffffff82000000 2028K ro NX pte > 0xffffffff82000000-0xffffffff8214f000 1340K RW GLB NX pte > 0xffffffff8214f000-0xffffffff82281000 1224K RW NX pte > 0xffffffff82281000-0xffffffff82400000 1532K RW GLB NX pte > 0xffffffff82400000-0xffffffff83200000 14M RW PSE GLB NX pmd > 0xffffffff83200000-0xffffffffc0000000 974M pmd > > After: > [ 0.145062] vDSO @ ffffffff81da1000 > [ 0.146057] vDSO @ ffffffff81da4000 > ---[ High Kernel Mapping ]--- > 0xffffffff80000000-0xffffffff81000000 16M pmd > 0xffffffff81000000-0xffffffff81800000 8M ro PSE GLB x pmd > 0xffffffff81800000-0xffffffff819f3000 1996K ro GLB x pte > 0xffffffff819f3000-0xffffffff81a00000 52K ro NX pte > 0xffffffff81a00000-0xffffffff81e00000 4M ro PSE GLB NX pmd > 0xffffffff81e00000-0xffffffff81e0b000 44K ro GLB NX pte > 0xffffffff81e0b000-0xffffffff82000000 2004K ro NX pte > 0xffffffff82000000-0xffffffff8214c000 1328K RW GLB NX pte > 0xffffffff8214c000-0xffffffff8227e000 1224K RW NX pte > 0xffffffff8227e000-0xffffffff82400000 1544K RW GLB NX pte > 0xffffffff82400000-0xffffffff83200000 14M RW PSE GLB NX pmd > 0xffffffff83200000-0xffffffffc0000000 974M pmd > > Based on work by PaX Team and Brad Spengler. > > Signed-off-by: Kees Cook <keescook@chromium.org> > Acked-by: Andy Lutomirski <luto@kernel.org> Acked-by: H. Peter Anvin <hpa@linux.intel.com>
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@amacapital.net> |
|---|---|
| Date | 2016-01-20 04:00 +0100 |
| Message-ID | <qSRa3-5e-49@gated-at.bofh.it> |
| In reply to | #1312415 |
On Tue, Jan 19, 2016 at 10:08 AM, Kees Cook <keescook@chromium.org> wrote:
> The vDSO does not need to be writable after __init, so mark it as
> __ro_after_init. The result kills the exploit method of writing to the
> vDSO from kernel space resulting in userspace executing the modified code,
> as shown here to bypass SMEP restrictions: http://itszn.com/blog/?p=21
>
> The memory map (with added vDSO address reporting) shows the vDSO moving
> into read-only memory:
>
> Before:
> [ 0.143067] vDSO @ ffffffff82004000
> [ 0.143551] vDSO @ ffffffff82006000
> ---[ High Kernel Mapping ]---
> 0xffffffff80000000-0xffffffff81000000 16M pmd
> 0xffffffff81000000-0xffffffff81800000 8M ro PSE GLB x pmd
> 0xffffffff81800000-0xffffffff819f3000 1996K ro GLB x pte
> 0xffffffff819f3000-0xffffffff81a00000 52K ro NX pte
> 0xffffffff81a00000-0xffffffff81e00000 4M ro PSE GLB NX pmd
> 0xffffffff81e00000-0xffffffff81e05000 20K ro GLB NX pte
> 0xffffffff81e05000-0xffffffff82000000 2028K ro NX pte
> 0xffffffff82000000-0xffffffff8214f000 1340K RW GLB NX pte
> 0xffffffff8214f000-0xffffffff82281000 1224K RW NX pte
> 0xffffffff82281000-0xffffffff82400000 1532K RW GLB NX pte
> 0xffffffff82400000-0xffffffff83200000 14M RW PSE GLB NX pmd
> 0xffffffff83200000-0xffffffffc0000000 974M pmd
>
> After:
> [ 0.145062] vDSO @ ffffffff81da1000
> [ 0.146057] vDSO @ ffffffff81da4000
> ---[ High Kernel Mapping ]---
> 0xffffffff80000000-0xffffffff81000000 16M pmd
> 0xffffffff81000000-0xffffffff81800000 8M ro PSE GLB x pmd
> 0xffffffff81800000-0xffffffff819f3000 1996K ro GLB x pte
> 0xffffffff819f3000-0xffffffff81a00000 52K ro NX pte
> 0xffffffff81a00000-0xffffffff81e00000 4M ro PSE GLB NX pmd
> 0xffffffff81e00000-0xffffffff81e0b000 44K ro GLB NX pte
> 0xffffffff81e0b000-0xffffffff82000000 2004K ro NX pte
> 0xffffffff82000000-0xffffffff8214c000 1328K RW GLB NX pte
> 0xffffffff8214c000-0xffffffff8227e000 1224K RW NX pte
> 0xffffffff8227e000-0xffffffff82400000 1544K RW GLB NX pte
> 0xffffffff82400000-0xffffffff83200000 14M RW PSE GLB NX pmd
> 0xffffffff83200000-0xffffffffc0000000 974M pmd
>
> Based on work by PaX Team and Brad Spengler.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Acked-by: Andy Lutomirski <luto@kernel.org>
> ---
> arch/x86/entry/vdso/vdso2c.h | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/entry/vdso/vdso2c.h b/arch/x86/entry/vdso/vdso2c.h
> index 0224987556ce..eb93a3137ed2 100644
> --- a/arch/x86/entry/vdso/vdso2c.h
> +++ b/arch/x86/entry/vdso/vdso2c.h
> @@ -140,7 +140,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
> fprintf(outfile, "#include <asm/vdso.h>\n");
> fprintf(outfile, "\n");
> fprintf(outfile,
> - "static unsigned char raw_data[%lu] __page_aligned_data = {",
> + "static unsigned char raw_data[%lu] __ro_after_init __aligned(PAGE_SIZE) = {",
> mapping_size);
> for (j = 0; j < stripped_len; j++) {
> if (j % 10 == 0)
> @@ -150,7 +150,7 @@ static void BITSFUNC(go)(void *raw_addr, size_t raw_len,
> }
> fprintf(outfile, "\n};\n\n");
>
> - fprintf(outfile, "static struct page *pages[%lu];\n\n",
> + fprintf(outfile, "static struct page *pages[%lu] __ro_after_init;\n\n",
I spoke a bit too soon. This line of code is gone in -tip:
https://git.kernel.org/cgit/linux/kernel/git/tip/tip.git/commit/?h=x86/asm&id=05ef76b20fc4297b0d3f8a956f1c809a8a1b3f1d
My ack stands for the other change in here, though.
--Andy
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web