From patchwork Tue Dec 3 04:23:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 13891689 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 0A733E6C5FB for ; Tue, 3 Dec 2024 04:23:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E4756B0089; Mon, 2 Dec 2024 23:23:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 693236B008A; Mon, 2 Dec 2024 23:23:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 533D56B008C; Mon, 2 Dec 2024 23:23:34 -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 36C8D6B0089 for ; Mon, 2 Dec 2024 23:23:34 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B88101A0608 for ; Tue, 3 Dec 2024 04:23:33 +0000 (UTC) X-FDA: 82852353654.16.D3B53DA Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf21.hostedemail.com (Postfix) with ESMTP id 8A4261C0002 for ; Tue, 3 Dec 2024 04:23:07 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UX71rN2c; spf=pass (imf21.hostedemail.com: domain of thehajime@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=thehajime@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733199803; 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=jMDksIbcOLWGwD0vO5eo1YOj8LatyWo9RypORfUk9j4=; b=Jsgdzc5+1jdGI++EoXxfYLKSJLV90jQ5sW8sEYRoZRCM7xDrYTRi3anVZEvbiubc4LuUYN QUeQF1ckRpxEpj3rsFSXxnj4wsimT6eQmgjemPtEruxuzDLXWomhi3LK8eFTNI3TlDCvvi S7xH9Sl3hJCG5x5Y8RxDsr7y22ZVCt4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UX71rN2c; spf=pass (imf21.hostedemail.com: domain of thehajime@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=thehajime@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733199803; a=rsa-sha256; cv=none; b=Z6vjraNRk5WqNu4ClWyE/BKSw4JAazTx53Bbodihccn7951xCL6g5GOPve3zwDSM9d+qPQ DvKFEKQDMtX0JMEGNBZZyjDNpPIvJfse7YsnrqtbCS+xfr2nbpJ/O9prYrm1q70wXsR2Cs vnLKloN7FxJEjEDM61zeuqIacb9qG4Y= Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7f46d5d1ad5so3940840a12.3 for ; Mon, 02 Dec 2024 20:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733199810; x=1733804610; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jMDksIbcOLWGwD0vO5eo1YOj8LatyWo9RypORfUk9j4=; b=UX71rN2cp7skFEo0McRACN+ytAh7zWceGe+jR9D4a2qmRZe7wyVRKWZpa7iTNr6bta B7+6omAB2iI8Kiyyw1YEQtWRoyDY7pHhpga8iyrQD1RVoa67RB0jxxZmgyfquluVk8T6 ubDI3Jq9G2V+VWdz94uvi2k1+Kvp7d61bsyRWFyY9wOCsxshFqqzsLt9fYSJROcMtQ0p evF90rc8q2QNs3jK8Md8y0n2yphVNg1CwIClzRda+5xqDbRSf1pJt8+KiYPVF9vbr7ru mV62rquMgx3Y3PMB5aWiP+aLXHmnLPF3WiZccqt2zyOX5a5J7x2HYJQWtE3j5eDtL4H4 WtWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733199810; x=1733804610; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jMDksIbcOLWGwD0vO5eo1YOj8LatyWo9RypORfUk9j4=; b=masZMawlsYw05yAQLgGrw9444fqs2L/I2ks4hnO7lj6mMNZSzYrGP6/6pLLbBwXhBL mzui+rIs1NCU5QpBxUVH4BFHy1c3sACmYkIqrwPjI/43j4uZyhI405qR9e+Ah02WTYSE b0AmQNLNrQIkih9COgCvVkT6R1kuuwdw9euB967REhxiSkUmfmjEteAM4NaWcY8fu9lE tz3vhDIvzKVaarX64ghEFdC53o3o2tlUup/SRYm793mnhvvoo5bSQ182eME6udzWxIOP ehECBp6OpczN+tpjpMdSt0ZkyppTkvmTBnc8/uQvGYFE60k4+zrNbVPySwK8xn69qb1/ WZJg== X-Forwarded-Encrypted: i=1; AJvYcCW8pHQSSS1I0AqazqQ9E8wuOSanSu0S69AovKQHKn4ggGPZHPcwTXmVQcVNCyoccdqy9R18+ctVrA==@kvack.org X-Gm-Message-State: AOJu0YzkoylqnbgnzdNbZOzErKliEAfYMLdUi8wprokGkpL4jvOKyO3i tJikkaa4AR6MfuwBISBuafnTcenu2Javu8CfXgsR212lxIkPbCQu X-Gm-Gg: ASbGncvBvtzFB3HTUiKk5X3QCK415urGRqVBZcorocs3DIu6Y/INwWzX03x9RxhoGsG gP8cN4E5oYIV7o/DiHnn69FNqkp0uLru5bW8aWF3q7CggDnggcPi5+rznMIRQG+chDoaJbRL6Jg M3K1Lpkz3FEa2PeclaibEMt2/MK3I4zl4WQGfPcziRT4IGgysIfcq6keuZ7aGAfZVQ7pNkdpeLC DZOCU9m4JQVm867DB6rsuxXHJmxOAjEFNfpZ78lNsqlvtNUiX8cYwFr0gE+nizjYDQT827EoQQg pFheUO1gyKksNq6Wsclu X-Google-Smtp-Source: AGHT+IE8xdk48VpCN/lmNtJ4mSg7KBUaDEkPOtXNpXZN6KheBo7QC4wgFHpv7a0bXxkvqLx6Sq1RtQ== X-Received: by 2002:a05:6a20:3941:b0:1e0:d859:e1bd with SMTP id adf61e73a8af0-1e1653a7bb4mr1623878637.1.1733199810346; Mon, 02 Dec 2024 20:23:30 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72541848924sm9701523b3a.180.2024.12.02.20.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 20:23:29 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 4E210DD39FB; Tue, 3 Dec 2024 13:23:27 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 02/13] x86/um: nommu: elf loader for fdpic Date: Tue, 3 Dec 2024 13:23:01 +0900 Message-ID: <215895272109f7b0a4a00625e86b57f39fa13af8.1733199769.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: 3jt1ypwt63fwiqaisga9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tuWV4jl7yrkoOyb6RvdbHVQqx4MmH9z4BJg7WEOZv3BTGESzXA4lRfdgPELzf6vINGitkZ697/688q1Nky9Pigb1nVS5oxyL+/1mN1CFK5KdJzK+g+6e23rUw03mz25Yxam95vSbHlJoba+txMrV+F7iuD6xJ/W0PcC6JGylduqnuFgx51ud9cPGvF9t1ron9nhMeKshO6gojIhquwwXg66WG8v8Oq62qqyYXNj2W0+gBavEEGOMWChYkymJgd36KDBhihG0lTevoD5JFbwT7VUcuojr28KPOBUeNNHzdm3BwW1UFGl5h8iODAbIAsLYOsXP5ebKvTufRd8bXjO5xASzNtfukdACT7cMd7VEjo+V6sEhgvwrYViAk/F9mVGKeC2DbH33KCKrukIYb43cGn86ImLE5NbAKAM55O8veOGfvlUvXdpTU6uHNMWk/FiazGKHVQ6A2KPE2aOjmHmSLbqaNKxOJT5XCW+xp9vfQ2tIFK4EWLTRayVGih/AsU59+zlPrZr9Vqth2xbvxcDTEU/spBrI+vsQW0I8R6hBB36s0fodUybcZgV9o4m6kHYyZNCzTOc6Q2oh3f++nu1nJg7 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: As UML supports CONFIG_MMU=n case, it has to use an alternate ELF loader, FDPIC ELF loader. In this commit, we added necessary definitions in the arch, as UML has not been used so far. It also updates Kconfig file to use BINFMT_ELF_FDPIC under !MMU environment. Cc: Eric Biederman Cc: Kees Cook Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/asm/Kbuild | 1 + arch/um/include/asm/mmu.h | 5 +++++ arch/um/include/asm/ptrace-generic.h | 6 ++++++ arch/x86/um/asm/elf.h | 8 ++++++-- arch/x86/um/asm/module.h | 24 ------------------------ fs/Kconfig.binfmt | 2 +- 6 files changed, 19 insertions(+), 27 deletions(-) delete mode 100644 arch/x86/um/asm/module.h diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild index 428f2c5158c2..04ab3b653a48 100644 --- a/arch/um/include/asm/Kbuild +++ b/arch/um/include/asm/Kbuild @@ -13,6 +13,7 @@ generic-y += irq_work.h generic-y += kdebug.h generic-y += mcs_spinlock.h generic-y += mmiowb.h +generic-y += module.h generic-y += module.lds.h generic-y += param.h generic-y += parport.h diff --git a/arch/um/include/asm/mmu.h b/arch/um/include/asm/mmu.h index a3eaca41ff61..01422b761aa0 100644 --- a/arch/um/include/asm/mmu.h +++ b/arch/um/include/asm/mmu.h @@ -14,6 +14,11 @@ typedef struct mm_context { /* Address range in need of a TLB sync */ unsigned long sync_tlb_range_from; unsigned long sync_tlb_range_to; + +#ifdef CONFIG_BINFMT_ELF_FDPIC + unsigned long exec_fdpic_loadmap; + unsigned long interp_fdpic_loadmap; +#endif } mm_context_t; #endif diff --git a/arch/um/include/asm/ptrace-generic.h b/arch/um/include/asm/ptrace-generic.h index 4696f24d1492..4ff844bcb1cd 100644 --- a/arch/um/include/asm/ptrace-generic.h +++ b/arch/um/include/asm/ptrace-generic.h @@ -29,6 +29,12 @@ struct pt_regs { #define PTRACE_OLDSETOPTIONS 21 +#ifdef CONFIG_BINFMT_ELF_FDPIC +#define PTRACE_GETFDPIC 31 +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 +#endif + struct task_struct; extern long subarch_ptrace(struct task_struct *child, long request, diff --git a/arch/x86/um/asm/elf.h b/arch/x86/um/asm/elf.h index 62ed5d68a978..33f69f1eac10 100644 --- a/arch/x86/um/asm/elf.h +++ b/arch/x86/um/asm/elf.h @@ -9,6 +9,7 @@ #include #define CORE_DUMP_USE_REGSET +#define ELF_FDPIC_CORE_EFLAGS 0 #ifdef CONFIG_X86_32 @@ -190,8 +191,11 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, extern unsigned long um_vdso_addr; #define AT_SYSINFO_EHDR 33 -#define ARCH_DLINFO NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr) - +#define ARCH_DLINFO \ +do { \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, um_vdso_addr); \ + NEW_AUX_ENT(AT_MINSIGSTKSZ, 0); \ +} while (0) #endif typedef unsigned long elf_greg_t; diff --git a/arch/x86/um/asm/module.h b/arch/x86/um/asm/module.h deleted file mode 100644 index a3b061d66082..000000000000 --- a/arch/x86/um/asm/module.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __UM_MODULE_H -#define __UM_MODULE_H - -/* UML is simple */ -struct mod_arch_specific -{ -}; - -#ifdef CONFIG_X86_32 - -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr - -#else - -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym -#define Elf_Ehdr Elf64_Ehdr - -#endif - -#endif diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index bd2f530e5740..419ba0282806 100644 --- a/fs/Kconfig.binfmt +++ b/fs/Kconfig.binfmt @@ -58,7 +58,7 @@ config ARCH_USE_GNU_PROPERTY config BINFMT_ELF_FDPIC bool "Kernel support for FDPIC ELF binaries" default y if !BINFMT_ELF - depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU) + depends on ARM || ((M68K || RISCV || SUPERH || UML || XTENSA) && !MMU) select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual load