From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756415Ab2ARTik (ORCPT ); Wed, 18 Jan 2012 14:38:40 -0500 Received: from mail-tul01m020-f174.google.com ([209.85.214.174]:53611 "EHLO mail-tul01m020-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752999Ab2ARTii convert rfc822-to-8bit (ORCPT ); Wed, 18 Jan 2012 14:38:38 -0500 MIME-Version: 1.0 In-Reply-To: References: <20120116183730.GB21112@redhat.com> <20120117164523.GA17070@redhat.com> <20120117170512.GB17070@redhat.com> <49017bd7edab7010cd9ac767e39d99e4.squirrel@webmail.greenhost.nl> <20120118015013.GR11715@one.firstfloor.org> <20120118020453.GL7180@jl-vm1.vm.bytemark.co.uk> <20120118022217.GS11715@one.firstfloor.org> From: Andrew Lutomirski Date: Wed, 18 Jan 2012 11:38:16 -0800 X-Google-Sender-Auth: UMwXhCv13grAnH1roNj0T0ZPJsY Message-ID: Subject: Re: Compat 32-bit syscall entry from 64-bit task!? To: Linus Torvalds Cc: Indan Zupancic , Andi Kleen , Jamie Lokier , Oleg Nesterov , Will Drewry , linux-kernel@vger.kernel.org, keescook@chromium.org, john.johansen@canonical.com, serge.hallyn@canonical.com, coreyb@linux.vnet.ibm.com, pmoore@redhat.com, eparis@redhat.com, djm@mindrot.org, segoon@openwall.com, rostedt@goodmis.org, jmorris@namei.org, scarybeasts@gmail.com, avi@redhat.com, penberg@cs.helsinki.fi, viro@zeniv.linux.org.uk, mingo@elte.hu, akpm@linux-foundation.org, khilman@ti.com, borislav.petkov@amd.com, amwang@redhat.com, ak@linux.intel.com, eric.dumazet@gmail.com, gregkh@suse.de, dhowells@redhat.com, daniel.lezcano@free.fr, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, olofj@chromium.org, mhalcrow@google.com, dlaor@redhat.com, Roland McGrath Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 18, 2012 at 11:31 AM, Linus Torvalds wrote: > The actually used code just does > >                /* Check CS register value. On x86-64 linux it is: >                 *      0x33    for long mode (64 bit) >                 *      0x23    for compatibility mode (32 bit) >                 * It takes only one ptrace and thus doesn't need >                 * to be cached. >                 */ >                if (upeek(tcp, 8*CS, &val) < 0) >                        return -1; >                switch (val) { >                        case 0x23: currpers = 1; break; >                        case 0x33: currpers = 0; break; > > which is the reasonable and obvious approach. *sigh* It's reasonable, obvious, and even more wrong than it appears. On Xen, there's an extra 64-bit GDT entry, and it gets used by default. (I got bitten by this in some iteration of the vsyscall emulation patches -- see user_64bit_mode for the correct and unusable-from-user-mode way to do this.) --Andy From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Lutomirski Subject: Re: Compat 32-bit syscall entry from 64-bit task!? Date: Wed, 18 Jan 2012 11:38:16 -0800 Message-ID: References: <20120116183730.GB21112@redhat.com> <20120117164523.GA17070@redhat.com> <20120117170512.GB17070@redhat.com> <49017bd7edab7010cd9ac767e39d99e4.squirrel@webmail.greenhost.nl> <20120118015013.GR11715@one.firstfloor.org> <20120118020453.GL7180@jl-vm1.vm.bytemark.co.uk> <20120118022217.GS11715@one.firstfloor.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Indan Zupancic , Andi Kleen , Jamie Lokier , Oleg Nesterov , Will Drewry , linux-kernel@vger.kernel.org, keescook@chromium.org, john.johansen@canonical.com, serge.hallyn@canonical.com, coreyb@linux.vnet.ibm.com, pmoore@redhat.com, eparis@redhat.com, djm@mindrot.org, segoon@openwall.com, rostedt@goodmis.org, jmorris@namei.org, scarybeasts@gmail.com, avi@redhat.com, penberg@cs.helsinki.fi, viro@zeniv.linux.org.uk, mingo@elte.hu, akpm@linux-foundation.org, khilman@ti.com, borislav.petkov@amd.com, amwang@redhat.com, ak@linux.intel.com, eric.dumazet@gmail.com, gregkh@suse.de, dhowells@redhat.com, daniel.lezcano@free.fr, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, olofj@chromium.org, mhalcrow@google.com, dlaor@redhat.com, Roland McGrath Return-path: In-Reply-To: Sender: linux-security-module-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Wed, Jan 18, 2012 at 11:31 AM, Linus Torvalds wrote: > The actually used code just does > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Check CS register value. On x86-64 = linux it is: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0 =A0 =A00x33 =A0 =A0for long mod= e (64 bit) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0 =A0 =A00x23 =A0 =A0for compatib= ility mode (32 bit) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * It takes only one ptrace and thus d= oesn't need > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * to be cached. > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (upeek(tcp, 8*CS, &val) < 0) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -1; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0switch (val) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0case 0x23: currpers =3D= 1; break; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0case 0x33: currpers =3D= 0; break; > > which is the reasonable and obvious approach. *sigh* It's reasonable, obvious, and even more wrong than it appears. On Xen, there's an extra 64-bit GDT entry, and it gets used by default. (I got bitten by this in some iteration of the vsyscall emulation patches -- see user_64bit_mode for the correct and unusable-from-user-mode way to do this.) --Andy -- To unsubscribe from this list: send the line "unsubscribe linux-securit= y-module" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html