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 */ From patchwork Tue Dec 3 04:23: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: 13891689 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 0A733E6C5FB for ; Tue, 3 Dec 2024 04:23:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E4756B0089; Mon, 2 Dec 2024 23:23:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 693236B008A; Mon, 2 Dec 2024 23:23:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 533D56B008C; Mon, 2 Dec 2024 23:23:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 36C8D6B0089 for ; Mon, 2 Dec 2024 23:23:34 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B88101A0608 for ; Tue, 3 Dec 2024 04:23:33 +0000 (UTC) X-FDA: 82852353654.16.D3B53DA Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by imf21.hostedemail.com (Postfix) with ESMTP id 8A4261C0002 for ; Tue, 3 Dec 2024 04:23:07 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UX71rN2c; spf=pass (imf21.hostedemail.com: domain of thehajime@gmail.com designates 209.85.215.182 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=1733199803; 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=jMDksIbcOLWGwD0vO5eo1YOj8LatyWo9RypORfUk9j4=; b=Jsgdzc5+1jdGI++EoXxfYLKSJLV90jQ5sW8sEYRoZRCM7xDrYTRi3anVZEvbiubc4LuUYN QUeQF1ckRpxEpj3rsFSXxnj4wsimT6eQmgjemPtEruxuzDLXWomhi3LK8eFTNI3TlDCvvi S7xH9Sl3hJCG5x5Y8RxDsr7y22ZVCt4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=UX71rN2c; spf=pass (imf21.hostedemail.com: domain of thehajime@gmail.com designates 209.85.215.182 as permitted sender) smtp.mailfrom=thehajime@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733199803; a=rsa-sha256; cv=none; b=Z6vjraNRk5WqNu4ClWyE/BKSw4JAazTx53Bbodihccn7951xCL6g5GOPve3zwDSM9d+qPQ DvKFEKQDMtX0JMEGNBZZyjDNpPIvJfse7YsnrqtbCS+xfr2nbpJ/O9prYrm1q70wXsR2Cs vnLKloN7FxJEjEDM61zeuqIacb9qG4Y= Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7f46d5d1ad5so3940840a12.3 for ; Mon, 02 Dec 2024 20:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733199810; x=1733804610; 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=jMDksIbcOLWGwD0vO5eo1YOj8LatyWo9RypORfUk9j4=; b=UX71rN2cp7skFEo0McRACN+ytAh7zWceGe+jR9D4a2qmRZe7wyVRKWZpa7iTNr6bta B7+6omAB2iI8Kiyyw1YEQtWRoyDY7pHhpga8iyrQD1RVoa67RB0jxxZmgyfquluVk8T6 ubDI3Jq9G2V+VWdz94uvi2k1+Kvp7d61bsyRWFyY9wOCsxshFqqzsLt9fYSJROcMtQ0p evF90rc8q2QNs3jK8Md8y0n2yphVNg1CwIClzRda+5xqDbRSf1pJt8+KiYPVF9vbr7ru mV62rquMgx3Y3PMB5aWiP+aLXHmnLPF3WiZccqt2zyOX5a5J7x2HYJQWtE3j5eDtL4H4 WtWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733199810; x=1733804610; 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=jMDksIbcOLWGwD0vO5eo1YOj8LatyWo9RypORfUk9j4=; b=masZMawlsYw05yAQLgGrw9444fqs2L/I2ks4hnO7lj6mMNZSzYrGP6/6pLLbBwXhBL mzui+rIs1NCU5QpBxUVH4BFHy1c3sACmYkIqrwPjI/43j4uZyhI405qR9e+Ah02WTYSE b0AmQNLNrQIkih9COgCvVkT6R1kuuwdw9euB967REhxiSkUmfmjEteAM4NaWcY8fu9lE tz3vhDIvzKVaarX64ghEFdC53o3o2tlUup/SRYm793mnhvvoo5bSQ182eME6udzWxIOP ehECBp6OpczN+tpjpMdSt0ZkyppTkvmTBnc8/uQvGYFE60k4+zrNbVPySwK8xn69qb1/ WZJg== X-Forwarded-Encrypted: i=1; AJvYcCW8pHQSSS1I0AqazqQ9E8wuOSanSu0S69AovKQHKn4ggGPZHPcwTXmVQcVNCyoccdqy9R18+ctVrA==@kvack.org X-Gm-Message-State: AOJu0YzkoylqnbgnzdNbZOzErKliEAfYMLdUi8wprokGkpL4jvOKyO3i tJikkaa4AR6MfuwBISBuafnTcenu2Javu8CfXgsR212lxIkPbCQu X-Gm-Gg: ASbGncvBvtzFB3HTUiKk5X3QCK415urGRqVBZcorocs3DIu6Y/INwWzX03x9RxhoGsG gP8cN4E5oYIV7o/DiHnn69FNqkp0uLru5bW8aWF3q7CggDnggcPi5+rznMIRQG+chDoaJbRL6Jg M3K1Lpkz3FEa2PeclaibEMt2/MK3I4zl4WQGfPcziRT4IGgysIfcq6keuZ7aGAfZVQ7pNkdpeLC DZOCU9m4JQVm867DB6rsuxXHJmxOAjEFNfpZ78lNsqlvtNUiX8cYwFr0gE+nizjYDQT827EoQQg pFheUO1gyKksNq6Wsclu X-Google-Smtp-Source: AGHT+IE8xdk48VpCN/lmNtJ4mSg7KBUaDEkPOtXNpXZN6KheBo7QC4wgFHpv7a0bXxkvqLx6Sq1RtQ== X-Received: by 2002:a05:6a20:3941:b0:1e0:d859:e1bd with SMTP id adf61e73a8af0-1e1653a7bb4mr1623878637.1.1733199810346; Mon, 02 Dec 2024 20:23:30 -0800 (PST) Received: from ikb-h07-29-noble.in.iijlab.net ([202.214.97.5]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72541848924sm9701523b3a.180.2024.12.02.20.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 20:23:29 -0800 (PST) Received: by ikb-h07-29-noble.in.iijlab.net (Postfix, from userid 1010) id 4E210DD39FB; Tue, 3 Dec 2024 13:23:27 +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 v3 02/13] x86/um: nommu: elf loader for fdpic Date: Tue, 3 Dec 2024 13:23:01 +0900 Message-ID: <215895272109f7b0a4a00625e86b57f39fa13af8.1733199769.git.thehajime@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Stat-Signature: 3jt1ypwt63fwiqaisga9aeug57ygigpc X-Rspamd-Queue-Id: 8A4261C0002 X-Rspam-User: X-HE-Tag: 1733199787-634822 X-HE-Meta: U2FsdGVkX19T5BWgzP5fLbIjDw6gUjQdKXXP8jnfHT66EYUSPLA9bqq1H4Kjq5WXXI7B1vrvn8RZSBdH+ZmntCJo+UtNO6loXutNVPIWFZvc9B7UwcUreaDak0YzfbEL6slkL3K6dC4rdK419hufz8hPbHKYCpO9PWEpPv8d7agvQJhB5rT3AqRt65f5Y7XWvfuafNPAgbst6gzrIMOOunjsM5xR6K0szClUK/l9VCvW2T/yyRnCRn47AoDbac0dZ1s1EaFsv3uB0mZVAtlMra9xIboVsigb5dX6DkxdGIdNRnhrdEAYzqRZSdwA0jQZ9n3xoUwavfdxoBAHXR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vlUvXdpTU6uHNMWk/FiazGKHVQ6A2KPE2aOjmHmSLbqaNKxOJT5XCW+xp9vfQ2tIFK4EWLTRayVGih/AsU59+zlPrZr9Vqth2xbvxcDTEU/spBrI+vsQW0I8R6hBB36s0fodUybcZgV9o4m6kHYyZNCzTOc6Q2oh3f++nu1nJg7 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 Signed-off-by: Hajime Tazaki Signed-off-by: Ricardo Koller --- arch/um/include/asm/Kbuild | 1 + arch/um/include/asm/mmu.h | 5 +++++ arch/um/include/asm/ptrace-generic.h | 6 ++++++ arch/x86/um/asm/elf.h | 8 ++++++-- arch/x86/um/asm/module.h | 24 ------------------------ fs/Kconfig.binfmt | 2 +- 6 files changed, 19 insertions(+), 27 deletions(-) delete mode 100644 arch/x86/um/asm/module.h diff --git a/arch/um/include/asm/Kbuild b/arch/um/include/asm/Kbuild index 428f2c5158c2..04ab3b653a48 100644 --- a/arch/um/include/asm/Kbuild +++ b/arch/um/include/asm/Kbuild @@ -13,6 +13,7 @@ generic-y += irq_work.h generic-y += kdebug.h generic-y += mcs_spinlock.h generic-y += mmiowb.h +generic-y += module.h generic-y += module.lds.h generic-y += param.h generic-y += parport.h 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/arch/x86/um/asm/module.h b/arch/x86/um/asm/module.h deleted file mode 100644 index a3b061d66082..000000000000 --- a/arch/x86/um/asm/module.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __UM_MODULE_H -#define __UM_MODULE_H - -/* UML is simple */ -struct mod_arch_specific -{ -}; - -#ifdef CONFIG_X86_32 - -#define Elf_Shdr Elf32_Shdr -#define Elf_Sym Elf32_Sym -#define Elf_Ehdr Elf32_Ehdr - -#else - -#define Elf_Shdr Elf64_Shdr -#define Elf_Sym Elf64_Sym -#define Elf_Ehdr Elf64_Ehdr - -#endif - -#endif 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