From patchwork Wed Sep 29 22:02:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12537967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57526C4332F for ; Wed, 29 Sep 2021 22:02:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D1FD61406 for ; Wed, 29 Sep 2021 22:02:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346852AbhI2WEF (ORCPT ); Wed, 29 Sep 2021 18:04:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346531AbhI2WED (ORCPT ); Wed, 29 Sep 2021 18:04:03 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3AF8C061768 for ; Wed, 29 Sep 2021 15:02:21 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id om12-20020a17090b3a8c00b0019eff43daf5so3117771pjb.4 for ; Wed, 29 Sep 2021 15:02:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5WCcuqE5ATqYYHgSY5EFkOCbHMpsSpyspHQpjUNcv5Y=; b=auL8+W3vWjgmvU2tpA+erOXzo26U1U+3xcJSDWNYhxjCshW4qRv6EuJyBzF+NF+ALI VtFzV5eIXd9AJWySPinc3ZYYQvnPsqmVS3V6IoTI0GD6gspmuxNSGc8jbwxm/Vg8og3X 56m/Y56wUuRRWtKXu2Uu6yB4QOf5dPLgXDGyA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5WCcuqE5ATqYYHgSY5EFkOCbHMpsSpyspHQpjUNcv5Y=; b=XJEXatacN8jEee1+AK2IJFrxuST32NV069jimzeigoRZXXFqLI0TlRPOXSIDNbHzKu uOrUeWcv7nJF+uFso7AmmC7+AzAsbe17IpWQOv4nTmRbDqZtnbsU6QdK3ZWBpd4eSCZt cbaABfkgzEA/O1cOD2i+ex2K/wGQmNOlYfKsWkxKI6My5jOXZ7D1iteO+Oy4NyRAxvrR KiL5a2kmmTXCcyVneMJu5aQ19Wa7Hx2BOx2A32g8vgz0pBh64K46s87KWfWxmFUPnpW9 Zy+lGdR+qNU5cA8bxp9n4Ep2sVKq4B2R6rl+99cBeO7yc6Z/5750epq0/d+5M4n11gFS MHgA== X-Gm-Message-State: AOAM533eV6o/WJvZh2vFqgmUz6lNkERyecQgEM1WkW71DslAU+AQ8/T5 EKQK+6nFLi412ltqAYhCbMNncQ== X-Google-Smtp-Source: ABdhPJzwLR/Ap0q0v0NMoFhrZVvZI/xyv011wmpW7jJR760oWKWM1Dryn4XWEISn5sCM7FhYCnSVNg== X-Received: by 2002:a17:902:c3c5:b0:13d:efe4:c10a with SMTP id j5-20020a170902c3c500b0013defe4c10amr768762plj.54.1632952941354; Wed, 29 Sep 2021 15:02:21 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y8sm671348pfe.217.2021.09.29.15.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 15:02:20 -0700 (PDT) From: Kees Cook To: Peter Zijlstra Cc: Kees Cook , kernel test robot , Vito Caputo , Jann Horn , stable@vger.kernel.org, Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Andrew Morton , Christian Brauner , Anand K Mistry , "Kenta.Tada@sony.com" , Alexey Gladkov , =?utf-8?q?Michael_Wei=C3=9F?= , Michal Hocko , Helge Deller , Qi Zheng , "Tobin C. Harding" , Tycho Andersen , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , Mark Rutland , Jens Axboe , Stefan Metzmacher , Lai Jiangshan , Andy Lutomirski , Dave Hansen , "Eric W. Biederman" , Ohhoon Kwon , Kalesh Singh , YiFei Zhu , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 1/6] Revert "proc/wchan: use printk format instead of lookup_symbol_name()" Date: Wed, 29 Sep 2021 15:02:13 -0700 Message-Id: <20210929220218.691419-2-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929220218.691419-1-keescook@chromium.org> References: <20210929220218.691419-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1921; h=from:subject; bh=48rNinxgYhX0MMt+z9ytmuG8GHuOw2IZ5/XYplBnCcc=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhVOJo3aAmkY3cNkeh8mx6qR4Wd4ABLM9VfEd7+ihZ Bx7vHSCJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYVTiaAAKCRCJcvTf3G3AJiiED/ wKvQpREXh7suSjafXjjgxvDNfXY3HL8kOvjEmH4RtOMi5mz+9HRnMPSrE7uRwIaONoG4ufwr/n3H3P 6Kja0xtlj0MeCsARdSb7yfNwDwdkvJTU9zYmkc6FD0HWZOwMbOzRTj5YX6cI3xzvdliMv7iBmIo83d 8Me5vaMEeP4ipheIbrebMIjZ3wRD3Q2jjWQciQI5VRPe9u8u1Le06t9baVYeg49LWj0IrFoOy11jLp E8Qjwbx2yLB26dZ1HeFyXOrO4Kn+0RX4s3Xu3TPOUme/W4000nwYEFFuGJOrSqsoIHYiLaq4KsPSmg yCixLdJvE6BnqSi5k3tGK1/y3iNDnlK4v2mGquYuFgSwtOnkYOY8x6q1baJAyWvt7ttfZaP6h65PEx +VS94JngCROP2FMOdyUzkqOW1lXm67lV9aT+bMPTO2PYZJPpFl4DpK2W/vqUsWFvo98UUgYIGbiFfE xeDctTh2NhYvhW2pOQKdzEaEDHJD0+4ipb6NlrtI0vse43Uana/wFt55xPCcvTymIT2RnxjbJu0d6Z JPSErNRmubclWQ50ZRZoeUD2CVmsqqqfcMqdzGtcuzuCnL9s9nfe7vIK2d3CHP0cwjYDrnBy6PBmcb YSK36RKsGmsiO4nzn/++uNyY8O30t5BSglmAsrFBqHEQJ1eU9lTE1CaE78WQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org This reverts commit 152c432b128cb043fc107e8f211195fe94b2159c. When a kernel address couldn't be symbolized for /proc/$pid/wchan, it would leak the raw value, a potential information exposure. This is a regression compared to the safer pre-v5.12 behavior. Reported-by: kernel test robot Link: https://lore.kernel.org/all/20210103142726.GC30643@xsang-OptiPlex-9020/ Reported-by: Vito Caputo Link: https://lore.kernel.org/lkml/20210921193249.el476vlhg5k6lfcq@shells.gnugeneration.com/ Reported-by: Jann Horn Link: https://lore.kernel.org/lkml/CAG48ez2zC=+PuNgezH53HBPZ8CXU5H=vkWx7nJs60G8RXt3w0Q@mail.gmail.com/ Cc: stable@vger.kernel.org Signed-off-by: Kees Cook --- fs/proc/base.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 533d5836eb9a..1f394095eb88 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -386,17 +387,19 @@ static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task) { unsigned long wchan; + char symname[KSYM_NAME_LEN]; - if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) - wchan = get_wchan(task); - else - wchan = 0; + if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) + goto print0; - if (wchan) - seq_printf(m, "%ps", (void *) wchan); - else - seq_putc(m, '0'); + wchan = get_wchan(task); + if (wchan && !lookup_symbol_name(wchan, symname)) { + seq_puts(m, symname); + return 0; + } +print0: + seq_putc(m, '0'); return 0; } #endif /* CONFIG_KALLSYMS */ From patchwork Wed Sep 29 22:02:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12537973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC4F8C433F5 for ; Wed, 29 Sep 2021 22:04:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8CB9A61406 for ; Wed, 29 Sep 2021 22:04:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346938AbhI2WEG (ORCPT ); Wed, 29 Sep 2021 18:04:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346531AbhI2WEF (ORCPT ); Wed, 29 Sep 2021 18:04:05 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B733CC061767 for ; Wed, 29 Sep 2021 15:02:23 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id 17so4151472pgp.4 for ; Wed, 29 Sep 2021 15:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uRhBWrgFlaAm1vNONWn7eBn+C1gWiV8BF1SotpY7wF4=; b=XKTJ3egRbn88mEWHt3e+NT5KCfMY5twURwT5zz5ZEAy4HBp8LSwa/+FnrXK3LRRKkT z6g2BRe8HPSATIQEdZO9kSxRUJH9iUGNXS5qMILUhHDhj8MwNkfpgrdoFzdwmxBE3ALy dACyf1uiHL0kU9LpK6/Jwb0rEZezv2HsKTPx4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uRhBWrgFlaAm1vNONWn7eBn+C1gWiV8BF1SotpY7wF4=; b=zJLrBizMqafYC5WkFkCgJzd+dqLFW73RtdKq+mLPwItZ0pVuzRKRDCW3jfQMpYXttD dgyz1r/vrtMkpEb6+YSuJsRpNvqgQVToqyMn7Xex2uZEG+prd+Kp9qviP8uwVsuk2jjP jBOx5kKEh4LPw3jrwvMocsRbc3iGco0rLQL/2FMoi2P8Jm7Fq4Va/haMV/lLYhrmN0HL tQQVoQVy7B6bpo87iS8L/OyIQbbps9IeOp0K72Px5i/DPGrf6CxGBzp/oXR43k23YVNi mrdne4S58MNVe0CP2f4feu1V1D2HnBiAJVo+SmsWW9vMrd6RdWqjrR4j9IvYzl1eaob8 QHMA== X-Gm-Message-State: AOAM530DsORC6Qed1WYko5WbY37+v0xHTMe5gQeHk6+eyq4P/RgJcaex 8bysffV1DZJ4nA2QKpjAgM5Zfg== X-Google-Smtp-Source: ABdhPJxC17A4z/lSx47PDiLiFULUOvXwmBTm++Bv6j1g8B33SA4QeFQDMuP4z5hdB2v8p/omo/yiPg== X-Received: by 2002:a62:51c6:0:b0:43d:e849:c69d with SMTP id f189-20020a6251c6000000b0043de849c69dmr843514pfb.31.1632952943316; Wed, 29 Sep 2021 15:02:23 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u6sm582368pgr.3.2021.09.29.15.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 15:02:20 -0700 (PDT) From: Kees Cook To: Peter Zijlstra Cc: Kees Cook , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , kernel test robot , Vito Caputo , Jann Horn , Andrew Morton , Christian Brauner , Anand K Mistry , "Kenta.Tada@sony.com" , Alexey Gladkov , =?utf-8?q?Michael_Wei=C3=9F?= , Michal Hocko , Helge Deller , Qi Zheng , "Tobin C. Harding" , Tycho Andersen , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , Mark Rutland , Jens Axboe , Stefan Metzmacher , Lai Jiangshan , Andy Lutomirski , Dave Hansen , "Eric W. Biederman" , Ohhoon Kwon , Kalesh Singh , YiFei Zhu , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 2/6] sched: Add wrapper for get_wchan() to keep task blocked Date: Wed, 29 Sep 2021 15:02:14 -0700 Message-Id: <20210929220218.691419-3-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929220218.691419-1-keescook@chromium.org> References: <20210929220218.691419-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2019; h=from:subject; bh=hDSVcS+yS4zZDdIDUOZIhgW3NO0PbtwfKyydbAUGaMU=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhVOJoXE4lnUJcVhzfp3ihdwxyB+SepKuT2zcL6CCW aOKOM4iJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYVTiaAAKCRCJcvTf3G3AJtD4EA CKIae2l/Y4dicmSYuz6SdCtnqA0Rd5XecPN40jZIiItJs97tI0zHJfZJ0grAuBL62iw0oTrDAep0rJ hbKWV0M7J6ZcSqjI/alre0T7Jp1q8rOp/PnsXrdt23dO2vZXQh/6qvDemzNIvxOpQ4xk1cEann4FyQ mb1o02iC6K5JJaKT7HJXFfQo3fi++ezzGECuBqyyZYFcIMx5RuTUS+ZpWNgraW+WZpPgzl6ZXGP4bn xB+1NZDZqY5Q9oZ8vuDm1SC/+QwmZJCrgyeQTS213hV7Kuv0qIo/GTM+v/+/jTbqfXPZUWNKUbB28I TxAnDGXvT77m6f1R0ihCffDBj36GLZF6X+u1Mb8BeSeg7UGxXLf9EdwMsZIGs9PhUL6titRBgNwAc0 R7vAin9+bCS4p/0Tl9HfHtJoIRUWleimK8KDxGOz6LuA8ZozXBRcwUuCoTwT+9nF4T06Nou/8fcvfF BSG0SkCgkr0ug2ebMP2txQ8gxIXcWKntvutRuw0xuKNeHWIGtg8JMccsidYwQ6l2D0q6FMDcE+K1QJ YU4/m+ZEpM1mrWDvBfI0i2fkC85s++MH3kuyyx15f8J6ZosClV6STeF5l8QBbZC5wWgoxEdV50MX+A QOOb4MBGs24mNWLO/oiPqGS21M141Fn88kp6/GifGhov5UAVvVKoaTEUseeA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Having a stable wchan means the process must be blocked and for it to stay that way while performing stack unwinding. Cc: Ingo Molnar Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Daniel Bristot de Oliveira Suggested-by: Peter Zijlstra Signed-off-by: Kees Cook Signed-off-by: Kees Cook Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Peter Zijlstra (Intel) --- include/linux/sched.h | 1 + kernel/sched/core.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/linux/sched.h b/include/linux/sched.h index 39039ce8ac4c..0c8185089e20 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2137,6 +2137,7 @@ static inline void set_task_cpu(struct task_struct *p, unsigned int cpu) #endif /* CONFIG_SMP */ extern bool sched_task_on_rq(struct task_struct *p); +extern unsigned long sched_task_get_wchan(struct task_struct *p); /* * In order to reduce various lock holder preemption latencies provide an diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1bba4128a3e6..4a30455e1ff5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1962,6 +1962,22 @@ bool sched_task_on_rq(struct task_struct *p) return task_on_rq_queued(p); } +unsigned long sched_task_get_wchan(struct task_struct *p) +{ + unsigned int state; + unsigned long ip = 0; + + /* Only get wchan if task is blocked and we can keep it that way. */ + raw_spin_lock_irq(&p->pi_lock); + state = READ_ONCE(p->__state); + smp_rmb(); /* see try_to_wake_up() */ + if (state != TASK_RUNNING && state != TASK_WAKING && !p->on_rq) + ip = get_wchan(p); + raw_spin_unlock_irq(&p->pi_lock); + + return ip; +} + static inline void enqueue_task(struct rq *rq, struct task_struct *p, int flags) { if (!(flags & ENQUEUE_NOCLOCK)) From patchwork Wed Sep 29 22:02:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12537977 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 39C29C433EF for ; Wed, 29 Sep 2021 22:04:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 174496124D for ; Wed, 29 Sep 2021 22:04:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346891AbhI2WGV (ORCPT ); Wed, 29 Sep 2021 18:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346848AbhI2WEE (ORCPT ); Wed, 29 Sep 2021 18:04:04 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E2C7C061770 for ; Wed, 29 Sep 2021 15:02:22 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id k24so4129487pgh.8 for ; Wed, 29 Sep 2021 15:02:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FXiCuxEPMvqVSi+g+P0evOsDZPlbh8jjQbS0s6wZm8k=; b=SRrGW9zo/d6XA0WfD3zwDEcbIo+Z1I96cCKPaPYXClI+Qfg8s9OJNo/xb7TEDE5aYr Ho17NV6HPaJkzNytOQUl6mp8zKXpU0ULv+wkVZg+EBUY+CEH/WHSNssW9o9ZppK3PwaO fhhITLjFDcaVBGI2nxkxo8lrt6URHO+miQv6Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FXiCuxEPMvqVSi+g+P0evOsDZPlbh8jjQbS0s6wZm8k=; b=UzeneQcRcwWKnS4sDE+lhKDZMDw03syr7Du04pGyCoZlmzPFVXW8EIfsOjbj0WeMzg opBZSDnWiGdZEei78t8fXbV+a6SLDw4YVKuzhtEH8BaAmvmriCbaV54digTm0nmYpga3 yBOB+SyxQiovPArpc05R2ACDApPuKXOGFCCfUgTr/P7Eq0GnqQntKFPnw8vMUZzPyVkt zAG3RZyrgmIRG2mVyIIc1dp+V+8pbVuYejZWZ9nFkZcc5cxjsRVrmyVY4wpKKvZixzYT mMEbXJZhqIb1i8SP9jzpunMJT/+MUV3CWyAEFSPkaGD5SeDek5JXlMSb2agMIDDUwbq/ fFwg== X-Gm-Message-State: AOAM53235+YWtwModMMIIZC5Ne8IigyEPtseGxtiqSChSduhg2l/mZEY CpeidtleKgOflBATodanLyn8Pg== X-Google-Smtp-Source: ABdhPJzliJ0RYWBweCHHWJ+P3Zmj4CAL9EDfVBAf9D4cTfaBNZUREv4N4JrivSvzlyTgfNZ7/6QD/Q== X-Received: by 2002:a63:1e60:: with SMTP id p32mr1903923pgm.234.1632952941938; Wed, 29 Sep 2021 15:02:21 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id o16sm561897pgv.29.2021.09.29.15.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 15:02:20 -0700 (PDT) From: Kees Cook To: Peter Zijlstra Cc: Kees Cook , Andrew Morton , Christian Brauner , Anand K Mistry , "Kenta.Tada@sony.com" , Alexey Gladkov , =?utf-8?q?Michael_Wei=C3=9F?= , Jann Horn , Michal Hocko , Helge Deller , linux-fsdevel@vger.kernel.org, kernel test robot , Vito Caputo , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Qi Zheng , "Tobin C. Harding" , Tycho Andersen , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , Mark Rutland , Jens Axboe , Stefan Metzmacher , Lai Jiangshan , Andy Lutomirski , Dave Hansen , "Eric W. Biederman" , Ohhoon Kwon , Kalesh Singh , YiFei Zhu , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 3/6] proc: Use task_is_running() for wchan in /proc/$pid/stat Date: Wed, 29 Sep 2021 15:02:15 -0700 Message-Id: <20210929220218.691419-4-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929220218.691419-1-keescook@chromium.org> References: <20210929220218.691419-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1702; h=from:subject; bh=vEcA8vhX2LIYTyny+lSt9vtrmOxzTbXuNEQhn5SMUqg=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhVOJo4pEo1xkbc20ffT7DBLQ7oi+h8cwMpfxIYeBP 9Dwzkr+JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYVTiaAAKCRCJcvTf3G3AJoEdD/ 9KIWtXlguBEKgRhhajeWO7Pq+iFfZvVJRNJmrg0tcqcStHiicYq1RMWEekffyqtSOir3ypL+ZJQjSF 6GDHvBFJh7991cXxetyQeqCTAKuTRoa5QBNJCbVfjQjoehkd1NR4BodXDO8xKDStibOXos+qMk7CBm Cz+QSk9v7a6MmB3IuTuNYKf5moDvV53v0OFtDA4714WSd5ShHTdMGUTZXLzHTprDTrIsdgUJDWcgwU NoE2htw5yghyl0k2oadQlfuXAL44IaBAvchMl13m3h7zgyIzy7KLWQExSSB1XshnESbPLqMU0N3xue 9Lfw/GNXEm+nJgzx85rt8cpn2deSM2SUnYiGPwwZDItrgLHxkd7MX8MygS+wIteE1AGdSus2UaIhlt 7t1hMuRkDzT7WkChhvwrSXHsyJhI01x+Igb6+RJ9j4EDiKXCkPd0v1p+0kzEJjAllijhODUtrKZ3Z2 atfnQ3RiRcuYjhlsadJ29M4C7rlbDE3TB2bKss8qHqUxOaTbQg7iDZ8XPr3Aqp4Gx4H6rxo7FyWtfO UgeXQf+UH1M+SV0t/DDebEW4zwUheVNQC7i6+QxMbEmHf5G6DWKoKCytjqMoemLz3MWCpuI7CrTAnw LE7THqJDnJuZVjESgcd7V8f6lxhoVL2AI2WJSi4sKEScJQLVH9CxLpOzqWkQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org The implementations of get_wchan() can be expensive. The only information imparted here is whether or not a process is currently blocked in the scheduler (and even this doesn't need to be exact). Avoid doing the heavy lifting of stack walking and just report that information by using task_is_running(). Cc: Andrew Morton Cc: Christian Brauner Cc: Anand K Mistry Cc: "Kenta.Tada@sony.com" Cc: Alexey Gladkov Cc: Peter Zijlstra Cc: "Michael Weiß" Cc: Jann Horn Cc: Michal Hocko Cc: Helge Deller Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Kees Cook --- fs/proc/array.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index 49be8c8ef555..77cf4187adec 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -541,7 +541,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, } if (permitted && (!whole || num_threads < 2)) - wchan = get_wchan(task); + wchan = !task_is_running(task); if (!whole) { min_flt = task->min_flt; maj_flt = task->maj_flt; @@ -606,10 +606,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, * * This works with older implementations of procps as well. */ - if (wchan) - seq_puts(m, " 1"); - else - seq_puts(m, " 0"); + seq_put_decimal_ull(m, " ", wchan); seq_put_decimal_ull(m, " ", 0); seq_put_decimal_ull(m, " ", 0); From patchwork Wed Sep 29 22:02:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12537975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44155C433F5 for ; Wed, 29 Sep 2021 22:04:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D38861423 for ; Wed, 29 Sep 2021 22:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347014AbhI2WF5 (ORCPT ); Wed, 29 Sep 2021 18:05:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346920AbhI2WEF (ORCPT ); Wed, 29 Sep 2021 18:04:05 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04F32C06176C for ; Wed, 29 Sep 2021 15:02:23 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id rm6-20020a17090b3ec600b0019ece2bdd20so3136831pjb.1 for ; Wed, 29 Sep 2021 15:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nyOyOlsEKGoiL/2uVNNvOLt4uOk9SOe6cJyNtLyvzOQ=; b=kRo9hk0UyGdTkqt77Dr046kgIcuTjrjw5oEmWNDGmgIBl3aWShjXYNka6SUmRqg4y+ ihdhFSMkv2SnJUrLFS5OtchqcINVW6hlSfuhT6JTuwYPaUP7/gcp/aGWaSEgDV5Agd5c 4o7rqV3x3NbwkCbiBVPZcUHUEl95/qr1hSJWg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nyOyOlsEKGoiL/2uVNNvOLt4uOk9SOe6cJyNtLyvzOQ=; b=dRT6eRRddxG2yk8tyYvSyX8h8HwEsE5fMmIRcO3Tc571tFu6egwMk9xW3W6EkluTT7 rU2GTHbrTIuUrfQpEmhm+PEFSUA3hGGUBJZu7esUbh3kXtzCoWNalt01d/5s6e0xrD5M qTewAKLI5GPyOl9/ZpCKUz3JeKqmMjdtcdEsLv8vyGiAgQ6z+NHnAfpnl9SOtSIydQlS i9yDCkBYBzg/rdx7FgR8joS5x4FUwDnD0MXB4Obhlvvtz2HHIMaYCKAYjjQNl1LAUN3N 1ClzYbJ8GiIXEib3xUDEK2HBQA6yEoA51vLtjMJut5R0Ukq8NgiNi2zl1ZSs8ln+Qliy odfQ== X-Gm-Message-State: AOAM530yojVtJh7UeJYflhkEVxnxdtHd0wydntBw7RYj2Ga4r0zzOOYa DP7j0od9mfzB3X8sv4MdKFaKpA== X-Google-Smtp-Source: ABdhPJwINc9gT+N/bpklJl0wNNp4lZVB77p5Vn7pgqDHE6xW6YcFnaW+8mOWThyWIb0j2VFrVYZYEA== X-Received: by 2002:a17:903:1103:b0:13a:1dd7:485f with SMTP id n3-20020a170903110300b0013a1dd7485fmr2107982plh.6.1632952943592; Wed, 29 Sep 2021 15:02:23 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u6sm574131pgc.68.2021.09.29.15.02.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 15:02:20 -0700 (PDT) From: Kees Cook To: Peter Zijlstra Cc: Kees Cook , Andrew Morton , Christian Brauner , Jann Horn , Michal Hocko , Helge Deller , linux-fsdevel@vger.kernel.org, kernel test robot , Vito Caputo , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Anand K Mistry , "Kenta.Tada@sony.com" , Alexey Gladkov , =?utf-8?q?Michael_Wei=C3=9F?= , Qi Zheng , "Tobin C. Harding" , Tycho Andersen , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , Mark Rutland , Jens Axboe , Stefan Metzmacher , Lai Jiangshan , Andy Lutomirski , Dave Hansen , "Eric W. Biederman" , Ohhoon Kwon , Kalesh Singh , YiFei Zhu , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 4/6] proc: Only report /proc/$pid/wchan when process is blocked Date: Wed, 29 Sep 2021 15:02:16 -0700 Message-Id: <20210929220218.691419-5-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929220218.691419-1-keescook@chromium.org> References: <20210929220218.691419-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1207; h=from:subject; bh=xZsf3ZWiO9WXhoaOn6NNrzDXL4l3Q1Xs8ZxRNuqWhk4=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhVOJp63g3iVewdohBr8uE9oIrIG7jiG9FYdaSRwEy c4fWtEWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYVTiaQAKCRCJcvTf3G3AJmhgEA CsnKYCJhMFtSI3AqsLX3bsDhyI7wOq0Saq/NYAqYCvCq9g4cXqSuOflggSmlTaoSXDpv5t2Dnlnhxz 6XhgODSU2KL6AIV7Fy+jvK5l62k1IiRhgq3BqvyxsGpcRiYVsik6JhDflr4NwuluohTHRgNvdj38Si 5mFYBHWH4qTJwB6j56IeldFcHhathjBQfoPmJJioTFrWmpd5rIzMf5I2GoUMT+H6tNXwXxOra6BmFD ZdM0yd/sVsTdUdSxsachoBzbrgmPtwk4vl7z8IE0G2LAWSh6xkKSVjoVBypZdqnOOkTme2MYotGxoi ImPZ7Pv9Q6scFffQJwaGyBmbH/cXII2T3lvZLSr+nzHEPxFLzj+RVn3vJdi14HncieRnjPFs/9deMO go4JYUKHkUkM0qn5j4CCvHytqWpNicubvOZ27WM+3YDzkbv47vJXP7/zdmEmSEBYIPiU2jcXjT3ZUL uhTd39ED9JDUa3X45f4Er/ROKGL4/6zNlt/COxx5+qJoEl4Kw3PLizNaC4avTg2x1dSW6a75b55M0k kPRNhOeU/1Xgz1usdvtu7DsJzoi1qzdutOczBLNrztztGqom8ClQZdA3Pwe8hV775H0zRNTYN4IgtG xmBgZw4AbucsLG+w1ab8oxXU9KpajHNUz/12TEuUah+9CYyT3/qTBz2zURQg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org The current get_wchan() implementations do their best to avoid problems when walking a stack given a process in an unknown state, but this is fragile and unnecessary. It's only useful to report wchan if a process is actually blocked, so use the new sched_task_get_wchan() instead. Cc: Andrew Morton Cc: Christian Brauner Cc: Jann Horn Cc: Michal Hocko Cc: Helge Deller Cc: linux-fsdevel@vger.kernel.org Signed-off-by: Kees Cook --- fs/proc/base.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 1f394095eb88..7853592778b2 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -392,7 +392,8 @@ static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns, if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) goto print0; - wchan = get_wchan(task); + wchan = sched_task_get_wchan(task); + /* Must only report symbolized addresses and never raw pointers. */ if (wchan && !lookup_symbol_name(wchan, symname)) { seq_puts(m, symname); return 0; From patchwork Wed Sep 29 22:02:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12537971 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDCCAC433F5 for ; Wed, 29 Sep 2021 22:03:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5412613CE for ; Wed, 29 Sep 2021 22:03:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346439AbhI2WFT (ORCPT ); Wed, 29 Sep 2021 18:05:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346846AbhI2WEG (ORCPT ); Wed, 29 Sep 2021 18:04:06 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 190B1C061767 for ; Wed, 29 Sep 2021 15:02:25 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id e7so4150927pgk.2 for ; Wed, 29 Sep 2021 15:02:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=24HVUmck1VAppvs7Tv/9xSBlIyZfrWIg2aOoPOSGCPk=; b=Z7lHWLK+hOMb6TEvynvt5OOVH+QHo2cH2h2k1Ry8FKJTYlHQETIp6IxEc+SmF1BeTX yJOzvuRU5hMPQzdYuHJ65wJIoEZw01G5PrAIGEON27gmtBXYz/wKT09kpuwkF/QySjet PmgwVIZDx7jTYnmGY8m2xgJopVcTncBlMz/2k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=24HVUmck1VAppvs7Tv/9xSBlIyZfrWIg2aOoPOSGCPk=; b=0vaIE2Y+JDGrPcQsfQTYJHu2pwFdoHWTiir7ru3w4sSiUne1ffau7F35d4sD2Qk2d7 F4pMmSTD2ABXQiuc0bMg9JTX4sTqua6YD3dKsJgOSZHhZtjgU3gJtzoy1kj+BOupoIpZ SRWHOQxufKW6dNO/jfsQSG+Tme0cDqft3cvr0n+xdWoegfPOulgUWBKsj4vdYoz9Cf1l bxByh56yGyUApHN06FYLmgJQZPTvQcvNdXecy1J10afDwe1Yxz5axD110j4VZTa+O1bC Lyb6P3MoO9LWeHg9+gG1elT6vEnTSwWNWjesMLTcRRosL3mH3JHqctHMhQmPrJjmpSh6 b9Gw== X-Gm-Message-State: AOAM532yxaGrUgykdPYFb/adosfj/X8TtVQ722aW8gXuvKPHMDHkW1OC ombIXpn98ifBUDuya8Au8T6voQ== X-Google-Smtp-Source: ABdhPJwTXGwIeBPVP+42Jds8fbtC28D1cwIq/SGc7KPzUX4XorS7Wwdx4edKqckr5//XoxuyCbyXgQ== X-Received: by 2002:a05:6a00:1a04:b0:44b:346a:2a25 with SMTP id g4-20020a056a001a0400b0044b346a2a25mr753024pfv.59.1632952944631; Wed, 29 Sep 2021 15:02:24 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u24sm720217pfm.81.2021.09.29.15.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 15:02:23 -0700 (PDT) From: Kees Cook To: Peter Zijlstra Cc: Kees Cook , Qi Zheng , kernel test robot , Vito Caputo , Jann Horn , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Andrew Morton , Christian Brauner , Anand K Mistry , "Kenta.Tada@sony.com" , Alexey Gladkov , =?utf-8?q?Michael_Wei=C3=9F?= , Michal Hocko , Helge Deller , "Tobin C. Harding" , Tycho Andersen , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , Mark Rutland , Jens Axboe , Stefan Metzmacher , Lai Jiangshan , Andy Lutomirski , Dave Hansen , "Eric W. Biederman" , Ohhoon Kwon , Kalesh Singh , YiFei Zhu , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 5/6] x86: Fix get_wchan() to support the ORC unwinder Date: Wed, 29 Sep 2021 15:02:17 -0700 Message-Id: <20210929220218.691419-6-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929220218.691419-1-keescook@chromium.org> References: <20210929220218.691419-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2627; i=keescook@chromium.org; h=from:subject; bh=Q52zDV9YajI3kkCmjslJF3Brs06bPq6a2KD+X5RLir0=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhVOJpPZoMxuXMkWZwnGRPVVYkoF0bnz3DmLyKHCXu Uc/LlKWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYVTiaQAKCRCJcvTf3G3AJhkJEA CSWLiYfLZArGwkCuomnnMwflTp76Al/53DgAspMiCGY+D9t1wxV/T0OQ+XuriYreg1Ob4OTVbSc7Ai MIFwyTGivV6BZBrE8hrDHjIUqcuKSeX4OU8TW9mDA79zmYv3etEQtpaliZi9F3ib9JuVjOJUKxBXly NXBX9p6RRX5RuxkNaiWIe1fiQfx4mF6ngBP+kyX40O6ZiIfnycCs6M9fqnaMf29HacI1kGKmfXieIL eZCQGdWLmGBwAaqhzhBcsPkPoCRmD+Z6NXu0xcwg7UeCQ2iwEOfdauHk/jIhQBy6eQ2ulLTqKHEFqV 22syyb7kEo3Nd0KxZGwIlLBko8LvmTaTgxNkOWSWBEycJgFO4z1myxXJath5y8VAxxJ9VL5VYQcE5E Rvi0MmCFsX1m9uW9jbtc8KHyJCH+Vosizn748Dgw/qV71Gb9cELpPnhe+qQxDw6kbw1/cklbxXc5n1 YrmgxCiKjSK6IAEcgHRKx/gQl/erbweNjGqeveXvp4hkKYd9YdLhRVVVeodSH32F105/S7GbYXGdzn NtN1ijRVXePtNwpGATDj8mNZfPIVZWevD0LHAFv1SnqnN2Y8yXFQx1bqThDITEct88Cuxujc2H7/kl bkSfx/sgrTI0SMpE9A+H4LKkTmQ1xD+aPxQ47C/a6x/lxMtP7AGoPiRrASmg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Qi Zheng Currently, the kernel CONFIG_UNWINDER_ORC option is enabled by default on x86, but the implementation of get_wchan() is still based on the frame pointer unwinder, so the /proc//wchan usually returned 0 regardless of whether the task is running. Reimplement get_wchan() by calling stack_trace_save_tsk(), which is adapted to the ORC and frame pointer unwinders. Fixes: ee9f8fce9964 ("x86/unwind: Add the ORC unwinder") Signed-off-by: Qi Zheng Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20210831083625.59554-1-zhengqi.arch@bytedance.com --- arch/x86/kernel/process.c | 51 +++------------------------------------ 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 1d9463e3096b..e645925f9f02 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -944,58 +944,13 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) */ unsigned long get_wchan(struct task_struct *p) { - unsigned long start, bottom, top, sp, fp, ip, ret = 0; - int count = 0; + unsigned long entry = 0; if (p == current || task_is_running(p)) return 0; - if (!try_get_task_stack(p)) - return 0; - - start = (unsigned long)task_stack_page(p); - if (!start) - goto out; - - /* - * Layout of the stack page: - * - * ----------- topmax = start + THREAD_SIZE - sizeof(unsigned long) - * PADDING - * ----------- top = topmax - TOP_OF_KERNEL_STACK_PADDING - * stack - * ----------- bottom = start - * - * The tasks stack pointer points at the location where the - * framepointer is stored. The data on the stack is: - * ... IP FP ... IP FP - * - * We need to read FP and IP, so we need to adjust the upper - * bound by another unsigned long. - */ - top = start + THREAD_SIZE - TOP_OF_KERNEL_STACK_PADDING; - top -= 2 * sizeof(unsigned long); - bottom = start; - - sp = READ_ONCE(p->thread.sp); - if (sp < bottom || sp > top) - goto out; - - fp = READ_ONCE_NOCHECK(((struct inactive_task_frame *)sp)->bp); - do { - if (fp < bottom || fp > top) - goto out; - ip = READ_ONCE_NOCHECK(*(unsigned long *)(fp + sizeof(unsigned long))); - if (!in_sched_functions(ip)) { - ret = ip; - goto out; - } - fp = READ_ONCE_NOCHECK(*(unsigned long *)fp); - } while (count++ < 16 && !task_is_running(p)); - -out: - put_task_stack(p); - return ret; + stack_trace_save_tsk(p, &entry, 1, 0); + return entry; } long do_arch_prctl_common(struct task_struct *task, int option, From patchwork Wed Sep 29 22:02:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 12537969 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 938C1C433FE for ; Wed, 29 Sep 2021 22:03:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A5446124D for ; Wed, 29 Sep 2021 22:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347042AbhI2WEw (ORCPT ); Wed, 29 Sep 2021 18:04:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346957AbhI2WEG (ORCPT ); Wed, 29 Sep 2021 18:04:06 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58F98C06176A for ; Wed, 29 Sep 2021 15:02:25 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so5208809pjc.3 for ; Wed, 29 Sep 2021 15:02:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1QzeUoqKUKdU45cYdDidDgQLqIck3N8SW7XLzzdbDWQ=; b=BOsK5j3gBTuXIo4JAyKTKnh5Y6FqjY5O6nb39X3/BEMzlOW69S8VBg9/Cyx402X0uC VX/hFTT8z3UwyDNLpYNgGyCtbxbAIco+EprvI+J0pXmbFfnxT/d78RlmJLnQ11mBalcR O80GyLP+BQjIy+cE6RbaI87yF/Et808MUydXU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1QzeUoqKUKdU45cYdDidDgQLqIck3N8SW7XLzzdbDWQ=; b=f8sOI8mNE6IrrJWLrKjGSmi2417H0sOaFtCpz35gKc17gZjfs5s91MyIcL01HMkYxm C5f2+mnBfxkqQU8l2ZPAg8jkOm2c5q30EeR7dMGdMSkm0UkTLbWlj691JUE297iTub1C 1UciBY/OeUnRxLNEYEWHeV7uFgCvufOx+EfdFrFJNLPioW4NizQ+WmUAZDRyShl6PYYq z/Pbzm14enABhT2aFrZhnV3WN7u0f6sWuy+2nNqvufI85LoIK6/1v0kvAAS3MUuUmGhr CqN+/g4T5UszSnSdCjvqSG1jrhbvYI6GDml47oe2cy9y1OlsrvqgWLg024y19SziBCb1 7J3A== X-Gm-Message-State: AOAM530mK11hhrxjo9ViaaX/o9LEwhmLlfmxsZSwwlp3yA0XHwsEybsX CcCVSW/rReMshokaKtaMwgX5cA== X-Google-Smtp-Source: ABdhPJyYAgg64aWsOOg387OZcNjUHpe2vAG1a6SQuAqSkmq2/IZophCGC6DN2YrUFepeRzTUc2Qvrw== X-Received: by 2002:a17:902:d202:b0:13a:709b:dfb0 with SMTP id t2-20020a170902d20200b0013a709bdfb0mr2069664ply.34.1632952944925; Wed, 29 Sep 2021 15:02:24 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id p2sm576691pgd.84.2021.09.29.15.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Sep 2021 15:02:23 -0700 (PDT) From: Kees Cook To: Peter Zijlstra Cc: Kees Cook , "Tobin C. Harding" , Tycho Andersen , linux-hardening@vger.kernel.org, kernel test robot , Vito Caputo , Jann Horn , Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Andrew Morton , Christian Brauner , Anand K Mistry , "Kenta.Tada@sony.com" , Alexey Gladkov , =?utf-8?q?Michael_Wei=C3=9F?= , Michal Hocko , Helge Deller , Qi Zheng , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , Mark Rutland , Jens Axboe , Stefan Metzmacher , Lai Jiangshan , Andy Lutomirski , Dave Hansen , "Eric W. Biederman" , Ohhoon Kwon , Kalesh Singh , YiFei Zhu , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, x86@kernel.org Subject: [PATCH v2 6/6] leaking_addresses: Always print a trailing newline Date: Wed, 29 Sep 2021 15:02:18 -0700 Message-Id: <20210929220218.691419-7-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210929220218.691419-1-keescook@chromium.org> References: <20210929220218.691419-1-keescook@chromium.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1034; h=from:subject; bh=gRG/Q2MrocgVaHNX+D6+wn0nA1KaXO0grvA92z8kHco=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhVOJpJCOqg+W5SWXrgp1mr8bnFhnfCdWico8ZwiP5 /UURmdWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYVTiaQAKCRCJcvTf3G3AJh9EEA CGh7l0IuvGKvTlNBIftnvwHCcGybMPaL+NoLj8Q2pXBA286EzXeLUQMmzKYZ8Nd9Nz2b9zwZkYGFRn PD8E1mcA5i6fvu1E0EnKJhbDAdHu2HrYMl6sQbDO7ktRye0z9jfjZ5VfiXQkY+EqKyoz7DCwn04XDr nMHuX2tbkdllWdOu8RKgWHg5WiCl1pp8gfuvx3HD0cAx/Wmbml34p/9tSmWXZnxgLKdkrpyme7jiwY lQxgNRV3i85T6cdRJIa9oIrU8GC5UGWW+mb43gH0xJC8rCj7WTZ7TtsfR18cQDwqyxRanWyV3v88sX 3VHTBz5vZe/nZ/e42QZmevNF/CtrpFcN4lYBc2oCEcdMcP2/mTy9ZZpGD6fGzjauMPq3et29rhgaai ulI53iwA+nb45Ws2ySpyuTPH0+I2YRBOhTr3lpxIoYq1NN8UqvWUYdhu1JoV4DGiVxqv6qrOBNyIiV vjtDjdVlLIXK/PlarcJ6tWCNYQmJmhS7d+BALx2PAmCOx67kEdCxKwTIJs9VJ6ETDPUORKDTR1bnod qMHp3dMi2rSDxypc+un39fnjpynqpAO4GHycrr55/PQkJJ1MO/Ttp8264Njz8ekWOv4EBIsRCLKdEu ibXp6FkICQ7j4zsLYQN9LiqRuG9CTkBP2B83gbSNTQSmQ+gu+KfS3wGGABrg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org For files that lack trailing newlines and match a leaking address (e.g. wchan[1]), the leaking_addresses.pl report would run together with the next line, making things look corrupted. Unconditionally remove the newline on input, and write it back out on output. [1] https://lore.kernel.org/all/20210103142726.GC30643@xsang-OptiPlex-9020/ Cc: "Tobin C. Harding" Cc: Tycho Andersen Cc: linux-hardening@vger.kernel.org Signed-off-by: Kees Cook Acked-by: Tycho Andersen --- scripts/leaking_addresses.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl index b2d8b8aa2d99..8f636a23bc3f 100755 --- a/scripts/leaking_addresses.pl +++ b/scripts/leaking_addresses.pl @@ -455,8 +455,9 @@ sub parse_file open my $fh, "<", $file or return; while ( <$fh> ) { + chomp; if (may_leak_address($_)) { - print $file . ': ' . $_; + printf("$file: $_\n"); } } close $fh;