Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2395639pxk; Sat, 3 Oct 2020 20:27:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLCzPOgjDEo/PZ87TVNCn+7UsqXc8TaFJ+GSAFlaQ8gcfRiT8Cv9dw9OH+agexAzzVihGb X-Received: by 2002:a17:906:ae82:: with SMTP id md2mr8785890ejb.538.1601782073858; Sat, 03 Oct 2020 20:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601782073; cv=none; d=google.com; s=arc-20160816; b=f43VuLeqm+/RjAYROZHV6tyn1Zb6zGvEUSmIB1N74/cRa95NMgL0f4slfmW6lWexmQ JKEmMH5Hp3ngYAOrL+DzP6+bGgzU9GePkdgDeXSjE8VTz6aIHsW6HUWRjv7e5A0BXeZB N8RNdLlZWoeC5wHt1jZWqBMsqh8GVvk27k+Y21CuXVfUuzl2EYnA+J1HHpotJ+GDhdmz 4sz+A0kLtsGrG2NKKbAcxO1rQ1cqO9pKw5ZauP7njVfmrRoBJsA2WoeGk5wLXjGP6B9h WXT6p6jVjpWdMrb2v1dYzk/txs4oxOTIadlmDSAW3W7JipmIuOiV1X6QqRpYzcwMvYrL LLfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=a7gob8ca6Al2+iNt07rKikoOLh1XsTupllOm6uhz2y4=; b=Oii0JBdB8mJZdwsWXrOEl2zGMhgPJ6YgweC/ZIgdfbDkj6VkR6jBdxowYRJI324Td5 KAuT8zwGxqgZ0nMF4VCV/0maaKpUXBTYPZOopk3g4Jzq8vOhleZ5zQMwGhyJyTbwsEp8 7seYbIFOC9TIUM3HAgg+xBNZY5psvYNEs+4IqOoabHZsdhEa9dn9m1qOj5aHLpe//Wna bruxvQLanSG0I97BPHO3eOrMV96+QjLHno5phTSK/95fSKzTxGKohYQ/wGnma2+5sjCj 46rC5EkYUTzJQOEy2MirT6I4AOF6jTyn8OuY8Eq+7RP3EtLwfXPqzGK7xwzuQz+8Fd2n rruQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d8si4581797edj.569.2020.10.03.20.27.31; Sat, 03 Oct 2020 20:27:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726602AbgJDD0F (ORCPT + 99 others); Sat, 3 Oct 2020 23:26:05 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35082 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726226AbgJDD0E (ORCPT ); Sat, 3 Oct 2020 23:26:04 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 602EC29B004 From: Gabriel Krisman Bertazi To: luto@kernel.org, tglx@linutronix.de Cc: hch@lst.de, hpa@zytor.com, bp@alien8.de, rric@kernel.org, peterz@infradead.org, mingo@redhat.com, x86@kernel.org, linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com, sean.j.christopherson@intel.com, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v3 05/10] elf: Expose ELF header in compat_start_thread Date: Sat, 3 Oct 2020 23:25:31 -0400 Message-Id: <20201004032536.1229030-6-krisman@collabora.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201004032536.1229030-1-krisman@collabora.com> References: <20201004032536.1229030-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Like it is done for SET_PERSONALITY with x86, which requires the ELF header to select correct personality parameters, x86 requires the headers on compat_start_thread to choose starting CS for ELF32 binaries, instead of relying on the going-away TIF_IA32/X32 flags. This patch adds an indirection macro to ELF invocations of START_THREAD, that x86 can reimplement to receive the extra parameter just for ELF files. This requires no changes to other architectures who don't need the header information, they can continue to use the original start_thread for ELF and non-ELF binaries, and it prevents affecting non-ELF code paths for x86. Signed-off-by: Gabriel Krisman Bertazi --- fs/binfmt_elf.c | 2 +- fs/compat_binfmt_elf.c | 9 +++++++-- include/linux/elf.h | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 13d053982dd7..7fec77a38b8d 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1279,7 +1279,7 @@ static int load_elf_binary(struct linux_binprm *bprm) #endif finalize_exec(bprm); - start_thread(regs, elf_entry, bprm->p); + START_THREAD(elf_ex, regs, elf_entry, bprm->p); retval = 0; out: return retval; diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c index 2d24c765cbd7..12b991368f0a 100644 --- a/fs/compat_binfmt_elf.c +++ b/fs/compat_binfmt_elf.c @@ -106,8 +106,13 @@ #endif #ifdef compat_start_thread -#undef start_thread -#define start_thread compat_start_thread +#define COMPAT_START_THREAD(ex, regs, new_ip, new_sp) \ + compat_start_thread(regs, new_ip, new_sp) +#endif + +#ifdef COMPAT_START_THREAD +#undef START_THREAD +#define START_THREAD COMPAT_START_THREAD #endif #ifdef compat_arch_setup_additional_pages diff --git a/include/linux/elf.h b/include/linux/elf.h index 5d5b0321da0b..6dbcfe7a3fd7 100644 --- a/include/linux/elf.h +++ b/include/linux/elf.h @@ -22,6 +22,11 @@ SET_PERSONALITY(ex) #endif +#ifndef START_THREAD +#define START_THREAD(elf_ex, regs, elf_entry, start_stack) \ + start_thread(regs, elf_entry, start_stack) +#endif + #define ELF32_GNU_PROPERTY_ALIGN 4 #define ELF64_GNU_PROPERTY_ALIGN 8 -- 2.28.0