Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp521082lqt; Thu, 6 Jun 2024 10:04:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUG0qW+qqKmA0pgQj38oOX28+bb8w2Xqi9SxD+MJr+5Oy3NkGDLXPt9tTwqnJ5I2nHegkHLXuyotOa4yr/D1C2dVZq3KohVrZCPQZmAhg== X-Google-Smtp-Source: AGHT+IHlFyIX1DCUIK5Sp2lPfkepgR4ahmogSVSKyUnU5IWX1K9mJCU0JCZ+OgdncG6a9Zyokf/F X-Received: by 2002:a05:6358:5e13:b0:19c:655d:1756 with SMTP id e5c5f4694b2df-19f1ff862f2mr36833055d.20.1717693443980; Thu, 06 Jun 2024 10:04:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717693443; cv=pass; d=google.com; s=arc-20160816; b=Gvs+0rgpwp9/Wbxrz4VmJZVK4HSXhJlB2Ld/3YND9eX6r893Vd2xZQrP3kZFx2MWQP NllwP1mCxHsj/QhPiUODUSgRoH2ChZnGLPx7z6BBofoXYpZmMp158fQhjBCUDWcp0wUV LZQ9JqRidSoxrYEe8f2saNOBmW2yXwEty4EqegS4sXonbGHSIEJ2wYq8nhE+HWjEugEX EAb7fzbQNq5Bg1wJ32/JvFACtLCI8NE6TG0H9XbXvgVJqwR4xu1UWdV+dUPm5NTIMF+M vT0yQsAIWxC7IgbWjAkp20YMv1loQ+aGlthX77/SjfFuFUUeeHvNHRxk7w7IzhQO8zr5 3h9g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=12SCf/jBTy7eK+7KYg6NLYNlOZ3t7D2JjPK/ZcEcsUQ=; fh=MM7LsMaMEi8WvppDT3+vNYNyyrFxGz1jfkPOUL3RIlY=; b=dYFGCsGLNwN+dcnokBr9lJ9csCKRPbROFtATsSdfDBHHhyNXQsK1p6uI8rVhngyBc3 Y6AVkm5lU1323UUZOV8xJ/wLJsRGakH5FyEWt658Prv0GpRKkbtsDxFEIQBPsog5wZS3 WqC9a/KJ0cLui0tKJxUywtB4BwYFMXnJSGOTqtFzyBNcIW0BTl/Plrubw5oKvjiWYbVh gPIcUP+8x7DJUn5fSiFp7vS+BlAqV5gq0UEXukmNcyQmJWoJUEqkMnX8MLUXMxqyJ8Oy W3FZDjW6QEJ3LfjZ8ZaBNAtV28aM4m2ilC6OCXJ2+rxhDJP+ThZw2xavE/gZDpE6coXv Jy4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=depOaQsQ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-204761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204761-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 71dfb90a1353d-4eb4ad7c839si433816e0c.295.2024.06.06.10.04.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 10:04:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204761-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=@redhat.com header.s=mimecast20190719 header.b=depOaQsQ; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-204761-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204761-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 9DC6A1C26639 for ; Thu, 6 Jun 2024 17:03:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DFDCA1991A5; Thu, 6 Jun 2024 17:00:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="depOaQsQ" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 825BC26AE3 for ; Thu, 6 Jun 2024 17:00:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717693256; cv=none; b=GithEObt8xDlKTvevZj3+SQN40mtfNM5WiZFJoYsBz4CPwnih3499NPGAeybo9uGuBRuy+2Xd9xfsRnTfvlX7MNyXaobn3TrWYWmOD7qelZVrAFm3dgxlCGrcWDCB6gJoFvpLnindQfGLQ5xSrwEvAx6W/m0aB3dc+UoA7pbJ5w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717693256; c=relaxed/simple; bh=gYqCnMw2W8NFjNyji+0KS2A9bl9lLZNC5dxAjJhfRWM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JMqmk/No81YG9mTwe6ixOEgLgStyZ17AIBaE6exqqmaqCwGJ/jeyKOwiOmjyNzYCvTfGuEPtoLrIfZQar53RL4PSFCBGgrUQi8me0uotpsOB4fTWkEuw0eJ1zbbFnSK9TSHChwFTwA0PeD2F2MVXdn0n9OpVEWnIlhXk+Y7TY1o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=depOaQsQ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717693253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=12SCf/jBTy7eK+7KYg6NLYNlOZ3t7D2JjPK/ZcEcsUQ=; b=depOaQsQdXlJS78usxk+iIKrb7H/tMsOcBnqXJ7uIzA6DX3x7ilGVndyjVVv4EA4lc8qIR BuqxofxSjD/9be3Hjxac1Pt59Aa5qUhIX+D3SC3KQsX7eDMVPGDVjNIj5dthrdmsH7WCOR 7aE+Ct+Ec1vujfM1blGL4oHv2nSosYk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-qH1YXT1RNY-owifrvKOuJw-1; Thu, 06 Jun 2024 13:00:49 -0400 X-MC-Unique: qH1YXT1RNY-owifrvKOuJw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5D1BA800074; Thu, 6 Jun 2024 17:00:49 +0000 (UTC) Received: from optiplex-lnx.redhat.com (unknown [10.22.16.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CD1E37E0; Thu, 6 Jun 2024 17:00:48 +0000 (UTC) From: Rafael Aquini To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Arnd Bergmann , Heiko Carstens , Petr Mladek , Mike Rapoport , Paul McKenney , Samuel Holland , Rafael Aquini Subject: [PATCH] mm: mmap: allow for the maximum number of bits for randomizing mmap_base by default Date: Thu, 6 Jun 2024 13:00:26 -0400 Message-ID: <20240606170026.101839-1-aquini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 An ASLR regression was noticed [1] and tracked down to file-mapped areas being backed by THP in recent kernels. The 21-bit alignment constraint for such mappings reduces the entropy for randomizing the placement of 64-bit library mappings and breaks ASLR completely for 32-bit libraries. The reported issue is easily addressed by increasing vm.mmap_rnd_bits and vm.mmap_rnd_compat_bits. This patch just provides a simple way to set ARCH_MMAP_RND_BITS and ARCH_MMAP_RND_COMPAT_BITS to their maximum values allowed by the architecture at build time. [1] https://zolutal.github.io/aslrnt/ Signed-off-by: Rafael Aquini --- arch/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/Kconfig b/arch/Kconfig index 975dd22a2dbd..b142f0752dc5 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1046,10 +1046,21 @@ config ARCH_MMAP_RND_BITS_MAX config ARCH_MMAP_RND_BITS_DEFAULT int +config FORCE_MAX_MMAP_RND_BITS + bool "Force maximum number of bits to use for ASLR of mmap base address" + default n + help + ARCH_MMAP_RND_BITS and ARCH_MMAP_RND_COMPAT_BITS represent the number + of bits to use for ASLR and if no custom value is assigned (EXPERT) + then the architercure's lower bound (minimum) value is assumed. + This toggle changes that default assumption to assume the arch upper + bound (maximum) value instead. + config ARCH_MMAP_RND_BITS int "Number of bits to use for ASLR of mmap base address" if EXPERT range ARCH_MMAP_RND_BITS_MIN ARCH_MMAP_RND_BITS_MAX default ARCH_MMAP_RND_BITS_DEFAULT if ARCH_MMAP_RND_BITS_DEFAULT + default ARCH_MMAP_RND_BITS_MAX if FORCE_MAX_MMAP_RND_BITS default ARCH_MMAP_RND_BITS_MIN depends on HAVE_ARCH_MMAP_RND_BITS help @@ -1084,6 +1095,7 @@ config ARCH_MMAP_RND_COMPAT_BITS int "Number of bits to use for ASLR of mmap base address for compatible applications" if EXPERT range ARCH_MMAP_RND_COMPAT_BITS_MIN ARCH_MMAP_RND_COMPAT_BITS_MAX default ARCH_MMAP_RND_COMPAT_BITS_DEFAULT if ARCH_MMAP_RND_COMPAT_BITS_DEFAULT + default ARCH_MMAP_RND_COMPAT_BITS_MAX if FORCE_MAX_MMAP_RND_BITS default ARCH_MMAP_RND_COMPAT_BITS_MIN depends on HAVE_ARCH_MMAP_RND_COMPAT_BITS help -- 2.45.1