Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1191404
| Path | csiph.com!aioe.org!bofh.it!news.nic.it!robomod |
|---|---|
| From | Kees Cook <keescook@chromium.org> |
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v3 2/3] x86/ldt: Make modify_ldt optional |
| Date | Fri, 24 Jul 2015 01:40:02 +0200 |
| Message-ID | <pPyfM-527-11@gated-at.bofh.it> (permalink) |
| References | <pP7Sh-qJ-13@gated-at.bofh.it> <pP7Si-qJ-27@gated-at.bofh.it> <pPlVf-3Ua-11@gated-at.bofh.it> |
| X-Original-To | Willy Tarreau <w@1wt.eu> |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=KUa/gO80W6Rl6Hljtn6Hvu8CmU+EVnk10S7q6NrT668=; b=oofR34iUIXCQlTp/ae5XUW7Ho1VV4n/csUqM9XuCUHO6mgAnCOdYIG03szCo06ZY/O R4YNVxlZMi3HoEEXas54NMEbT2TIDIkgwWnoLUQv05nJYXJS5cLnRnuzGAD7YPp1lBrh IzBZmHBhoTBuA0VA9m8PI/0FcTikF4h4i8vh3o8fPlGPp3Bvrjflrgr+tomBDZ3RdvkO kQ7ACm4MawB5FwmbxwZw0PrXPUcbokStoa7dsM13io6/VdmDwa07ucPj9PANJHeHWFeO IAam+EXbl7HPMXvIZjdvXEqUqslzlOGx1HR1DURvbpRizlnyXbM59JA3xyV37zyoqe/6 cvRg== |
| Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=KUa/gO80W6Rl6Hljtn6Hvu8CmU+EVnk10S7q6NrT668=; b=W+rZMj6QJ2CBHzBjhJfsai3S3t2n/qeYDldCyItmp/HfpjW4eP7c0nAWywRDOv/K47 M5BSwSpl9ouGswDwWHFnlJbg6G/OL9FxFbgISWUoOsZ4iYbNOTlj9ddCG6yUTYa9H713 KWLmOi553/igVtYT61bBdL5ej3rjoPnVfh/Zo= |
| X-Google-Dkim-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=KUa/gO80W6Rl6Hljtn6Hvu8CmU+EVnk10S7q6NrT668=; b=Fo/NjvwxC3HrlMBkcFrnTiakZ00FGfIzoTNONpSwwfgtvXGQDKAHq6lSgXt/QNEfWD o7hv8BAMAwdSFHqs6TWR2agPnoDgvhU5EOymTXjJITHQzXZ+v1IaWH1iT0EoOhw82392 5FkrkJCW3ANL0GlaDabZn9RDZlXkTuB4QhYuwxLbTpwl0xEGdV5zwzMzPJwogOEGb36J bBAUZ8ZTL1tkAqnpkYOK4XT3cls1ZIoOUh09IWa7Oomlka9N80x2k1twfAltNaxnFUb0 jKlcV+yKpega9N/xk78joTNkd+F55dAD3r7+d117uFrj5r7baij73KwznkxbjTkelFnH qshA== |
| X-Gm-Message-State | ALoCoQn3aMp0DWSgU9rRWaj7FrSvcDZLV6fnYxMNoa3fVJYTpADPSc3heoPoyVEpoWwpvi8tkOQW |
| MIME-Version | 1.0 |
| X-Received | by 10.107.138.152 with SMTP id c24mr15964299ioj.74.1437694597938; Thu, 23 Jul 2015 16:36:37 -0700 (PDT) |
| X-Google-Sender-Auth | RICF7p2NqOmtM5i-5zVyP7GIQec |
| Content-Type | text/plain; charset=UTF-8 |
| Sender | robomod@news.nic.it |
| List-ID | <linux-kernel.vger.kernel.org> |
| X-Mailing-List | linux-kernel@vger.kernel.org |
| Approved | robomod@news.nic.it |
| Lines | 205 |
| Organization | linux.* mail to news gateway |
| X-Original-Cc | Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Steven Rostedt <rostedt@goodmis.org>, "security@kernel.org" <security@kernel.org>, X86 ML <x86@kernel.org>, Borislav Petkov <bp@alien8.de>, Sasha Levin <sasha.levin@oracle.com>, LKML <linux-kernel@vger.kernel.org>, Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>, Boris Ostrovsky <boris.ostrovsky@oracle.com>, Andrew Cooper <andrew.cooper3@citrix.com>, Jan Beulich <jbeulich@suse.com>, xen-devel <xen-devel@lists.xen.org> |
| X-Original-Date | Thu, 23 Jul 2015 16:36:37 -0700 |
| X-Original-Message-ID | <CAGXu5j+yEWLuxJ9JUGyN7BxME+iOVXfpFgrZ-_2WXUn6A=0dVg@mail.gmail.com> |
| X-Original-References | <cover.1437592883.git.luto@kernel.org> <7bfde005b84a90a83bf668a320c7d4ad1b940065.1437592883.git.luto@kernel.org> <20150723102434.GA2929@1wt.eu> |
| X-Original-Sender | linux-kernel-owner@vger.kernel.org |
| Xref | aioe.org linux.kernel:1191404 |
Show key headers only | View raw
On Thu, Jul 23, 2015 at 3:24 AM, Willy Tarreau <w@1wt.eu> wrote:
> Hi Andy,
>
> On Wed, Jul 22, 2015 at 12:23:47PM -0700, Andy Lutomirski wrote:
>> The modify_ldt syscall exposes a large attack surface and is
>> unnecessary for modern userspace. Make it optional.
>
> Wouldn't you prefer something like this which makes it possible to re-enable
> it at runtime so that we can hope distros ship with it disabled by default ?
>
> It's pretty efficient on your ldtgdt testcase :
>
> # echo 1 > /proc/sys/kernel/modify_ldt
> # ./a.out
> [OK] LDT entry 0 has AR 0x0040FA00 and limit 0x0000000A
> [OK] LDT entry 0 has AR 0x00C0FA00 and limit 0x0000AFFF
> [OK] LDT entry 1 is invalid
> [OK] LDT entry 2 has AR 0x00C0FA00 and limit 0x0000AFFF
> [OK] LDT entry 1 is invalid
> [OK] LDT entry 2 has AR 0x00C0FA00 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D0FA00 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D07A00 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00907A00 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D07200 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D07000 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D07400 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00507600 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507E00 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507C00 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507A00 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507800 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507800 and limit 0x0000000A
> [RUN] Test fork
> [OK] LDT entry 2 has AR 0x00507800 and limit 0x0000000A
> [OK] LDT entry 1 is invalid
> [OK] LDT entry 0 has AR 0x0040FA00 and limit 0x0000000A
> [OK] LDT entry 0 has AR 0x00C0FA00 and limit 0x0000AFFF
> [OK] LDT entry 1 is invalid
> [OK] LDT entry 2 has AR 0x00C0FA00 and limit 0x0000AFFF
> [OK] LDT entry 1 is invalid
> [OK] LDT entry 2 has AR 0x00C0FA00 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D0FA00 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D07A00 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00907A00 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D07200 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D07000 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00D07400 and limit 0x0000AFFF
> [OK] LDT entry 2 has AR 0x00507600 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507E00 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507C00 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507A00 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507800 and limit 0x0000000A
> [OK] LDT entry 2 has AR 0x00507800 and limit 0x0000000A
> [RUN] Test fork
> [OK] Child succeeded
> [OK] modify_ldt failure 22
> [OK] LDT entry 0 has AR 0x0000F200 and limit 0x00000000
> [OK] LDT entry 0 has AR 0x00007200 and limit 0x00000000
> [OK] LDT entry 0 has AR 0x0000F000 and limit 0x00000000
> [OK] LDT entry 0 has AR 0x00007200 and limit 0x00000000
> [OK] LDT entry 0 has AR 0x00007000 and limit 0x00000001
> [OK] LDT entry 0 has AR 0x00007000 and limit 0x00000000
> [OK] LDT entry 0 is invalid
> [OK] LDT entry 0 has AR 0x0040F200 and limit 0x00000000
> [OK] LDT entry 0 is invalid
> [SKIP] Cannot set affinity to CPU 1
>
>
> # echo 0 > /proc/sys/kernel/modify_ldt
> # ./a.out
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] LDT entry 1 is invalid
> [OK] modify_ldt is returned -ENOSYS
> [OK] LDT entry 1 is invalid
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [SKIP] Skipping fork test because have no LDT
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [OK] modify_ldt is returned -ENOSYS
> [SKIP] Cannot set affinity to CPU 1
>
> The patch is quite small (I stole your comment for the config option).
>
> Willy
>
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 226d569..b926f65 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -1012,6 +1012,23 @@ config X86_16BIT
> this option saves about 300 bytes on i386, or around 6K text
> plus 16K runtime memory on x86-64,
>
> +config DEFAULT_MODIFY_LDT_SYSCALL
> + bool "Allow userspace to modify the LDT (local descriptor table)"
> + default y
> + ---help---
> + Linux can allow user programs to install a per-process x86
> + Local Descriptor Table (LDT) using the modify_ldt(2) system
> + call. This is required to run 16-bit or segmented code such as
> + DOSEMU or some Wine programs. It is also used by some very old
> + threading libraries.
> +
> + Enabling this feature increases the low-level kernel attack
> + surface. Disabling it disables the modify_ldt(2) system call by
> + default. Note that even when disabled it remains possible to
> + enable it at runtime by setting the sys.kernel.modify_ldt sysctl.
> +
> + Say 'N' here if you don't expect to use DOSEMU or Wine often.
> +
> config X86_ESPFIX32
> def_bool y
> depends on X86_16BIT && X86_32
> diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
> index c37886d..2f10b6c 100644
> --- a/arch/x86/kernel/ldt.c
> +++ b/arch/x86/kernel/ldt.c
> @@ -20,6 +20,12 @@
> #include <asm/mmu_context.h>
> #include <asm/syscalls.h>
>
> +#ifdef CONFIG_DEFAULT_MODIFY_LDT_SYSCALL
> +int sysctl_modify_ldt __read_mostly = 1;
> +#else
> +int sysctl_modify_ldt __read_mostly = 0;
> +#endif
> +
> #ifdef CONFIG_SMP
> static void flush_ldt(void *current_mm)
> {
> @@ -254,6 +260,9 @@ asmlinkage int sys_modify_ldt(int func, void __user *ptr,
> {
> int ret = -ENOSYS;
>
> + if (!sysctl_modify_ldt)
> + return ret;
> +
> switch (func) {
> case 0:
> ret = read_ldt(ptr, bytecount);
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 2082b1a..60270c6 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -111,6 +111,9 @@ extern int sysctl_nr_open_min, sysctl_nr_open_max;
> #ifndef CONFIG_MMU
> extern int sysctl_nr_trim_pages;
> #endif
> +#ifdef CONFIG_X86
> +extern int sysctl_modify_ldt;
> +#endif
>
> /* Constants used for minimum and maximum */
> #ifdef CONFIG_LOCKUP_DETECTOR
> @@ -962,6 +965,13 @@ static struct ctl_table kern_table[] = {
> .mode = 0644,
> .proc_handler = proc_dointvec,
> },
> + {
> + .procname = "modify_ldt",
> + .data = &sysctl_modify_ldt,
> + .maxlen = sizeof(int),
> + .mode = 0644,
> + .proc_handler = proc_dointvec,
> + },
> #endif
> #if defined(CONFIG_MMU)
> {
I've been pondering something like this that is even MORE generic, for
any syscall. Something like a "syscalls" directory under
/proc/sys/kernel, with 1 entry per syscall. "0" is "available", "1" is
disabled, and "-1" disabled until next boot.
-Kees
--
Kees Cook
Chrome OS Security
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread
Re: [PATCH v3 2/3] x86/ldt: Make modify_ldt optional Kees Cook <keescook@chromium.org> - 2015-07-24 01:40 +0200
Re: [PATCH v3 2/3] x86/ldt: Make modify_ldt optional Andy Lutomirski <luto@amacapital.net> - 2015-07-24 01:50 +0200
Re: [PATCH v3 2/3] x86/ldt: Make modify_ldt optional Willy Tarreau <w@1wt.eu> - 2015-07-24 02:00 +0200
Re: [PATCH v3 2/3] x86/ldt: Make modify_ldt optional Kees Cook <keescook@chromium.org> - 2015-07-24 02:10 +0200
Re: [PATCH v3 2/3] x86/ldt: Make modify_ldt optional Willy Tarreau <w@1wt.eu> - 2015-07-24 09:30 +0200
Re: [PATCH v3 2/3] x86/ldt: Make modify_ldt optional Willy Tarreau <w@1wt.eu> - 2015-07-24 09:50 +0200
csiph-web