From nobody Sun Feb 8 10:49:43 2026 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 636171AE875 for ; Thu, 19 Dec 2024 21:16:03 +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=1734642965; cv=none; b=RsTHYaWG33SdAlYKdyw/z8IWsUhJ2KMnrkrTumpWwpbIOFtkAXQ4PuzqKSjGVX1VUcn8uiPOY/MAfGmJss/gXmnGsGpcZHUd+55t403tmvQTnNHSI7ijnslG1bVNSHqZGotxSntPvD/RIdi8ELGK3imVNMM5gXxyDbjJM9pqimc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734642965; c=relaxed/simple; bh=14m97Z+0pTm5EqtiSnKQfxjW3EYxc4y788S3qm7BmPM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Fe8Syaa405jz71CYmZ8PkXFrzEQMEWhuLVZCJxFJT1p2Az+5+H5CK/OLKcHaduKBRE7V4T2IVFjqR+imn4IteoMyTA2BwuxGVHyeHXjtT3KLyOfjP5IiI5Jc+wI6YO6XqPFvj5WOufpUiDg8N8slxsbJCi10wUV74nhcAP8k/HU= 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=dxjjQHrO; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dxjjQHrO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734642962; 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=moQeyil1+AjvNER5TVocjwkHTlSiFKfmMESCw1RaFqc=; b=dxjjQHrO1ejsAER0B0wbjWTc7IyaZpLECGCWC3XGDHL6g4OiG5XsXpcnJZp/NLRS15pPub xqrvhJ6gtzCU55l77TywBjKiXAaQLl2VVtgXeSVdH59VQDXT7gUbrYSimcyxM8uhufbA26 WSX9o1F5ZdM6lNm0DZp6E8FBwr0tQVE= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-692-elRDH3eiN8qVwr18UScA4A-1; Thu, 19 Dec 2024 16:15:58 -0500 X-MC-Unique: elRDH3eiN8qVwr18UScA4A-1 X-Mimecast-MFC-AGG-ID: elRDH3eiN8qVwr18UScA4A Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 589DB1955F3B; Thu, 19 Dec 2024 21:15:57 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.80.160]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A5F9A19560AD; Thu, 19 Dec 2024 21:15:54 +0000 (UTC) From: Audra Mitchell To: linux-mm@kvack.org Cc: audra@redhat.com, raquini@redhat.com, aris@redhat.com, akpm@linux-foundation.org, willy@infradead.org, william.kucharski@oracle.com, linux-kernel@vger.kernel.org Subject: [PATCH] mm: Stop PMD alignment for PIE shared objects Date: Thu, 19 Dec 2024 16:15:52 -0500 Message-ID: <20241219211552.1450226-1-audra@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: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Content-Type: text/plain; charset="utf-8" After commit 1854bc6e2420 ("mm/readahead: Align file mappings for non-DAX") any request through thp_get_unmapped_area would align to a PMD_SIZE, causing shared objects to have less randomization than previously (9 less bits for 2MB PMDs). As these lower 9 bits are the most impactful for ASLR, this change could be argued to have an impact on security. Running the pie-so program [1] multiple times we can see the randomization loss as the lower address bits get aligned to a 2MB size on x86 (pie-so): # ./all-gather && ./all-bits ---------[SNIP]--------- aslr heap 19 bits aslr exec 00 bits aslr mmap 29 bits aslr so 00 bits aslr stack 31 bits aslr pie-exec 30 bits aslr pie-heap 30 bits aslr pie-so 20 bits aslr pie-mmap 29 bits aslr pie-stack 30 bits Fix this issue by checking that the request is aligned to the PMD_SIZE, otherwise fall back to mm_get_unmapped_area_vmflags(). [1] https://github.com/stevegrubb/distro-elf-inspector Fixes: 1854bc6e2420 ("mm/readahead: Align file mappings for non-DAX") Signed-off-by: Audra Mitchell --- mm/huge_memory.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ee335d96fc39..696caf6cbf4a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1101,6 +1101,9 @@ static unsigned long __thp_get_unmapped_area(struct f= ile *filp, if (len_pad < len || (off + len_pad) < off) return 0; =20 + if (!IS_ALIGNED(len, PMD_SIZE)) + return 0; + ret =3D mm_get_unmapped_area_vmflags(current->mm, filp, addr, len_pad, off >> PAGE_SHIFT, flags, vm_flags); =20 --=20 2.45.0