From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B8C20C48BC3 for ; Sat, 17 Feb 2024 06:51:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kI7WqutFPyVgl5ZiSxiNncLoIjxfIW7OhIItO5a3P5k=; b=crNGPciYTLeWa/ C26SabfiJZJBHmfmQ2s9lYYEym6gxEZ198ityeCM4vvc4zp7BUsoCqhePKEA9AKHynjPnwU1cj+CY UNvP26Vj0Kq9sWPIxtJRvpk6Et1KGTICtbX3+nK+rrouT5IFF8pE4Fn/m4AfiWCMI4BKb0wL/oucq 1b2cF9TBvVTZ97ILXvH81yHtoua/QdOuv9seJ1ZLxE8Wq279PFH7Rsy7D02846BMxgRlmwUxX/DxO ns2eK+vUVgfHmTqSR9r/JS2mWmpwhhERis1LsZzx8b6tPR4N4FZVMy9PgS1welvyOY/4G8mFkdHJm K8/nhw49sKiGF2I2s1vg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbEXH-00000004mEL-1kjb; Sat, 17 Feb 2024 06:50:55 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rbEXE-00000004mDq-0fTx for linux-arm-kernel@lists.infradead.org; Sat, 17 Feb 2024 06:50:53 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1d944e8f367so26261335ad.0 for ; Fri, 16 Feb 2024 22:50:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708152651; x=1708757451; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=M0q5qNIApr2OHWTfe/JN5Axwx5QFdCs/VPp5utoSVVg=; b=JALa71SlUpPJUtO4phKGSE3Wj8bI7/W6v8Ut5N3CPiVgXEzQGbOiGVb9f8RDMTEqVt m+aWcwJSoF8Ny7h4KndM/l6ep/pjWILmBbBvsAum/k1zEr+cpcnfqo6yxS2EVOTMlqz6 TqVdQ6G+Ryw1vIYj0Ix5KQUi/tTmwRRdEWolk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708152651; x=1708757451; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=M0q5qNIApr2OHWTfe/JN5Axwx5QFdCs/VPp5utoSVVg=; b=oWCYGCKMnVexAVfp1nR0VYdtyN/O+rcADyBo3ZpSj98hjhmUpqS1b/9nkb4zGyPizZ 3Fg59XgPxBLMoyujSPZ+JznRYNz5FUekQKcn3kVhYzLJVLJOctfqNeiKjl5t8cM+GBWD RDn6hl7aSSk8ULrvbTbHYHjw+Zhec9o6d17BxAo1pS0tK4R8rH0Gz+y0XEYGHIq9c7U9 0CNx+VxtgFmicZ8R043FzjjLB/l9e6o8NJ5g1p5cu4ifWImA3snURT9dwS4FCTGaBv60 oBugLMifw6WIQBG3lx3ETbdEkema69N7An2WJOj9fAs9fFzoTFBuW6Oc2Y/8xX9qW7so fSKQ== X-Forwarded-Encrypted: i=1; AJvYcCXRBbEhCvhzkFqQrc2aqkmOIAjgTA4bBolEEGOLR/+vKK/fglTbu/7NWc6xNVVlHHC4+O8rLPeep+e3tUnaLCXtaWZu0N89ONEqmGvsi2WJfi8V5U4= X-Gm-Message-State: AOJu0Yy63dZlWBYoDwxDJ6e1XTUrk0jI/iOzpSSQn8X5jwv54eHf5lPO YiiwMnhLvgB7UOebVtyN+DM+LiEwdHx+kjGa9EfDJTpBhJ3hm01q7GhtsyD+qw== X-Google-Smtp-Source: AGHT+IFSRrYHCfvNmI4dBaEfzwYrVFvg0hjm2ZEaDRlwH/ZNcq3QNYV4GRamj4PDHKIaB210IqDS8w== X-Received: by 2002:a17:902:eb83:b0:1db:aef8:8db4 with SMTP id q3-20020a170902eb8300b001dbaef88db4mr3585714plg.24.1708152650948; Fri, 16 Feb 2024 22:50:50 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id w16-20020a1709029a9000b001db60446abdsm815390plp.262.2024.02.16.22.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 22:50:50 -0800 (PST) Date: Fri, 16 Feb 2024 22:50:49 -0800 From: Kees Cook To: Kostya Serebryany , Vitaly Buka , glider@google.com Cc: Evgeniy Stepanov , Daniel Micay , Dmitry Vyukov , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Pratyush Anand , Dong Bo , Dmitry Safonov , Rik van Riel , Andy Lutomirski , Grzegorz Andrejczuk , linux-arm-kernel@lists.infradead.org, Reid Kleckner , Andrew Morton , Peter Collingbourne , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, address-sanitizer@googlegroups.com Subject: Re: [PATCH] mm: Revert x86_64 and arm64 ELF_ET_DYN_BASE base Message-ID: <202402162238.E5D08F5968@keescook> References: <20170807201542.GA21271@beast> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170807201542.GA21271@beast> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_225052_250698_DE7DA4DC X-CRM114-Status: GOOD ( 30.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org *extreme thread[1] necromancy* On Mon, Aug 07, 2017 at 01:15:42PM -0700, Kees Cook wrote: > Moving the x86_64 and arm64 PIE base from 0x555555554000 to 0x000100000000 > broke AddressSanitizer. This is a partial revert of: > > commit eab09532d400 ("binfmt_elf: use ELF_ET_DYN_BASE only for PIE") > commit 02445990a96e ("arm64: move ELF_ET_DYN_BASE to 4GB / 4MB") > > The AddressSanitizer tool has hard-coded expectations about where > executable mappings are loaded. The motivation for changing the PIE > base in the above commits was to avoid the Stack-Clash CVEs that > allowed executable mappings to get too close to heap and stack. This > was mainly a problem on 32-bit, but the 64-bit bases were moved too, > in an effort to proactively protect those systems (proofs of concept > do exist that show 64-bit collisions, but other recent changes to fix > stack accounting and setuid behaviors will minimize the impact). I happened to be looking at this again today, and wondered where things stood. It seems like ASan's mappings are documented here: https://github.com/google/sanitizers/wiki/AddressSanitizerAlgorithm#64-bit This implies that it would be safe to move the ELF_ET_DYN_BASE from 0x555555554000 down to 0x200000000000, since the shadow map ends at 0x10007fff7fff. (Well, anything above there would work, I was just picking a "round" number above it. We could just as well use 0x100080000000, I think.) Is this correct? I'd like to open up some more room between mmap and stack... Thanks! -Kees [1] https://lore.kernel.org/lkml/20170807201542.GA21271@beast/ > > The new 32-bit PIE base is fine for ASan (since it matches the ET_EXEC > base), so only the 64-bit PIE base needs to be reverted to let x86 and > arm64 ASan binaries run again. Future changes to the 64-bit PIE base on > these architectures can be made optional once a more dynamic method for > dealing with AddressSanitizer is found. (e.g. always loading PIE into > the mmap region for marked binaries.) > > Reported-by: Kostya Serebryany > Cc: stable@vger.kernel.org > Signed-off-by: Kees Cook > --- > arch/arm64/include/asm/elf.h | 4 ++-- > arch/x86/include/asm/elf.h | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h > index acae781f7359..3288c2b36731 100644 > --- a/arch/arm64/include/asm/elf.h > +++ b/arch/arm64/include/asm/elf.h > @@ -114,10 +114,10 @@ > > /* > * This is the base location for PIE (ET_DYN with INTERP) loads. On > - * 64-bit, this is raised to 4GB to leave the entire 32-bit address > + * 64-bit, this is above 4GB to leave the entire 32-bit address > * space open for things that want to use the area for 32-bit pointers. > */ > -#define ELF_ET_DYN_BASE 0x100000000UL > +#define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3) > > #ifndef __ASSEMBLY__ > > diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h > index 1c18d83d3f09..9aeb91935ce0 100644 > --- a/arch/x86/include/asm/elf.h > +++ b/arch/x86/include/asm/elf.h > @@ -247,11 +247,11 @@ extern int force_personality32; > > /* > * This is the base location for PIE (ET_DYN with INTERP) loads. On > - * 64-bit, this is raised to 4GB to leave the entire 32-bit address > + * 64-bit, this is above 4GB to leave the entire 32-bit address > * space open for things that want to use the area for 32-bit pointers. > */ > #define ELF_ET_DYN_BASE (mmap_is_ia32() ? 0x000400000UL : \ > - 0x100000000UL) > + (TASK_SIZE / 3 * 2)) > > /* This yields a mask that user programs can use to figure out what > instruction set this CPU supports. This could be done in user space, > -- > 2.7.4 > > > -- > Kees Cook > Pixel Security -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel