Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1037617pxb; Thu, 23 Sep 2021 16:40:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydtCj/I5otbi8LhMb0cvObNGJ/Zp+oHo4S1rXV80qFNv5VEMuu4dgFxHCzHIeoG6P614W5 X-Received: by 2002:a5e:c018:: with SMTP id u24mr6378095iol.129.1632440414965; Thu, 23 Sep 2021 16:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632440414; cv=none; d=google.com; s=arc-20160816; b=f8FDZG5a1UwdaEps0U++BruaW4ngA6lyIHO97LvQEu/mPn3L1kU7mKn5KOxqE6Rggt 8UskeiHvfte5596ttICCXo+84bdsh+cj6Y46hBkP8tCP1/FOsnl69rHhvAsnNw+f1ueX tD4105pR2faQ32aDqWx8dqGYsnmfIferjZJcWVhjVdlTfzrUcGkG6qbcZDtKJHJe4whJ 0wwnCX5f4eIf+m20F17Pxfo+MN9idK8K3RXp80q+RTNmvvRkbqNki8DxiGLI+JCVQGSW 21gKUyG0BJxpa+PvL3XGykXONLLAUhCJMmnF//ioX/B3+gVXvFNS1lQwMYWUpbr5jhiM WBBw== 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:dkim-signature; bh=5/WAgNALfvsB4KP6m0qi12xIQRzUGya+l2VNZgSQQFs=; b=ccDy4iAQu6KuOxG4IvFxFShiuV1Am6YHNxQvKAtC0T1egPbICLUAdKSBAXDkJqq+dN /EU1CKgADFrF07h0bSgZdassyhJ+kkxh6YhyAvjucrsSxCzX4BnK4axi5vVAvK9Jbm0u tBB1mUKuLT/3RNPAeX2J7EETAZ/L0ouzoIiyg790P8z+K/ukR+7WdmH678frBl2soXay uhpEz4ZvQg1Ar0qSx0zeB7r++vUn5l9GW0IyVDpt36AZWvCRHL9FTXO/72CBZ6BoSRma WbPLrQrU3m4BDOl3jQ9R2ZqZyG+So+2R2RmSmz34s7SWmnPEHCBI7mysGveCyzcr8Oba b4NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=UUrHZBh8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m16si9734264jat.53.2021.09.23.16.39.59; Thu, 23 Sep 2021 16:40:14 -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; dkim=pass header.i=@chromium.org header.s=google header.b=UUrHZBh8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240661AbhIWXkB (ORCPT + 99 others); Thu, 23 Sep 2021 19:40:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243550AbhIWXkA (ORCPT ); Thu, 23 Sep 2021 19:40:00 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1C63C061756 for ; Thu, 23 Sep 2021 16:38:28 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id k23-20020a17090a591700b001976d2db364so6043982pji.2 for ; Thu, 23 Sep 2021 16:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5/WAgNALfvsB4KP6m0qi12xIQRzUGya+l2VNZgSQQFs=; b=UUrHZBh8vYnktVCpv8EX35Ama1oym9Nh8GVSqcMGyZtB/zI51bp8GnrNlnumoMvDLP pL7TtKl+bSA9hnB6pHh067v8/9z4C6BV6aiHOfxHoDTsSJffSTxgttXCfcoVAH35RuHK vFuKm1/WezYhGxxQhvrW2Fc7WpGP4+ohknJ3Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5/WAgNALfvsB4KP6m0qi12xIQRzUGya+l2VNZgSQQFs=; b=MUakQWo8OtI2RSP0PGr58Yu0lGSdk9TchJWiBq86VIaP1KlShAcHGtvjKa9gV5RA2S 1HB72+iWBKAQtu/htsriQ2bIELp/7nOjVR8JHFGdWZ2jtZnOtdoUSMlKMr8x2dDS5VL/ WVfLvMz2f1ac7TFPIj7UWHdAkFFrI0ZKN3JH4jTZkQl4ngpvmKzFM2iA6NDf0iEsfUCO 5uSIf7H56dBrI+QHNj/bd2Sbl4mIDvXo6xQBYsRMpZEQlQ8Cg8xFc+YIRnVxGcTncs9y Z9N8vsriA/G6fidMGXqupG7aOkfQ9rWDhWId5k8HqcDGiNosY8WCshxO93SyhBDWB9tz bGrA== X-Gm-Message-State: AOAM531jQOwoPHs2NCsCWn9qFmq5sBE86EwGxbDPjk2/4NA4TT2u9nsR 904gp+phD9onun7QRvq/Jq5mng== X-Received: by 2002:a17:90a:aa14:: with SMTP id k20mr20461715pjq.88.1632440308367; Thu, 23 Sep 2021 16:38:28 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h16sm6423013pjt.30.2021.09.23.16.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 16:38:27 -0700 (PDT) Date: Thu, 23 Sep 2021 16:38:26 -0700 From: Kees Cook To: Qi Zheng Cc: Thomas Gleixner , Josh Poimboeuf , Vito Caputo , 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 =?iso-8859-1?Q?Wei=DF?= , 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: <202109231636.C233D6D82@keescook> References: <20210923233105.4045080-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210923233105.4045080-1-keescook@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. I forgot to CC Qi Zheng on this patch. Now corrected. :) > 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? If the fair scheduler would actually benefit from still using get_wchan, I think this patch: https://lore.kernel.org/all/20210831083625.59554-1-zhengqi.arch@bytedance.com/ should still be applied too. If not, we can rip get_wchan() out completely (across all architectures). -Kees > [1] https://lore.kernel.org/lkml/20210922001537.4ktg3r2ky3b3r6yp@treble/ > > Cc: Josh Poimboeuf > Cc: Vito Caputo > Signed-off-by: Kees Cook > --- > arch/x86/kernel/process.c | 2 +- > fs/proc/array.c | 16 +++++----------- > fs/proc/base.c | 16 +--------------- > 3 files changed, 7 insertions(+), 27 deletions(-) > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > index 1d9463e3096b..84a4f9f3f0c2 100644 > --- a/arch/x86/kernel/process.c > +++ b/arch/x86/kernel/process.c > @@ -937,7 +937,7 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) > } > > /* > - * Called from fs/proc with a reference on @p to find the function > + * Called from scheduler with a reference on @p to find the function > * which called into schedule(). This needs to be done carefully > * because the task might wake up and we might look at a stack > * changing under us. > diff --git a/fs/proc/array.c b/fs/proc/array.c > index 49be8c8ef555..8a4ecfd901b8 100644 > --- a/fs/proc/array.c > +++ b/fs/proc/array.c > @@ -452,7 +452,7 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, > static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, > struct pid *pid, struct task_struct *task, int whole) > { > - unsigned long vsize, eip, esp, wchan = 0; > + unsigned long vsize, eip, esp; > int priority, nice; > int tty_pgrp = -1, tty_nr = 0; > sigset_t sigign, sigcatch; > @@ -540,8 +540,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, > unlock_task_sighand(task, &flags); > } > > - if (permitted && (!whole || num_threads < 2)) > - wchan = get_wchan(task); > if (!whole) { > min_flt = task->min_flt; > maj_flt = task->maj_flt; > @@ -600,16 +598,12 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, > seq_put_decimal_ull(m, " ", sigcatch.sig[0] & 0x7fffffffUL); > > /* > - * We used to output the absolute kernel address, but that's an > - * information leak - so instead we show a 0/1 flag here, to signal > - * to user-space whether there's a wchan field in /proc/PID/wchan. > - * > + * We used to output the absolute kernel address, and then just > + * a symbol. But both are information leaks, so just report 0 > + * to indicate there is no wchan field in /proc/$PID/wchan. > * This works with older implementations of procps as well. > */ > - if (wchan) > - seq_puts(m, " 1"); > - else > - seq_puts(m, " 0"); > + seq_puts(m, " 0"); > > seq_put_decimal_ull(m, " ", 0); > seq_put_decimal_ull(m, " ", 0); > diff --git a/fs/proc/base.c b/fs/proc/base.c > index 533d5836eb9a..52484cd77f99 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -378,24 +378,10 @@ static const struct file_operations proc_pid_cmdline_ops = { > }; > > #ifdef CONFIG_KALLSYMS > -/* > - * Provides a wchan file via kallsyms in a proper one-value-per-file format. > - * Returns the resolved symbol. If that fails, simply return the address. > - */ > static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns, > struct pid *pid, struct task_struct *task) > { > - unsigned long wchan; > - > - if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) > - wchan = get_wchan(task); > - else > - wchan = 0; > - > - if (wchan) > - seq_printf(m, "%ps", (void *) wchan); > - else > - seq_putc(m, '0'); > + seq_putc(m, '0'); > > return 0; > } > -- > 2.30.2 > -- Kees Cook