From patchwork Tue Jan 14 11:30:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 13938630 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 6AF2EE77188 for ; Tue, 14 Jan 2025 11:31:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF79B6B007B; Tue, 14 Jan 2025 06:31:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DA6226B0083; Tue, 14 Jan 2025 06:31:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6DA46B0085; Tue, 14 Jan 2025 06:31:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A9FB16B007B for ; Tue, 14 Jan 2025 06:31:07 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 59EC8C08E0 for ; Tue, 14 Jan 2025 11:31:07 +0000 (UTC) X-FDA: 83005840974.09.10862C9 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf11.hostedemail.com (Postfix) with ESMTP id 680C54000B for ; Tue, 14 Jan 2025 11:31:05 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aAM+1srZ; spf=pass (imf11.hostedemail.com: domain of thehajime@gmail.com designates 209.85.216.48 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=1736854265; 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=ukyNfs65nuvgTdhSkdJYZ2Y9345NLuFCWN/gVQv/aLg=; b=KGIpMWhaxzUwfubd8RlLxsb7dHbtITy/ZKXBj0r5AYFbSC3BdVhTv5SeLo7/C7zpKV/3+B H4giHbIuBC00luOAnKOcnVnWUNuOAcBDkDYMvH82iyFHahOCq1X2I700IR1UbSu1UuIOxs L9qXqzhd8BRvFI/wBwRwGqOdVOqnfz0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736854265; a=rsa-sha256; cv=none; b=MjRa2eQQKvcwCK833EFK4sVH5bUh1DmzH0hrigo6/sIq3mkvjkSA8vhzQrGUOD6oI9o/FY T4IOSPWTu1Wgb9X08yMbsM0nKgXulg7P4fnFxUBAw/LjqN/oEgBj3DKzzRE/HIW/Af8sBO dFU1QbFlMoX96usOOFtLAu4cD80BLeI= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aAM+1srZ; spf=pass (imf11.hostedemail.com: domain of thehajime@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=thehajime@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2ee74291415so7083050a91.3 for ; Tue, 14 Jan 2025 03:31:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736854264; x=1737459064; 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=ukyNfs65nuvgTdhSkdJYZ2Y9345NLuFCWN/gVQv/aLg=; b=aAM+1srZgnWku+Dlmhw4LyNBzCbkHd0/lnRuz29UJL1yU9vQnPusmqV3ah+IkW1/oN zFXnov3m4XcvFF5pEuGlUIdur5yR1iG0G7/51jADXmUtMgfD12PKDzQQFBfneWIXu2Fo wE6PZGybuW2k0SGzHqe4rFgUgFNNFOQ/bqWfaUqaPQC8uiS/bN0KoHtvooUp6RRgg3Yg PLbOOaHckJIaEKPNTFX5Ht4QKQRoqWmEJexqJu50YHpv3zmxv22azqInNNeuWDdSoO5H FqspZTG+pSKmwwJitY0Ghi5WYtHK/tQHWbxKVLP6XGTnZOZs9r0PhnbuoZLRspROcv+A ToEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736854264; x=1737459064; 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=ukyNfs65nuvgTdhSkdJYZ2Y9345NLuFCWN/gVQv/aLg=; b=jzOgplBIa3zIn37pe4Z0gZAf+dce6UuRYwfCfWDuHd5mR91ZAik1hn1vCf4/Mu5kXk UMwkLwuTq93okcvKG6Rijf7qqo7ha9iCpbdlmmHbBar5NkLMOuKJzDyuTg2yKtPwlMTd sDMQ6n9qwzruJb61Y4JuqQ4miIvcxZbSBAwz6jGPApqIdGw6M59c1LUxRWtg5CxXPx6q 8d/SUWvijbUWdNsk1aeWyUmHp3/EbK3wYeMCvXNKh4sgkEPn7X7hwOo0p6Y6ph96wVmI gsQohim/nBFsF8ihWToGiZXEsJE8s6ErSPXAIX45ljK0NhkdPkEztiuaYehGEYN73CAA BPQA== X-Forwarded-Encrypted: i=1; AJvYcCXfbS/8eK46bZ8FtukNCtxgphgMGcGWVIjTlgttq9+F3oswdX/MsLYzO5JUzoorMdXmmgmAm+lgQQ==@kvack.org X-Gm-Message-State: AOJu0YwhDNjVG2EnZCk5u+bfPC20HMZKxz/3GvsBwk6yIMzjj6uLj9Es ue1hp91S9vNGIYF1CmNb5qv6wqJ9YcgERF5Kt0FqUpIj7ls0i82x X-Gm-Gg: ASbGncs6knuuN1xpB1yVEejkpas93zSFVQoYPcoa+v2oNgSQ6Ijl/nxbwnr3jFppLr1 OJ/3TqE5zCVhJ1+ayHbrpl+f47Fp7pm0pNeFkJCr9KMGZMCQth4Vdj2V/k7KEyDLsrhESccFQYD hRrWS+otuh9KTUJl7VPV98yaGzC+f75lAIoTb3zezWrGCoeOhBgSDalILDJJao9rdKFdWk5ncut uIOkkijTkMMbkJMfKDVlNAilRHwhmTLovQ0r/ttarKEZt42fOKsLMn00MVTKupZPUYK0XQUW6iP KyLBRTMjos3YsFHqW5PtxQGwQRmM X-Google-Smtp-Source: AGHT+IFUwZHNFEc67jBbRXeFTOn0tcZ1umDdW5kX+lEEHYdmJnaChB7NhkDCIdArY2EVW1a5YS/C9A== X-Received: by 2002:a17:90b:5208:b0:2ef:33a4:ae6e with SMTP id 98e67ed59e1d1-2f548eba9c4mr42260944a91.12.1736854263922; Tue, 14 Jan 2025 03:31:03 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f22ee09sm65234765ad.200.2025.01.14.03.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 03:31:03 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 5DC8BE1AB50; Tue, 14 Jan 2025 20:31:01 +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 v6 02/13] x86/um: nommu: elf loader for fdpic Date: Tue, 14 Jan 2025 20:30:40 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 680C54000B X-Rspam-User: X-Rspamd-Server: rsp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Ltf P7pmKMoPyI8/7/oPbY1yf2sFFvEfKIp/Q4l8yWbfT1uVD5IgW5oODz9E0MG9mGLEikAKRDq69sqmE8VU4foafFnLKGK23VnBjhD6oKwmsoX+OHubOBBqWr74OtWZjVSB3PgUKSzxEHNdzsGzWEJN2F2Dtczxh/qauWxXf0SAFv0lgRjH9YFFFTCwx+6k7iLg307cycs1+6aeuHRlqHi48RfSChUzsJ6SQqymeY79MfJngdiTqerBnOLt5VPgymUUPHRkcJz55Adw/FE++1GtxgaRmgz9KVYrmQuol7gEnqGWIb7egbMwMSnQk07UHzo+lQ07gG+IgEhj9kTiga1rB4EB1UD7ryq+9vdO5CTMkmm4XM3oayyQ3CrRML53pK5Gbwnm4twxHWw4GV+ZmtpwEi+Y34hihBpA7DxhQSFEuaSb4Of2GdfZnCEqoECx4F9e9fc2NT9JxXdgCAtiOwa4dMRyH+3Y3V42oMdoJQAoBxASv79hNoz6uiX84SWhHuWw/ynWpCQimirJ4NEpeC2/CZuDsK7+SVZkAD1zM7txqVl5pOmLuwHuJ0SSyxymlvcUaL0LTqPbo4aQuyx+E2CrmJXWTrDn7afyKFAEd 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 Acked-by: Kees Cook Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/asm/mmu.h | 5 +++++ arch/um/include/asm/ptrace-generic.h | 6 ++++++ arch/x86/um/asm/elf.h | 8 ++++++-- fs/Kconfig.binfmt | 2 +- 4 files changed, 18 insertions(+), 3 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..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/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