Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5599436imm; Tue, 26 Jun 2018 14:18:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI09mQubiQ2FYRPVPJExPzZE9PfnXiCE2vewa4GXAY5zNv63846MNTRNZbN0weQ+o0YCgJF X-Received: by 2002:a65:6616:: with SMTP id w22-v6mr2744260pgv.332.1530047919573; Tue, 26 Jun 2018 14:18:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530047919; cv=none; d=google.com; s=arc-20160816; b=Ot8E/qNG+lbTtq+pwSsrKqifCSrKLJrJwwf+YwZZEGOEdX3r5ckfnT7aigOk5AJOfb T+yvcwsxmGw5aRl+Sab/7zzpIjDlUVQddF7LWhU+lFhoOW2eV8YV8rau57zFKRp7Pqj4 3v6wqzrAhbLMXGnBBF2Om6oVWkbj9V8X3F72Ce+u5PfRwLjgIvuJ1UhOSFobmVmuXSDR +spqsVCk7O2IFOBuAk1H1XvvULwqan+s7vlTqXmq+8balHVD7iRyUNckDmIUPaAoQTPn zSQlVQ0DtM4TsbnSQxJz7wQJ9/Ytw6HUZHr2GE56gjpY68CYGbd3RESG6bmoLNNGHuV6 Ejog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=40zVm4fxxpUlNASy/ALDWkXeA72jWSKyt8DoN6qtPH0=; b=oCAkPuypCD5bdylAOpnp1MLhG1+YcfrMroN1M1gMZipOH/HVNd4e+nI96D+5ASJf++ TFWEc6XIn0Fse54mRruYd4sSocy76VnIBz12TDYy5kesh2ggcaHZw3fnVsXP68UYWmoP KJyufhlfid+gRa/RuphY8ZIYr+tPU+fYifbm1skdHO5UbwV7v7WhClxJuXokChnQlK4m 61Ol0y93G+m3g74y8tEZ/jkQkQD1N04D0TempKRgD3Rs8N1HO8PGfbUzuxt/ffhe6/Rb +Hc0TfxSzgnsHcztF+1xsCCrmsYRWBj0DCsLj9pYveAarD95O27+kBxXiCHw6HBNMlvV MupA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=Rgw3nowL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ay2-v6si2255850plb.266.2018.06.26.14.18.25; Tue, 26 Jun 2018 14:18:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=Rgw3nowL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752579AbeFZVQk (ORCPT + 99 others); Tue, 26 Jun 2018 17:16:40 -0400 Received: from mail.efficios.com ([167.114.142.138]:41000 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751894AbeFZVQh (ORCPT ); Tue, 26 Jun 2018 17:16:37 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 88AFA22DAE0; Tue, 26 Jun 2018 17:16:36 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id Ot20XGlPZCTu; Tue, 26 Jun 2018 17:16:35 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id BC91322DAD6; Tue, 26 Jun 2018 17:16:35 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com BC91322DAD6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1530047795; bh=40zVm4fxxpUlNASy/ALDWkXeA72jWSKyt8DoN6qtPH0=; h=From:To:Date:Message-Id; b=Rgw3nowLKm/1EfvY/ixQ2k2ZkY37ro7ikEPrNgr9M0VbyxbYOhGI9e6/zcjKMZUZ9 fRB8z6AMt49fwqoFGgjqbSu3jjW4oKqApZQEsO9pclS50t6s9eIvipvMz0/E4tvK9J quuWVTHtKRSUvFxL06rlvWuv8xZQP1UKGXoelYRi9nosnT2OnWlg1qlYfu9px6XlhS wLsA8pdmKaw7OsYQWVucm8JFjLuxO3i7nxMRSbTGX/ssQbvhXPQLLute0sTkiqtl5n HaDUQlIuETg4fPVwF5RgUKXu9A+MLhneNlTXfjfEnZ/UWKopzOHlhqsCTm+qpyRzXq 32lhgcba0QiLA== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id a1bL8rbmBZ2g; Tue, 26 Jun 2018 17:16:35 -0400 (EDT) Received: from thinkos.internal.efficios.com (192-222-157-41.qc.cable.ebox.net [192.222.157.41]) by mail.efficios.com (Postfix) with ESMTPSA id 54B2722DAD0; Tue, 26 Jun 2018 17:16:35 -0400 (EDT) From: Mathieu Desnoyers To: Andy Lutomirski , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Joel Fernandes , Peter Zijlstra , Catalin Marinas , Dave Watson , Will Deacon , Andi Kleen , "H . Peter Anvin" , Chris Lameter , Russell King , Andrew Hunter , Michael Kerrisk , "Paul E . McKenney" , Paul Turner , Boqun Feng , Josh Triplett , Steven Rostedt , Ben Maurer , linux-api@vger.kernel.org, linux-arch@vger.kernel.org, x86@kernel.org, Andrew Morton , Linus Torvalds Subject: [RFC PATCH for 4.18 1/2] compat: Introduce is_compat_frame Date: Tue, 26 Jun 2018 17:16:16 -0400 Message-Id: <20180626211617.8933-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org x86 is moving from is_compat_task() to in_compat_syscall(). However, in_compat_syscall cannot be used to check whether a signal is being delivered on a compat task. Introduce is_compat_frame to allow performing this check from architecture agnostic code. On all architectures except x86, it invokes is_compat_task(). On x86, it uses is_ia32_frame() and is_x32_frame() to check whether the signal frame is 32-bit. This is needed by restartable sequences to detect whether it needs to clear the top bits of the start_ip, abort_ip, and post_commit_offset rseq_cs fields on signal delivery, thus ensuring identical behavior for a 32-bit binary executed on 32-bit and 64-bit kernels. Signed-off-by: Mathieu Desnoyers Cc: Thomas Gleixner Cc: Joel Fernandes Cc: Peter Zijlstra Cc: Catalin Marinas Cc: Dave Watson Cc: Will Deacon Cc: Andi Kleen Cc: "H . Peter Anvin" Cc: Chris Lameter Cc: Russell King Cc: Andrew Hunter Cc: Michael Kerrisk Cc: "Paul E . McKenney" Cc: Paul Turner Cc: Boqun Feng Cc: Josh Triplett Cc: Steven Rostedt Cc: Ben Maurer Cc: linux-api@vger.kernel.org Cc: linux-arch@vger.kernel.org Cc: x86@kernel.org Cc: Andy Lutomirski Cc: Andrew Morton Cc: Linus Torvalds --- arch/x86/include/asm/compat.h | 24 ++++++++++++++++++++++++ arch/x86/kernel/signal.c | 17 ----------------- include/linux/compat.h | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h index fb97cf7c4137..1405a8df5215 100644 --- a/arch/x86/include/asm/compat.h +++ b/arch/x86/include/asm/compat.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -242,4 +243,27 @@ struct compat_siginfo; int __copy_siginfo_to_user32(struct compat_siginfo __user *to, const siginfo_t *from, bool x32_ABI); +static inline int is_ia32_compat_frame(struct ksignal *ksig) +{ + return IS_ENABLED(CONFIG_IA32_EMULATION) && + ksig->ka.sa.sa_flags & SA_IA32_ABI; +} + +static inline int is_ia32_frame(struct ksignal *ksig) +{ + return IS_ENABLED(CONFIG_X86_32) || is_ia32_compat_frame(ksig); +} + +static inline int is_x32_frame(struct ksignal *ksig) +{ + return IS_ENABLED(CONFIG_X86_X32_ABI) && + ksig->ka.sa.sa_flags & SA_X32_ABI; +} + +static inline bool is_compat_frame(struct ksignal *ksig) +{ + return is_ia32_frame(ksig) || is_x32_frame(ksig); +} +#define is_compat_frame is_compat_frame /* override the generic impl */ + #endif /* _ASM_X86_COMPAT_H */ diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c index 92a3b312a53c..cb488e3e952d 100644 --- a/arch/x86/kernel/signal.c +++ b/arch/x86/kernel/signal.c @@ -664,23 +664,6 @@ SYSCALL_DEFINE0(rt_sigreturn) return 0; } -static inline int is_ia32_compat_frame(struct ksignal *ksig) -{ - return IS_ENABLED(CONFIG_IA32_EMULATION) && - ksig->ka.sa.sa_flags & SA_IA32_ABI; -} - -static inline int is_ia32_frame(struct ksignal *ksig) -{ - return IS_ENABLED(CONFIG_X86_32) || is_ia32_compat_frame(ksig); -} - -static inline int is_x32_frame(struct ksignal *ksig) -{ - return IS_ENABLED(CONFIG_X86_X32_ABI) && - ksig->ka.sa.sa_flags & SA_X32_ABI; -} - static int setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs) { diff --git a/include/linux/compat.h b/include/linux/compat.h index b1a5562b3215..2e1ffba65117 100644 --- a/include/linux/compat.h +++ b/include/linux/compat.h @@ -1022,6 +1022,19 @@ static inline struct compat_timeval ns_to_compat_timeval(s64 nsec) return ctv; } +/* + * For most but not all architectures, "is this a compat sigframe?" and + * "am I a compat task?" are the same question. For architectures on which + * they aren't the same question, arch code can override is_compat_frame. + */ + +#ifndef is_compat_frame +static inline bool is_compat_frame(struct ksignal *ksig) +{ + return is_compat_task(); +} +#endif + #else /* !CONFIG_COMPAT */ #define is_compat_task() (0) @@ -1029,6 +1042,10 @@ static inline struct compat_timeval ns_to_compat_timeval(s64 nsec) static inline bool in_compat_syscall(void) { return false; } #endif +#ifndef is_compat_frame +static inline bool is_compat_frame(struct ksignal *ksig) { return false; } +#endif + #endif /* CONFIG_COMPAT */ #endif /* _LINUX_COMPAT_H */ -- 2.11.0