From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753289Ab1GLNZG (ORCPT ); Tue, 12 Jul 2011 09:25:06 -0400 Received: from s15228384.onlinehome-server.info ([87.106.30.177]:35844 "EHLO mail.x86-64.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753096Ab1GLNZE (ORCPT ); Tue, 12 Jul 2011 09:25:04 -0400 Date: Tue, 12 Jul 2011 15:24:49 +0200 From: Borislav Petkov To: Andrew Lutomirski Cc: Borislav Petkov , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , Ingo Molnar , John Stultz , Borislav Petkov Subject: Re: [PATCH v2 1/8] x86-64: Improve vsyscall emulation CS and RIP handling Message-ID: <20110712132449.GB11336@aftab> References: <2215c119e580b40f243c37d284e7bced309d975f.1310267866.git.luto@mit.edu> <20110711221432.GA10164@liondog.tnic> <20110712071832.GA17616@liondog.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 12, 2011 at 08:58:58AM -0400, Andrew Lutomirski wrote: > On Tue, Jul 12, 2011 at 3:18 AM, Borislav Petkov wrote: > > On Mon, Jul 11, 2011 at 06:20:50PM -0400, Andrew Lutomirski wrote: > >> > I'm wondering: why don't you make this function return negative value on > >> > error, i.e. -EINVAL and the vsyscall number on success so that you can > >> > get rid of returning it through the arg pointer? > >> > > >> > Then at the callsite you can do: > >> > > >> >        vsyscall_nr = addr_to_vsyscall_nr(addr); > >> >        if (vsyscall_nr < 0) > >> >                warn_bad_vsyscall(...) > >> > >> Because I don't want a warning about ret being used without being initialized. > > > > not if you preinit it... > > I kind of like that warning as a sanity check, and preiniting it > grates against my irrational desire to over-optimize :) :-) > > > >> With the code in this patch, the compiler is smart enough to figure > >> out that either vsyscall_nr is 0, 1, or 2 or that the EINVAL branch is > >> taken.  I'll see if it works the other way. > > > > here's what i mean, I changed your patch a bit: > > How about this: > > static int addr_to_vsyscall_nr(unsigned long addr) > { > int nr; > > if ((addr & ~0xC00UL) != VSYSCALL_START) > return -EINVAL; > > nr = (addr & 0xC00UL) >> 10; > if (nr >= 3) > return -EINVAL; > > return nr; > } > > ... > > int vsyscall_nr; > > ... > > vsyscall_nr = addr_to_vsyscall_nr(regs->ip - 2); > if (vsyscall_nr < 0) { > warn_bad_vsyscall(KERN_WARNING, regs, > "illegal int 0xcc (exploit attempt?)"); > goto sigsegv; > } > > gcc 4.6 at least does not warn. Yep, looks good. > Also, IRQ disabling was still mismatched in the sigsegv path. I'll > fix that as well. oh yeah. Thanks. -- Regards/Gruss, Boris. Advanced Micro Devices GmbH Einsteinring 24, 85609 Dornach GM: Alberto Bozzo Reg: Dornach, Landkreis Muenchen HRB Nr. 43632 WEEE Registernr: 129 19551