From patchwork Mon Nov 11 06:27:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 13870272 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 69A1CD12D77 for ; Mon, 11 Nov 2024 06:27:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFAF16B0085; Mon, 11 Nov 2024 01:27:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA9446B0088; Mon, 11 Nov 2024 01:27:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4A7D6B0089; Mon, 11 Nov 2024 01:27:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B59D06B0085 for ; Mon, 11 Nov 2024 01:27:52 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 413E41616FB for ; Mon, 11 Nov 2024 06:27:52 +0000 (UTC) X-FDA: 82772831526.07.A3FF1F1 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf28.hostedemail.com (Postfix) with ESMTP id 75CDBC0012 for ; Mon, 11 Nov 2024 06:27:09 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Y2zbahVz; spf=pass (imf28.hostedemail.com: domain of thehajime@gmail.com designates 209.85.215.172 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=1731306329; 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=xOVZBEb1qaBKyIOwwQleK43822fSZbq/jfSKIeFdX6E=; b=u/xtOlihYws64twMQtnJO8Vtd3gbMiSg3fJ1pwR+uZlfR3sjh97RlIB0RHEzMR5XnGv9aU G1MkXJuVqyubhH4Oqxj0ByrYKGlCk/qJTSgxqjcyrs5BmNJ6Fih5KMb+oMccbXKEZhWvkI 6AgEfsgFgK7MzhsCUbcl5umlPnsso70= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731306329; a=rsa-sha256; cv=none; b=qaVIa6dxfJfCYXGpXByKtEGPhs5WiWL/6lBcrqKgcdZ6ZrmE6IG1oz6Fynaafk/D2jkb1g kFDwaGq3rdH5urLyVT3qX1ynLuvjHs5ap800ePEtZTQ2sXIhdAZNiXok8GR9mEN33KTivS MidSk/3y49IM9YH2V58g4GSdm7G9JHE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Y2zbahVz; spf=pass (imf28.hostedemail.com: domain of thehajime@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=thehajime@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7ea8c4ce232so3660702a12.0 for ; Sun, 10 Nov 2024 22:27:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731306469; x=1731911269; 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=xOVZBEb1qaBKyIOwwQleK43822fSZbq/jfSKIeFdX6E=; b=Y2zbahVzqOkAFtMz0XT17iIXbyIqGHWcXQ7M+ao2ZTDb0/aX6vjD/nJb9BZJSX/XnI G2wcDh7UijVPHrSr443A3HpwRu257NxuxB5ol4CearjOFwpOmZwXNlfySTcN8Ppm05kf kkYlB5vE/s19Xe1xoVZ6bBHJbLMflcWOuJXgA7xklXKVVgMtqLf7YzT5hJkx8F6kJqGc dAEr9nN6lm/sMMY2aPWZGg4GtMXZfPI20vT78JsTOjr5AK8OUweajRC8EHZ5jjN1AFI4 Tm1xTSu7CFScOVrryrOufm5dGDYf8e3ZRV/DX9otSmOSRDuJYesKjhqs/a8Ywt016rH2 CZ5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731306469; x=1731911269; 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=xOVZBEb1qaBKyIOwwQleK43822fSZbq/jfSKIeFdX6E=; b=Dbxo3tE9VhPou9imZjGnD5qsgrLpZMPpjuUh94cRw4wVupkAcD1i0JLH9fr+5QELHE fDx/4FI7WvPgoyb+w7y4H6mv6189y90/ZvysvGDCS22IgR/RazsHYfU4ja9iprKueghA Cj5vhkEzHBKsN2LDuy7Ptjx57AgbnIDwPydqWpzGmp34qPF4sdAvh95xvNXMkZv9nNeN Zp1Kwp9xVN1KimdGeDRe8UHB+UMIqbQhvo2fi5UFXvP11iWiJSIzlYTYYphSNT++9U3m SLgY8oc0RdtHaPz8usGiZhfekZHkurwWNC4WMjWmXh4oojyXd7Cuh+12HPFwFz+WnI8M F0Pg== X-Forwarded-Encrypted: i=1; AJvYcCU4y96Q5fKGl22QfC7QRFLCixYutkVq4h5AxKiXLuBqXsDUARSN5Cl83Hc45XEE7cqLWtkJ9DFIIQ==@kvack.org X-Gm-Message-State: AOJu0YwUFmm+SBgF44TROv9OM+V4h+Abh3rwQL5rNe9JUXI++61og3Ol SXMkAVsih/CswmuQA5zMef1gjrX+P1Y6HN6qIF3nRn3MgV9zpab4 X-Google-Smtp-Source: AGHT+IHr4mrXQCJG6ehz4R575ji8XJjfRwnS/MkIAJ3E4bPBw/vNBMDgKXMb0Ui2eNQcCUFveGlOmw== X-Received: by 2002:a05:6a20:4324:b0:1db:f06e:f666 with SMTP id adf61e73a8af0-1dc22b91c5emr16383347637.41.1731306469013; Sun, 10 Nov 2024 22:27:49 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9a5f8f5d3sm7819534a91.27.2024.11.10.22.27.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 22:27:48 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 43199DBA916; Mon, 11 Nov 2024 15:27:46 +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: [RFC PATCH v2 02/13] x86/um: nommu: elf loader for fdpic Date: Mon, 11 Nov 2024 15:27:02 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 75CDBC0012 X-Stat-Signature: jzza8mb9byiww6sbqtirhxdbjx9i5epy X-HE-Tag: 1731306429-7530 X-HE-Meta: U2FsdGVkX1+VDIcwc83tgQJjJgAFw0OXWW0V5zK0H0fEy/zSKyc9NwxveiXqTJKSG3l24M4pCSncZJzgj7U4ds/6lo9ps1o9F/wXNDvho+mngOHISPIXlqbKcn6NWrVA6lvzoZ2nM/Iey+YNZgSusqyGrVSvTFCGNlazNPH1Vw3ZJMI9yn/Lb1zRwI4Y82iIDSlJBaLXxNJvRFtxCWYqRfrUsbWmvuPkxwITW9jLXizj3+Hgxr9etAHaO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4puV2/UIQL7yfFGlfmF7sE2Ck4Dd++udRy5PYdUGKt6SzHHefCKgjHWcMmp0vu/OlWCNX+Q5sWFjAHZjm3Y1s8f/SU7WmiYD+ioaHVTksWq0FKq5ctEcuaaO8R5kY4r/52rtWq6nn+05KIbsvgL//H1NipT+RInBUeuSdrlxS1SedVe51yj94ui6BoQOdIOWptKLnpG5Z9N5aRzighJkq7AGdMODXN3AyHNCTsczsBD5cw2eKvj0M+ZAi6Npl838+G47IJ7swhfZX 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 18f902da8e99..cf8260fdcfe5 100644 --- a/arch/um/include/asm/Kbuild +++ b/arch/um/include/asm/Kbuild @@ -14,6 +14,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