Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752463AbbH1Pbm (ORCPT ); Fri, 28 Aug 2015 11:31:42 -0400 Received: from mail-db3on0080.outbound.protection.outlook.com ([157.55.234.80]:47719 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751924AbbH1Pbi (ORCPT ); Fri, 28 Aug 2015 11:31:38 -0400 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; ezchip.com; dkim=none (message not signed) header.d=none;ezchip.com; dmarc=none action=none header.from=ezchip.com; From: Chris Metcalf To: Gilad Ben Yossef , Steven Rostedt , Ingo Molnar , Peter Zijlstra , Andrew Morton , "Rik van Riel" , Tejun Heo , Frederic Weisbecker , Thomas Gleixner , "Paul E. McKenney" , Christoph Lameter , Viresh Kumar , Catalin Marinas , Will Deacon , , , CC: Chris Metcalf Subject: [PATCH v6.1 3/6] task_isolation: support PR_TASK_ISOLATION_STRICT mode Date: Fri, 28 Aug 2015 11:31:21 -0400 Message-ID: <1440775881-21631-1-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <20150826103651.GA30466@arm.com> X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD048;1:pAGkBa7IbAAN78xBG5w+vVz9Hu7eCo1ZyyfdSblmMwIVYYrQ4VohjCs5Q3oQoYAiheBxBIHAIPVWuoAKBJiMhyfl/ug8rLRelZAS9KPaHqgbzgRo6FgKiP07zwytJ63VG44cYIY6DVFd0fr78nR57PN8u4adIdQFbdn3zuug8d0ZtNzBhai2kLmJ2kcWFhH8sdvgP1PCilJIyOruBXkUVnrH+XO2XbGcznLSiHmbNjWoLUUIqs2Hj4bWuxdBofMSTFgUGFJ2pdYJwDAOFI1MjaCmeudu2yykdXZdD+a8JsNjZEZ+nS2Ii4ChEIYfi4u3dA1+FOz9jyO1gK2fule+sLJDGR79Q9NHO4YQwNYUUz8s0jBemjtxcebiy1ghGu3Q X-Forefront-Antispam-Report: CIP:12.216.194.146;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(339900001)(3050300001)(189002)(199003)(19580405001)(106356001)(107886002)(5001960100002)(77156002)(85426001)(68736005)(189998001)(50466002)(106476002)(81156007)(48376002)(5001770100001)(105606002)(5001860100001)(36756003)(5007970100001)(106466001)(5001830100001)(4001540100001)(97736004)(42186005)(19580395003)(104016003)(5003940100001)(2950100001)(229853001)(62966003)(92566002)(46102003)(50226001)(50986999)(64706001)(87936001)(2201001)(6806004)(47776003)(86362001)(33646002)(575784001)(9376005)(921003)(4001430100001)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR02MB0777;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;PTR:InfoNoRecords;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;HE1PR02MB0777;2:i4xlh3mNjfv4KOEyV0aukypTQKnltL65sr6qn9CuDmMdymp0dPzQMXv8G3ZMRwHV5T9jF7leFM9jubQYrSRWtI10btWw1NY/1qdYQ/tdfGU1kT/egNuy8WX0/cg6VPadFbGxT5GipGMyGsNQSgZKGe3rjtcIAA4I9h7vBJVE8fk=;3:D1khHQUtL36K8h9Q4Vlmd5BKf6w9SsVBfA47yMUnMQRCacZJWWCaYUzek+XToN433ywagfLWvMDlZDiMpcnsL1RA3aZAQhjLF+bsDyuNN1uMKwoTB91y3clxZJbmJ1jrP8whENqhrre4dl8eec0wAoKIhp5TVT5+dyZnECxMzGf1Fu4IkDopMaVTDgsRKvo/UoosEo0nRwWkwgWCwEO0yWGiBpxSFJVeIcmOq4kLjCuvtCGlpjavctrJbailHbkE;25:Vbc5HfxN0Ln0OEtDFkV2JSk9D7jnUTAw0jFFnQrfO73h0m1Fy/3VRBNpnmL/9KZdYrjbKLwM/oUK8/x0w8v3j4CVS9fzi9pWsaqbarI7U6jQm3uSC8wGbiqRS/LEx/NcCZTBClWGjmJ3yj0uDJBOBfVpHCy6G/Q4YDXKxpLQ2bDymDYxCOlZk7Z1It3hIEzX0HOd9itIDZSip+zbrAyWU5QigGJs+Rzgp+G21Qe0gEfE8BTEhUZsWBwS12sBLmvFqxaOHGRqy4sSCnsZ/+LQ9Q==;20:ge6HPSyN9P5y7hEBmO2zIOi44ubr9wfYD+d2hgasUmDCTicU3Ea5SroMlLvgtE/ITZLw2FJSHxR8pi8uFjUFqb9baK5xZTvKoGzoZifiOocybvx5Dnvjo4lhCxy/e2/YI/2XwoFcSg7FY2OfRVBEh8xClHUJUYGgJS7ja6fFYFU= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR02MB0777; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(8121501046)(5005006)(3002001);SRVR:HE1PR02MB0777;BCL:0;PCL:0;RULEID:;SRVR:HE1PR02MB0777; X-Microsoft-Exchange-Diagnostics: 1;HE1PR02MB0777;4:2yig9DBtP/OQdBnq2Ucm9RCc4mjP+AYgsLW6QwLYAJbbOeBo7vN7oZqdsODBpDpEHcbYbC6/biI0S23YdDnAwRjCbKsxr+CNIkm9T1R2mkDrgugZgULX294k0uAlzMxeLnZSrr5zA9tAF+KMC5+goXr06g15AK9Hpfepmssb52GvBnWYHnGfQYwKDbomPaFHx2QjFxvxUjptkE3zxjli076ny1yEjH1sQgXO03WMhfON/a/1WMSCAGidprlMwUg5zITFLnCKSaiD/d46knlBo8F1ZZl8CCpdLWKg8YCahCCmKjeFbTDUH1+hX8fpWdID X-Forefront-PRVS: 0682FC00E8 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR02MB0777;23:ecurC6fIpZEzYSkreH7OD2k66HzxzTlbNhyZLk6t3?= =?us-ascii?Q?PTMyVLJmITR6WNhbCdFre58T7z6nU+lYiqtzA2TcKvW2mmeulS32fhuAQtFn?= =?us-ascii?Q?g9Ck8ew/EK620kWjgLx83ve85R+YMxp4Sz16kNi2O1+b/RuxqH28E33Ao6n/?= =?us-ascii?Q?aw+bVHt3deQ+8UUIi5ihGkFGwoStBKv0/h2B+2vjCm/N3LlZpucj15X1ko79?= =?us-ascii?Q?Ien/8J4IdxRYaorsjwPOK2bPhxKauiIgi9rUJweR+j7CHnERH1gosa67S60C?= =?us-ascii?Q?S95gpsMBJ4ruHp3S/fYuBeAcknvtGLHZdWZOwrvXfPbOcZDHOVynk/xIyabE?= =?us-ascii?Q?I7atp8Qbs98NQS3nWsWYMuMHE3lX6CJT35Biml0u4B1wOs9pjeqEuQSItFuW?= =?us-ascii?Q?g1s4W+QJfLCy+qUe5Bu848UhNHNCr81h7v9KcWeTJi33xE3zum+iE/Yu4pCd?= =?us-ascii?Q?NaiarBnq8Sc4BWrOMSRJOJyxYzCO5Jz10mwyHVGXOfcbg65zUyFMvWiqHAOf?= =?us-ascii?Q?3u1V/lTt9C4J9/Rs3dkDAzWdJcF+DUI5zBVSw3+rmnkEUWvd93QxzJSzaLS3?= =?us-ascii?Q?LLrWE10VAkp4ApodDbxJjGnpI5XRPepqS/PLoi3ZiTdw73sZMrSRk+RDorsG?= =?us-ascii?Q?7RjdwZEzu7Xpk+zFb8krl461bzTKai6NOdWpigkOlcsc5ujSK/J3mYUSqIBm?= =?us-ascii?Q?tJ0l+NseAfpM+dUr9VXvUH9LRXGs0H7Uf9Ni1s2rf3S5USKdTU90AxI9TyTM?= =?us-ascii?Q?Alw0491pxd9bhBci2VYgftiWEAKSqPiPZLA217j9F+G/dgeOokKTpaLegxT1?= =?us-ascii?Q?O5cuPKx/5cwTY24vga757XZXfext3tirCnWr9oWIRCP/ZDpYuhFUhmiCTKgl?= =?us-ascii?Q?2QrGqtWRLnQD3Na2YTkCcBInfoADcajVJTvisaj3FcaeTqyigcXiI9331IWW?= =?us-ascii?Q?VKoY7KpzBSx/OiMf9u6duHiYJ3h9HRl8DTyxKKWzV5X2rq4VcLRpzmUPlWHh?= =?us-ascii?Q?L/ser3zdPnMel3VPeK+BHeayWrQ2a+U7hbzX0JDquHiiQxobtW+vNQdXRvfL?= =?us-ascii?Q?ocGhFUdoool1BVCBr4okSJEKJ3YGusymCDlxYxFNC6ZfvlGHOdWRRyk37Euq?= =?us-ascii?Q?mZMXm0CYFXgHnhH/7YlAkVZBcBzkDGKIJLxBC9/60wwWuF747gix7IfnyKyQ?= =?us-ascii?Q?2A2Q66WchiKE0CCJOFmmwJlDE9BhON8bHlpZMELGn4xxS7sy0+ZyatXU7gc5?= =?us-ascii?Q?kerBWUf4Cm5GYNwzjwwMe6ctVDcpmhYXHIcquM9llFSLq3vnWO+bQRgm4L62?= =?us-ascii?Q?VcB1y+Ny/0yewIzfvjCHzvJ47fTH6HxTaXKdt0SaX1l?= X-Microsoft-Exchange-Diagnostics: 1;HE1PR02MB0777;5:ckx1YVDjEJAt2SRUKpY47YUgWFcYvo7yB1qkeGPu7Du29IBc8so+s1G52ZiYdFQUxO9lTd5a29/hAbfD0WEbcgon/VnFgVtt0ZzpG9iZE+/bhZ9+oZzN7+A4LQm55B93opjrhEU2BPqGrRRTfey0DA==;24:LfAm3LOXm3poJIPH2kpzEf0NckrfELzL9TQm4uMrLbZJK4mkD27AaT4TJ+DsA9PacuYvSrvIv+XfYU0uiAgPLf9oDh7l6LprGhMb/gfUVtM=;20:1clAqj23G1aodHiFC/5VoTHl7NJTNMa4zzeAB9rM1HFzjo6kydCopmtMqUvNKnLtJuWEshDT6cZx98aYT35NPg== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2015 15:31:32.8446 (UTC) X-MS-Exchange-CrossTenant-Id: 0fc16e0a-3cd3-4092-8b2f-0a42cff122c3 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0fc16e0a-3cd3-4092-8b2f-0a42cff122c3;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR02MB0777 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9014 Lines: 273 With task_isolation mode, the task is in principle guaranteed not to be interrupted by the kernel, but only if it behaves. In particular, if it enters the kernel via system call, page fault, or any of a number of other synchronous traps, it may be unexpectedly exposed to long latencies. Add a simple flag that puts the process into a state where any such kernel entry is fatal. To allow the state to be entered and exited, we ignore the prctl() syscall so that we can clear the bit again later, and we ignore exit/exit_group to allow exiting the task without a pointless signal killing you as you try to do so. This change adds the syscall-detection hooks only for x86, arm64, and tile. For arm64 we use an explict #ifdef CONFIG_TASK_ISOLATION so we can both achieve no overhead for !TASK_ISOLATION, but also achieve low latency (test TIF_NOHZ first) for TASK_ISOLATION. The signature of context_tracking_exit() changes to report whether we, in fact, are exiting back to user space, so that we can track user exceptions properly separately from other kernel entries. Signed-off-by: Chris Metcalf --- This "v6.1" is just a tweak to the existing v6 series to reflect Will Deacon's suggestions about the arm64 syscall entry code. I've updated the git tree with this updated patch in the series. A more disruptive change would be to capture the thread flags up front like x86 and tile, which allows the test itself to be optimized away if the task_isolation call becomes a no-op. arch/arm64/kernel/ptrace.c | 6 ++++++ arch/tile/kernel/ptrace.c | 5 ++++- arch/x86/kernel/ptrace.c | 2 ++ include/linux/context_tracking.h | 11 ++++++++--- include/linux/isolation.h | 16 ++++++++++++++++ include/uapi/linux/prctl.h | 1 + kernel/context_tracking.c | 9 ++++++--- kernel/isolation.c | 38 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 81 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index d882b833dbdb..5d4284445f70 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -1154,6 +1155,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs) if (secure_computing() == -1) return -1; +#ifdef CONFIG_TASK_ISOLATION + if (test_thread_flag(TIF_NOHZ) && task_isolation_strict()) + task_isolation_syscall(regs->syscallno); +#endif + if (test_thread_flag(TIF_SYSCALL_TRACE)) tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); diff --git a/arch/tile/kernel/ptrace.c b/arch/tile/kernel/ptrace.c index f84eed8243da..c327cb918a44 100644 --- a/arch/tile/kernel/ptrace.c +++ b/arch/tile/kernel/ptrace.c @@ -259,8 +259,11 @@ int do_syscall_trace_enter(struct pt_regs *regs) * If TIF_NOHZ is set, we are required to call user_exit() before * doing anything that could touch RCU. */ - if (work & _TIF_NOHZ) + if (work & _TIF_NOHZ) { user_exit(); + if (task_isolation_strict()) + task_isolation_syscall(regs->regs[TREG_SYSCALL_NR]); + } if (work & _TIF_SYSCALL_TRACE) { if (tracehook_report_syscall_entry(regs)) diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c index 9be72bc3613f..2f9ce9466daf 100644 --- a/arch/x86/kernel/ptrace.c +++ b/arch/x86/kernel/ptrace.c @@ -1479,6 +1479,8 @@ unsigned long syscall_trace_enter_phase1(struct pt_regs *regs, u32 arch) if (work & _TIF_NOHZ) { user_exit(); work &= ~_TIF_NOHZ; + if (task_isolation_strict()) + task_isolation_syscall(regs->orig_ax); } #ifdef CONFIG_SECCOMP diff --git a/include/linux/context_tracking.h b/include/linux/context_tracking.h index b96bd299966f..e0ac0228fea1 100644 --- a/include/linux/context_tracking.h +++ b/include/linux/context_tracking.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -11,7 +12,7 @@ extern void context_tracking_cpu_set(int cpu); extern void context_tracking_enter(enum ctx_state state); -extern void context_tracking_exit(enum ctx_state state); +extern bool context_tracking_exit(enum ctx_state state); extern void context_tracking_user_enter(void); extern void context_tracking_user_exit(void); @@ -35,8 +36,12 @@ static inline enum ctx_state exception_enter(void) return 0; prev_ctx = this_cpu_read(context_tracking.state); - if (prev_ctx != CONTEXT_KERNEL) - context_tracking_exit(prev_ctx); + if (prev_ctx != CONTEXT_KERNEL) { + if (context_tracking_exit(prev_ctx)) { + if (task_isolation_strict()) + task_isolation_exception(); + } + } return prev_ctx; } diff --git a/include/linux/isolation.h b/include/linux/isolation.h index fd04011b1c1e..27a4469831c1 100644 --- a/include/linux/isolation.h +++ b/include/linux/isolation.h @@ -15,10 +15,26 @@ static inline bool task_isolation_enabled(void) } extern void task_isolation_enter(void); +extern void task_isolation_syscall(int nr); +extern void task_isolation_exception(void); extern void task_isolation_wait(void); #else static inline bool task_isolation_enabled(void) { return false; } static inline void task_isolation_enter(void) { } +static inline void task_isolation_syscall(int nr) { } +static inline void task_isolation_exception(void) { } #endif +static inline bool task_isolation_strict(void) +{ +#ifdef CONFIG_TASK_ISOLATION + if (tick_nohz_full_cpu(smp_processor_id()) && + (current->task_isolation_flags & + (PR_TASK_ISOLATION_ENABLE | PR_TASK_ISOLATION_STRICT)) == + (PR_TASK_ISOLATION_ENABLE | PR_TASK_ISOLATION_STRICT)) + return true; +#endif + return false; +} + #endif diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index 79da784fe17a..e16e13911e8a 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -194,5 +194,6 @@ struct prctl_mm_map { #define PR_SET_TASK_ISOLATION 47 #define PR_GET_TASK_ISOLATION 48 # define PR_TASK_ISOLATION_ENABLE (1 << 0) +# define PR_TASK_ISOLATION_STRICT (1 << 1) #endif /* _LINUX_PRCTL_H */ diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c index c57c99f5c4d7..17a71f7b66b8 100644 --- a/kernel/context_tracking.c +++ b/kernel/context_tracking.c @@ -147,15 +147,16 @@ NOKPROBE_SYMBOL(context_tracking_user_enter); * This call supports re-entrancy. This way it can be called from any exception * handler without needing to know if we came from userspace or not. */ -void context_tracking_exit(enum ctx_state state) +bool context_tracking_exit(enum ctx_state state) { unsigned long flags; + bool from_user = false; if (!context_tracking_is_enabled()) - return; + return false; if (in_interrupt()) - return; + return false; local_irq_save(flags); if (!context_tracking_recursion_enter()) @@ -169,6 +170,7 @@ void context_tracking_exit(enum ctx_state state) */ rcu_user_exit(); if (state == CONTEXT_USER) { + from_user = true; vtime_user_exit(current); trace_user_exit(0); } @@ -178,6 +180,7 @@ void context_tracking_exit(enum ctx_state state) context_tracking_recursion_exit(); out_irq_restore: local_irq_restore(flags); + return from_user; } NOKPROBE_SYMBOL(context_tracking_exit); EXPORT_SYMBOL_GPL(context_tracking_exit); diff --git a/kernel/isolation.c b/kernel/isolation.c index d4618cd9e23d..a89a6e9adfb4 100644 --- a/kernel/isolation.c +++ b/kernel/isolation.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "time/tick-sched.h" /* @@ -73,3 +74,40 @@ void task_isolation_enter(void) dump_stack(); } } + +static void kill_task_isolation_strict_task(void) +{ + dump_stack(); + current->task_isolation_flags &= ~PR_TASK_ISOLATION_ENABLE; + send_sig(SIGKILL, current, 1); +} + +/* + * This routine is called from syscall entry (with the syscall number + * passed in) if the _STRICT flag is set. + */ +void task_isolation_syscall(int syscall) +{ + /* Ignore prctl() syscalls or any task exit. */ + switch (syscall) { + case __NR_prctl: + case __NR_exit: + case __NR_exit_group: + return; + } + + pr_warn("%s/%d: task_isolation strict mode violated by syscall %d\n", + current->comm, current->pid, syscall); + kill_task_isolation_strict_task(); +} + +/* + * This routine is called from any userspace exception if the _STRICT + * flag is set. + */ +void task_isolation_exception(void) +{ + pr_warn("%s/%d: task_isolation strict mode violated by exception\n", + current->comm, current->pid); + kill_task_isolation_strict_task(); +} -- 2.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/