Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1635939pxb; Fri, 13 Nov 2020 19:32:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLESxTcDP1wU9/3DPiXNGkS+H19kuvh5eHD9RQ2LJaWeeG5IDoxKAdSH4r49nHrd8AJXY2 X-Received: by 2002:aa7:d9c2:: with SMTP id v2mr5665606eds.95.1605324768862; Fri, 13 Nov 2020 19:32:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605324768; cv=none; d=google.com; s=arc-20160816; b=smBlUf09Gu93A0XuUaU4TTRmouT+Mqf6B5YG4b5nF82LJ6NP/kHFHfBEvHRWm/1OaL Ieh/900yZH9cBoV8Ff7rvUApHvqw10lPSQ2d+zNYk0W/niphMpbLL249ApHvsTRndcol 52dTxmrrrSQDagys1JbOjtGAyVmCVnce4I7HASCj0GcsLWtWiOkVeSHn/gxdWy14z7Ch VxAkkom2v+16WPtl3HSBraDMsEe8ACgCo/yqu0+t6jKIvn8rSBhtvULTbmpIYZI2mVQ/ ZFiT02z1bJKk1dXHsFSsgWYFaSs0K/o6YnjPnX6xFDWKDn+IKB8AAoIfAOkT4pJS6cco FjNA== 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=qWjGpL1cxXYqDB2sF4NUBqS5IexvLo/ZkGgJhP4ilEI=; b=Kr/kDyFvEAam4kULobYB0K8Es2aEhn23zJKoI+9nvuHkCojFXvIFIQ5sUku3V7fGOM GHfIqc90jqKr72dhCs+FrvUOOoXKxWY2TigGck2U3k2md4t9NesVMKjeyj3aGX0jYo8F 1UFFSr/mfVblx+sqwhaQj4X+BKoIIBzxr0yTjAKuNnhlVbQt7NxZav+03lu5WaNvxYk7 YJ5ffzzUo/JxpXUBq4IAlAeRk38YrTPQJJ5zzhXbMNTPV449byoy6w1ShKlgZcx5U0Sr 1VKOGX8D0S1pzLMJ9KNq5JZYFivBIB9ItbX1H36+Umty2AcyEBuD7s3UBn/dCnG6aimS ZHbQ== 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 ar8si7431055ejc.496.2020.11.13.19.32.26; Fri, 13 Nov 2020 19:32:48 -0800 (PST) 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 S1726469AbgKND3y (ORCPT + 99 others); Fri, 13 Nov 2020 22:29:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725981AbgKND3x (ORCPT ); Fri, 13 Nov 2020 22:29:53 -0500 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFD84C0613D1; Fri, 13 Nov 2020 19:29:53 -0800 (PST) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 885131F47988 From: Gabriel Krisman Bertazi To: tglx@linutronix.de Cc: mingo@redhat.com, keescook@chromium.org, arnd@arndb.de, luto@amacapital.net, wad@chromium.org, rostedt@goodmis.org, paul@paul-moore.com, eparis@redhat.com, oleg@redhat.com, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH 04/10] seccomp: Migrate to use SYSCALL_WORK flag Date: Fri, 13 Nov 2020 22:29:11 -0500 Message-Id: <20201114032917.1205658-5-krisman@collabora.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201114032917.1205658-1-krisman@collabora.com> References: <20201114032917.1205658-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When one the generic syscall entry code, use the syscall_work field in struct thread_info and specific SYSCALL_WORK flags to setup this syscall work. This flag has the advantage of being architecture independent. Users of the flag outside of the generic entry code should rely on the accessor macros, such that the flag is still correctly resolved for architectures that don't use the generic entry code and still rely on TIF flags for system call work. Signed-off-by: Gabriel Krisman Bertazi --- include/linux/entry-common.h | 8 ++------ include/linux/seccomp.h | 2 +- include/linux/thread_info.h | 6 ++++++ kernel/entry/common.c | 2 +- kernel/fork.c | 2 +- kernel/seccomp.c | 6 +++--- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/linux/entry-common.h b/include/linux/entry-common.h index cbc5c702ee4d..f3fc4457f63f 100644 --- a/include/linux/entry-common.h +++ b/include/linux/entry-common.h @@ -21,10 +21,6 @@ # define _TIF_SYSCALL_TRACEPOINT (0) #endif -#ifndef _TIF_SECCOMP -# define _TIF_SECCOMP (0) -#endif - #ifndef _TIF_SYSCALL_AUDIT # define _TIF_SYSCALL_AUDIT (0) #endif @@ -49,7 +45,7 @@ #endif #define SYSCALL_ENTER_WORK \ - (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \ + (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_EMU | \ ARCH_SYSCALL_ENTER_WORK) @@ -64,7 +60,7 @@ (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \ _TIF_SYSCALL_TRACEPOINT | ARCH_SYSCALL_EXIT_WORK) -#define SYSCALL_WORK_ENTER (0) +#define SYSCALL_WORK_ENTER (SYSCALL_WORK_SECCOMP) #define SYSCALL_WORK_EXIT (0) /* diff --git a/include/linux/seccomp.h b/include/linux/seccomp.h index 02aef2844c38..47763f3999f7 100644 --- a/include/linux/seccomp.h +++ b/include/linux/seccomp.h @@ -42,7 +42,7 @@ struct seccomp { extern int __secure_computing(const struct seccomp_data *sd); static inline int secure_computing(void) { - if (unlikely(test_thread_flag(TIF_SECCOMP))) + if (unlikely(test_syscall_work(SECCOMP))) return __secure_computing(NULL); return 0; } diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h index 18755373dc4d..fb53c24fc8a6 100644 --- a/include/linux/thread_info.h +++ b/include/linux/thread_info.h @@ -35,6 +35,12 @@ enum { GOOD_STACK, }; +enum syscall_work_bit { + SYSCALL_WORK_SECCOMP = 0, +}; + +#define _SYSCALL_WORK_SECCOMP BIT(SYSCALL_WORK_SECCOMP) + #include #ifdef __KERNEL__ diff --git a/kernel/entry/common.c b/kernel/entry/common.c index 5a4bb72ff28e..ef49786e5c5b 100644 --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -54,7 +54,7 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall, } /* Do seccomp after ptrace, to catch any tracer changes. */ - if (ti_work & _TIF_SECCOMP) { + if (work & _SYSCALL_WORK_SECCOMP) { ret = __secure_computing(NULL); if (ret == -1L) return ret; diff --git a/kernel/fork.c b/kernel/fork.c index 7199d359690c..4433c9c60100 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1625,7 +1625,7 @@ static void copy_seccomp(struct task_struct *p) * to manually enable the seccomp thread flag here. */ if (p->seccomp.mode != SECCOMP_MODE_DISABLED) - set_tsk_thread_flag(p, TIF_SECCOMP); + set_task_syscall_work(p, SECCOMP); #endif } diff --git a/kernel/seccomp.c b/kernel/seccomp.c index 8ad7a293255a..f67e92d11ad7 100644 --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -356,14 +356,14 @@ static inline void seccomp_assign_mode(struct task_struct *task, task->seccomp.mode = seccomp_mode; /* - * Make sure TIF_SECCOMP cannot be set before the mode (and + * Make sure SYSCALL_WORK_SECCOMP cannot be set before the mode (and * filter) is set. */ smp_mb__before_atomic(); /* Assume default seccomp processes want spec flaw mitigation. */ if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0) arch_seccomp_spec_mitigate(task); - set_tsk_thread_flag(task, TIF_SECCOMP); + set_task_syscall_work(task, SECCOMP); } #ifdef CONFIG_SECCOMP_FILTER @@ -929,7 +929,7 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, /* * Make sure that any changes to mode from another thread have - * been seen after TIF_SECCOMP was seen. + * been seen after SYSCALL_WORK_SECCOMP was seen. */ rmb(); -- 2.29.2