Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755427AbcCBUKc (ORCPT ); Wed, 2 Mar 2016 15:10:32 -0500 Received: from mail-am1on0090.outbound.protection.outlook.com ([157.56.112.90]:20644 "EHLO emea01-am1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755040AbcCBUKX (ORCPT ); Wed, 2 Mar 2016 15:10:23 -0500 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 , Andy Lutomirski , , , CC: Chris Metcalf Subject: [PATCH v10 06/12] task_isolation: support PR_TASK_ISOLATION_STRICT mode Date: Wed, 2 Mar 2016 15:09:30 -0500 Message-ID: <1456949376-4910-7-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1456949376-4910-1-git-send-email-cmetcalf@ezchip.com> References: <1456949376-4910-1-git-send-email-cmetcalf@ezchip.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CPI:12.216.194.146;IPV:NLI;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(2980300002)(1109001)(339900001)(189002)(199003)(50466002)(5003940100001)(47776003)(189998001)(92566002)(2950100001)(5001970100001)(33646002)(5008740100001)(5001770100001)(4001430100002)(19580395003)(50986999)(11100500001)(81156011)(48376002)(19580405001)(104016004)(50226001)(36756003)(229853001)(87936001)(4326007)(586003)(105606002)(106466001)(76176999)(2201001)(85426001)(1220700001)(2906002)(6806005)(107886002)(42186005)(1096002)(921003)(42882005)(2101003)(83996005)(1121003);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR05MB1692;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;DB3FFO11FD014;1:bBNSmvuv6U+aALORsZvCQaBswAbA3lUTAFU09Cu8Wg1WThy8tfZXWkE+hiCPHHe52GHrXIticZioZDZwFBmTMMiuSD/3feWqwTy0WmEN0Or293k7omEoSxnZhcQ0/sXdh8WYcLqTl+nunh+aGx1k0/yDlvWofPJ3G/hQYyFb4nqYfz8ULtWg5H39AmYhYZmHHRSffbe5ax1ahZ5OaCGkxj7+D8Lttzd/l7cadr5eIW5ozOsdiNP+5/CWrl+Q0aU2tvwB7DMokyz6cr7xXiaeEVm1w2+D/oAUTjQHZ7OXAg5U8G+08tksodDuqJsrRVk3GdPSz++fdnCewCd/i/6EaeiY22ja8fhnwd0TkDrwUBtVxkCKx9O8jmgQqK5P1yQ8jjjBIU3/xrV4ud/2vLUIifEuxJnJQAfb0PfRGBlhmIgh2GnZsWmM+DpWwwuVoqOQ7lOHXc13IwvXZ9v33aV4jehRTwQ0ApKpaHMhykKtkeVzBKXyznzb2t3vWKZ0qs1f MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1692;2:KVo4B8rlc1bQI+LyXxNzjuWfMNAlp1NWf6arSjjSSkFA4bEmntIHJZMbns8fJjAhiA7xT6gmX4dWlAVS76Dc24ZbWUBE5Cd5kQYSpUXuWMFunc/X0Fd4n4Vto3aAWbHITbSiA2wyIQsQZVAFcPHQhg==;3:gL4uHOxZl5kY7B1EkuGRXaBpXe/gTPeJbhU9z0BJGHvYjCtmnRddYahb71wT5Us6QVk6vrArh7g8Ac9buiOyjBSc/CisUIZ4qI8iQSwv2pAb1TMBjp4JZnbyCCiRmPAkzvKjIT1rCj2QQQETBQC60Q5l/KCya/PRTVXiqK7O7wQ=;25:OohDOgNRJfsulz0FeUIJOLyofB8PKviPZjEkGoky9gk2NmuoEZPU/UIcmTeMmp++X1twXYRFJxVZYCH2ulHI8OmFRTBO460BvrL/kiCLgtREa+W3vocsKcEBk9pXVRwfN4gEHyEen9eceai/4Yf64UK46NzaZi0NDac/9k1BRg6KyjxBazPVQ2lhmUVmBBmi/qNXYb820VKsvdPaMAprMjBvsl9UT2e7qJQB3HBFkO6/8/J2OvLqdZ/Yf4g4IOWLyYcCJTBRf+exo/kIjAsJCxRK+sYZdzHyCeUsw2GtQdoiFcuTBFbL0jD17i70ANTbScZbgy0j58Xn9luj2lDjjA== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:HE1PR05MB1692; X-MS-Office365-Filtering-Correlation-Id: 52aa7df7-6c0d-49c1-78aa-08d342d6acdc X-MLNXRule-EZCH-Linux: Rule triggered X-MLNXRule-Acc-Dom-4: Rule triggered X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1692;20:GNODzDHDLbGa/6fn+SSXmXv+Gch1ni7BFJ/XHgqQqbMmCKP7sne2wYPrIylUUKDzddGtd0PzouC0WJpp70bdERgXeAEPHBDzwqlTxw6BVNVybINrUWnZdEgOggDPCuINdt0QKTOC47BVwj3nRTiGe3HCc5GjEXEnfA3y8Gjj7j9qadDX+EE9GEZNd1QXR0hv77GdfOfB6fe2ojkBaMht6FRZrbWkDuKsLjvCxwy1tswC7WQGGixbDbCuva1hHNJOiGHkKghUOAChdFZ3EBf/by3uZ74AMeobws/9S8p5O4KJPduWgHJqLgMxECPz0UlHle/YfeKhD3gnUT/k3yxfn7DRsNZohNSaJthPetP8v1Y6uUMvdM0SwscCdWY7gmlL/YdWXq75lwiC24xkj4UY+50Y0eF0JqLLDNpv7IgFa2Bk+LRJynE2hc27H4N+Il2BKqQTkZzZlAq3fy2yGEm5mrwxgAmi8kcIrxwIvP1qxw9FsrszmynbU84qnXq+omL8eJ1VqfMrCuGbMIKqQtmg6PNz/Ym8TiSq//dWhyneeITNUqNlGFHrzkHOxpJ5msBwhMfUCnHCW0secHGuT1+fyfDVei4XfNbSDInCaXlk3Po= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(13018025)(13015025)(13023025)(8121501046)(13017025)(13024025)(5005006)(10201501046)(3002001);SRVR:HE1PR05MB1692;BCL:0;PCL:0;RULEID:;SRVR:HE1PR05MB1692; X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1692;4:Q3re+iU6ly9awricFaTVWqN8FWwfPkkGAHT2I8czFoVsw2/9JT5rPAROgEq1JXHd3esty9iJ+O6vOeFSz4ETNhrsRsykDucQ9EreKz8XrclMEpD1wfFhO7lL1OL5SDBvjlbyOxaspFzk2HOo7CZAjoqZUoVD8ulzWi1vyELHu0XyNSKXVQAQU4FXoRY6D3vP9qZYdH2h+PyqS6szVUmzGq9Ma0fJwEMlRmfsBn4Kn+FR4ZjPXGv6YRlrbi2rRbYBudRRgHDJp5YHEk0d1mVVWDmxAxH7pXtrM+fK0Jd5Wujx/6jY0KOkIFFcE/4TmSVIDUw3EapjqctZNQwM62VL1mHPUhfAuxO3OgKJcfLjSt5IqdW4d9yk/whk0KuMA/N/qsiBHeXQ2zggSNxC9i+9CAMqf0mvjyepsSO68vgYICzVgviSzA7Q1bkRyCnZWqf+jnTKTgRjO+YZkmiAs1y23g== X-Forefront-PRVS: 086943A159 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR05MB1692;23:YyzH3Hs/s8u9kJzOfYsm3CazjVozPPQHIR96UgHzY?= =?us-ascii?Q?clW8SEMGEgpC8KLK6PWQvn44dR3ogZpjc2K8bOCdPKb1DJExBV3MBNgNI/db?= =?us-ascii?Q?luJg8JlV/lEq1i9PH2ZIQ5jGP/T6D4HJnsNvgXON6X41A+f6yD0V69czQpp6?= =?us-ascii?Q?DX8Mro+XtkPxl2sNXrJW88BBP1L+RNYq3P0aH1MfeXGvhqykFMrtMZ9+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IfSdKVqAzmnIX6x1PqWv1pt2wbTBfyq+b?= =?us-ascii?Q?xNSGKFutu/kiTuoBDbosKMJZ725CUPfUKTa/ia6P4CkSmjl5HXzSv9nqdzZD?= =?us-ascii?Q?xuAPEuym0nrj6MYnE0otkkmwMwK7in1lrYc?= X-Microsoft-Exchange-Diagnostics: 1;HE1PR05MB1692;5:dt6xwR/fFrjH3wk7nL+WJUJNBl7hd08RtntLz3R9H40f+ZP3Yog9kjINEGsQrIFlsUB4bGuPR5n3YagQEkCbHqJeTzversZsHvOh+OW1ef68uk5oE+gnGsFsDxYaLOd6vLCRQa7JgCeaVN0pvTW1oA==;24:b12mVoXzRcwUyHV+DAYn+P0/MKboE3vjGYQZr0fDh3zPzUHGzeYr1FMDgwFdZhOMCDr6ErdqlUuxMd3GDOYYHgrQdKlwr5B9Zu9x/+aTH/s= X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2016 20:10:17.4632 (UTC) X-MS-Exchange-CrossTenant-Id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=a652971c-7d2e-4d9b-a6a4-d149256f461b;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR05MB1692 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5018 Lines: 155 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; this is defined as happening immediately before the SECCOMP test. By default, the task is signalled with SIGKILL, but we add prctl() bits to support requesting a specific signal instead. 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. Signed-off-by: Chris Metcalf --- include/linux/isolation.h | 25 +++++++++++++++++++ include/uapi/linux/prctl.h | 3 +++ kernel/isolation.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) diff --git a/include/linux/isolation.h b/include/linux/isolation.h index c564cf1886bb..ba6c4d510db8 100644 --- a/include/linux/isolation.h +++ b/include/linux/isolation.h @@ -42,12 +42,37 @@ static inline void task_isolation_enter(void) _task_isolation_enter(); } +extern bool task_isolation_syscall(int nr); +extern void task_isolation_exception(const char *fmt, ...); +extern void task_isolation_interrupt(struct task_struct *, const char *buf); + +static inline bool task_isolation_strict(void) +{ + return ((current->task_isolation_flags & + (PR_TASK_ISOLATION_ENABLE | PR_TASK_ISOLATION_STRICT)) == + (PR_TASK_ISOLATION_ENABLE | PR_TASK_ISOLATION_STRICT)) && + task_isolation_possible(raw_smp_processor_id()); +} + +static inline bool task_isolation_check_syscall(int nr) +{ + return task_isolation_strict() && task_isolation_syscall(nr); +} + +#define task_isolation_check_exception(fmt, ...) \ + do { \ + if (task_isolation_strict()) \ + task_isolation_exception(fmt, ## __VA_ARGS__); \ + } while (0) + #else static inline void task_isolation_init(void) { } static inline bool task_isolation_possible(int cpu) { return false; } static inline bool task_isolation_enabled(void) { return false; } static inline bool task_isolation_ready(void) { return true; } static inline void task_isolation_enter(void) { } +static inline bool task_isolation_check_syscall(int nr) { return false; } +static inline void task_isolation_check_exception(const char *fmt, ...) { } #endif #endif diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h index 67224df4b559..a5582ace987f 100644 --- a/include/uapi/linux/prctl.h +++ b/include/uapi/linux/prctl.h @@ -201,5 +201,8 @@ struct prctl_mm_map { #define PR_SET_TASK_ISOLATION 48 #define PR_GET_TASK_ISOLATION 49 # define PR_TASK_ISOLATION_ENABLE (1 << 0) +# define PR_TASK_ISOLATION_STRICT (1 << 1) +# define PR_TASK_ISOLATION_SET_SIG(sig) (((sig) & 0x7f) << 8) +# define PR_TASK_ISOLATION_GET_SIG(bits) (((bits) >> 8) & 0x7f) #endif /* _LINUX_PRCTL_H */ diff --git a/kernel/isolation.c b/kernel/isolation.c index 42ad7a746a1e..5621fdf15b17 100644 --- a/kernel/isolation.c +++ b/kernel/isolation.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "time/tick-sched.h" cpumask_var_t task_isolation_map; @@ -122,3 +123,62 @@ void _task_isolation_enter(void) if (!tick_nohz_tick_stopped()) set_tsk_need_resched(current); } + +void task_isolation_interrupt(struct task_struct *task, const char *buf) +{ + siginfo_t info = {}; + int sig; + + pr_warn("%s/%d: task_isolation strict mode violated by %s\n", + task->comm, task->pid, buf); + + /* + * Turn off task isolation mode entirely to avoid spamming + * the process with signals. It can re-enable task isolation + * mode in the signal handler if it wants to. + */ + task->task_isolation_flags = 0; + + sig = PR_TASK_ISOLATION_GET_SIG(task->task_isolation_flags); + if (sig == 0) + sig = SIGKILL; + info.si_signo = sig; + send_sig_info(sig, &info, task); +} + +/* + * This routine is called from any userspace exception if the _STRICT + * flag is set. + */ +void task_isolation_exception(const char *fmt, ...) +{ + va_list args; + char buf[100]; + + /* RCU should have been enabled prior to this point. */ + RCU_LOCKDEP_WARN(!rcu_is_watching(), "kernel entry without RCU"); + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + task_isolation_interrupt(current, buf); +} + +/* + * This routine is called from syscall entry (with the syscall number + * passed in) if the _STRICT flag is set. + */ +bool 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 false; + } + + task_isolation_exception("syscall %d", syscall); + return true; +} -- 2.1.2