From patchwork Tue Mar 12 22:28:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 13590671 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 0516AC54E58 for ; Tue, 12 Mar 2024 22:29:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 831C78E0023; Tue, 12 Mar 2024 18:29:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B9FC8E0011; Tue, 12 Mar 2024 18:29:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 659C48E0023; Tue, 12 Mar 2024 18:29:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 503818E0011 for ; Tue, 12 Mar 2024 18:29:10 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2B3D8A0740 for ; Tue, 12 Mar 2024 22:29:10 +0000 (UTC) X-FDA: 81889828860.12.C4E089F Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by imf15.hostedemail.com (Postfix) with ESMTP id 260BBA0005 for ; Tue, 12 Mar 2024 22:29:07 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YlWgh+XJ; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf15.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.198.163.15 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710282548; 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=dU/wD7jO/OHK4JfqA79jGNc+9DBVuFZY+83XluY+FGA=; b=YsZlkm08/7afk/tqlB1b4O6NScx79H0LpOes6z9kFFHXNR56OTPmQl9o05azBWcDDkNfkJ XFfoF6lNrHoVtolh6O5O1odTxpMlvp0vm9v6JGf3fYHrf7oa36b5l0BI3sA5R4Imd76PkJ dwDHciY2pCQKxKoF0iKxxGjFDF5P+m8= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YlWgh+XJ; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf15.hostedemail.com: domain of rick.p.edgecombe@intel.com designates 192.198.163.15 as permitted sender) smtp.mailfrom=rick.p.edgecombe@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710282548; a=rsa-sha256; cv=none; b=i2/PBEl+QytrPV8eUoSEzfUGqcan8j7YF5eil0BkSAWVVSnVoiMASQLCMFrMIe51DIJgYC F6VveDmHMqa1lvuZ0f79q2uo/77efnx/IukufDJIu5D4rq9ADoPw7uUlIhGnY6eg4ZhIQ1 ZUbZ+rPgGPlzTKLewnROPhrooFY0EWE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1710282548; x=1741818548; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u8AE1TgBiBYssYKjxzzEC6IaZ9p99XcwVxRZfDUcRoE=; b=YlWgh+XJ6F+Ll9FvYBtWk9zJ0x+S4guMqq3owhv4OpS/d//spXWtFZQ3 /+To6A7fItKP59uVDafSFHiIcjAaDK2+xaKoAcZ3o2e9rPA2xuELGYZTX PwjrbsFRhT4oT7zOnfKctgbvBW8lgUJWAsKMladPV9VdG5q8Wgpu4XiIl lKjIKi/nz4pAcXPm3fAHgDaYNqiuWTTJ6f6EzqNBQ5NSYnp0Kzi8mE8VX wmXAPZKgIdjHtm9Q9uxmdfdaBcLaYXuPamwmFajOs36uuFmKjrwSV1xsq zlWpt1HkjUycNHKcuqN3ZMh18VqBxAmR0RA19fqFDuPa5UdjukzmlChxS w==; X-IronPort-AV: E=McAfee;i="6600,9927,11011"; a="5191972" X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="5191972" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 15:29:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,119,1708416000"; d="scan'208";a="16356852" Received: from gargayus-mobl1.amr.corp.intel.com (HELO rpedgeco-desk4.intel.com) ([10.255.231.196]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Mar 2024 15:29:02 -0700 From: Rick Edgecombe To: 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, tglx@linutronix.de, x86@kernel.org, christophe.leroy@csgroup.eu Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, rick.p.edgecombe@intel.com, Guo Ren , linux-csky@vger.kernel.org Subject: [PATCH v3 05/12] csky: Use initializer for struct vm_unmapped_area_info Date: Tue, 12 Mar 2024 15:28:36 -0700 Message-Id: <20240312222843.2505560-6-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240312222843.2505560-1-rick.p.edgecombe@intel.com> References: <20240312222843.2505560-1-rick.p.edgecombe@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 260BBA0005 X-Stat-Signature: wdc3i4wsk5h3g88zejfjrkz3c36nw63m X-HE-Tag: 1710282547-433963 X-HE-Meta: U2FsdGVkX192KJCrMb87opz5607gKdTqR4rhm+sJgxKSJ3HqY+yk0i4cAFLZET0zzBD8JZS2fzWBsAy2OE2MpQsr0WflH9WngJzGNwK08s+6FGE/k9pTPIqG1W7XPRm1AMSNpWl0iUXHkKFC/By0Uv/5GZjUI+TU2rWuBtDYG2CQ44Ry/+DWoOnNs8IU80newgNQdS1ehU/aHe0QuiM7lCXSeRN/4t6kpf6NeB5n8R9inuqinF6lrP1yTKSaMafM/mGe8U8B67ZDSNwGpE3SCrAZd/pVjg2YdNfI7g4Qm7ER+gqEqDVujmkl5/ScIoXI6WCGQvV/d3ueuoHzodSTSTqDvTObgFM5/938D4235Ug9fubfvRvERxmR2kzD7/cdEipQcurxeirDi1Myv9tCExJWwzZBY7HhVI42HQabXIAHufUOw2bpOC9fo7TycvppTvXx/m/h+2hpoNeHgS9HGclLM2cTH/6OpucR07F+6pY1GMC+7Krpo0jSvh7GFAYZbl1E8rSAQrcq74sMHf2K5bMcXY7vKJ1b+2gly1YPRjdQAaNz1S1XHCkCoZucj0io2TnHx55rRHP59ochft3PFR7CMMA4PTbjw5qBFkn02ebZi4jMcGrOGRxEmJGCtWg2fmlQVN/kb6rvapsKUcnyowhCXafLTw7DRK4NE9OPxYzRQgfqo5dpSqShlTfTlwivDgTU7qZjiV4YNFeEPzrAU3pkGpEFauqNDGY/BVBSIr9ZqHlyRqBJLNdHZc2PLucB8wewpm6eO/d4zubspqNvNhgkUiD3T5EAYxhBYnqk444KXkPndymVjoRPM/dwwpOlefSlg8vB8w5MH07TvaW+ez+CcJpg+TuSrmnToB8uIuOW/84LJ7nEiBiX7Y6LC3VXgCADUY6yap6Ce2N1xnne+0HBLVO/oMB63hkSM+IZNIsjJXzjpST8JVNDXfAtbn/fdfPDgFpTZ4mYbGSAtMW WxATU8YO QwJkrP9O9BMULWSyTi/9wWa2Vxdg2TN1eRv0u2IKOD5GBVrlH/wl4mSjt4kuSmwWfrO03l5x7cnvcyuaZ9MB8K1sz7r/++ZoTvT8K5kMVEhiuW1DFUd/gLrOot6okiDYp9GDjDBKd4H40i+9LU+4G1XTwu3R5XwGqu/VR2bAgbs/+AEn4DImDBepsDA7S1EPVlBGca1lmXKT5e3A4CQM6wYxffPdgTr6ukCtYma3f7UU0xYkMVyqBz8XYCD5FBDVF/5CKkzNOxa/zBTY= 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 member manually, so if new members are added they will be uninitialized and the core code parsing the struct will see garbage in the new member. It could be possible to initialize the new member manually to 0 at each call site. This and a couple other options were discussed, and a working consensus (see links) was that in general the best way to accomplish this would be via static initialization with designated member 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 member addition misses a call site that initializes each member 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 members that are manually set to zero, as it would no longer be required. So to be reduce the chance of bugs via uninitialized members, instead simply continue the process to initialize the struct this way tree wide. This will zero any unspecified members. Move the member initializers to the struct declaration when they are known at that time. Leave the members out that were manually initialized to zero, as this would be redundant for designated initializers. Signed-off-by: Rick Edgecombe Reviewed-by: Guo Ren Cc: Guo Ren Cc: linux-csky@vger.kernel.org Link: https://lore.kernel.org/lkml/202402280912.33AEE7A9CF@keescook/#t Link: https://lore.kernel.org/lkml/j7bfvig3gew3qruouxrh7z7ehjjafrgkbcmg6tcghhfh3rhmzi@wzlcoecgy5rs/ Reviewed-by: Christophe Leroy --- v3: - Fixed spelling errors in log - Be consistent about field vs member in log 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 compile tested only. There was further discussion that this method of initializing the structs while nice in some ways has a greater risk of introducing bugs in some of the more complicated callers. Since this version was reviewed my arch maintainers already, leave it as was already acknowledged. Thanks, Rick [0] https://lore.kernel.org/lkml/20240226190951.3240433-6-rick.p.edgecombe@intel.com/ --- arch/csky/abiv1/mmap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/csky/abiv1/mmap.c b/arch/csky/abiv1/mmap.c index 6792aca49999..7f826331d409 100644 --- a/arch/csky/abiv1/mmap.c +++ b/arch/csky/abiv1/mmap.c @@ -28,7 +28,12 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, struct mm_struct *mm = current->mm; struct vm_area_struct *vma; int do_align = 0; - struct vm_unmapped_area_info info; + struct vm_unmapped_area_info info = { + .length = len, + .low_limit = mm->mmap_base, + .high_limit = TASK_SIZE, + .align_offset = pgoff << PAGE_SHIFT + }; /* * We only need to do colour alignment if either the I or D @@ -61,11 +66,6 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, return addr; } - info.flags = 0; - info.length = len; - info.low_limit = mm->mmap_base; - info.high_limit = TASK_SIZE; info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0; - info.align_offset = pgoff << PAGE_SHIFT; return vm_unmapped_area(&info); }