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: 13848844 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 4D628CE8E68 for ; Thu, 24 Oct 2024 12:10:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA25F6B0085; Thu, 24 Oct 2024 08:10:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2B906B0088; Thu, 24 Oct 2024 08:10:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9CBE46B0089; Thu, 24 Oct 2024 08:10:05 -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 7A40E6B0085 for ; Thu, 24 Oct 2024 08:10:05 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 51FFE1412D9 for ; Thu, 24 Oct 2024 12:09:42 +0000 (UTC) X-FDA: 82708376730.25.9B2DE06 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf02.hostedemail.com (Postfix) with ESMTP id 9856C80010 for ; Thu, 24 Oct 2024 12:09:24 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WmE3UKOu; spf=pass (imf02.hostedemail.com: domain of thehajime@gmail.com designates 209.85.215.176 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=1729771647; 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=PIytQe80ylla7Sl/fe5LxDRRHtWVNhv8vhvelm/o17c=; b=D0mOtg9VvMWShqzLB59GXfyKlXXoOp3qBTSCami1Y3ppA9fcv4OCcmJlvCY76ALXj0So74 egllFo65q2gVHX5vr9wYQlLRb/ksykTGCuGcFKRGnTJCnVogkBxMwrKOTFe+or39DDwqG+ w0jBH+RVDLa1DarK72zj6mArORgeXvQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729771647; a=rsa-sha256; cv=none; b=kMbU4vvP5cr6AR0FgJTH7bNrm6E2d90sBRiSGnu3x1WDnw2yXNzNpqI51VeT4+q2XVhzVJ 65g+3vGlp5z8YMx2soVlVm45ws+y4VlpSSWclLfJBmzrbU0zF5UsoMTix+22eVcwSSbX5j R+mmxZc351c/wKmY5FyvRNDFozm+Gdo= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WmE3UKOu; spf=pass (imf02.hostedemail.com: domain of thehajime@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=thehajime@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-7d916b6a73aso417629a12.1 for ; Thu, 24 Oct 2024 05:09:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729771798; x=1730376598; 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=PIytQe80ylla7Sl/fe5LxDRRHtWVNhv8vhvelm/o17c=; b=WmE3UKOuRnHUO2YOuHo7YsYdqZtX9+YhhLW8A0nETKkthnytQoa2DGYYm3EXouHgA/ 0NR1rFxI+/mNf7MKbe5CItlKZVQkyNrHhQrRE6sveknwGNIFcxVZGnTGrDQmu+19jNlb n1/kLZTanwyCN0/b5ldxX80jiI3bbf+tnS7j8ss0IBJJRN25LNweU0pMwVsSYZXZ5Pxs cqZ8JoUrlvOnNg4ev6hlsWsLydtUEOOLX9HYbhLJn7w7be2Q0zE5R51+1bnyM6a6k0Kx zop8hkVlmBFcTlblU+JOyMhQB10xRYf42JnuMayLGABFnXewebFcyO6+H+BevuD0SRob YzCQ== 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=NyoSs+vQ3GeVmgW+DLV6o+turbA8QGznPiHFyo5VhuBsG3Oo3P/H9p5ixJOIMx7+Zg AWT3gQ9ajunKMteoXUklkjad2OiuJy9BCSvbkNPgrhEVNu9o0y1XTJ1ZgkleKrU8Asvl hIoM8hEBeasquSZHuoXKeIAmE2ilhCu9eeQGwGfadZi9SXdR6vMjHTmLJa6Y39WvE5rj 6tcPQ04I2eO709A3Jgc/V+brsNdrKQjnapOWYu+HfxXWBSheJbaoLJy3fHMsIUXKx0jH ZqOV/cKQ+6Q26UdsHGVOhqXyMj1uSEEGiQ7MPuYC+PLNYV3dwgVEXngQClBYWW3f/wss JaFA== X-Forwarded-Encrypted: i=1; AJvYcCXjFc2b3it8hAgttIZh2BkdhkMq2ZpI/uNfqYJgMKFB/nTqZaZF3kLO6YjJgovx2SK5D7dK3zmJNg==@kvack.org X-Gm-Message-State: AOJu0YwU0+fTa1g0EdJgNmh1OELarHxOqvf2BTguKpROnrkE4OxzKL00 /wxy79XPfAz8080nmEMkZ85Rqbk416ebRs2K+XPHVFhQsxNFnvvB 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: MIME-Version: 1.0 X-Rspamd-Queue-Id: 9856C80010 X-Stat-Signature: nee713fppxe84w3tkaspwtft1ud9xgba X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729771764-812628 X-HE-Meta: U2FsdGVkX1+ZcWoXEfxvlaWHJzPjeWXcjJB3PGt4gUmLW00S7ahoYe+PIUUDCH3Tg4Y2a5OJ1P2TV6lBZoECGAvHNeaxbeZOnBPaQuQ6Jn2pUQAZ1C6yRULwEuMiI4bo1izhSxfCEuf/y56MZ5BVbH/Tu/ArWUfe9o7Oy6F+rJf9u0lqAOK9pFoWtyBJ0d8CKN9qR3QnmOws2XTVGLJY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ujKh6p40ama6BWFrJq2u5mmijlvDvHxj5gky9ui5vlirzyizCY3/ahjdL4ZyNclp8UnbQUyWzqQUukuQTIKbzHaWEy1pENtj7iE0mtLdQRNZQhTlk2ekOtsKdb4/m5jM8eiMiIM5+ZarOMzqorM634QVf+jmCfu404W3DJgW+nL9BWhK9ZCsmGOLgORjmEZhJNits6PKyiCOQ8DxpmCjkfHSSpBUIMhx191P6Q36CHVm8YfF2JWbDF6SnFNLYLAml97ObkJ38DoDTLyyy1g4GH9Okww/fBQPATjxINHAkh6y72jml5YMY+zk 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/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