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: 13891701 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33D462BD1D for ; Tue, 3 Dec 2024 04:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733199808; cv=none; b=h0u+M4EeEjJkRunX9W07Hmu+uGl3OmGJPtj9n7rF0RsQlg+cVevOFC2MgP+3UzFZcKnZ/XG+km+TgyxSVKldB/cqZefnEekOMegoT7+X0LdltW1laS6bGOf4ryJEUX+wIKgA/rCm3/KaPuK26+xrbBbi9NmfAp/gy1JzA7ksnhE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733199808; c=relaxed/simple; bh=VnAijWycY27v/ZEoUwG9XDvgf4fiUkPZp0Ki0GmZ+Zw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QAtGiCoT2FbZiKlEywz7myExpDxZL0HAtOZWYw2MobLU7efSSglsY56rYT85SHWB1icCXEpEBaVd8Pepurs/zsUGiADYJWW2vjqOXzUfENlbnffHp8FqF4mDntqZ6prAwuseGUbrZsW19IZ+6TLUfleCrW3oVF8Lnw311+cxiOA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZWm7AiaZ; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZWm7AiaZ" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-724e6c53fe2so3760022b3a.3 for ; Mon, 02 Dec 2024 20:23:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733199805; x=1733804605; darn=vger.kernel.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=ZWm7AiaZEhNEH8TXea3xkGydRYXm4WIR0UMe0+SVwdsuSFdTzjJUEM9QQFRt96LlJ8 1wgs1Rua4S4I+g8Ih7ff5NAJl5w6GehCGKtgjTyh19CiTJTCSBzjrGXk1er3fV1Uq6gS 4YKe0LBGDlAoEOIb8Cmb2b3n+7CjOjcZTquhZ17uH4t2x7Go385BfS8gO2n4zoZxTQYP 4YTuqNIxuhi45qNWBlBpPChs9hhvTugbfwqnug+JB2W4/3Dkwwo2K0Xzxu7oesasbYir Eq6FoyusTMjdi4yObzoy6c0KlEE9ZiZQPWe0ThBM3mM7YOs4fFqgRbIV9ksTf+UWToVG qHqw== 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=VTxkeUpc36/NOrCVut9qMzSRcEN9tUjOIHyec65dMjchwx/eGm3YU0ckiXTsYPaxXJ 810weUC4aTEzHUM0gCRAU1Vkf2gCXIg0fltmBVq3t3WpbhnIQToyjMaGJ6fZopsm6JEI 9QmqSswfmQ3kRCx9MuKhbG49wg9H5Kkz7cuAFRKDx6b+/lLd4LBw899InXakphXkBKxJ EfWLgzYnjmcf3LA0Mc0QVCJn9fLtXd0VjlcGE9bwXK0v8ZUNFrOzAf7eU3biAC/p5+M7 zikS6YkgXrnCHhllnhBrjf+cjhNVbtccFI9cAiRESkdW1NgWw/elEMBZr9L74HO4eMFd Ewkg== X-Forwarded-Encrypted: i=1; AJvYcCURJZn1SmQLMsNEkxe3PzvhBZVY+QsWEt5DvRC0btKNSRL3Yc3RvNnPvSlmT8AQRVe5FKXbQ2J24zCLA0MV@vger.kernel.org X-Gm-Message-State: AOJu0Yw4u5/DSu6wVt2RivZ+/qdmxHIjaNjzGxwY2eMfGTNvFkE3IMpQ V+u7BOi/uqZdKpji+nZukfIsIEirnz5gDe0Iha+YYXqJvwdhEIRL X-Gm-Gg: ASbGncsnwoj5k+QDEfir9WZbsFiioWNH/YxR4ciHV2pYOjKdqj1dFJZEgyfTd+s0AFQ 2Cf65AIE7flwsm8Rns6ULiS98IU0tei3VE0VliwyIIlE1BSq7FVvVhvHts/rVPiQd2yXQqlxoPB mIytXiUWxwycdH2v6ALqfxTEmV0lUhekk8hhnNzGdAJo2Wrb9Z+ZOQv6AvaK7vDyRXNFfdxiXVv 6HoII+nb/pJck5AKSGdU822N8H+kXRZ0YvR/wBk5t7jMxrKWScngPtPcUh1FUklPz2Cg6liVmO6 ILuvr4Vw/KTLh3eV2tJl 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: Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 */