Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp568250ybg; Tue, 28 Jul 2020 13:02:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzufu8gc568XhLFeS9She1e7rUPxF/Rq20tl1tn8/RYeiOIaHTyzxDw5ou+DN3cHX6r3Xa X-Received: by 2002:aa7:c40f:: with SMTP id j15mr10091615edq.64.1595966549970; Tue, 28 Jul 2020 13:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595966549; cv=none; d=google.com; s=arc-20160816; b=oNdSn7Uzw5Vdnv5QvaIUWkG6zyIkS81xxoQEZSQbkhLJrE80o02yRIB7cqysBIGGa8 mdpJ6gYMKaaPCJjzapIi5FRNj0PHxIsbclDxssHbf3QhwbffL9BLBq87Z3JAkC4sQOI3 DOe5zKvoE7g0QHzSvj7l2i4RCKM5ijW34FkaXDOGvGkoIZRujqRRCkuX6YuFB84rrqVa OJmmL1Z0NSqph+SDsaE1dzd+SHeTgCmYxYrl4mreeyhDLJtCUYMV6oUjFMNk79S5amvX 1uWGZYY7NKPysSMNcFW3ekiXPEqu8NQpJ++yS9PpvmY5xXew4B6M1TVa6IpgM4cHt1Yd bE8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=TaFsAVS0lZBW1E0K1tJXZw+X9y9cUqIZOaViTh1v9Co=; b=pexO/WVMVoIxLSJmkzxW9ASOvcKRQ2AFlRbgKLvMVdAWv3YmyLG1gHXG6OpO+AC/ZS NozcqympRbEukAjc9XoL7lgCKYqko0tuB5tOw4pQ8iKKnRxZdN3sXBH+zSRwoM1dREqg T8sgwHBFwQDr/P0vs00Ymbxib/fm/JNzipTU0Umm34XQgweJP8ca3GHNXO5mg47DhgYs Et9FrE4avVlNNPt6zRUD1CFpJT1up23sppXF2RCIl2If4v2QaiZUPeYhaDoSi6kpukoU r3/ND1/MQe27W8HcEbKgAm7uS745RPpTnWMrIJAcomFuSmLH4LZ1NXKyL7Crg6Vw4hB2 cfSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MpLAr6Se; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e8si5250559eja.31.2020.07.28.13.02.06; Tue, 28 Jul 2020 13:02:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MpLAr6Se; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729477AbgG1St6 (ORCPT + 99 others); Tue, 28 Jul 2020 14:49:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729124AbgG1St5 (ORCPT ); Tue, 28 Jul 2020 14:49:57 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C712C061794 for ; Tue, 28 Jul 2020 11:49:57 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id lw1so369789pjb.1 for ; Tue, 28 Jul 2020 11:49:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=TaFsAVS0lZBW1E0K1tJXZw+X9y9cUqIZOaViTh1v9Co=; b=MpLAr6SeWtwR4OcpgIILP/A5hI3CfCLGNwNMziorMDAK4dN1Apnl5tsYKGjrPFdGbI 1TV987WZwJLg+gnsZBxQ46a8/7uNLnITCm+1xdsYUZ3xkZHZV1c/Wrbz0gXmlCPqQtRd /xn4hPaYnRKvLMF1Pz/NiIay42ZH0xqcJ/kSU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=TaFsAVS0lZBW1E0K1tJXZw+X9y9cUqIZOaViTh1v9Co=; b=THsaxRIG1R2y9o5gRnWlG4bpiCe69go99hayC+cqkgl7j9jHO3WYORR2CbAmOiJ5c/ LOrbeqW5YQn4jiMA6zivv2wORmxaqihs1mTUaCAUU5032wh4FvOS+SWm+t8cp1jylylA Ur+V2JEYBF0poohXPr3HFPHf/Hgl54VUuHhCHiW9yczcrtetrNnDOaE3Cc1Bh7d1uDlF gP984p8aVA3JnvA3TjFSlJCuazn8t0XwX9VWMTb4QGpIgSNpnBM50rsVf5B2UkuPC5sO rTePqm/yenhwr4HzoeYN0acde4Fhl3l43IWjKhDJOwUTgPfJvmWceCJiPpz9ZXD87TcT 0GWQ== X-Gm-Message-State: AOAM532A97+Wi3hJ4Um9fwDT/4qeWNboKkzQiRBXTqba7aa/GruCPrxE 9nQxogaOGCusrJTfV2picJp2XzbcrTI= X-Received: by 2002:a17:90b:138a:: with SMTP id hr10mr5633535pjb.161.1595962197185; Tue, 28 Jul 2020 11:49:57 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a24sm1377812pfg.113.2020.07.28.11.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 11:49:56 -0700 (PDT) Date: Tue, 28 Jul 2020 11:49:55 -0700 From: Kees Cook To: Arvind Sankar Cc: x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/8] x86/kaslr: Initialize mem_limit to the real maximum address Message-ID: <202007281133.739AAFD2AF@keescook> References: <20200727215047.3341098-1-nivedita@alum.mit.edu> <20200727230801.3468620-5-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200727230801.3468620-5-nivedita@alum.mit.edu> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 27, 2020 at 07:07:57PM -0400, Arvind Sankar wrote: > On 64-bit, the kernel must be placed below MAXMEM (64TiB with 4-level > paging or 4PiB with 5-level paging). This is currently not enforced by > KASLR, which thus implicitly relies on physical memory being limited to > less than 64TiB. > > On 32-bit, the limit is KERNEL_IMAGE_SIZE (512MiB). This is enforced by > special checks in __process_mem_region. > > Initialize mem_limit to the maximum (depending on architecture), instead > of ULLONG_MAX, and make sure the command-line arguments can only > decrease it. This makes the enforcement explicit on 64-bit, and > eliminates the 32-bit specific checks to keep the kernel below 512M. > > Check upfront to make sure the minimum address is below the limit before > doing any work. > > Signed-off-by: Arvind Sankar Acked-by: Kees Cook -- Kees Cook