From patchwork Mon Nov 11 06:27:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hajime Tazaki X-Patchwork-Id: 13870271 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 BF3E1D12D77 for ; Mon, 11 Nov 2024 06:27:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 201536B007B; Mon, 11 Nov 2024 01:27:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B12D6B0083; Mon, 11 Nov 2024 01:27:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 078EB6B0085; Mon, 11 Nov 2024 01:27:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DE67A6B007B for ; Mon, 11 Nov 2024 01:27:42 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5C2E61416FA for ; Mon, 11 Nov 2024 06:27:42 +0000 (UTC) X-FDA: 82772831862.21.B10ECFB Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf18.hostedemail.com (Postfix) with ESMTP id 96C5B1C000C for ; Mon, 11 Nov 2024 06:27:22 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kbpDtUPM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of thehajime@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=thehajime@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731306398; a=rsa-sha256; cv=none; b=DWn1n0+dC1FdMap26bYaEBudo5NN85lXyu3R9SgCpyOi2FYzDhX+CKEAPbM5tz4rDeZg3I qDJMg7sYFeQf7VAXQ4mEwYoiBZziDpcmDDKQbEVOvnxHJ1j/YhOQVboogpQGDNZaIGZX1e zZIURAAGRuP1lqe03QAMZZi0+z37vrc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kbpDtUPM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf18.hostedemail.com: domain of thehajime@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=thehajime@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731306398; 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=6rxsmZtwDE9hveMIBPCsasEv3gNTZZ8QeBClxURXh1g=; b=GYPmj67gtcgl3jb8hXdNTln0VT0ejjgaKMVgdEG6dCrpEBNUFE0fLKkZUGa8T9LLWRXx4s JVb39k+S0aEkhHutSVpoJSmAqWdW1NpJzH+UNVHTFwqO1fkV9+X6oCkw6LkCIU+SDEMo3Z XTy368B/mr/ZLwzIhqDZTxB4i/jBzKY= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20c693b68f5so42070585ad.1 for ; Sun, 10 Nov 2024 22:27:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731306459; x=1731911259; 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=6rxsmZtwDE9hveMIBPCsasEv3gNTZZ8QeBClxURXh1g=; b=kbpDtUPM2QhM+OGvK48mdOocdsgrX6F9vHLDqO2XsPtZJvanP0+DhxT5aZUBMSK7Gq bVkf8lpPy7iaj1zC+ei7xRZeC6leSRoFaxokGDo7uR/fYpjsh5VaSJG/9I9UK1TQVbQj SvvGzAHhN5pAhXPcwEZA2mmbHKGwPXEaKuZnYey7TimIio1ZF467oFZ5lfde910mY6j2 hJ0WJXW9i7Ml0lYt1EL+pXfkoUFkGM5qR7jWz/bTnugd3ZNPfaefOOYEIprXaHJtzaJR MsSmMz9EcU+mnenF43bn8CLRKzV5Jgx2v8XbAr4n6as+HCqMAkJwLAIyS1OoUSokty+m n5mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731306459; x=1731911259; 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=ABwxtlCthzMqFGsvRSC8nfAbPQ3IvONOgg6yuB6RTqnDRZ/ljXavwGIwXhzStrcn8s QGjl9yCbYFOYGjZ5X120TBi6mb/pmO3LXpWcSlwhAnIzbuhd2HMwYCHvlWjst5fhyjNo tInDAJiJhJrSf/C7b4Mzt79P4higjIy0Pv0v5HumlMn9agRVEzHF+5Oz08oeYhjoa8Jh 1wGPQlWIGX/OC21V1F5crTocTSE5pogt3ZYtU3Q0krtyJoBA8mAq/OKc2X627g08eUDe LnjlANANh/p6vvNVQ6kxTUGNIobs/lMcEpHovPDpWdAzMLI92pEoPNaIBrz8fkx0R9Xh tT6A== X-Forwarded-Encrypted: i=1; AJvYcCUFSngIN3t6pw1taKMf6WDYazimnvckJEE4GcvsdloYB22Tar30jTh0mPQ1JZ01uYOgjT7+7n3Vvg==@kvack.org X-Gm-Message-State: AOJu0YwyGg2OumG0WljFsEbs2g7JdxDEiF7j6d0rnyOOiQ67l5h9Ifci 321EqmuyEz0dh2cMKd7Nz5iH6TsdjNBHBe4fdf25Vi6P2CNf80LM X-Google-Smtp-Source: AGHT+IHwpmnY7dnXQcsSzHRDD73tGXzcdssS5VVzqSGyOahZ7QhXBU0+7Fxo/FbpiQKc5P/v4ljTRA== X-Received: by 2002:a17:903:245:b0:20b:5645:d860 with SMTP id d9443c01a7336-211835bf105mr168324925ad.36.1731306458982; Sun, 10 Nov 2024 22:27:38 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21177dc836bsm68741545ad.13.2024.11.10.22.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2024 22:27:38 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id E5712DBA914; Mon, 11 Nov 2024 15:27:36 +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: [RFC PATCH v2 01/13] fs: binfmt_elf_efpic: add architecture hook elf_arch_finalize_exec Date: Mon, 11 Nov 2024 15:27:01 +0900 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 96C5B1C000C X-Rspamd-Server: rspam01 X-Stat-Signature: djg55tffkx9rdykjjzu959ea7stua4pf X-HE-Tag: 1731306442-114259 X-HE-Meta: U2FsdGVkX1/HMA3cRMwaqcIucMlPAxA17jUOKVoJj1rf7BltMk1yVYAyRhBRiCIPJrAGrYYaMmPBeTA+2ZZvVmovjGhcl0r7L8z/lfrGxD/W2twJJX9cy9YUzGb2+VqoOmCq69GDMDcf7IF0bjwuVxTwjcUWLMC629R9U+sbLckB6wLp4fUPdYtgTRKNIhTYJD8lzMQFA2YZUQVGch7hEuSRkE1UC7Pt/sXI42U5OxXnhPAu1G9C8ZpcTWKZ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iBXmbXt7Gur5P2F1CntfxmJNQigCthenIWpwXLpwdafmMTEMJPQy3Js5rzBoJ5sv9hyEW2MddV4IQz28elH21BHaf993T+Jo+84RzRf6rlzD9XYufJ6/AFMNDx250GksZXQKQaRDCCEWTGp7bpkVkETl9kSs9SbZXr6Srli1X2IMokzbje87OhTnBDNmpzviXmG9KJ9dxh4dPKX/BCxgO2xFwTLawkD78HiTq0SGaFOhJYJL6FnmgPsYRS6Jkn6+1xpqPdHH6rpaSHVbYjkz0KOA9rO7K8ZSS269tCQ1tARfJHHW/13g== 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 ++++++++++ 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;