From patchwork Tue Jul 11 13:39:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Ungerer X-Patchwork-Id: 13308754 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 DD56DEB64DC for ; Tue, 11 Jul 2023 13:41:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A4166B0075; Tue, 11 Jul 2023 09:41:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 253C06B0078; Tue, 11 Jul 2023 09:41:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 143366B007B; Tue, 11 Jul 2023 09:41:12 -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 03C666B0075 for ; Tue, 11 Jul 2023 09:41:12 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B7DBD80292 for ; Tue, 11 Jul 2023 13:41:11 +0000 (UTC) X-FDA: 80999442342.03.5FF7C9C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id 9D3AC40025 for ; Tue, 11 Jul 2023 13:41:09 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PE+keElR; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of gerg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gerg@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689082869; a=rsa-sha256; cv=none; b=AgfgOrvMCA3TqPWr5x4+zedL2HiQdJnSOFL+86FTV0iRTzeKTrkgWDQUkWtTSHyyYR6P5+ gOmXeggFRxsx8yFIiXPPM8y5gnl/KQPFaksVMdmIOaHNG33qAyWH6atOmuAISrXVpMWWmK 5gnZhMkHSe2ggqiUtc0fcHfRd1Gd8vg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=PE+keElR; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of gerg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gerg@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689082869; 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=KLp+sDP9dxkfpn0hXxT/rDzda2eM8IfsgzW5rD63ERc=; b=Th/QHLScyaI27nRFfcjRCcHDcwVKL4j84lHfGXvY4qf9UH7QdJSHdM+WHhC9dhAyO/xWeZ ZpsTXibTcFqyrJbNlGEFOuS7mPploJsbDHGJYYiGbnab9WKGxTEET2hQ7ET67eAbE/Johb Xc2sIX4pFkfTQZmBLo/3GaLdKv5VaFE= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 63611614FA; Tue, 11 Jul 2023 13:41:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBF89C433C9; Tue, 11 Jul 2023 13:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689082867; bh=Bt9oDG1nWUVU70SGgtLyjWqFDPmkWPg2aId2ZSi4znQ=; h=From:To:Cc:Subject:Date:From; b=PE+keElRYQA9uP4QPujGWqf6/drIHtnka+nWIrfzFQZSxcLxyUGA8r4vMoLQWZ6XY QUVO+309XQJneVLOF5laAXy+wOq5RZ19Rcpo5oHDGfvQNEO/KEWziwrX8syzLW8m/e scwFHJGDtj6PjpNde7fNpKRyCcUiXtPczYQc+LCZDCLyEXxuARGZ87qvXSXn4kYDHQ jKsarGPmWAXdHxtCi2ZCeB8QC+HHNSK6P3S4z3jUi04e/EwITLrVh6Vf2KpGqQQ9bM NBISZIxosDcvlSKlehT9ugsQROjnjEhlhOgvWUp9rnQh1Ee7WtutYXYi2Ok0wF6u45 LlqRTthplaRRg== From: Greg Ungerer To: linux-arm@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: viro@zeniv.linux.org.uk, ebiederm@xmission.com, keescook@chromium.org, brauner@kernel.org, Greg Ungerer Subject: [PATCH] fs: binfmt_elf_efpic: fix personality for fdpic ELF Date: Tue, 11 Jul 2023 23:39:55 +1000 Message-Id: <20230711133955.483393-1-gerg@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9D3AC40025 X-Stat-Signature: rr9huf1ombejgryp8i7do7u5uibkejnu X-HE-Tag: 1689082869-757925 X-HE-Meta: U2FsdGVkX18iMNske4d5BhM1hapD36vK2IIHpYjBkdjEwo/eUv16kPzoxhQKVlBl/i5uGg4Y5T6TKZpepbuO7TXu6H/NsIRaR4YBDbWoGG1BsPIKzDoxAnUaa+RhJV67l9nM5EU8Pag0/JQSbAkLy/Bn/hGyaCI+d5HLPteYjQ9sih2mgm3bb1VAJCa5Bh0P7kHyY0B+XK3VHfetkAniIHaV6dgjqpr9Im3xoaszkjhkLXY5OsZ1KRdCnGbgnFzLrEzbPYYwlwbfeCXuo69EcHmb06+pt6GTUiutwQEsT87oA0lqcjOvtqitMIZvqL+1x9Xb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ogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The elf-fdpic loader hard sets the process personality to either PER_LINUX_FDPIC for true elf-fdpic binaries or to PER_LINUX for normal ELF binaries (in this case they would be constant displacement compiled with -pie for example). The problem with that is that it will lose any other bits that may be in the ELF header personality (such as the "bug emulation" bits). On the ARM architecture the ADDR_LIMIT_32BIT flag is used to signify a normal 32bit binary - as opposed to a legacy 26bit address binary. This matters since start_thread() will set the ARM CPSR register as required based on this flag. If the elf-fdpic loader loses this bit the process will be mis-configured and crash out pretty quickly. Modify elf-fdpic loaders personality setting for ELF binaries so that it preserves the upper three bytes by using the SET_PERSONALITY macro to set it. This macro in the generic case sets PER_LINUX but and preserves the upper bytes. Architectures can override this for their specific use case, and ARM does exactly this. Signed-off-by: Greg Ungerer --- Is anyone out there using elf-fdpic on ARM? This seems to break it rather badly due to the loss of that ADDR_LIMIT_32BIT bit from the process personality. fs/binfmt_elf_fdpic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index a05eafcacfb2..f29ae1d96fd7 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -348,7 +348,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) if (elf_check_fdpic(&exec_params.hdr)) set_personality(PER_LINUX_FDPIC); else - set_personality(PER_LINUX); + SET_PERSONALITY(exec_params.hdr); if (elf_read_implies_exec(&exec_params.hdr, executable_stack)) current->personality |= READ_IMPLIES_EXEC;