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,URIBL_BLOCKED, 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 55CE5C433B4 for ; Fri, 30 Apr 2021 20:44: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 D3EE061449 for ; Fri, 30 Apr 2021 20:44:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3EE061449 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=rJGLzsvP/dT6TdVJ9JZttfnd9 GrsEKJp1k17z0VogPBFOnXf7dQ2GiSj46V8CVLDMmEhdGnqSppG6rayhTzbwlx+mKe/S+wSe5qVm8 ITe6Wr7gFzR2duKmtmKlmX7NnJKshUMSLqzK4XDC9EYyLj4XKMqYtewp5MUtX2BOvGxSISOdBUQqq V+7IeoMae33ypn8o/kKqhBysYGyvr/XuaxgiSYlgWN0J+YwkQoQ0Xz1gbcMRNWOM39NYLz4hhV6jG YmfQJMG9AGlhQVR3w9UJABONRZx6hMOG0W5COjHKKCNoXt6DAAJLphoSZKXKCDZOBTtMKjgHY/fa3 70BeGcptw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lcZx5-008YpU-Ti; Fri, 30 Apr 2021 20:41:32 +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 1lcZu5-008YFo-DR for linux-arm-kernel@desiato.infradead.org; Fri, 30 Apr 2021 20:38:25 +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=bRdP1ZOwjSqPNWV7gDQOV8yEHU H9lROuQpGMOs2sxfXETzpKdX8BXJyHcsTixJwRh8ys/9a5BqgYD9/I9jbC1Dt3eNkss/Xqg9DlqTu fi5oAvGtFaA171JVDJo0PhwgfcIdTCQKwfKsBt0SijB3LpLkHs6P5KT5ppw/P8KK1hF9cx2f7f7cL QWvrkW+itA4Bg2un4DmxIRgWfwwomiKVB73a9Lm4HemAmble3mB2QYqnjjleVCdr6oQfCArIaye4I vlwS0+5VuSKeuBT3nnmZPwQ4w3w05nWKUB+oT+ZAhvbz03BvxDTYkAUbyqxmrcuXeuIdqz8h/HQfg zG39BKLw==; Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lcZu2-001elS-Bp for linux-arm-kernel@lists.infradead.org; Fri, 30 Apr 2021 20:38:24 +0000 Received: by mail-wr1-x433.google.com with SMTP id v12so141611wrq.6 for ; Fri, 30 Apr 2021 13:38:19 -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=Tnwq+5UxdRYkBVHdXf/QrQ9s4F6nnVtKUKD2NYkttreUp9iUecEx1AKt/DzsxjodxD X0lMEOhpA5f9h1KEPQ0NaUxS3WDq6Yb58ovj5y0OKHlqmw7xYsXu95tD66XtCVPpxhL1 zp2/hBkjR0a1b7KlJKVvnN9vd5t8T24iNbF/cg7CQGMQsxAZCxs26nkElLFObpMcridR YJXB7X2j91NwAdja7B0bIQTjCesZaSS3wQNP7tYu7iSzcYAuDNjMEFUdiDx0Yx76kwdK H6xh3IbtNg4prfokDfTgXw/h3I/ufVI2kaQm9kZbi6arBc/dj8gkNH+uOCo/5+rQBsV/ Gf2Q== 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=PJk70alPC4O5z8BpdGQEdyzooRWj2rraOpoTtzkKPkktBrHxXY0ZCGIF/5g/t5TKA8 FywVYZl8LB4QfEf4NCLrMYsB9ERcoQ867N3TzuRZt8dvg40InBZMgg6d6dC5oifi5rad FpM3X1ZJcwDhnkI6BK8vj8uRLif15Gha3fqwcct61AmaWue6XGDBa/wicMKooW4cgw20 WVEY96QKgV3esniocXcU6+eTaK2gni6j8diU52lvRgLEo4WZECA37BqxPUNd70UOVE14 aVInT2WdHXePX/YlsrPDgZ2tjI20LJTzffz26pBYBjWYoqIL8pTIhV9kqQQQsWV+aW4g A4PA== X-Gm-Message-State: AOAM53275lUOlm/isDdoO77jLW+pA7DgzshaXMfpSDdkhKK/pTngnsDM OFLFZM+h3Rmbs1aW+M12KJI= X-Google-Smtp-Source: ABdhPJwkHUBHZjxsMejlk4q2z3yroJTh21vFO8NECQS2otHtdv4mPUmcoMfoHgrOhcxtXwFgXF+8jQ== X-Received: by 2002:adf:ffcc:: with SMTP id x12mr9722457wrs.162.1619815098163; Fri, 30 Apr 2021 13:38:18 -0700 (PDT) Received: from amanieu-desktop.home ([2a00:23c6:f081:f801:93ef:94e:9f8:1f0]) by smtp.gmail.com with ESMTPSA id r5sm4384239wmh.23.2021.04.30.13.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Apr 2021 13:38:17 -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: [PATCH v4 8/8] arm64: Allow 64-bit tasks to invoke compat syscalls Date: Fri, 30 Apr 2021 21:37:57 +0100 Message-Id: <20210430203757.47653-7-amanieu@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210430202810.44092-1-amanieu@gmail.com> References: <20210430202810.44092-1-amanieu@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210430_133822_425521_B3EDA9AC X-CRM114-Status: GOOD ( 22.97 ) 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