From patchwork Thu Oct 24 12:09:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 13848841 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 068FE1C9B87 for ; Thu, 24 Oct 2024 12:09:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729771790; cv=none; b=NGiZ+ZyhN2Ohr8jhItqqyyw+5gy2lwG0dLrJqXlba36O9JLjcbUO+rU110bdtjkTYo1adi+VghScwNW4ysiWQAwHYkAYPbZKc3PRLjJgDIxhRv0Aa2A6j9++NzM0AR8C6Q/PBnmcGtbADcSbGZm+08X2cEG/+DXl467NHLaKraU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729771790; c=relaxed/simple; bh=HqbW5bV/sY3+LicbeQRJWIlOnWPC9iWwyogiu93iFOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ip+6lKesP2BJJhO6Y6GSxiOZOJ+eZKs1os2dPzP8h2uU4OjRF7oKXynIsb/W+ruZDCaXRDSVN6S/IU4BF9sNHJwYHm7HJpzRbrRCXGcqEh455ezfI6vu9MTNRriqw2eGkznNa0+MLXHdMK0NWnEbU6SMZUrQ8vK+hCQPorZoj0I= 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=TEpo8HAm; arc=none smtp.client-ip=209.85.215.169 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="TEpo8HAm" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-7db908c9c83so441279a12.2 for ; Thu, 24 Oct 2024 05:09:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729771788; x=1730376588; 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=TEpo8HAm9+xx4faO0iMTFnzEUbJVL2msTWJvVlUaAsngOtVwqMq7UH7OGJmePZZkr5 WqFspXHp04AxvIV6/1FA03o9HL0AE/iKkE9QpaRalKQ0tGTQQabA6ce0wBBCTOjKxQAQ aGxMPytWlyygdcgREz/8LZHAHOV4vaymKFt5JJn3XSJA7yasdhlUDec91G1D4ULe6e7v Qr41SDSIfYvhrXpTorzCNDhcXxWMM2SS2UsHgMPd0qtmBzP8iCWQOjDOg94IhbUKbi+I ISfktXZflZAatlwBDuyiDRGDZlxK/0M3LL7BiZTkd76MFtSpgnA68ywBlKErE+1r2JOH 3r1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729771788; x=1730376588; 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=Y8ScRn7mUocSQxP2gGcC5hluyJ4dVQTPgZrytWgoJi8D8umKZNhpod2Wt5iLjSgng/ 4TmSa9UCpTX/8Hk85PBvNreIly36+4OV2eUyWoGhaU8B74whwxKYMZlB2IgEb7KDpOvl alufo4C5v3PIepZiPH6r8qfwrR0jI5VxSp4fBOkk/xPD5SB01nXlKPpqn8C1GfRVSDpG 2otgxLKfj+YqXfE5SdyL50Y6if3uMPZAHVdVtDyWpl2S9TFgVMpeZ6U0kf5omg0NSPwi mV0F7wHuv7x2Q+0vNasvktUVHHYdeFWthG4bvpmdQUHRtmW3Sw3uc4oqdBikvhRfLqQp ww7A== X-Forwarded-Encrypted: i=1; AJvYcCXw/UMUdMX6A5/XHvzEwSJtWPSP0GxY/ZjpYZ4ZRNTZsSXycGAte+4zzfOlR4gT3ziZBGNN0sNam1NrdEnJ@vger.kernel.org X-Gm-Message-State: AOJu0YxA8OjvxjNYrnVB6PhaX/0TnCACTN1FfWiX1e2uztOPnNQvCoc3 M1I6ckPwnxejCTl0ImxXJqutUeV+K/ngMhqEaRufhaAvt+vVkRt3 X-Google-Smtp-Source: AGHT+IEDeGgbLE/zgvIx9Neo7X/Tvc/kwVBKGo3SVswnkbyJjKLA71wygrf5Z7lZwgpXfxWF3CU2mQ== X-Received: by 2002:a17:90a:f0d2:b0:2e2:973b:f8e7 with SMTP id 98e67ed59e1d1-2e76b70c381mr5909794a91.38.1729771788065; Thu, 24 Oct 2024 05:09:48 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e76df50eb7sm3335163a91.16.2024.10.24.05.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 05:09:47 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 0CDB1D51249; Thu, 24 Oct 2024 21:09:46 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net Cc: thehajime@gmail.com, ricarkol@google.com, Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 01/13] fs: binfmt_elf_efpic: add architecture hook elf_arch_finalize_exec Date: Thu, 24 Oct 2024 21:09:09 +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 Thu Oct 24 12:09:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 13848842 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 B569B1D1E72 for ; Thu, 24 Oct 2024 12:09:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729771800; cv=none; b=NE/QxsmP1Ay5MfrOKONW/dYSI73+MKUVkyhqIeUXp++ov2wTtLxB0nItM44J93a6k1pivAD4bFKs1k3wJxgmX29yNAG58FuIcOJfEHux2W3i/4ylYBnBVr+9lQfM9eeC9TFlbncaEh1/endpybwLyjGKEp6yvMoQF23ChT86Pbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729771800; c=relaxed/simple; bh=1x4d11aIFG1EZdWmBSrSH52hZelRmwZOy9d/XQFCGPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HiKjXFcdWL7XckfRGDy7+dTp21EWYweTBJXPscU1DvhG74wqiXj4jNZbiSPsCkqZCkdron80ZBKv+szuSCg5Q3vSPL9dmVjJBdmR0Cg1AVpzoMwd0JglqnCYQjre5Nb1Fkxhxz0mK6gj1Db+02ep8x8F8wWSkGAIyatTXyvcxeI= 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=II7RILky; arc=none smtp.client-ip=209.85.210.174 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="II7RILky" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-71e74900866so589840b3a.1 for ; Thu, 24 Oct 2024 05:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729771798; x=1730376598; 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=PIytQe80ylla7Sl/fe5LxDRRHtWVNhv8vhvelm/o17c=; b=II7RILky/BD+W2OHkzJsK/T5pc3hrrbg2Hz1HWVGM7uvKJoYbYCg0kQWXp2sNnVbZh qISRb1Z3oKaUrsuzy4VwZ5XQsf9VbJAuOyrvT9toVuNL+I+YwAkfxQ8W/HpluZ6h7poG QX1TLXY5gVQw3vg4jtxylTmYRdRUt3eJuDMip50agvX5ng3ZY7igL38Wl2BJGEkz0arL s3O9jKaIWEJGXvuaaPa6x/CLckla/8VLS4JkQV+GCAYJQ8sbPJpgY1QPOFJc6rrbfCp0 mKP5Nz5MzGnXtxNYREnzFsdNvwiCQu8yhBw/lrtxgVyqO8Oohip+B0ctyjl+y6YgH35v ymXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729771798; x=1730376598; 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=PIytQe80ylla7Sl/fe5LxDRRHtWVNhv8vhvelm/o17c=; b=PmILX+xXzfrTN4w+chC/exef3q0qem30zutP13PR4mn/BDqmU4KbqCoIpjI8lrVIBR CxCCb08enFKaaL/CHUgq4lJ0edClXzKJey+CWCXiLO0C9VgH3oaor/K0kJqma1gKu786 kkcWTNHf4p/RMZ1RJl5LYz7fkD73XReRxEwvq1HdwL1inqfJXiS3kH5X7Sf6wmDDF5RO YqJVfwsqyGvfOcVqzKEatC30kJ2QVFxsLOSFLVkecGm+WoAbIuBzglTP82ZXbG64L5as wMbpslzVRA4glc/RlEQgk8FOFIswyG76NHvFUOHeZsGgXpRgEKbNw/ckBx6FbqMYUbq6 B5UQ== X-Forwarded-Encrypted: i=1; AJvYcCUcxYX6Xdg4e6YdUL3p9Vqe1N4aY0FC2agGnToo4U3n4OdDpnYogLOEu5Tysf6AB02PIvK8opbsRGqVsW/u@vger.kernel.org X-Gm-Message-State: AOJu0Yx3uxweTSyQUqMiJwh9NbhsLJsMm+iBbGPiZ1FsEGtomSu4W0pY RiG+rDBVLc1ufEq2poogQBWXOxot+buOG4js9GGTuEDmXT7I9670 X-Google-Smtp-Source: AGHT+IEWx31qom/T9NynWTwcS94S2CIs7HjdghwcESDW4t/deHJ+ZjzUUv7QSQwXyIjcl4756ZTDog== X-Received: by 2002:a05:6a20:43a7:b0:1d8:d3b4:7a73 with SMTP id adf61e73a8af0-1d9898fda0cmr2115741637.4.1729771797871; Thu, 24 Oct 2024 05:09:57 -0700 (PDT) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7eaeabda22fsm8492096a12.88.2024.10.24.05.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 05:09:57 -0700 (PDT) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 4C46BD5124B; Thu, 24 Oct 2024 21:09:55 +0900 (JST) From: Hajime Tazaki To: linux-um@lists.infradead.org, jdike@addtoit.com, richard@nod.at, anton.ivanov@cambridgegreys.com, johannes@sipsolutions.net Cc: thehajime@gmail.com, ricarkol@google.com, Eric Biederman , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: [RFC PATCH 02/13] x86/um: nommu: elf loader for fdpic Date: Thu, 24 Oct 2024 21:09:10 +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/mmu.h | 5 +++++ arch/um/include/asm/ptrace-generic.h | 17 +++++++++++++++++ arch/x86/um/asm/elf.h | 9 +++++++-- arch/x86/um/asm/module.h | 19 +------------------ fs/Kconfig.binfmt | 2 +- 5 files changed, 31 insertions(+), 21 deletions(-) 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..fefa7631394e 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, @@ -44,6 +50,17 @@ extern void clear_flushed_tls(struct task_struct *task); extern int syscall_trace_enter(struct pt_regs *regs); extern void syscall_trace_leave(struct pt_regs *regs); +#ifndef CONFIG_MMU +#include + +static inline const struct user_regset_view *task_user_regset_view( + struct task_struct *task) +{ + WARN_ON_ONCE(true); + return 0; +} +#endif + #endif #endif diff --git a/arch/x86/um/asm/elf.h b/arch/x86/um/asm/elf.h index 6052200fe925..4f87980bc9e9 100644 --- a/arch/x86/um/asm/elf.h +++ b/arch/x86/um/asm/elf.h @@ -8,6 +8,8 @@ #include #include +#define ELF_FDPIC_CORE_EFLAGS 0 + #ifdef CONFIG_X86_32 #define R_386_NONE 0 @@ -188,8 +190,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 index a3b061d66082..4f7be1481979 100644 --- a/arch/x86/um/asm/module.h +++ b/arch/x86/um/asm/module.h @@ -2,23 +2,6 @@ #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 +#include #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