From patchwork Tue Feb 28 13:51:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Ungerer X-Patchwork-Id: 13154927 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 E26BAC64EC7 for ; Tue, 28 Feb 2023 13:52:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7212B6B007B; Tue, 28 Feb 2023 08:52:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D27B6B007D; Tue, 28 Feb 2023 08:52:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C1276B007E; Tue, 28 Feb 2023 08:52:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4E84D6B007B for ; Tue, 28 Feb 2023 08:52:44 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 25E56120862 for ; Tue, 28 Feb 2023 13:52:44 +0000 (UTC) X-FDA: 80516841048.26.3F0C6C3 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf06.hostedemail.com (Postfix) with ESMTP id 5A19C18000F for ; Tue, 28 Feb 2023 13:52:42 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UIA1PW7z; spf=pass (imf06.hostedemail.com: domain of gerg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gerg@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677592362; a=rsa-sha256; cv=none; b=Xec7vBhMP9NDagsmLnS5Z7DufSKbu+6W4ixh4Ty1PlJm52am8+8uCqAGSEeelc0ohY5NdD WJnLyshTcXHxrTtxkb1VOGQ2+qa2276QHDpx7IjgdNLqxQTHWUq8zk5Oe8DNySmhIZzd0C Ibe11VQqZZvc3BHb4Hm6dFY0qqexbRA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UIA1PW7z; spf=pass (imf06.hostedemail.com: domain of gerg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gerg@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677592362; 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=lxtdlK/TlN3uVcOlzgqqiP6ii8i6sDaYmfglqMoXzvw=; b=iMQiS85MJCZxT1FgiF2HXxdv7j5YVvGnst63t2Gl1vmKN321/vOvzE8lZO37DXrr8kRlVD VZs3BzFYR4b9UVwE/P6Fl99R95EGPXK3Btb4fsBhbHcJ9uYjBBW6l6T7pPQNXiY1D1yHVr VhMRERGJK1F72z99XdgsxsFQ/KYJLSU= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7DC3961009; Tue, 28 Feb 2023 13:52:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9511C433EF; Tue, 28 Feb 2023 13:52:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677592360; bh=38kfVv0+EiOAjlOlOCBBSeSgUje7psw6l+cniGuf0lg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UIA1PW7zhKYyXR1Mph54j3KqknZw1aX5tyz7WWquTK6eYzWytS0HsjV1piSPdY99U Pg/yjx3Mvo22nVan2dpvlFtcrpk3xae9/lKjQyWvcWatWOV8b+2/Vb1qSn2zCpbTok fIL39dMC3Sv+RF6yINq+hqmN6iJSnuYYc7Obh+Ug4Y8OOjKiKWZa8x5IEubzMm/Gzk CYUCjpoK5QQbzWo3CTSwq5NpjPT3DIezt0T++0T8bO2lfOIWSQEGKsicIrxqyC0Tkt vNo6V+8TdrJoEGUtI4QQZKtPc62KrJZMEgCCgHdSfyfPedo0o88SbAlo0LzaVcs/T2 wRDKxRp3AWj9A== From: Greg Ungerer To: linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Greg Ungerer Subject: [PATCH 1/2] binfmt_elf_fdpic: support 64-bit systems Date: Tue, 28 Feb 2023 23:51:25 +1000 Message-Id: <20230228135126.1686427-2-gerg@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230228135126.1686427-1-gerg@kernel.org> References: <20230228135126.1686427-1-gerg@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 5A19C18000F X-Rspamd-Server: rspam01 X-Stat-Signature: dip9x4p8c1qy5i8ekuy4npwco14x6saj X-HE-Tag: 1677592362-101564 X-HE-Meta: U2FsdGVkX19R3Kc4u8l40sZgAARO59XgE3ywzYwTJ9ks9VS6zlj9LGv4jlo7OPR0+trW+lEi/6sGEqnpW8MXCc0e4KkjGaD/jxoX1j5JWxFpBEtpexR2sMAUlmlTAx1YsN6+ntjjjnIF0YIJyRmb5KUDecdxvf/1Wfs+2vLwUpv0dP3kyASieyOZ9s7Y2OfSXhMUEb3ZdL4jBpcYESpkuZyfvK+ilknwPeVe7iuAGSMXPeVEWJ4oGVKp6GSLmR0fiI5BHdRW8iuuzqPWaBL/71zLwJa4kJ3cr6ORcPRFEhggnoAfBVuMhiXYEPT6dPbkczjA8nxBTmmEFQMkf64Sd1LpzoxqSTJoJhcPQI1rH47RtwNpi92STjwZcloIm2OL5nuENh84fmWrjFs6bVcfKWHpw3WzQIj6PE5dmUZLtYOA4Y+gCVuvorMOBdfvpkvZlmQwXMHD/5kwFd7DwMeefkVNIfOK0V+rp7ubBQjuwDSybb2sbypEMkCl+Yt9AJCy3zQKy56m8rY/Zj2VYRoiAocNacjtmsnISW4AoLFF+CQpddf9pKMYjx9Vc7eH/7ZhudtYDKbF6E+IDF3AhhAv4sJLv1eSb9y/bhE3SHz8HjguQ4Dq8863MS10R4EoR6w9k/8I0xlw4Uaxt5u5CpDzoALb7cj+EGfFqQ/NrbV9PGQ7sQnd4S7y/j31htVPQXYRyqhfCfgNmZA+Ejc3xOSOPBhientruyOmHYBSLIOxbbmy1CMht9eEae4R1Il2JdHKrcuxVvirgZRbzspKT6hWxkgoO4Hg/fdwCJf/OavhnnQEeXod2+JwRtfNlywAYndb6LFkQMxlKFfLpIsLkP0mC5XMEBMePbt382L81/AxRlvn3kYRIprktENMqkkjRV5YmhNRZeUOrcmG8OXRRtctyqaFnd754lPUsq44tj6+Kx77EK7TACxpg/BeLDsIrXdjh8jRy71CoR4FHvEm5lN vROsxxwK LnNzP7ceJoxWksPY1RWkgz/F7NSDoa2H+SjwbitWHrLwkaCx2y+xrW9tFJ3R0RTL5O6exui7HN49OiUdxepThJFgbpQyL6Y2/jw2DXTTeXuKv18UcMQTzvokoqo0Tke3uGVpu0Z8LyJiB4DLuT2VISctsiVHGQhu8SyXy7FfL+ZulHDnP4QHYNd6KHojNLli4iqjaX52xCyFPkHSUNJ9BgQ1gV6t5U2t53VR0EIPb+fcvP519+uQYqDXFXc5dAlMmBIvNpmhfAryaif4Z78ja/8prDXI1XbEwhWQjTw7M5yDrruubjpq7khO5zSnqXyrJ0TJnBFb7QkFZu+C1peMFvDS885yfaXz4PRhC9PNzlUnKdewNT5Yo0kitJkJKtQqtTLNQBXVKYX373y6WbEoUL2/x9A== 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: The binfmt_flat_fdpic code has a number of 32-bit specific data structures associated with it. Extend it to be able to support and be used on 64-bit systems as well. The new code defines a number of key 64-bit variants of the core elf-fdpic data structures - along side the existing 32-bit sized ones. A common set of generic named structures are defined to be either the 32-bit or 64-bit ones as required at compile time. This is a similar technique to that used in the ELF binfmt loader. For example: elf_fdpic_loadseg is either elf32_fdpic_loadseg or elf64_fdpic_loadseg elf_fdpic_loadmap is either elf32_fdpic_loadmap or elf64_fdpic_loadmap the choice based on ELFCLASS32 or ELFCLASS64. Signed-off-by: Greg Ungerer Acked-by: Palmer Dabbelt --- fs/binfmt_elf_fdpic.c | 38 +++++++++++++++++----------------- include/linux/elf-fdpic.h | 14 ++++++++++++- include/uapi/linux/elf-fdpic.h | 15 ++++++++++++++ 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index a05eafcacfb27..2eea6dd429fd6 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -138,7 +138,7 @@ static int is_constdisp(struct elfhdr *hdr) static int elf_fdpic_fetch_phdrs(struct elf_fdpic_params *params, struct file *file) { - struct elf32_phdr *phdr; + struct elf_phdr *phdr; unsigned long size; int retval, loop; loff_t pos = params->hdr.e_phoff; @@ -560,8 +560,8 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm, sp &= ~7UL; /* stack the load map(s) */ - len = sizeof(struct elf32_fdpic_loadmap); - len += sizeof(struct elf32_fdpic_loadseg) * exec_params->loadmap->nsegs; + len = sizeof(struct elf_fdpic_loadmap); + len += sizeof(struct elf_fdpic_loadseg) * exec_params->loadmap->nsegs; sp = (sp - len) & ~7UL; exec_params->map_addr = sp; @@ -571,8 +571,8 @@ static int create_elf_fdpic_tables(struct linux_binprm *bprm, current->mm->context.exec_fdpic_loadmap = (unsigned long) sp; if (interp_params->loadmap) { - len = sizeof(struct elf32_fdpic_loadmap); - len += sizeof(struct elf32_fdpic_loadseg) * + len = sizeof(struct elf_fdpic_loadmap); + len += sizeof(struct elf_fdpic_loadseg) * interp_params->loadmap->nsegs; sp = (sp - len) & ~7UL; interp_params->map_addr = sp; @@ -740,12 +740,12 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, struct mm_struct *mm, const char *what) { - struct elf32_fdpic_loadmap *loadmap; + struct elf_fdpic_loadmap *loadmap; #ifdef CONFIG_MMU - struct elf32_fdpic_loadseg *mseg; + struct elf_fdpic_loadseg *mseg; #endif - struct elf32_fdpic_loadseg *seg; - struct elf32_phdr *phdr; + struct elf_fdpic_loadseg *seg; + struct elf_phdr *phdr; unsigned long load_addr, stop; unsigned nloads, tmp; size_t size; @@ -767,7 +767,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, params->loadmap = loadmap; - loadmap->version = ELF32_FDPIC_LOADMAP_VERSION; + loadmap->version = ELF_FDPIC_LOADMAP_VERSION; loadmap->nsegs = nloads; load_addr = params->load_addr; @@ -843,8 +843,8 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, if (phdr->p_vaddr >= seg->p_vaddr && phdr->p_vaddr + phdr->p_memsz <= seg->p_vaddr + seg->p_memsz) { - Elf32_Dyn __user *dyn; - Elf32_Sword d_tag; + Elf_Dyn __user *dyn; + Elf_Sword d_tag; params->dynamic_addr = (phdr->p_vaddr - seg->p_vaddr) + @@ -854,11 +854,11 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, * one item, and that the last item is a NULL * entry */ if (phdr->p_memsz == 0 || - phdr->p_memsz % sizeof(Elf32_Dyn) != 0) + phdr->p_memsz % sizeof(Elf_Dyn) != 0) goto dynamic_error; - tmp = phdr->p_memsz / sizeof(Elf32_Dyn); - dyn = (Elf32_Dyn __user *)params->dynamic_addr; + tmp = phdr->p_memsz / sizeof(Elf_Dyn); + dyn = (Elf_Dyn __user *)params->dynamic_addr; if (get_user(d_tag, &dyn[tmp - 1].d_tag) || d_tag != 0) goto dynamic_error; @@ -927,8 +927,8 @@ static int elf_fdpic_map_file_constdisp_on_uclinux( struct file *file, struct mm_struct *mm) { - struct elf32_fdpic_loadseg *seg; - struct elf32_phdr *phdr; + struct elf_fdpic_loadseg *seg; + struct elf_phdr *phdr; unsigned long load_addr, base = ULONG_MAX, top = 0, maddr = 0; int loop, ret; @@ -1011,8 +1011,8 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, struct file *file, struct mm_struct *mm) { - struct elf32_fdpic_loadseg *seg; - struct elf32_phdr *phdr; + struct elf_fdpic_loadseg *seg; + struct elf_phdr *phdr; unsigned long load_addr, delta_vaddr; int loop, dvset; diff --git a/include/linux/elf-fdpic.h b/include/linux/elf-fdpic.h index 3bea95a1af537..e533f45131945 100644 --- a/include/linux/elf-fdpic.h +++ b/include/linux/elf-fdpic.h @@ -10,13 +10,25 @@ #include +#if ELF_CLASS == ELFCLASS32 +#define Elf_Sword Elf32_Sword +#define elf_fdpic_loadseg elf32_fdpic_loadseg +#define elf_fdpic_loadmap elf32_fdpic_loadmap +#define ELF_FDPIC_LOADMAP_VERSION ELF32_FDPIC_LOADMAP_VERSION +#else +#define Elf_Sword Elf64_Sxword +#define elf_fdpic_loadmap elf64_fdpic_loadmap +#define elf_fdpic_loadseg elf64_fdpic_loadseg +#define ELF_FDPIC_LOADMAP_VERSION ELF64_FDPIC_LOADMAP_VERSION +#endif + /* * binfmt binary parameters structure */ struct elf_fdpic_params { struct elfhdr hdr; /* ref copy of ELF header */ struct elf_phdr *phdrs; /* ref copy of PT_PHDR table */ - struct elf32_fdpic_loadmap *loadmap; /* loadmap to be passed to userspace */ + struct elf_fdpic_loadmap *loadmap; /* loadmap to be passed to userspace */ unsigned long elfhdr_addr; /* mapped ELF header user address */ unsigned long ph_addr; /* mapped PT_PHDR user address */ unsigned long map_addr; /* mapped loadmap user address */ diff --git a/include/uapi/linux/elf-fdpic.h b/include/uapi/linux/elf-fdpic.h index 4fcc6cfebe185..ec23f08711292 100644 --- a/include/uapi/linux/elf-fdpic.h +++ b/include/uapi/linux/elf-fdpic.h @@ -32,4 +32,19 @@ struct elf32_fdpic_loadmap { #define ELF32_FDPIC_LOADMAP_VERSION 0x0000 +/* segment mappings for ELF FDPIC libraries/executables/interpreters */ +struct elf64_fdpic_loadseg { + Elf64_Addr addr; /* core address to which mapped */ + Elf64_Addr p_vaddr; /* VMA recorded in file */ + Elf64_Word p_memsz; /* allocation size recorded in file */ +}; + +struct elf64_fdpic_loadmap { + Elf64_Half version; /* version of these structures, just in case... */ + Elf64_Half nsegs; /* number of segments */ + struct elf64_fdpic_loadseg segs[]; +}; + +#define ELF64_FDPIC_LOADMAP_VERSION 0x0000 + #endif /* _UAPI_LINUX_ELF_FDPIC_H */ From patchwork Tue Feb 28 13:51:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Ungerer X-Patchwork-Id: 13154928 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 13AD8C7EE2E for ; Tue, 28 Feb 2023 13:52:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E4746B007D; Tue, 28 Feb 2023 08:52:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 794FD6B007E; Tue, 28 Feb 2023 08:52:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65CA06B0080; Tue, 28 Feb 2023 08:52:53 -0500 (EST) 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 571346B007D for ; Tue, 28 Feb 2023 08:52:53 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2F57D140A6C for ; Tue, 28 Feb 2023 13:52:53 +0000 (UTC) X-FDA: 80516841426.16.5DAA689 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf05.hostedemail.com (Postfix) with ESMTP id 79A8910001F for ; Tue, 28 Feb 2023 13:52:51 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Boyhyv71; spf=pass (imf05.hostedemail.com: domain of gerg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gerg@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677592371; 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=aymF10duhQpdus2CaW1oS/BAnGBD6aVgFR8p+Bv6IxE=; b=NK+fpZR8tDl0oaMvfqAhdgvfLiQi/XlOGdDl70HqcGD5DfFnQgokkl/LZJt2xlZcgT1ZMi YkyE67t/N8sE79J226v9fyxgBwulKT9tgCgU6uEyEoIrAmai1kzV6iOLqRIWIwdK3N13nn BFvPbkL293KQrs50i+gvKuj56khwkEQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Boyhyv71; spf=pass (imf05.hostedemail.com: domain of gerg@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=gerg@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677592371; a=rsa-sha256; cv=none; b=CiiWtRqCnlp4x5xSWdad+MqhfS6lvElNTtKQhgXUf2MF1fH3eMPeqBEx1kEbMhwagaHyu6 cI5ygYBXOtt85V+7cD0D0tCgsubc+nAc95emFYsNjoljB5TNbAhamt3lbaCX6NKNOlC/hx 8HdOuo7XtEaN6JP36Auukj6d9N/1bo8= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A0EA061059; Tue, 28 Feb 2023 13:52:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3263C4339B; Tue, 28 Feb 2023 13:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1677592370; bh=sUmjqdECpzhBzLfzvtQfNGKN7mDNJWpISMfwa2tW33U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Boyhyv71FzWm40DrM+Drdf72LjQFrF8AHpWmkg5DOe9wjg6w+XJdL/M9yJ/fIvYrH Po6NftZvGdme/ZlecbcNrBfx0klhFEcwZ06OJYzJNppwaap9/rEj+KA4n+KD78eCnp d9KS8dGiWMkM/WGE9yO5CyrQH+H9VzPXuDzFzb18BC0C8Xpf8nZ2+hZeJ1zSIkmIqS 99Owj8rS1vjZJn/XGaZgAebaYTR61DeKsel6vXO7AWDquYQ1DyZHjeDgsr31tVo94b lbTB2jyn2+RCN9nQb5kJ0YvmIhyVsil9h1mKkzoQroWo8WLvjGItnNlLFRHXiuPd+m fVjKuCUH/UF7Q== From: Greg Ungerer To: linux-riscv@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Greg Ungerer Subject: [PATCH 2/2] riscv: support the elf-fdpic binfmt loader Date: Tue, 28 Feb 2023 23:51:26 +1000 Message-Id: <20230228135126.1686427-3-gerg@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230228135126.1686427-1-gerg@kernel.org> References: <20230228135126.1686427-1-gerg@kernel.org> MIME-Version: 1.0 X-Stat-Signature: e4fben1g5ypci3cj84ib7ge9ydgb1w8k X-Rspam-User: X-Rspamd-Queue-Id: 79A8910001F X-Rspamd-Server: rspam06 X-HE-Tag: 1677592371-891048 X-HE-Meta: U2FsdGVkX1/iDuq/M0nmyw79IrwQmgZ+NwqU8PF1gijcvnWNHTE5tQu/rZ36+8+6TH8aJjZiqK+eQhMNdSQ+Tn52ZWkJRdTONu/LTze8uQd37LSJi671vMaGWsjJGxVjdArrFQS3HIp4/Y7IKAJPhF+APFmYdGBaycmEATWnAa9LvWf19HnlYsd/loZYJkhhZmMUSvUufr1HgFhu5911HcqnSU2aJsS/qROfzZwkbBXywgkYevnlPQhtve2jDhkSG1FAHv3Fsv/owQceUpy2ipVkUuOM13e1zjlw/fuBcmkrFqpSKQWtedSC4NXIjZijhVmTw4Y5KcUk8Of3GL0XWKus0S0Jyac9krZJNDiwDlvbTazdXm8gjYOhbaK3ZNFHD0Tvde7qEBVWWWuANfyd7cABdgaVah0q+YSeTSc05u/p88x5zszmshIU+pGvDQBocUbJO3eJXuuMhrIbpmIM2MctMLQH7rZ4z82UZIWhVMg2EBQHUEa2/D4Y3KOG+JVOwDpUjLFFrhnxefzKVieimhdoHnR/ZAv3KSjkc/OKq3MVVLiDBwUNHcxjBpnygFeMZFBd7Uib+a/6lo2fg9xTr2uCgMIlqhVOme/8Jtt+ZxDrwoAV1zn47928eFW3sn76Z8OBuwAFQh4oAuzwmhS6m18OGi2OiOmQrkDvTAlT9rQ7M/itU4FbXeUzmqSLwZGUWsZrBst1GkMdIAvv2MlElBx+BXIyCWH4gKYT9QT5Mh8YFKI6UrFwz2mF4WulcvZrjQtQWbL5liCHyGUgWeIFJuZwibW5EPPBS4/MSqao1sjLWsieXVNDPEDx67qf9tIDZ3VUfq3/aElLkilaxYtOGeTNTCZHlbaIKEpK5Mpzf0VtqSxPLnOftEAB9WECuv8kcXrTLPJLM0e8GhOjeetJf35mPdR3oxRFjFtOxh6Df7M2ItV22Rr6ftRjLdz4gWutL+p9c52FycJy0ATFcx5 wzB4/amY OFGtcz455x14UqXV9P7kTwC6DpjRGrcF5/wn61lk7sBoYahOkug4zJeeeCwXXYvdIrWcE6vefNL+5Ec+RqRwSVEsnkQTg5KB4VCyhbODFGh9UnfHYc01gIPuWBv2AitVXtp7taFd/a3ny7fbay0Jc9mUhrdb8QEBIZt2RYNqLTC+T7bl6QcrId8JVnC6rUEYUgakbm1m5v8bmCEIm+qFxmJA1z5Wn0ducc/CV/gctAmQvKzYt/KaKH+WbB3VmYdDjImAxS3hhMqzUcKusnIMySBy91n8fPoTCnuyFYcvy1G30iJrz1rF389PcwOiWeZ05MDnnEEUb9coTe53mfTjpr6D8joV33z+AhaCd 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: Add support for enabling and using the binfmt_elf_fdpic program loader on RISC-V platorms. The most important change is to setup registers during program load to pass the mapping addresses to the new process. One of the interresting features of the elf-fdpic loader is that it also allows appropriately compiled ELF format binaries to be loaded on nommu systems. Appropriate being those compiled with -pie. Signed-off-by: Greg Ungerer --- arch/riscv/include/asm/elf.h | 11 ++++++++++- arch/riscv/include/asm/mmu.h | 4 ++++ arch/riscv/include/uapi/asm/ptrace.h | 5 +++++ fs/Kconfig.binfmt | 2 +- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h index e7acffdf21d26..95747b35d3262 100644 --- a/arch/riscv/include/asm/elf.h +++ b/arch/riscv/include/asm/elf.h @@ -40,6 +40,7 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); #define compat_elf_check_arch compat_elf_check_arch #define CORE_DUMP_USE_REGSET +#define ELF_FDPIC_CORE_EFLAGS 0 #define ELF_EXEC_PAGESIZE (PAGE_SIZE) /* @@ -67,6 +68,13 @@ extern bool compat_elf_check_arch(Elf32_Ehdr *hdr); #define ELF_HWCAP (elf_hwcap) extern unsigned long elf_hwcap; +#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \ + do { \ + (_r)->a1 = _exec_map_addr; \ + (_r)->a2 = _interp_map_addr; \ + (_r)->a3 = dynamic_addr; \ + } while (0) + /* * This yields a string that ld.so will use to load implementation * specific libraries for optimization. This is more specific in @@ -76,7 +84,6 @@ extern unsigned long elf_hwcap; #define COMPAT_ELF_PLATFORM (NULL) -#ifdef CONFIG_MMU #define ARCH_DLINFO \ do { \ /* \ @@ -104,6 +111,8 @@ do { \ NEW_AUX_ENT(AT_L3_CACHEGEOMETRY, \ get_cache_geometry(3, CACHE_TYPE_UNIFIED)); \ } while (0) + +#ifdef CONFIG_MMU #define ARCH_HAS_SETUP_ADDITIONAL_PAGES struct linux_binprm; extern int arch_setup_additional_pages(struct linux_binprm *bprm, diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h index 5ff1f19fd45c2..af3fc3fb4d1ad 100644 --- a/arch/riscv/include/asm/mmu.h +++ b/arch/riscv/include/asm/mmu.h @@ -22,6 +22,10 @@ typedef struct { /* A local tlb flush is needed before user execution can resume. */ cpumask_t tlb_stale_mask; #endif +#ifdef CONFIG_BINFMT_ELF_FDPIC + unsigned long exec_fdpic_loadmap; + unsigned long interp_fdpic_loadmap; +#endif } mm_context_t; void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, diff --git a/arch/riscv/include/uapi/asm/ptrace.h b/arch/riscv/include/uapi/asm/ptrace.h index 882547f6bd5c9..93a690509b133 100644 --- a/arch/riscv/include/uapi/asm/ptrace.h +++ b/arch/riscv/include/uapi/asm/ptrace.h @@ -10,6 +10,11 @@ #include +#define PTRACE_GETFDPIC 31 + +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 + /* * User-mode register state for core dumps, ptrace, sigcontext * diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index 93539aac0e5b2..f5693164ca9a3 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 || SUPERH || XTENSA) && !MMU) + depends on ARM || ((M68K || RISCV || SUPERH || XTENSA) && !MMU) select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual load