From patchwork Sat Sep 7 17:53:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 13795241 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 14F5EEB64CD for ; Sat, 7 Sep 2024 17:53:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 981A16B00AB; Sat, 7 Sep 2024 13:53:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9310C6B00AC; Sat, 7 Sep 2024 13:53:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81FED6B00AD; Sat, 7 Sep 2024 13:53:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 629136B00AB for ; Sat, 7 Sep 2024 13:53:26 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 02CE3818D5 for ; Sat, 7 Sep 2024 17:53:25 +0000 (UTC) X-FDA: 82538689212.06.2237EDA Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 73BA8180009 for ; Sat, 7 Sep 2024 17:53:23 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lxTU3HZJ; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of deller@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=deller@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725731602; a=rsa-sha256; cv=none; b=tFn102Nwm6V3B/J4n219MP23gkC5huifVo5Sm4MqPCjokXleyxCicra7M9WwieQdOKlqB9 6lFRT/70V3LmfG8DDSJ1Pq20FlZG9FDzaVKg0RKxcCXOTbOylSfod4kvFSXvoocjx+QSNR PN3M2LWoVEwHDUHuoG76wgguYrHf/rw= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=lxTU3HZJ; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of deller@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=deller@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725731602; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=SPx3hrWzIgocPK9RTenPjV3kWoa4f/08mg+bMUy478w=; b=3ySCpESB2rMP4A4Og0aOT9tb/n/ypibPnr3Q3uE+v2UZs+AUtsb7ufBiueQ+7tIXBfCOX2 I8CM1k1Gouyh0uQ/PbkdexwdYGZ9+FWzoOQr9TUqOq919tfpAg8D7zMBOifxvIAobbBd5B 9yXLuP+CE3hgqz23c3T0PUtr9kgunpY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C4DCA5C18E1; Sat, 7 Sep 2024 17:53:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A43A0C4CEC2; Sat, 7 Sep 2024 17:53:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725731602; bh=xc49QaUyEGz04dknKL94FaZoL15AuSjqWvoXA7HwTZE=; h=Date:From:To:Subject:From; b=lxTU3HZJ0LZOWhdCqtWNRpnBZxtD3I3Dlus+jymMk2ltnvQvWOix2qZUmmCWypxWL pFvrHVdCw22D41mdtqH+2TnxZWU0jyF+kPFfYByOU9QQemAUqDzzaMBZuEvE4pTjan w+xE+qbw9H/ATGWcVNoOGvSA3QpOVrsdcnKbnVVpRqs4516UccLLZMZsWe0CKOSU7Q P9Y6AWae4UZP0Wgt3BISmG4H+8IeOGNbCL0ww3SFz6L3fosVh1LXQEU6XYR7mR0SF4 IbWNiFS0TDVarcJGkrZIfpSsXmDg55yCKJdkyGKarWhPbr3RgrnXri8WmcMo/ORrUI cQTGLjKjkkExQ== Date: Sat, 7 Sep 2024 19:53:18 +0200 From: Helge Deller To: linux-parisc@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Camm Maguire Subject: [PATCH] exec: parisc: Fix stack start for ADDR_NO_RANDOMIZE personality Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Rspam-User: X-Stat-Signature: 7ypqrfj5pfapcmifmbrek69hk4u7ixhn X-Rspamd-Queue-Id: 73BA8180009 X-Rspamd-Server: rspam02 X-HE-Tag: 1725731603-673575 X-HE-Meta: U2FsdGVkX1/mHfLoEUQpmMOH+/IWnzg0pNrq27Gs3+ImItZ4ys6/e9PuCtloijjJ3fvlc7Kg+zITMl00j0KrTN3Jn6Ldt7mrpXwRZ8AODb1cHC1AIXK+HdCpxSJBGDllZc12b8OHQeFeHi84Wjl5dIFyoAWrW3xav7+vhZMYyl21OlZPxfIFPcrXwGJ+Ss+WgL+Y0/21e51BVMrugS7l0gPePIqe94ACkIkhn/FXwEgPCdwSyQQM/Kv+Q0wsFhxdODfliaZyTmf9NH0smEvWbjblF8L3qAKs+S2jAOpcQsjJpjHz0XehsXc0zgKYt4XuiSBaOM8jhoRtpLA217wlE6RxHdn15AN7O72/F5LKwsCRK4Nn9li1IGTfJF3CDO9nfo4U6mVGk/i7UpEjYe3qLY/o3GkVCyjCYL2rDCwy8P2FJmRf9CtWTz31lgqpAMVV9ejM8nTbBfrUmpZ7bCi2Z39ORBzQt4MMaT0SA//PMr1ukuXkDhO9GYN5zulIcvf4f81LuZ97iSCc07YuafdJzxH+DNZLlK5nJrmI15nFZNygU+HzJNFv8KpENMv4wzXfT+sxfjqT7ERhUc7B5mpLHISZKq7uQ3ZoEb1JnpCBUVzVipfetcE+C/S5Nz0nsDi5inuMASvRH6V0T7P66OS9Iw1UE42BswBrl739FUK0XlBhlV3CbUbparGGBA1mdEeYl0cXwkDhEHqobveLGitaqFhZJJymNPyU2GhIL5mXLcHwQVIK8sCuS1XrZ3q/RS8vU99GIafnV3pJH1CVw1ySK8YO99ukN2x/x/48QHbNWok4qUf72wjFAhB+CM26K97Cc5PEfv0jZWOC9h8KLFVgge1deTGwQ0x4xyDMHsIS4yxTxEcTxqIDkPmPKf1XSQDZiktfF14m+TyMpf737dq6foaDZbcYCH3x4WC/wjLbtBd4MI8rIW4FSmpuLZAGKJTfcGjZf/GvnGIZAxtkGR4 MVeRwhRi gLC3uXS2PRB/30Z5gY04Qi0l5kgdrpsyaQBv3CuKQPBBHuN7DP1tygLGW9Na5x8UDlyRJEAO3heBCRlsIjaDbbQmJDDJmcSEd2NuubAqPAdcoqinEgDgErV1W6Zq+xOkPXU0ma+cx0KwFKXzQKGg97+ts368m1idT2a4ms2i1bSDTghDAWm4S7THnaElGnPIwo1gEWMS7DjpxKE3QIfEk12Z+Oz0oJpefOtANwB7+krkka1a1jYgSHznElRtUF1RD2jWtINlaJETIqW0X7iviio6hjl2uaiprFSDOxUO+ulJpaYT31d6zYwe8tDX47sE5AHZ67NmqET71yWY= 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: Fix the stack start address calculation for the parisc architecture in setup_arg_pages() when address randomization is disabled. When the ADDR_NO_RANDOMIZE process personality is disabled there is no need to add additional space for the stack. Note that this patch touches code inside an #ifdef CONFIG_STACK_GROWSUP hunk, which is why only the parisc architecture is affected since it's the only Linux architecture where the stack grows upwards. Without this patch you will find the stack in the middle of some mapped libaries and suddenly limited to 6MB instead of 8MB: root@parisc:~# setarch -R /bin/bash -c "cat /proc/self/maps" 00010000-00019000 r-xp 00000000 08:05 1182034 /usr/bin/cat 00019000-0001a000 rwxp 00009000 08:05 1182034 /usr/bin/cat 0001a000-0003b000 rwxp 00000000 00:00 0 [heap] f90c4000-f9283000 r-xp 00000000 08:05 1573004 /usr/lib/hppa-linux-gnu/libc.so.6 f9283000-f9285000 r--p 001bf000 08:05 1573004 /usr/lib/hppa-linux-gnu/libc.so.6 f9285000-f928a000 rwxp 001c1000 08:05 1573004 /usr/lib/hppa-linux-gnu/libc.so.6 f928a000-f9294000 rwxp 00000000 00:00 0 f9301000-f9323000 rwxp 00000000 00:00 0 [stack] f98b4000-f98e4000 r-xp 00000000 08:05 1572869 /usr/lib/hppa-linux-gnu/ld.so.1 f98e4000-f98e5000 r--p 00030000 08:05 1572869 /usr/lib/hppa-linux-gnu/ld.so.1 f98e5000-f98e9000 rwxp 00031000 08:05 1572869 /usr/lib/hppa-linux-gnu/ld.so.1 f9ad8000-f9b00000 rw-p 00000000 00:00 0 f9b00000-f9b01000 r-xp 00000000 00:00 0 [vdso] With the patch the stack gets correctly mapped at the end of the process memory map: root@panama:~# setarch -R /bin/bash -c "cat /proc/self/maps" 00010000-00019000 r-xp 00000000 08:13 16385582 /usr/bin/cat 00019000-0001a000 rwxp 00009000 08:13 16385582 /usr/bin/cat 0001a000-0003b000 rwxp 00000000 00:00 0 [heap] fef29000-ff0eb000 r-xp 00000000 08:13 16122400 /usr/lib/hppa-linux-gnu/libc.so.6 ff0eb000-ff0ed000 r--p 001c2000 08:13 16122400 /usr/lib/hppa-linux-gnu/libc.so.6 ff0ed000-ff0f2000 rwxp 001c4000 08:13 16122400 /usr/lib/hppa-linux-gnu/libc.so.6 ff0f2000-ff0fc000 rwxp 00000000 00:00 0 ff4b4000-ff4e4000 r-xp 00000000 08:13 16121913 /usr/lib/hppa-linux-gnu/ld.so.1 ff4e4000-ff4e6000 r--p 00030000 08:13 16121913 /usr/lib/hppa-linux-gnu/ld.so.1 ff4e6000-ff4ea000 rwxp 00032000 08:13 16121913 /usr/lib/hppa-linux-gnu/ld.so.1 ff6d7000-ff6ff000 rw-p 00000000 00:00 0 ff6ff000-ff700000 r-xp 00000000 00:00 0 [vdso] ff700000-ff722000 rwxp 00000000 00:00 0 [stack] Reported-by: Camm Maguire Signed-off-by: Helge Deller diff --git a/fs/exec.c b/fs/exec.c index 0c5f06d08c35..e5805108e940 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -782,7 +782,8 @@ int setup_arg_pages(struct linux_binprm *bprm, stack_base = calc_max_stack_size(stack_base); /* Add space for stack randomization. */ - stack_base += (STACK_RND_MASK << PAGE_SHIFT); + if (current->flags & PF_RANDOMIZE) + stack_base += (STACK_RND_MASK << PAGE_SHIFT); /* Make sure we didn't let the argument array grow too large. */ if (vma->vm_end - vma->vm_start > stack_base)