From patchwork Mon Nov 11 06:27: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: 13870269 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D41FCA933 for ; Mon, 11 Nov 2024 06:27:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731306461; cv=none; b=n0WSnhXj/WuH6aqNrLxIYN49cJwHTH1ivPqwQa+huMisv5hdPzwyTas9Ii1Z42/B1FVkEiJ7iTB1z4tMl4mKTbe57/gxDPv8h+Joo5HeNtDCSSid1a18gCN/cMeKcYY+l1AVNY8FoH/LrZHViY9+56pYoLVuUftFFJ196c1KXJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731306461; c=relaxed/simple; bh=HqbW5bV/sY3+LicbeQRJWIlOnWPC9iWwyogiu93iFOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FO79KqflAoP6uMAW9Uvmy81Nl0bNV2ybjaF7W1pVo+ne/gIHbSex+XUU6MWj0kzi0T2C7SS/WzNnvttTrbhTKXn8m8cKn/FHCGfGRd7ey/KmPbX+HC4peR5t6g345aNIMZDicTkDeZ7fl/VIhrqg5jKiInXJaHlF60AG0Us3udI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WeRkOeV+; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WeRkOeV+" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-20cf3e36a76so42567995ad.0 for ; Sun, 10 Nov 2024 22:27:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731306459; x=1731911259; darn=vger.kernel.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=6rxsmZtwDE9hveMIBPCsasEv3gNTZZ8QeBClxURXh1g=; b=WeRkOeV+n0Ba1k9dL6BXf7jYNIz/8zShbSVZurBr8SiWKwuwX9eSa7GwMV/3urfKEC JaOVHSxqunX2vJHbJyoGV469bJewxF1TmuvGe3CxIeP4wsnHjvYQnwtxGzJwSHelC0iX QgUER+KapVbA8lY94A5PWZ+NKZqoLVXr14/uxFlnTSA70o5w1AhyP7Dag1dpESL5OI8L PPX8PHXeKbaBxg6YsklRjagv/Dn0s7cuEPEmpS5Qojfnr1KUTD9Zq8dg6+4Rl1vqmZZ3 QJz1dOb8uP/8IjAk0JQg7N7a592ZoamP2F2G3DaCp6uMKpBiGWE9bcimFsFC3l3IB2ek lrTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731306459; x=1731911259; 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=6rxsmZtwDE9hveMIBPCsasEv3gNTZZ8QeBClxURXh1g=; b=GEGDH0gD6nsHWUM+c5EXsle7m7jkFVcOi0N3bdEs+hwQ71TylP8dE4hpW11utFMgoz CC7KiISAs53IE+zbPE7QllDmCogCMTCE4oVcvsQsBCEW98qqiHxti54SNa26dGX2z0Q3 ZsgFNRn+X6cgh/TDGxIPgraNS1EBQf55xzcvAwxT8HKS/kleBINRxs6c1Xqin79zHEU0 S5UeDGFKLiDdFYUgS080yBhA9f2luMoak1gePP5CYK18RGldtdKrL8/5C/zsziEA7P2k phZATxADUl5jlp9qaTcWsDg49sqGoZwRqT5hR3BtZg3tdJoYFmBjWwR6chR7OXOHFEYX xVZQ== X-Forwarded-Encrypted: i=1; AJvYcCV8wwx66vRIFdQ8qx1u6i4LAyE/U559CY1ohQzmtT6wxWDyVh7lB65ripy6VTz3LDPGQq0atCMWAVH7S8In@vger.kernel.org X-Gm-Message-State: AOJu0YyH4b96L7SvTUJg4J+GM+ga+1smJ7zHHnwKpdwEy6Xin03M1BYv D+UlV3LemvDX9EZEK0m/jprFfPCI3d3HBaPS8YA+XRkFABwhXbJa X-Google-Smtp-Source: AGHT+IHwpmnY7dnXQcsSzHRDD73tGXzcdssS5VVzqSGyOahZ7QhXBU0+7Fxo/FbpiQKc5P/v4ljTRA== X-Received: by 2002:a17:903:245:b0:20b:5645:d860 with SMTP id d9443c01a7336-211835bf105mr168324925ad.36.1731306458982; Sun, 10 Nov 2024 22:27:38 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177dc836bsm68741545ad.13.2024.11.10.22.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 22:27:38 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id E5712DBA914; Mon, 11 Nov 2024 15:27:36 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org Cc: thehajime@gmail.com, ricarkol@google.com, Liam.Howlett@oracle.com, Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH v2 01/13] fs: binfmt_elf_efpic: add architecture hook elf_arch_finalize_exec Date: Mon, 11 Nov 2024 15:27:01 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 FDPIC ELF loader adds an architecture hook at the end of loading binaries to finalize the mapped memory before moving toward exec function. The hook is used by UML under !MMU when translating syscall/sysenter instructions before calling execve. Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Hajime Tazaki --- fs/binfmt_elf_fdpic.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 4fe5bb9f1b1f..ab16fdf475b0 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -175,6 +175,12 @@ static int elf_fdpic_fetch_phdrs(struct elf_fdpic_params *params, return 0; } +int __weak elf_arch_finalize_exec(struct elf_fdpic_params *exec_params, + struct elf_fdpic_params *interp_params) +{ + return 0; +} + /*****************************************************************************/ /* * load an fdpic binary into various bits of memory @@ -457,6 +463,10 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) dynaddr); #endif + retval = elf_arch_finalize_exec(&exec_params, &interp_params); + if (retval) + goto error; + finalize_exec(bprm); /* everything is now ready... get the userspace context ready to roll */ entryaddr = interp_params.entry_addr ?: exec_params.entry_addr; 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: 13870270 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9F74A933 for ; Mon, 11 Nov 2024 06:27:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731306471; cv=none; b=QLRaQVNg5Ch5YYmmG/nJgFIrxRarDAVhtIGkTPQG1f1qmomiLV1+Xo8fbEkcxk5Pmls/iY80UYkrdT/0drnQIW/FJYuiY/MPlNEd0LoBMfdkMOMiKx9l0SErby1QTuAGjAs9hprmrdumrceKxeTp8YmsW+oyom0hndkmSIztQD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731306471; c=relaxed/simple; bh=G9EmF+0U43TyP3yqFZHh1/jQ40jHWSoJmoQ0KBtyI7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eguV42GiyhHcv7KdlxmfIZ079fjdOACNThPx/+A+o7ElTVdHcUyCKixu+rrNzi5YyhJy0FhKTb5s8XF0Esii5m7EI0Yhew0TBpTlCccCzlhsMA25iWvxUnDBpoFq4sSXiVZnVhIgjU7ExbUKEyi5XpTWZjq/sDTF1G1dbxxNu2A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=W7l3T/Uz; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W7l3T/Uz" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-72061bfec2dso3832256b3a.2 for ; Sun, 10 Nov 2024 22:27:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731306469; x=1731911269; darn=vger.kernel.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=W7l3T/UzA03APVISDKzhBt/4q92vGXajhrT4U1ea3cmyoSOM4CEz9Isqi3IJRK4FrD SGXmp7H7BIooojL9TkHxAt/kNKgm5TOSUTqi/mnom6+iDYNRzFbeYDn12y7XgqYXFVYB gjh3ZinRaLnyA1/xsW0dt2W1EvazUV1dpmOI1NU1AvsU64FOt+HwLnVIMdIkLwXWYam/ Sg5sMzP9aNgdZAp8Atq5yVyoLC+s6eOx61/WQT7RhCFdqzpQJrwplBVURYDGyjIrmgH2 Zeu8NNbU/Uwm1AHGz11oysdaHCSNhH9oRY2Ev829gHD4ZNhovMC4cGUl47ym1b0Uz8eT KFYA== 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=NFPOL0XgaKU1MOXSKgtK1bYjpala14gISfpVYWtC2NSeCrqnsRr8zKe53jwIUd8Wte /0nDYy0Yo0Qu6HYUyZJSHMG1JQ2jzcFR1j9/4QHHYu9HVG40wnxV+VPtuv2+lYwTabuE dxzJFcEhh0Y4g2CO1uMT944bI358pEmJ38PXPhX7gkI9/vr5Mu5rf55Um6HSC+qxZgW9 eDZR9/NW9hl3Z6kG7cD1mUli3F6/wMXFwUFx8DQrnEEuM0A1YTPkQypUuoAMkz4AkpgG AY2LBCNb+nvMayrSExvV2nAA+olIP4UW+L/29OY58NX3M32ZO721LnHQUIyQu33rcvrK S6Xg== X-Forwarded-Encrypted: i=1; AJvYcCWxisBRomx2+G1Op3ARiiGbaERd6eoyZi+urpWLNrc6OkFXzNKwAbxzgBB5CVyKzCA7wfEZQP1+uvqSVycX@vger.kernel.org X-Gm-Message-State: AOJu0YzrJ5wPmSChvmOhtdWxBhIUFZxtKgdwKk7rwCekzjbi7CCntM0y gEjCHMtlLx9pFsnzzWDS3Dq4HfDfGJ/bEOqSGeT851uGKfaRBbAu 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: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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