From patchwork Fri Jan 21 08:42:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12719508 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 B2194C433F5 for ; Fri, 21 Jan 2022 08:42:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46D836B00A1; Fri, 21 Jan 2022 03:42:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41D1A6B00A2; Fri, 21 Jan 2022 03:42:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2BD9D6B00A3; Fri, 21 Jan 2022 03:42:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 1CC7D6B00A1 for ; Fri, 21 Jan 2022 03:42:45 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D548793D95 for ; Fri, 21 Jan 2022 08:42:44 +0000 (UTC) X-FDA: 79053653448.12.54C1065 Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-eopbgr120072.outbound.protection.outlook.com [40.107.12.72]) by imf13.hostedemail.com (Postfix) with ESMTP id 6C69B20007 for ; Fri, 21 Jan 2022 08:42:44 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AX3Z2hTDUI3yohRYTfCpCFfK7ogCvIY3gI8q1zSw1H+X8P8TSM5gjujLrfLNeH5+z9aqdAE9+SjL9M4tZQ1GQA0JUmzhDU80okl6X2dan2w9OOvTZcmkqY/A05Nc+DUuPm6eVETUJZBl0eBlx3OjX9+S0fMHCnbPxJzdt9Zo8N68SRH36nmCN9Q0YX8UINBrbI/FOxxiEse2jZs+CCDFZ+BJgX/d7PWzeYVeHb6y/VlvaUHeS6h3UOpLdmV3SIFklWOqOx0w9jhWINdq7R6Ojl1mfE+g0THKs5ikKjq6OL2OeIyOnFKT4rTTLRyq/rVNvcrCeCZ7KbeQJxhZhYtrdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PM1tsV2E7+/dx7vpR2aV9rqndz5KU8OyEwLYpGyZ5i4=; b=CQ1CdBuwLYnepCl8JOU5k7epgLB2pN7d/Uq0U/6sZJ+RcJHnEuQrY/RUO1SDsvCWDOIDbndyRY43kec4g8EKQ19wNgjTEfr64ydbkiIK8P6HmeD/Tjd56lfyIx6WUHeMzHZ3lRrow4hyogPlifQYRCEI3/UiyBbqey3hZ7v2SkiNoDIx+tWBKdj6DIjRGukqp3uRR11zOjLUDsXXyyaucowAkqDE6tho2c2TBd6ojUMNkjIvFtZ7b9b1Fc6pqDEXmUMdZ7M9+9hDGXuWr0yDl+JuXBW5YlXS52lkT4+1jLW0lxg4Nf088UOXDwLEg6rwIP2i0GvzYFYjBkdWwjLmfg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PR0P264MB0201.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Fri, 21 Jan 2022 08:42:42 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::9d4f:1090:9b36:3fc5%5]) with mapi id 15.20.4909.008; Fri, 21 Jan 2022 08:42:42 +0000 From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "alex@ghiti.fr" CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "linux-mm@kvack.org" , "akpm@linux-foundation.org" , "catalin.marinas@arm.com" , "will@kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: [PATCH v7 12/14] powerpc/mm: Enable full randomisation of memory mappings Thread-Topic: [PATCH v7 12/14] powerpc/mm: Enable full randomisation of memory mappings Thread-Index: AQHYDqLadZ1PUGsqwUCDshHOaCgmUQ== Date: Fri, 21 Jan 2022 08:42:42 +0000 Message-ID: <675b7946a15dd18d5517bf10a8b49b09142b6c58.1642752946.git.christophe.leroy@csgroup.eu> References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7b692418-8b7f-4eb3-2775-08d9dcb9fd6b x-ms-traffictypediagnostic: PR0P264MB0201:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2887; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ajglEGKiaPxsU+ZeacAlUAYW9R/nQfHWTaVNiogMEf88iibxl2nxkm8p725MEf5jsPL2yFPQXDOdmO5N++4ThlaBaY70RK64Qi6RIxzoBGvKCgtZvkhRHxj7A3MfsrlHHIggvtagKkUAStTrZnE1AmshY7ogtZC0puvsq4ok7nA5FFrK2IBCZiCHtKfIKHLG06QcwR6+Hc9plo+9Ct4XGzMU9WwA/NwHjF2wm+lhy4S1TFon9FqsmPdUjPg41Amt/bwe9n1XCxgrWuoBXuaBSWuUzYJvZlMqfFs2GZCE8XI+Rs6X5v45mXpnE/7wmEMe4KHDygW1rX+FyitUS4hEZEP4V/bdAf0ozcI9WAYhCyVi7pqoFfHHYI1Uz1h+A5MjZm7TeW36NvYg/5J5Bm7ANCyLUI6yp9cXtljw9UkPL6Flkd31CU1ClyfAdaBYkfGhkZJcoPBjC/T5KRSh0e3JP3rTDxNOkLIrCi9RiMHmBsJuenbj81qNgUHphRZUEDA5waZiBzl2LPWFD6jKH+aVAS4NJa6GPDlMf+kDh2m0Fz3EgPebYJCECm2m4bc5SMr6fV2tYG7nU511A1AIbN7ktOvHWQuR/sp2G2bemdVDLjbO7BWKNgo0gmvrVdxnNVe5l9Tg8eRb+lb3cBWMBsFQkh9e7wN8muClPF1gQaFybJ9qN+mmvB2ehdyVDjE5u2qDJQFevH0xbUci8GqTqweV0A== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(4636009)(366004)(76116006)(91956017)(36756003)(66476007)(2906002)(5660300002)(66946007)(8676002)(6512007)(122000001)(71200400001)(8936002)(83380400001)(66446008)(64756008)(4326008)(66556008)(86362001)(26005)(508600001)(6486002)(54906003)(2616005)(44832011)(38070700005)(6506007)(186003)(38100700002)(7416002)(110136005)(316002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?+U9d1ltFf/r/v6RWXZGQW5l?= =?iso-8859-1?q?1JSyZTh+k695dQxkFj8Q5R1vjCIg5axsq9uCsy0aSaswxQPGdktasu3gEJ9U?= =?iso-8859-1?q?QzZ7TTyH1aF9Yv1JpdGREyMAq/YCiWNy1iIlNXWyH5YzJ03Us/E9ZuVO/I2F?= =?iso-8859-1?q?lqStN99nsefDod7rXQXYCbOJ4/D9HsmEOEfH5Nl67x0NqKO3M0TUwWwg0lS/?= =?iso-8859-1?q?iT+KBwxWLpUiXQVxlflitxAs/KwwIgwx4s+EwI/Gk46lnK1nCSudls4+p5rV?= =?iso-8859-1?q?E912BVx8hbnnhnzq1PfQZH1SxpmVVluetkx3aPhdV12AiqMD/lqKoEV7CoXg?= =?iso-8859-1?q?9YmqKqncnYG8c1kngmjXcXZOBDycW6wDRf3hDGaL80KkJRcqs9sgvi5/irLW?= =?iso-8859-1?q?a4H2YCwOYvOE3ptlQzihc8cbHqCjxLKgziYO30XHwvrVzeJ9fcIZbdEOLNt2?= =?iso-8859-1?q?ccr32t1InG5gwCVsLiaSk7pdUETqYvmFlbyYfar9trrw9ayPMhsfowypfjHP?= =?iso-8859-1?q?HIPaliOgXmZ3Jvj+V0hVmrZgX9DYobWXC/yNAuQASgq5e4c9UHMC87xOW2ax?= =?iso-8859-1?q?OswENcoS5nmzUCV5moX9vpkb9FwACOz0eFXBgWd7SuQvziKcRdYRc9g5vZK3?= =?iso-8859-1?q?IheEwHmXgMjA8O0+DnF+UIwKdv9crQyNdX26tpvjLbWFAqpR5tjuIYGKN7rx?= =?iso-8859-1?q?n3k4LfG51Rcu7Uh75yIbODuuZS2tQ3cwuX3ezzdVHlUZH8PYGrXBfOPt+bI+?= =?iso-8859-1?q?5Ul/UFI4PzFd0b3UqFOWFN4PjM1VyJu6zvKogD2zXc7avEpy+sUMIoYGTgVX?= =?iso-8859-1?q?qLpzm0WmwjypJTTSa3k+DGQ17Gkk9AMgAOz2MCWio4pHl3JHfaJs1ZUuL6VR?= =?iso-8859-1?q?rxtrXjfDtm1WUetNramg5TZuUft+lTbuU6dQmGUAHAl6SDlMum2E/q7nARLO?= =?iso-8859-1?q?vZtIo8aeN3d9PDIJJtNWBf1iO3dtvWfH65GoJ1earZZegEHfhV/I/7LPNZV0?= =?iso-8859-1?q?HRFs08vHX5haLZWHp3zCo1XKTUsHujMP+NjC4Z0OArhFe/LGl4NDle7CcZf6?= =?iso-8859-1?q?qxGYdjkKPxRBl2hnHZsNNpl2uD2IyslTRwSAfnTqZfAjumUJQbjFlVj1Fk9q?= =?iso-8859-1?q?KijBqtLkL8fOWTgPUJIs/sosuKd8D3hLWtHp6ERYCr4KgxLO17OEPsK5wFAD?= =?iso-8859-1?q?D1ihnrqTKZyqQsb9/WzPuH0Bhe1A/7oLDRYceItJ6DStWEI/nQ2mrx9i71FI?= =?iso-8859-1?q?Mp1VXpO73NesmhDQkQFWZIRap1K8NRpwfhveFGN/FbJhS7xwChmAq6zAA1Lz?= =?iso-8859-1?q?SriwY8p47jN7u4P0kRBTrE5WNX/Gqhdm99S4v1sLfySs2N32OXNW7wHaYJF2?= =?iso-8859-1?q?6zJRIFutfaBRIkApEvGOPgOPBzpxbDOZ7lua2TBvfZCLI8kwWybXBf1NUR2/?= =?iso-8859-1?q?tHyfZPXP+0hClYxX36GeezgZ0XrfagpuASXd8noSNARUShmeFRSsG8Gv2e6p?= =?iso-8859-1?q?RmhljOXizqbQOMS1vAz+pUwkIeIYp0hg+vVLEYlAN879pkCHh5CvgEu7/S1e?= =?iso-8859-1?q?e4/ekUM7O59E01VlmYdm/cml+0uT7VXWyU2Npmvzi7kaRw+5Bhv2AbkZF7vy?= =?iso-8859-1?q?Ktq+E7USV3fK5gEmCTLgPI0JSMYZt3TArWbGFMcDTL1GMgfoVnFbJkp+U4N2?= =?iso-8859-1?q?5qJIGVKOgNixKRYZ2eNqQGtg5IF4VzaqoK2Ln482RhTkiZaA/SreLgiyMRB3?= =?iso-8859-1?q?sJXk=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 7b692418-8b7f-4eb3-2775-08d9dcb9fd6b X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jan 2022 08:42:42.7885 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: YKv5QGv2tePGOq2d+ZQPrzd0hoLel+UOfxFUVHCxi0V/lbJKnTWWGWi4kOxxNYW18f+kWSdVLq9X5jEgIiTyB74c6zcQR0qNLeYCqhVy1/0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR0P264MB0201 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6C69B20007 X-Stat-Signature: efj1y6d1psn6jaujzcr7ephg9rpmeqsg Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf13.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 40.107.12.72 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu X-HE-Tag: 1642754564-893901 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: Do like most other architectures and provide randomisation also to "legacy" memory mappings, by adding the random factor to mm->mmap_base in arch_pick_mmap_layout(). See commit 8b8addf891de ("x86/mm/32: Enable full randomization on i386 and X86_32") for all explanations and benefits of that mmap randomisation. At the moment, slice_find_area_bottomup() doesn't use mm->mmap_base but uses the fixed TASK_UNMAPPED_BASE instead. slice_find_area_bottomup() being used as a fallback to slice_find_area_topdown(), it can't use mm->mmap_base directly. Instead of always using TASK_UNMAPPED_BASE as base address, leave it to the caller. When called from slice_find_area_topdown() TASK_UNMAPPED_BASE is used. Otherwise mm->mmap_base is used. Signed-off-by: Christophe Leroy --- arch/powerpc/mm/book3s64/slice.c | 18 +++++++----------- arch/powerpc/mm/mmap.c | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index 03681042b807..c0b58afb9a47 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -276,20 +276,18 @@ static bool slice_scan_available(unsigned long addr, } static unsigned long slice_find_area_bottomup(struct mm_struct *mm, - unsigned long len, + unsigned long addr, unsigned long len, const struct slice_mask *available, int psize, unsigned long high_limit) { int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); - unsigned long addr, found, next_end; + unsigned long found, next_end; struct vm_unmapped_area_info info; info.flags = 0; info.length = len; info.align_mask = PAGE_MASK & ((1ul << pshift) - 1); info.align_offset = 0; - - addr = TASK_UNMAPPED_BASE; /* * Check till the allow max value for this mmap request */ @@ -322,12 +320,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm, } static unsigned long slice_find_area_topdown(struct mm_struct *mm, - unsigned long len, + unsigned long addr, unsigned long len, const struct slice_mask *available, int psize, unsigned long high_limit) { int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); - unsigned long addr, found, prev; + unsigned long found, prev; struct vm_unmapped_area_info info; unsigned long min_addr = max(PAGE_SIZE, mmap_min_addr); @@ -335,8 +333,6 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, info.length = len; info.align_mask = PAGE_MASK & ((1ul << pshift) - 1); info.align_offset = 0; - - addr = mm->mmap_base; /* * If we are trying to allocate above DEFAULT_MAP_WINDOW * Add the different to the mmap_base. @@ -377,7 +373,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, * can happen with large stack limits and large mmap() * allocations. */ - return slice_find_area_bottomup(mm, len, available, psize, high_limit); + return slice_find_area_bottomup(mm, TASK_UNMAPPED_BASE, len, available, psize, high_limit); } @@ -386,9 +382,9 @@ static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len, int topdown, unsigned long high_limit) { if (topdown) - return slice_find_area_topdown(mm, len, mask, psize, high_limit); + return slice_find_area_topdown(mm, mm->mmap_base, len, mask, psize, high_limit); else - return slice_find_area_bottomup(mm, len, mask, psize, high_limit); + return slice_find_area_bottomup(mm, mm->mmap_base, len, mask, psize, high_limit); } static inline void slice_copy_mask(struct slice_mask *dst, diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c index 5972d619d274..d9eae456558a 100644 --- a/arch/powerpc/mm/mmap.c +++ b/arch/powerpc/mm/mmap.c @@ -96,7 +96,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) * bit is set, or if the expected stack growth is unlimited: */ if (mmap_is_legacy(rlim_stack)) { - mm->mmap_base = TASK_UNMAPPED_BASE; + mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; mm->get_unmapped_area = arch_get_unmapped_area; } else { mm->mmap_base = mmap_base(random_factor, rlim_stack);