Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp82435rdb; Fri, 16 Feb 2024 22:51:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWuYVEDvGDwIMX5fHflbxBJWn3h/NZ5HUehO9UOWF1zIv2naX02yGDXs0+4cGU0aMJ9MYwrk1lywv3fW0c8oRHT8JbSGRj6LVQb1p6pVQ== X-Google-Smtp-Source: AGHT+IFsqPZcPunrXHvDUgEhUU9u7rA6yv+DtnZ14sTfuO0iFIMu5fJpliB9SGuQuKoelMpTscVr X-Received: by 2002:a05:620a:4148:b0:787:4148:f74f with SMTP id k8-20020a05620a414800b007874148f74fmr4294457qko.29.1708152659839; Fri, 16 Feb 2024 22:50:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708152659; cv=pass; d=google.com; s=arc-20160816; b=DUJKBX6gUza4hiua0/x/zGUIr2AkxWuMDUeAyfr9MVPRtQ/o5nrL/8NMXfnyJDgKF2 jck1sZHNK35ITEvLtdM9IuWkY95ZbY3oLjVrC95Q3mol5YNnCPojy7KXmHeYhuWq1sek NPTVeXwAp9tYUW/fyaS3S3mrECwddn9ljFUjg2MMZj4w9J6ek2kgnWZ9Ifoj1MiwsVeb BWNFOM+HQS3zod9vTGqdnFGiaTcEbjsLtHyBfEPobbyM1e+1uyJ1jCDLLTZFMtWRl+4V qo/cU0KmAzNY8Pn4NBBlhQgTbxhKW5+mQIE30XRDqMWAUDXkRqXBK3W+owGaePVpD5IA fS+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=M0q5qNIApr2OHWTfe/JN5Axwx5QFdCs/VPp5utoSVVg=; fh=VcTwIY4gm1ebIZYb+HDnffxZZV02fmFa+9F1Sc2Vqg4=; b=A7Z+hxkCFkyt5P4nMDkzfAU5ASSVwHL/HssUsx74lIDQGnl6IE4HFgmpliL9h9KASx gE5qWR8Ocys9lue9Yz+PdOe+7hO0v1JyRtPln4QNfLvXzgxOg2N/hVsypqSaXNEOcHTq DVAicMbv4ouG3lSwTYyhwVTW35j93zCNpkMa/h1Ej+Wsw4bos80cGcSAnhhjwGbTpwwJ EqyGIz8jnDJKqdnEZ0ByAtJzZJ62bR2E1/z12dzAAmZe2TKVqqZ9pIgR9CanOZ7nvyK1 JpTZaGI5nGc8haHuVMzPjUIQvlKcHtSw49XiKXrbptFJ0h1spmb9sp4n2x/sM7MAeT34 7DGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FwTE1kEj; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-69709-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u18-20020a05620a121200b007874004135dsi1659990qkj.43.2024.02.16.22.50.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 22:50:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69709-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FwTE1kEj; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-69709-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 893B61C20DBF for ; Sat, 17 Feb 2024 06:50:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 27B421CAB7; Sat, 17 Feb 2024 06:50:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="FwTE1kEj" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B20C41C2BC for ; Sat, 17 Feb 2024 06:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708152653; cv=none; b=MtIIFJaOHEO+r49fXtgLk4oKFpoU8LqWBp5IGwfPDEC5pX3TPWQCTeVDayaHrgIpn9c+I/ny4jfPF0htg3stNd9jGP6S2YfFSe+P9ktMmJ75b4t6xBWXx4EMTkgkEC5Gvvn2Ol23wRu+ykqX4fdCC2s/6MR1J3qiVUXKK/vdCx0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708152653; c=relaxed/simple; bh=qcMK+mURa9874jU0PVCvy2wIzqu0h8z9BCMIzikP4I4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eNlYbo1hlGwt6gscSeQ8CgbfBjO0OiuCpFIDAM/fa0dvy6HsVGzgeADFgR0EUSUovAel365dEmYj+mzgrQNfjtzzCa3i6W9lF7iHKjdPWSDQOxuO3w6MsshbIH8x8kc2wDPk8xlJIx+nw/2KkPJxSCDdxIyPboljMVZAjHcuR6U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=FwTE1kEj; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1d934c8f8f7so28752885ad.2 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=vger.kernel.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=FwTE1kEj8HOolxCjt0151cLgEna5eDUBBoLRhpxQHvxUlq3tQKXlJERIgli9ZEmEA3 XJV/fNdSyPsnaJ+JOYXnwgQlD48CrFfLBNeemAKEcLpCzaNHI/oCia22tKVsicyGlMqq Npaq0Q5RdenO7WO/MSM4g1I1jlyNU3H4tI7ps= 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=knDN5IsFPngiPgSVfpLDeMhY7uTIkz+ofqRZF8JL/eyReGeFLkMlGNxTQTGVy7cpUs n+cs0TYTtaTwQ2irMQcYQ2xvU3anS4XcAO8TjVAhES0T02ErwcRWhg/hvle8lTPhzVTM G/L1tTfuo6Yni+VdZDX/LMP8oKsRBV2RWlVGAuToYWjh21c3Dsk4kGOwpaSSnHxWGmVP XHwC/cMgCZtRljqxCln4g1ufqOLMCL/FDVEAnL+0YHlvLogmxBnNy+QVEbZzYlhLhoBF sxyDnoi66ClIZCNCH+j76bY07MHMhmmx7/oCHZ9hFthUzOrSMz8Qs9IH5t41AVkFEX3W hadw== X-Forwarded-Encrypted: i=1; AJvYcCUO4XgpsqTSjp9fouRMl0zpgM+D++SjDvC6StXEHt0bmQ1oEw2lEmmORNESoZV92pC7bkf3kUaR0gWEmfMxtcuJF7b7eXTOcTZmwCDC X-Gm-Message-State: AOJu0YzunPPDhQOv60OlulAmltcN2vVHWVRsFNmxlcuA3pY80WcWDRzH j20hsZdGaQe0/gKmM+iRwvYB0Pcm5zYTwVHQNJg3BXWj4n/h6ZwOxpDohdSSBA== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170807201542.GA21271@beast> *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