From patchwork Thu Dec 19 21:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Audra Mitchell X-Patchwork-Id: 13915826 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2A8BE7718A for ; Thu, 19 Dec 2024 21:16:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 812936B007B; Thu, 19 Dec 2024 16:16:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C2A36B0082; Thu, 19 Dec 2024 16:16:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 68A4E6B0083; Thu, 19 Dec 2024 16:16:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 47E366B007B for ; Thu, 19 Dec 2024 16:16:05 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DAF91430E7 for ; Thu, 19 Dec 2024 21:16:04 +0000 (UTC) X-FDA: 82912964274.09.F1B6F30 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf30.hostedemail.com (Postfix) with ESMTP id BBBB080018 for ; Thu, 19 Dec 2024 21:14:58 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dxjjQHrO; spf=pass (imf30.hostedemail.com: domain of audra@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734642940; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=moQeyil1+AjvNER5TVocjwkHTlSiFKfmMESCw1RaFqc=; b=dpPR/CckWtf7QxSLjjBR2ymTzLFu3MElkcEr0kCXg0mZ32jg1b62Y2lvrHr0TbOL8OafPB JowvCXHggROBGXg5HBnEb7m/TfMGRXDY5c4l25jZNWJBelhUjdEuX0Jl9RWjNL6+l8VBO3 3wQ6/M31/cfxLYAXnDWyOAJy2fuY0Xs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dxjjQHrO; spf=pass (imf30.hostedemail.com: domain of audra@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734642940; a=rsa-sha256; cv=none; b=O618/EBxAobygGjIBn5qm9GRT7qoMffsNrvwwS1s4KrEvYAXVaZcJeNgDqrWM8clFbhHgE jBt9aVEzhkJdlHwlz+OAF2TYwwBY9dBh6Wyvr3R2gLFENUYmtIZU9h47SGVs+LWSkgPJYe NYiF1D5C4OpeoL0jMz8ReS5VwhjLxxI= 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> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Rspamd-Server: rspam05 X-Stat-Signature: 6uazwnoxzrat684njiya8hux5xekj4s5 X-Rspamd-Queue-Id: BBBB080018 X-Rspam-User: X-HE-Tag: 1734642898-594580 X-HE-Meta: U2FsdGVkX18l6zjvnXICoJIYDawW31D46AqgsS0Tu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4tMebwhjkE0asj5KqbpuJ3XwI4pPcIteCxfvZmy5ec0R3mXNFv14xVq21XzxMB21iPcM1Yz7nMvgVUrz8mK/2uyAsBIWF1MGPf4qu5JG/OlgI0J6Dgab0J5jOGcrvOhN4tdpKKjRju28wF1/7f/vCGagCZn+I5g9bLE+IQ++Z4a6YoyZ28VexG+Li12VROTpTMaamNKCkSCQ8b57I9AmYy/RgQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 file *filp, if (len_pad < len || (off + len_pad) < off) return 0; + if (!IS_ALIGNED(len, PMD_SIZE)) + return 0; + ret = mm_get_unmapped_area_vmflags(current->mm, filp, addr, len_pad, off >> PAGE_SHIFT, flags, vm_flags);