From patchwork Tue Dec 3 04:23:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 13891688 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 092A7E6C5F7 for ; Tue, 3 Dec 2024 04:23:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66E326B0085; Mon, 2 Dec 2024 23:23:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 61DFF6B0088; Mon, 2 Dec 2024 23:23:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E56F6B0089; Mon, 2 Dec 2024 23:23:29 -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 2E8D06B0085 for ; Mon, 2 Dec 2024 23:23:29 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id AC487C05E8 for ; Tue, 3 Dec 2024 04:23:28 +0000 (UTC) X-FDA: 82852353318.22.9D642F9 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf09.hostedemail.com (Postfix) with ESMTP id 16092140003 for ; Tue, 3 Dec 2024 04:23:17 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=E8ClCaxI; spf=pass (imf09.hostedemail.com: domain of thehajime@gmail.com designates 209.85.210.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=1733199801; 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=JZLXAGKXJsQaUwHOfGxb1XieHVDcZBF9xpfXO7H06r4=; b=Lmq8Ww+JTYfmjdNVz55mHKpk+OBWuqkD0WmxDSAVYGVqzdm9TayPwTwl1BKfg5VqjG1oVC 6JUCaJ3GSKec8p8z3UlHpiF4pJalGAG6e0yhFSZCZuOSohxcuJIT1inkmHEcxaDFTtsXWd rJlN9zvZs3PSkN5gNUKd6EwSJs9nRj8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733199801; a=rsa-sha256; cv=none; b=LMzAslekOBWwmcYTHE/wrfRmkgXrTUXLDms9BeQ68eLsj0Chms3c9SYY8iJlfm+swFO26Z K9s/6iawk4VHHZYq6byq0UiAqrkDRlSIx2IMV68rPn8dbckA/hdARLhmJgdEfaLQzD+Jys eKS5lrTfXA/X1SBUeRMdsTQ6UcsPHM0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=E8ClCaxI; spf=pass (imf09.hostedemail.com: domain of thehajime@gmail.com designates 209.85.210.176 as permitted sender) smtp.mailfrom=thehajime@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-724f383c5bfso3862393b3a.1 for ; Mon, 02 Dec 2024 20:23:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733199805; x=1733804605; 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=JZLXAGKXJsQaUwHOfGxb1XieHVDcZBF9xpfXO7H06r4=; b=E8ClCaxIAHr/S66wSfBgknMuquzpgJEqB0u9hvEzE5WwvKcczrZ8z2TtqzazLW+nWJ hiq7Adhwl8bnmUWaM60PSaAIgktAxLXNcLjYF9u0kJbfHa3BnZR4XcSqUei550MOHG9o WPH55u/QscsQ3U9G2QT7U0Hd2IAwF9+PHJH6w41txACic79plgYm3/lBMj3eDUYqdqbR 7KOVFVyNG12r6ylaBPWpuctJPBiwJxL34XIUMmVHG4+igro9u75aLraca+F0+CTMx7O6 IWaXBnU/QicfxU1mnRodt2R9r4fHGYLA/rooPoqlIbac3xHp3HagcFHBUqabNpiXTdJ0 C/yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733199805; x=1733804605; 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=JZLXAGKXJsQaUwHOfGxb1XieHVDcZBF9xpfXO7H06r4=; b=rC1ZVgkwHcj1hTx5i3b/m6yGCZZ/SaIQOLxnednlCuYepx/W5USdo0dLCKru3d1Q0b TQcc2wS4ldQndSO3BSnptZDLkFPkQWiREKKNzEjNqszXtF8CLb7HhPV4tRApahn1fnTi sYftFaAlplKjSNnwnqoCVfzDbwtWDjvc0YM7WIxk3FhvGiVj1iqJb4/PGOOY+GWoDVnT /H1wi0OPuM9ku50XoOEjSNgP+va5OAIggXbjQgnFAK7lP+zBG7n5E2c88+kR2V12mpUE n2iWPIfUV9RPIVsYr2pAS3+AhlQzxNlGJ1h7j29mzHBTmTtcZCuYHafDc2ctek80Z4fn /cIQ== X-Forwarded-Encrypted: i=1; AJvYcCVcXeaHbNZpPksHFrupqTQpgZbgTSwiF/2lDnsEUQ1PmsxyFGGGMQLDPvU4QFAk039QvkhTlNvk1w==@kvack.org X-Gm-Message-State: AOJu0YzQQbmEtAf9kaeM+zbLGmed7fGoiytl42aVD5CEsEuhZfpXlbUV bEDMoL1FnRv/mss/icYB80gtlCSqIeSGmGPpHfF15diQX6IxYQf5m/qRTIVx X-Gm-Gg: ASbGnctqdqGsUwqVURmecdpj7U5z0lUWgKCHKE1i4Pb9Te86KAoOMKF8kuQ7O0H0beK Lmf+QlipkMAGVaijnLbmLnU46p9KbJNhBmQYpAhylkpXzAtdoHjsD+nCWaEjZcyt9PO5ljxv95j zQqhQGxjy4oV3H2t62Ssvm3yyn3MEHoNMW8IJErzDmoxnyZJ/uJVdeIM7dGslLdI5/eBA3wMrM0 d/K7QEFI+tWpjqBvTwiIJ0c4xYCpwK+9RZwJEim3uVhQTX2RmYoAGHo3utqlnMJTCvjZUam/bvg fAw00q3I7eOYTv2L2Wqc X-Google-Smtp-Source: AGHT+IEnZhvotlCjjz+IuKEwK7J+M5+ZOMsyE8W8PZJgKuTfhkpQKEsccmo0ddOI+80XWjCWIaLEfg== X-Received: by 2002:a05:6a00:a02:b0:71e:7174:3ae with SMTP id d2e1a72fcca58-7257fa7272dmr1565478b3a.11.1733199805137; Mon, 02 Dec 2024 20:23:25 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7254176121asm9369077b3a.39.2024.12.02.20.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 20:23:24 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id CFF0EDD39F9; Tue, 3 Dec 2024 13:23:22 +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: [PATCH v3 01/13] fs: binfmt_elf_efpic: add architecture hook elf_arch_finalize_exec Date: Tue, 3 Dec 2024 13:23:00 +0900 Message-ID: <564f58c6c893f8817b07cb192b254f760c256580.1733199769.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: M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CDahP+IDxhwBoxuELqFVh383gfZNtgYsoJdhzvH8r1DwlHa0o ucfDtfYZ KuChjnNKcV7tm5Y3xPNaYvbgJ5jRzxru5Sy072avqiD9KFk7Cu7fTEcQcxj10G5bSxgSQ6rjBbrtbYq1TmrJoEcxclpXFzF+TlXV5VuKzVMUAd21U437PDl17z2JI0eE+hl3LGgOSlZQ0o2njg6RvpEwP1kBxiI01F+khBssH7mmQotCLyxblTea7ck9rxab2CemXIaRPjMX8QqnMLX/qdeCsjgZr6s48phuYYYukTdYwGlYtEKBI9YoPIpHsXdaRjQywPkJk3CibH84maUzY/lDY3gP2GqpE8OPkLaqfliECYeDUblzCnkiWWfZOeDY8tNTpmDolS8Way1AtsUi58ciSRiuSX7uJCJ3t4XoVNyuNy7e659QkEIOqYLAFmD2raAoolXC7/hKgmrNJ7oecatZ/qRFI8c+seLuSngnx5N/9T+2oX9wpmlUz3HNgIENpmrAC6ZtR8YMUixNlS4yr7nudAC0Opd/KVg2yiExI5a2N7KrktddNOtMiJPM757TVwfrI6w82uluDa2J3kv/UUuTYgoEYAod9vX12DAU6BmZlV2LecdbsqQ64IHbacXLmenpmcqQZqIrG8wFXM/Gle3EdIEEzdTA9yRbCHsJHO56GcaiL3JWDSZWFXA== 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: 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 ++++++++++ include/linux/elf-fdpic.h | 3 +++ 2 files changed, 13 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; diff --git a/include/linux/elf-fdpic.h b/include/linux/elf-fdpic.h index e533f4513194..e7fd85a1d10f 100644 --- a/include/linux/elf-fdpic.h +++ b/include/linux/elf-fdpic.h @@ -56,4 +56,7 @@ extern void elf_fdpic_arch_lay_out_mm(struct elf_fdpic_params *exec_params, unsigned long *start_brk); #endif +extern int elf_arch_finalize_exec(struct elf_fdpic_params *exec_params, + struct elf_fdpic_params *interp_params); + #endif /* _LINUX_ELF_FDPIC_H */