Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1032883pxb; Thu, 23 Sep 2021 16:32:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1itbwuj9VCrrKW67/cHubyiIlHnS0vOZFoh0E8jyaARlCIViS4ObeH253oVIQsNFbpQYL X-Received: by 2002:a05:6602:2188:: with SMTP id b8mr6198103iob.217.1632439925826; Thu, 23 Sep 2021 16:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632439925; cv=none; d=google.com; s=arc-20160816; b=LfoV8FAw2BQr0tWEb94gIaHZTixg5VVx6AEkzHDRg9JrsRmcLEFxMsXkO1Fs6keMEW YBsznd0s6UNBgYjjBBBYairQn7q0u6iGSG1FicspyNejYyxXohF571tsQ/cqcviAwxd0 aSR7WbiU+7vnI9Bzu0JpcF1WkhegFEB7NvGAetom0YEURRf+L3gXTtycKmWc7RYrykfi 0C1CTLIKfo+Tj3gzFbtguiEpzJcEjQLiTKTVJuaDdVv+8R8hOBZMeeU3SyoW6p16LEYE ZoNyWBPnRZmNPvvYJ+PRez2yVDIXL/EIpIj4w2J0VaFLzC6TEu2Z3ZBjSYPcdUFjPusc 627g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=K4JmpLMfEZBQDMzNklJ8FfcrVNZ01v7mucqNK5/dyZM=; b=HNcoQ2ZMSoo3/LcdHnX+Uewij0WYDRGQyejuO8KkdvOjuIZoxRkBtMuM2RcFeyC1OC 7i/SC6BPZFLNSv8FMIx4x1o9zPCaI/zoTjvlXGmBrIQI5ZTsuz6r1n2UwbATLvqSKu4Y cxs8kd/aBVlS1AqY/EiJK297avzzc+eQ4faxtYpr6POLEuMUXu6f19lyXJjACUTgu5mJ zJ9xkVIwN52Kh7MgKVgG+RG3CSfiqmicgLaysmLOtDYHjHZlhaqquq4eh4zq0zb5zQQe fgbFCD6sO7HYTp/e3TaFkzun/Yi9yZ62OAf0b5lOfkUFSb+5ecBG1v58AuWj1n+gvBGd iDiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=gkAVQneM; 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.31.52; Thu, 23 Sep 2021 16:32:05 -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=gkAVQneM; 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 S240717AbhIWXcl (ORCPT + 99 others); Thu, 23 Sep 2021 19:32:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235628AbhIWXck (ORCPT ); Thu, 23 Sep 2021 19:32:40 -0400 Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E881C061574 for ; Thu, 23 Sep 2021 16:31:08 -0700 (PDT) Received: by mail-pg1-x52a.google.com with SMTP id g184so7966971pgc.6 for ; Thu, 23 Sep 2021 16:31:08 -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:mime-version :content-transfer-encoding; bh=K4JmpLMfEZBQDMzNklJ8FfcrVNZ01v7mucqNK5/dyZM=; b=gkAVQneMwXP7Huc8zYfsd3+1f1zM7FLbbtgibwzhZyhgU55BgV5tzOdFE2ZrWDtWUf 22jHQ23C2B5DLppVf2q47Bd9BXZqXZbQmnCrUcB8gFHbJLpluqB/XOUCpBrsHQKnL+dT s104HCmPGY6HjNHsGhc1d+aSlUPg7supgiI/0= 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:mime-version :content-transfer-encoding; bh=K4JmpLMfEZBQDMzNklJ8FfcrVNZ01v7mucqNK5/dyZM=; b=4n883QUx4I83M8D517CX1iwABs/W8gmu+vLDtLbJ9KUMvW+hYsY37vgt4KTN0dQbWq F52pMGOcTtGaAr2zqMKT0qSzosyRWfom1U1qdinkHHTPxJgWoq1HbKPMXS36/MgvSJp+ yPdEHN0vf6Q/nQPuf9eUmRx40s3JNzeK4vOu8ZLFIDroC7zSRSi4ufgsw3XKX1M/+ym+ ed5gh5ZNozqvYsX4xxgYppy6sNf+8I/OJk70IPGNaCTnFnP/M24UQCc4T9pB0bRynFmb vkBlvRAl6/x7+njdabjFttO/Yr4En6GH7DVbk6mKAcwiPO4uUPZug/IaJ0mIhL2DYOkQ hnEQ== X-Gm-Message-State: AOAM530XCraWy4cX7P8Xe40eRdbtplOjmWNtmtqYv4AYc/Vn3rG2bH59 UTXxssry2eaOGu/mAZ8jvonn5A== X-Received: by 2002:a63:595f:: with SMTP id j31mr1147183pgm.109.1632439868090; Thu, 23 Sep 2021 16:31:08 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g15sm6628254pfu.155.2021.09.23.16.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 16:31:07 -0700 (PDT) From: Kees Cook To: Thomas Gleixner Cc: Kees Cook , 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 , =?UTF-8?q?Michael=20Wei=C3=9F?= , 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: [PATCH] proc: Disable /proc/$pid/wchan Date: Thu, 23 Sep 2021 16:31:05 -0700 Message-Id: <20210923233105.4045080-1-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Developer-Signature: v=1; a=openpgp-sha256; l=3943; h=from:subject; bh=U7oablg1sEKMje5UnBxNq5+kJW+PeEznOm0x7d0aYaI=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhTQ448wi0wTXGV8xEtY6E/CSU09UrdLNeiRXpCrh6 PoRw46mJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYU0OOAAKCRCJcvTf3G3AJiL3D/ 431c8P+vVpq52hw+H+OcLEs36FHusT1bdXUKccVVKLCHKpzUoI+dv/3CNx8vVD0c91XAVZ5gS5LOw8 Gc6QB0slsnBq6QeOXcmDSbO804cI3t62G0hyfBR3nzzQcx5EIlHOaSprFC6bv5WsbciVfNyarKZszP 8h1XiwaIOpzAluyGupS82TzsPEIK4qK/kf84J3c5SnxBaYDBaF8VwlapazTz0ioYt19SvV+2LwQuMu ViEGXi0++E+6zGLibw0QFNByU5pUQ87QaXoNYkk3G9OqQWQomVtC7r9hecBqylypGB81zHpR71Kp4f 1rAFHLjhRBIHMccBpMaR6Ctvn9cXdHbpdoHOgxTrAvq6dstt9mAutFMmcm5DenSceLRih93BpxcEbJ g+lICZwWoM66jLpQrS4Z4fxl6zvr4JwcK7BFgs7uX8oVbHf2/1qfawJ03f0fjt0t5wjuGry3SlwXtj PvEW87KK3u4N8eN+bMCjTcgCebhYL+i/a0H8rMyYT7gnEdhBTBnQBxPoiu0mlZLhvs7HxeO6fK+By2 87ViZG2+v+LimtPlO43Vstw4A0UE50JNHwjPI+JiZqwyo+jLTGUpduK1sp8BXTeLLUi7A491jg+BSV lnU0IozaYhGmrkDOZQRN95E7I5mZR4u3SSbOx1SquO5EFCG8l9+agPOxonSw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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