From patchwork Wed Sep 14 01:26:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 12975449 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 11ABDC6FA86 for ; Wed, 14 Sep 2022 01:26:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B4C16B0071; Tue, 13 Sep 2022 21:26:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 963BF80008; Tue, 13 Sep 2022 21:26:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8047880007; Tue, 13 Sep 2022 21:26:28 -0400 (EDT) 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 71E7B6B0071 for ; Tue, 13 Sep 2022 21:26:28 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2D6F21C5AD4 for ; Wed, 14 Sep 2022 01:26:28 +0000 (UTC) X-FDA: 79908950856.25.9743218 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf17.hostedemail.com (Postfix) with ESMTP id DE27840095 for ; Wed, 14 Sep 2022 01:26:27 +0000 (UTC) Received: by mail-pf1-f182.google.com with SMTP id e68so13409860pfe.1 for ; Tue, 13 Sep 2022 18:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=oGFQWiD9fL+FNWNuvlZs6HygR4mXZaszrHMNFbJR28M=; b=Z9G+QLsfasWj+mAHLkqoHE7cyRvkZr7aPERz1zimh2bMLEqN6EGIVQfihP+zULoMn8 hmybiwRR5Xi4ouSU0e5fTvUObcxaDnSCy4uKdKer6dWvgUV1cph3eLihOt898zNZkHka CpNJOWFKyfGQeYtmb5NBjc0qxMfwD743gUUGxZRK2Vw1w+Hu5+140Lqy2yvJ8mdFjqKF kKUZNCkwTK/T8dfZe63eSmQIe+lNk5mtpXSYv2XHJ4r2fPCK4vkF2UXg7W2OpQ8gtchU NrOlFJhAB+ldli5jbiknat8yu6J//x8Tv9QvA8gPwVibXrOW1NpNdScpD1yjc8VPKkzo hcZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=oGFQWiD9fL+FNWNuvlZs6HygR4mXZaszrHMNFbJR28M=; b=116DGtMZUOZGS7gcXmNi9cfp5MPDtkkaba0326YCtWq81Cn7jfG0fFKMvozHz776xF vI7HmMHX51QHGbcAFNj73rbztil6910j1qx13a5vzjOXNQtXCnWWAmXSQmov0J+61TrH OjnSBJDGBhYc0nux/dVXjz9jjJD/NHtw777Z0XStWQda7Nkfb9puANoQbL0/0r5oXTg3 gcS063oS2upBxBCucQXfjJYZR6v7EigGfsWt4SsSA459oc4dxMxyCtIj0N/trQgJkMm8 UjPkrYqtzGhRmNbme7jn9TvTh4i7k/LsJh9yzrovoswQHanmgW2FdVgkOyX3QZmGWLYj 5pUw== X-Gm-Message-State: ACgBeo2h8k5UIgGQY+RygKw8xpVvOvkW0SabVPk6S3ZSiPmWHIvlYWWs aAEv/2MCA6yMyw1ZUSVRTDM= X-Google-Smtp-Source: AA6agR5Xd07MDO/3cCT8qLGefsCo0EhfpkYGDJ2VrdGeyIqE0XoMrJgDBFxXaHwG6EEgOkhIFi+eAA== X-Received: by 2002:a05:6a00:1f05:b0:540:6552:dfbf with SMTP id be5-20020a056a001f0500b005406552dfbfmr29551303pfb.65.1663118786757; Tue, 13 Sep 2022 18:26:26 -0700 (PDT) Received: from octofox.metropolis (c-24-130-93-68.hsd1.ca.comcast.net. [24.130.93.68]) by smtp.gmail.com with ESMTPSA id x1-20020aa79a41000000b00536b2483aedsm6873603pfj.199.2022.09.13.18.26.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 18:26:26 -0700 (PDT) From: Max Filippov To: linux-xtensa@linux-xtensa.org Cc: Chris Zankel , linux-kernel@vger.kernel.org, Eric Biederman , Kees Cook , Alexander Viro , linux-mm@kvack.org, Max Filippov Subject: [PATCH] xtensa: add FDPIC and static PIE support for noMMU Date: Tue, 13 Sep 2022 18:26:10 -0700 Message-Id: <20220914012610.2734108-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Z9G+QLsf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of jcmvbkbc@gmail.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=jcmvbkbc@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663118787; a=rsa-sha256; cv=none; b=Ytacuw8D7JNuiwj2Kh8YQ/1Sd0xQlShC4HbN5JGOfbiOwBK9+mnA5HN/yqgiz0D2JPHx4p bD5s7YBNIwcbou7G+thR9BrKeBUuLMlfTgujw5u/V9HJjHfSo6CrMRKcBE5/WQLw9DIEAl 8zmXM/jOUehOEmujwccKOGP/WShmXu0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663118787; 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:references:dkim-signature; bh=oGFQWiD9fL+FNWNuvlZs6HygR4mXZaszrHMNFbJR28M=; b=z1NB8QYeorlEiR9Q64hnZYzOPvMZ0nzjDdbK8kwEooXFYCowiTaKAQSnvIK0ZpGJ27Qy5z bsvFKlxolzAxICVdglDDz0kdiOqDFIopakIvfuuNGqb6R5imVEL6YB1+BgJvEkdC3oEUZu A1Vg+11pf9YGNK2tuu0sBQeT9oixc6M= X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Z9G+QLsf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of jcmvbkbc@gmail.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=jcmvbkbc@gmail.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: DE27840095 X-Stat-Signature: m14hcnuqzokic5t1f1pmndbfqdst8s6e X-HE-Tag: 1663118787-735830 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: Define ELFOSABI_XTENSA_FDPIC and Use is as an OSABI tag in the ELF header to distinguish FDPIC ELF files from regular ELF files. Define ELF_FDPIC_PLAT_INIT and put executable map, interpreter map and executable dynamic section addresses into registers a4..a6. Update start_thread macro to preserve register values in the current register window. Add definitions for PTRACE_GETFDPIC, PTRACE_GETFDPIC_EXEC and PTRACE_GETFDPIC_INTERP. Signed-off-by: Max Filippov --- arch/xtensa/include/asm/elf.h | 11 +++++++++++ arch/xtensa/include/asm/processor.h | 3 +++ arch/xtensa/include/uapi/asm/ptrace.h | 4 ++++ fs/Kconfig.binfmt | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/xtensa/include/asm/elf.h b/arch/xtensa/include/asm/elf.h index 9c21897c6992..ffcf1ada19c6 100644 --- a/arch/xtensa/include/asm/elf.h +++ b/arch/xtensa/include/asm/elf.h @@ -93,6 +93,10 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG]; #define elf_check_arch(x) ( ( (x)->e_machine == EM_XTENSA ) || \ ( (x)->e_machine == EM_XTENSA_OLD ) ) +#define ELFOSABI_XTENSA_FDPIC 65 +#define elf_check_fdpic(x) ((x)->e_ident[EI_OSABI] == ELFOSABI_XTENSA_FDPIC) +#define ELF_FDPIC_CORE_EFLAGS 0 + /* * These are used to set parameters in the core dumps. */ @@ -164,6 +168,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG]; (_r)->areg[14] = 0; (_r)->areg[15] = 0; \ } while (0) +#define ELF_FDPIC_PLAT_INIT(_r, _exec_map_addr, _interp_map_addr, dynamic_addr) \ + do { \ + (_r)->areg[4] = _exec_map_addr; \ + (_r)->areg[5] = _interp_map_addr; \ + (_r)->areg[6] = dynamic_addr; \ + } while (0) + typedef struct { xtregs_opt_t opt; xtregs_user_t user; diff --git a/arch/xtensa/include/asm/processor.h b/arch/xtensa/include/asm/processor.h index 76bc63127c66..b75ba16ec080 100644 --- a/arch/xtensa/include/asm/processor.h +++ b/arch/xtensa/include/asm/processor.h @@ -205,9 +205,12 @@ struct thread_struct { #define start_thread(regs, new_pc, new_sp) \ do { \ unsigned long syscall = (regs)->syscall; \ + unsigned long current_aregs[16]; \ + memcpy(current_aregs, (regs)->areg, sizeof(current_aregs)); \ memset((regs), 0, sizeof(*(regs))); \ (regs)->pc = (new_pc); \ (regs)->ps = USER_PS_VALUE; \ + memcpy((regs)->areg, current_aregs, sizeof(current_aregs)); \ (regs)->areg[1] = (new_sp); \ (regs)->areg[0] = 0; \ (regs)->wmask = 1; \ diff --git a/arch/xtensa/include/uapi/asm/ptrace.h b/arch/xtensa/include/uapi/asm/ptrace.h index 50db3e0a6341..9115e86ebc75 100644 --- a/arch/xtensa/include/uapi/asm/ptrace.h +++ b/arch/xtensa/include/uapi/asm/ptrace.h @@ -37,6 +37,10 @@ #define PTRACE_SETXTREGS 19 #define PTRACE_GETHBPREGS 20 #define PTRACE_SETHBPREGS 21 +#define PTRACE_GETFDPIC 22 + +#define PTRACE_GETFDPIC_EXEC 0 +#define PTRACE_GETFDPIC_INTERP 1 #ifndef __ASSEMBLY__ diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt index 21e154516bf2..9d131a54226f 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) && !MMU) + depends on ARM || ((M68K || SUPERH || XTENSA) && !MMU) select ELFCORE help ELF FDPIC binaries are based on ELF, but allow the individual load