From mboxrd@z Thu Jan 1 00:00:00 1970 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 A84EFC54E4A for ; Sat, 2 Mar 2024 00:17:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 177EE6B009C; Fri, 1 Mar 2024 19:17:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1272E6B009D; Fri, 1 Mar 2024 19:17:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0A836B009E; Fri, 1 Mar 2024 19:17:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DBAEE6B009C for ; Fri, 1 Mar 2024 19:17:36 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 892DC1C0553 for ; Sat, 2 Mar 2024 00:17:36 +0000 (UTC) X-FDA: 81850185312.17.97B1131 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) by imf02.hostedemail.com (Postfix) with ESMTP id A499B80002 for ; Sat, 2 Mar 2024 00:17:33 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iGGiOGEw; spf=pass (imf02.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 198.175.65.15 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709338655; 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:in-reply-to:references:references:dkim-signature; bh=BmHBNlwKKYXrxqDowXi2YOR5AGULM3kr8MCmSzCw0TA=; b=MgcZUxptIhjsjs30s5gWbsolo25G6EkvyausS+ritWL1/rpZY5EMwVcDeKA6xKLZ8Jqu7Z 3XO8vJ8sIf3NpUG3kDQS7Iv1fOHarMA1IkYmXka5rc3gJsx3RfkjND1xqPJGkSaVDY9Svu T0/90WT2tDTX4blPwhtIPFDtRa+edvY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709338655; a=rsa-sha256; cv=none; b=vQTKXdGG1LQDLfFtAhI8Ry/B1OxfxbvwJfvuMEln/Wre+AlTwNTDBSuLd71MSDqczRy9X0 G82xqiArtk18QGzg9OAzxdVaPpfLhVvSOec3nXMsUvB8vPL0zAe+fJH056fbaSl5aUg9VR foa68SgW+c+TW9Z2loNxqzwW7GkWnZE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iGGiOGEw; spf=pass (imf02.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 198.175.65.15 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709338653; x=1740874653; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aUPn2kr2ywGgbEfcgtrb26nDcn4EKmG6jav1jyMSZgw=; b=iGGiOGEw6cP6qogjY6+EhitdfPUdC1/kv02zPdMVxQ8e+cL0cPvRWgB5 o3htjFopbtLkj9Ch7uk/L8k9xntHJo2MQoLLtdyaqLkYvQQIHw5+dvNnn TEvupR3YsSkA0drK86FIJ5XrohueEkePJlKr9ZExI5b4SDlwfK4mhyg/i yoQW0BWMOBBehVQwmoU3HUgtV8JUoNG5Hg1EeS3b23ooVcfSRRHMwry4i MiagLl7mD2EzuWbG9FSJDHYhnvZJKEHYrjZSdZuDBKjGULsqSBW0cGwEl 29c5nFPX7j9aScPit5V0ayokdpzDBPHaoOcjwO0kPZmSgpRcaoKmZvJEb Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11000"; a="7715825" X-IronPort-AV: E=Sophos;i="6.06,197,1705392000"; d="scan'208";a="7715825" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 16:17:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,197,1705392000"; d="scan'208";a="8496003" Received: from thwood-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.251.7.75]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2024 16:17:31 -0800 From: Rick Edgecombe To: rick.p.edgecombe@intel.com Cc: Liam.Howlett@oracle.com, akpm@linux-foundation.org, bp@alien8.de, broonie@kernel.org, dave.hansen@linux.intel.com, debug@rivosinc.com, hpa@zytor.com, keescook@chromium.org, kirill.shutemov@linux.intel.com, luto@kernel.org, mingo@redhat.com, peterz@infradead.org, sparclinux@vger.kernel.org, tglx@linutronix.de, x86@kernel.org, Muchun Song , linux-mm@kvack.org Subject: [RFC v2.1 12/12] hugetlbfs: Use initializer for struct vm_unmapped_area_info Date: Fri, 1 Mar 2024 16:17:14 -0800 Message-Id: <20240302001714.674091-12-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240302001714.674091-1-rick.p.edgecombe@intel.com> References: <20240226190951.3240433-6-rick.p.edgecombe@intel.com> <20240302001714.674091-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: c4rz3rtobus4b37tjm8z5io4zg8sfukt X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A499B80002 X-Rspam-User: X-HE-Tag: 1709338653-296644 X-HE-Meta: U2FsdGVkX1+/0k5RNcz8p9zcOD7k5FkLIC69KdTWALIGy0XZw1kcVsRI/sPNLgWBlweTqMXFifwxvzD53Kl3huxHc+oO6b1zyxqi5vltGCcNoQV/ikOCbsjRKFDc1j2MaxsRxxp9JNd5YKVhuTryD/ccEwDbEBX2tYrf5RE/hxUSXfTQ5PtlYtWhnxuZLZDfhrV6Ijlxdrpc8Z2jRWzGniBs+NfsjvBN1B63xGyr8F9KQnRayr4eQT4U4DFFr5rluPNrmpntBKX7/52km4oLb0gy7ti2Uncd8L7pl7ebe6DqF6Y/Vf3ce9be8RV8AhOB6fXU8xLopN5R8XKpGKqcyYC2BeAsch9rLU2B5lHSfNjY1HqSPbdMdLUVS4SRfXwi7/qMU40fubR2aSDtTgt74aCdVTPVod32wmzkCGNIwF5edpg4fa1oPUyvpE+APOjCIhh2Kxjk5Y6tkiPlUp75wSsBE7dAIUuflMCqMKhZqJh3wPBUU6ekrSFJbX8tbZTUXUfTksH2vEuy3itzR9qsSUrfhSZV9K6nPTopt84cUcU/QnZJUOGpDYM1YGr1+yYwBLqn8fOYH5M7t5UG210q6hvQVOVpnXyx+HLfLftRMLe1rPSVoqjWSHY3oHy4ZtHdpUEC/ax6MoTv63xhcmX7dPI7ezI4DHKBtjNWUW+TkCNaFLnUu2HCp9GIZRx7hSl9vG+AhAv5VgDSckCXXP3dzSD7Ma5SaZ9V57Amp9qCtQShhX+YpbgpdKTachJ6PMVjOXdcj/3TlscrH3H0xnvCpSESueDgknTDldSyV3rkdjdrBuuv40kAtcVgMQFzcqQRXLam8Su/iWw/Z5f0y/3gkAY42oMevgoxwTxtQTMr45EDiHq8ZDiXNM874tgHcR7pWTUbB8rCs2pAL4fUBDwqXlbV59aBHjjTK4g/cSvaJLWRxTXRhZrdvQ== 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: Future changes will need to add a new member to struct vm_unmapped_area_info. This would cause trouble for any call site that doesn't initialize the struct. Currently every caller sets each field manually, so if new fields are added they will be unitialized and the core code parsing the struct will see garbage in the new field. It could be possible to initialize the new field manually to 0 at each call site. This and a couple other options were discussed, and the consensus (see links) was that in general the best way to accomplish this would be via static initialization with designated field initiators. Having some struct vm_unmapped_area_info instances not zero initialized will put those sites at risk of feeding garbage into vm_unmapped_area() if the convention is to zero initialize the struct and any new field addition misses a call site that initializes each field manually. It could be possible to leave the code mostly untouched, and just change the line: struct vm_unmapped_area_info info to: struct vm_unmapped_area_info info = {}; However, that would leave cleanup for the fields that are manually set to zero, as it would no longer be required. So to be reduce the chance of bugs via uninitialized fields, instead simply continue the process to initialize the struct this way tree wide. This will zero any unspecified members. Move the field initializers to the struct declaration when they are known at that time. Leave the fields out that were manually initialized to zero, as this would be redundant for designated initializers. Signed-off-by: Rick Edgecombe Cc: Muchun Song Cc: linux-mm@kvack.org Link: https://lore.kernel.org/lkml/202402280912.33AEE7A9CF@keescook/#t Link: https://lore.kernel.org/lkml/j7bfvig3gew3qruouxrh7z7ehjjafrgkbcmg6tcghhfh3rhmzi@wzlcoecgy5rs/ --- Hi, This patch was split and refactored out of a tree-wide change [0] to just zero-init each struct vm_unmapped_area_info. The overall goal of the series is to help shadow stack guard gaps. Currently, there is only one arch with shadow stacks, but two more are in progress. It is 0day tested only. Thanks, Rick [0] https://lore.kernel.org/lkml/20240226190951.3240433-6-rick.p.edgecombe@intel.com/ --- fs/hugetlbfs/inode.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index a63d2eee086f..510e66598991 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -165,14 +165,13 @@ hugetlb_get_unmapped_area_bottomup(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info; + struct vm_unmapped_area_info info = { + .length = len, + .low_limit = current->mm->mmap_base, + .high_limit = arch_get_mmap_end(addr, len, flags), + .align_mask = PAGE_MASK & ~huge_page_mask(h), + }; - info.flags = 0; - info.length = len; - info.low_limit = current->mm->mmap_base; - info.high_limit = arch_get_mmap_end(addr, len, flags); - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - info.align_offset = 0; return vm_unmapped_area(&info); } @@ -181,14 +180,14 @@ hugetlb_get_unmapped_area_topdown(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct hstate *h = hstate_file(file); - struct vm_unmapped_area_info info; + struct vm_unmapped_area_info info = { + .flags = VM_UNMAPPED_AREA_TOPDOWN, + .length = len, + .low_limit = PAGE_SIZE, + .high_limit = arch_get_mmap_base(addr, current->mm->mmap_base), + .align_mask = PAGE_MASK & ~huge_page_mask(h) + }; - info.flags = VM_UNMAPPED_AREA_TOPDOWN; - info.length = len; - info.low_limit = PAGE_SIZE; - info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base); - info.align_mask = PAGE_MASK & ~huge_page_mask(h); - info.align_offset = 0; addr = vm_unmapped_area(&info); /* -- 2.34.1