From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E73ACC433B4 for ; Tue, 18 May 2021 09:11:03 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 781E160720 for ; Tue, 18 May 2021 09:11:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 781E160720 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hoiGvWGygri88bbq5Srv8uicO73niflml9NYO0ZxMHQ=; b=Dj93XJjJKgXq7281SITulAItA ffKe/MZNCbfAqn/OhtC9mf65mCoeH4arWpLKN5rSTZjJwlom9oDifCBpo09vR+MnEPr0imm4Q/eZg b7TktKVuRq1Mgam+pcW4MQX9Bja52mxOLf0nDFlKa2/4g4+X6Ij27deAZGV3/6jEfRz6mWTiHsyIg WqJnt8n8gbHv/pTty3hbRDSZvF98npKACMIWiO1fnHsMJK4uUh6PCFKWlPfuYkVic6dKhhfA7f9Y2 44JzJ5G21aR0+ZVLdQtJAhLSbw8BdxijAiKYxyjhNPJC3Lsnr4RUY6fcdr6/bvZyNUjWsV3Gxb8eF RCsO4J0uA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1livjF-0003P9-5C; Tue, 18 May 2021 09:09:30 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1livh7-0002bG-7C for linux-arm-kernel@desiato.infradead.org; Tue, 18 May 2021 09:07:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=W8HlNSywnIkavL/zIcpgi9C3SQjg+1ILx19xA07tItE=; b=yR6wxZFUdBin7p/dF0uchrQhiL MTo1RidmQjW9NL75Ac05L0/fpJ3YC8AxJDitPgIQanJG+Xbg0wkAj+mnT5RAf5LoPC96RaCoY8+K3 Zfqaw4GVXNkOW67kNlFS02DYgK3S53yspU4RxIUDGyCE3l+1N4PzG1L31IDkvLICe6hnDudMbtTrJ 0GLiQJjAU0cVfYVS4l3K7BTQBSONTX8a3hNOcoHrNJu5z5mfdYMmBsQiONWyuPbcMQ4ezluL6XHRt hAbhZjqRaTUKLAg1tpoUjGqsASC6odyqwCchOL+3lS4LnoOa/fT2uIPv9H15BRctEs3JL7jpCSQ52 5i2IZRsg==; Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1livh4-00EUWZ-8a for linux-arm-kernel@lists.infradead.org; Tue, 18 May 2021 09:07:15 +0000 Received: by mail-wr1-x42e.google.com with SMTP id v12so9329759wrq.6 for ; Tue, 18 May 2021 02:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W8HlNSywnIkavL/zIcpgi9C3SQjg+1ILx19xA07tItE=; b=Z6UuQJQJE8OzmnolFvAI66wj3VrgTvPdkPJlOmuWUhdHBCBObKZ0uCsL3fBc806Zb4 aT9EVjUe40ZY9D9bcEGL9WsiqYV7rjA6CaeRMi9C1yPCcEmzajr7rg37Te6upfx1STvn n0I74VwTfl+XPuwhnt6rt6TxlpSzNwPBJsHr83YcDGGi/UC951zihbkjNAWqLvcKai6j B+tGBRU/oNg+scxB3Yy3y9SOf9uI9HOjtuhiENwIXl2MCadHNRmRPppw70K2TUGI4Yc0 i0twL0zZCdNMAAEEHtLzIub4po047H69a5zDtNa9p3o8n4f7FEhxoj6bcmSFD/OhSQ5/ zo8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W8HlNSywnIkavL/zIcpgi9C3SQjg+1ILx19xA07tItE=; b=oWzj5ke1676BXfO4Va0Vm3lN01GM9+ewg0NzERn2dz/T4JsINV0kj4BV6PEouJ+F2s Myy2lM4TdIj/GqO82uiTtgW5b7khhTfrBc3IEjSxhEveJVTwenb5AD2cXfzoKkuU3dWt m43vd0o0RRweX8YR/yHvDKqVIebuAdLG+g8rn/1pf1nFkB0WY43o5tZ3ZbJhaaeNbY/e +gvDLREsS2DOIO/GDY6+uvpDl2bnNx00aAusRNCZOrXEAUs3CrbexdQxEP/ASrLKm4Xe 2ADkicG/n3nkTCwnEAry5exNyWTaFHAViCNsW8Nix3j4kp9nteYH84mDpYB7UlYZ8MaH mjHw== X-Gm-Message-State: AOAM532sAyBimrip7SqfAAyhkTxBQaBS5IYU7nkDlwDNQ0PdsuPOB+wf NbFvpbolFAVRvezrzEWXy1w= X-Google-Smtp-Source: ABdhPJx1UUqfv4BHIZswYgXTZX54aJ1DIP+CKgReBYH0NJNL1Y41RH5slNA4+TWC7X2yXZIiWOTgIA== X-Received: by 2002:a5d:448b:: with SMTP id j11mr5420767wrq.93.1621328833162; Tue, 18 May 2021 02:07:13 -0700 (PDT) Received: from amanieu-laptop.home ([2a00:23c6:f081:f801:91cf:b949:c46c:f5a9]) by smtp.gmail.com with ESMTPSA id z17sm7520306wrt.81.2021.05.18.02.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 02:07:12 -0700 (PDT) From: Amanieu d'Antras To: Cc: Amanieu d'Antras , Ryan Houdek , Catalin Marinas , Will Deacon , Mark Rutland , Steven Price , Arnd Bergmann , David Laight , Mark Brown , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH v4 8/8] arm64: Allow 64-bit tasks to invoke compat syscalls Date: Tue, 18 May 2021 10:06:58 +0100 Message-Id: <20210518090658.9519-9-amanieu@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210518090658.9519-1-amanieu@gmail.com> References: <20210518090658.9519-1-amanieu@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_020714_325648_76CD5CF4 X-CRM114-Status: GOOD ( 23.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Setting bit 31 in x8 when performing a syscall will do the following: - The remainder of x8 is treated as a compat syscall number and is used to index the compat syscall table. - in_compat_syscall will return true for the duration of the syscall. - VM allocations performed by the syscall will be located in the lower 4G of the address space. - Interrupted syscalls are properly restarted as compat syscalls. - Seccomp will treats the syscall as having AUDIT_ARCH_ARM instead of AUDIT_ARCH_AARCH64. This affects the arch value seen by seccomp filters and reported by SIGSYS. - PTRACE_GET_SYSCALL_INFO also treats the syscall as having AUDIT_ARCH_ARM. Recent versions of strace will correctly report the system call name and parameters when an AArch64 task mixes 32-bit and 64-bit syscalls. Previously, setting bit 31 of the syscall number would always cause the sygscall to return ENOSYS. This allows user programs to reliably detect kernel support for compat syscall by trying a simple syscall such as getpid. The AArch32-private compat syscalls (__ARM_NR_compat_*) are not exposed through this interface. These syscalls do not make sense in the context of an AArch64 task. Signed-off-by: Amanieu d'Antras Co-developed-by: Ryan Houdek Signed-off-by: Ryan Houdek --- arch/arm64/include/uapi/asm/unistd.h | 2 ++ arch/arm64/kernel/signal.c | 5 +++++ arch/arm64/kernel/syscall.c | 21 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/uapi/asm/unistd.h b/arch/arm64/include/uapi/asm/unistd.h index f83a70e07df8..5574bc6ab0a3 100644 --- a/arch/arm64/include/uapi/asm/unistd.h +++ b/arch/arm64/include/uapi/asm/unistd.h @@ -15,6 +15,8 @@ * along with this program. If not, see . */ +#define __ARM64_COMPAT_SYSCALL_BIT 0x80000000 + #define __ARCH_WANT_RENAMEAT #define __ARCH_WANT_NEW_STAT #define __ARCH_WANT_SET_GET_RLIMIT diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 6237486ff6bb..463c8a82050e 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -795,6 +795,11 @@ static void setup_restart_syscall(struct pt_regs *regs) { if (is_compat_task()) compat_setup_restart_syscall(regs); +#ifdef COMPAT + else if (in_compat_syscall()) + regs->regs[8] = __ARM64_COMPAT_SYSCALL_BIT | + __NR_compat_restart_syscall; +#endif else regs->regs[8] = __NR_restart_syscall; } diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c index e0e9d54de0a2..83747cf4b5b7 100644 --- a/arch/arm64/kernel/syscall.c +++ b/arch/arm64/kernel/syscall.c @@ -118,6 +118,11 @@ static void el0_svc_common(struct pt_regs *regs, int scno, int sc_nr, * user-issued syscall(-1). However, requesting a skip and not * setting the return value is unlikely to do anything sensible * anyway. + * + * This edge case goes away with CONFIG_COMPAT since a + * user-issued syscall(-1) is interpreted as a + * compat_syscall(0x7fffffff) which still ends up returning + * -ENOSYS in x0. */ if (scno == NO_SYSCALL) regs->regs[0] = -ENOSYS; @@ -165,7 +170,21 @@ static inline void sve_user_discard(void) void do_el0_svc(struct pt_regs *regs) { sve_user_discard(); - el0_svc_common(regs, regs->regs[8], __NR_syscalls, sys_call_table); + +#ifdef CONFIG_COMPAT + /* + * Setting bit 31 of x8 allows a 64-bit processe to perform compat + * syscalls. + */ + if (regs->regs[8] & __ARM64_COMPAT_SYSCALL_BIT) { + current_thread_info()->use_compat_syscall = true; + el0_svc_common(regs, + regs->regs[8] & ~__ARM64_COMPAT_SYSCALL_BIT, + __NR_compat_syscalls, compat_sys_call_table); + current_thread_info()->use_compat_syscall = false; + } else +#endif + el0_svc_common(regs, regs->regs[8], __NR_syscalls, sys_call_table); } #ifdef CONFIG_COMPAT -- 2.31.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel