Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1066352pxb; Thu, 23 Sep 2021 17:26:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOdd2TOtkoy1kZrXFT7NAxxYoBIUbCtbU5ua24fKP7CND7nX+aBLhN3C+ZaknxMTyv9mRq X-Received: by 2002:a17:906:6b1a:: with SMTP id q26mr7922425ejr.185.1632443178071; Thu, 23 Sep 2021 17:26:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632443178; cv=none; d=google.com; s=arc-20160816; b=btFQR63MQaz2ALa8p1/SM3APbaChbexOjIJTY1ra1pVReLHAzuKG9va7QZwZefgmFe PhD4Eebcujvv0cLlKVEwmEbYncSRkzEorwWo9LqIS/tofUKIkYdG9EjZVwh/j2w789T5 waAyUV7lRmqWP6ebzPrs9k4Vuh5kDvRvo9iSweeBJXf6tm6ZkWVQinNAJvYn+QzxNsZ/ IYUkKLb0DTzu4a8om7/lHh2Zf5M8TwdBUfJWC3GVNGq+d9ggFhDACF17lw44ldHubQs6 MdlG3K20OSVr7RLzN/492bLpsTPKBuB/AZoT0dbWMvgJYJLKqvUABwi9/5zPURcL+fJh cFDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=1Ik22PbANCYLSzbfZ8+AvNvgjDhA+hF9dmfPyLaISH4=; b=KbzamlWA94ps83xpVeeGHSb5kbJiUepEC+bEJTIURjxNu3wDvIIThtjVUUmx1D0X93 snGb+SAcstuA53yEDh94XRyZ6qCkOpFNXRkraoDF5WxrtibBsYYohF0krEuIktFHLc14 d2ZVjJLN8iQwyO/pOC0KWaTcrgVGTYeJUE2WcN56rh3/ysvzxkTIIYlH4Mt+gcP5SrPu M/9YWGRz6rbv0rWT+JfNVQMF5A6fTG3lubt/UIPcmssrD3X1wbqkph4aubzjVm7AA+vd 1XH0x9/QbLi5ID1zY9+MGOzpNtYDzfejIDQox5fGUqRmytQ8DY883d8BSkCXpsvDhtaJ V3Gg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gs9si7912277ejb.760.2021.09.23.17.25.51; Thu, 23 Sep 2021 17:26:18 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243599AbhIXAYE (ORCPT + 99 others); Thu, 23 Sep 2021 20:24:04 -0400 Received: from shells.gnugeneration.com ([66.240.222.126]:37182 "EHLO shells.gnugeneration.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243602AbhIXAYD (ORCPT ); Thu, 23 Sep 2021 20:24:03 -0400 Received: by shells.gnugeneration.com (Postfix, from userid 1000) id BA2931A56019; Thu, 23 Sep 2021 17:22:30 -0700 (PDT) Date: Thu, 23 Sep 2021 17:22:30 -0700 From: Vito Caputo To: Jann Horn Cc: Vito Caputo , Kees Cook , Thomas Gleixner , Josh Poimboeuf , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Jens Axboe , Mark Rutland , Peter Zijlstra , Stefan Metzmacher , Andy Lutomirski , Lai Jiangshan , Christian Brauner , Andrew Morton , "Kenta.Tada@sony.com" , Daniel Bristot de Oliveira , Michael =?utf-8?B?V2Vpw58=?= , Anand K Mistry , Alexey Gladkov , Michal Hocko , Helge Deller , Dave Hansen , Andrea Righi , Ohhoon Kwon , Kalesh Singh , YiFei Zhu , "Eric W. Biederman" , linux-kernel@vger.kernel.org, x86@kernel.org, linux-fsdevel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] proc: Disable /proc/$pid/wchan Message-ID: <20210924002230.sijoedia65hf5bj7@shells.gnugeneration.com> References: <20210923233105.4045080-1-keescook@chromium.org> <20210923234917.pqrxwoq7yqnvfpwu@shells.gnugeneration.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 24, 2021 at 02:08:45AM +0200, Jann Horn wrote: > On Fri, Sep 24, 2021 at 1:59 AM Vito Caputo wrote: > > On Thu, Sep 23, 2021 at 04:31:05PM -0700, Kees Cook wrote: > > > The /proc/$pid/wchan file has been broken by default on x86_64 for 4 > > > years now[1]. As this remains a potential leak of either kernel > > > addresses (when symbolization fails) or limited observation of kernel > > > function progress, just remove the contents for good. > > > > > > Unconditionally set the contents to "0" and also mark the wchan > > > field in /proc/$pid/stat with 0. > > > > > > This leaves kernel/sched/fair.c as the only user of get_wchan(). But > > > again, since this was broken for 4 years, was this profiling logic > > > actually doing anything useful? > > > > > > [1] https://lore.kernel.org/lkml/20210922001537.4ktg3r2ky3b3r6yp@treble/ > > > > > > Cc: Josh Poimboeuf > > > Cc: Vito Caputo > > > Signed-off-by: Kees Cook > > > > > > > > Please don't deliberately break WCHANs wholesale. This is a very > > useful tool for sysadmins to get a vague sense of where processes are > > spending time in the kernel on production systems without affecting > > performance or having to restart things under instrumentation. > > Wouldn't /proc/$pid/stack be more useful for that anyway? As long as > you have root privileges, you can read that to get the entire stack, > not just a single method name. > > (By the way, I guess that might be an alternative to ripping wchan out > completely - require CAP_SYS_ADMIN like for /proc/$pid/stack?) WCHAN is a first-class concept of the OS. As a result we have long-standing useful tools exposing them in far more organized, documented, and discoverable ways than poking around linux-specific /proc files at the shell. Even `top` can show WCHAN in a column alongside everything else it exposes, complete with sorting etc, and I've already demonstrated the support in `ps`. I also think it's worth preserving the ability for regular users to observe the WCHAN of their own processes. It's unclear to me why this is such a worry. If the WCHAN as-implemented is granular enough to expose too much kernel inner workings, then it should be watered down to be more vague. Even if it just said "ioctl" when a process was blocked in D state through making an ioctl() it would still be much more useful than saying nothing at all. Can't regular users see this much about their own processes via strace/gdb anyways? Instead of unwinding stacks maybe the kernel should be sticking an entrypoint address in the current task struct for get_wchan() to access, whenever userspace enters the kernel? Regards, Vito Caputo