From patchwork Thu Nov 17 23:43:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13047483 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B982C43219 for ; Thu, 17 Nov 2022 23:43:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50E308E0007; Thu, 17 Nov 2022 18:43:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4474D8E0002; Thu, 17 Nov 2022 18:43:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29AEA8E0007; Thu, 17 Nov 2022 18:43:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0BBE78E0002 for ; Thu, 17 Nov 2022 18:43:35 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DA5CD80283 for ; Thu, 17 Nov 2022 23:43:34 +0000 (UTC) X-FDA: 80144563548.08.968D651 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf26.hostedemail.com (Postfix) with ESMTP id 7AC8814000C for ; Thu, 17 Nov 2022 23:43:33 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id w3-20020a17090a460300b00218524e8877so5830120pjg.1 for ; Thu, 17 Nov 2022 15:43:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LPxyAZmVFIQ+hzeHNDklOMYnt0nT5zaSRXR3AKVl0no=; b=CAnKSUlMijYM3oVNjTZMp+QYoCaxz54Tvn3HQZid0a5tCbxs2wTS7qkaFFagJiUS4o vZ80dfmkV08AIKBz7/JDfnIUWIOQTe8o9D+UJybk1RQ1IAtZ15Nt/LroPCWZXlTywlCK pEuPftQpieWwcSn3Zz3nK5otvgpihOgdX6Qyo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LPxyAZmVFIQ+hzeHNDklOMYnt0nT5zaSRXR3AKVl0no=; b=gQEo7z7NigIIZ9MX/jGAgP8Nnk2cATMVwuFOuLQnD4blGowEnhcwTmJVW0yWsRfEPZ BiWs1V9A/IrF0IhzhaprnQhNFPnZvQjJNg40KHzUVr5sSHtvWHUr8mFDqUW+D4GD8lhe LylBsaJkaVl2bLNQ8PwxCL2oqeJLCIdUdREjXxaCt4DDogeQe034XIL7Xervj0nSPh3s F78ZJiSQzhr7/MSTYX3fb7aLcdWFsrdr+dx5Uodo5Cl2V91mhcDJJ0Iqbvr7LkmK8VoF mFIw9MdKeP2eURQh09tpBAAFa5QS0XcEP/YBRko9kqpjQm+a2oKHFVWHU7ORXRVL0wxt dmxg== X-Gm-Message-State: ANoB5pk5ah8IqRMFl2ULj5EAca9zmEG6O/iGmCLE7q43iX2W0nLSmMYb CkvLpmAykq+6dwavWnuoqx6Ffw== X-Google-Smtp-Source: AA0mqf5/HPUPf8kTcojd23Y21MDR9j+2oe33EmCLeeB5s1/w+jLFfaLm0IoriYNIk05T+q106xmteQ== X-Received: by 2002:a17:90a:dd83:b0:218:61bd:d00d with SMTP id l3-20020a17090add8300b0021861bdd00dmr8381157pjv.236.1668728612350; Thu, 17 Nov 2022 15:43:32 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id w184-20020a627bc1000000b0056bb99db338sm1763850pfc.175.2022.11.17.15.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 15:43:31 -0800 (PST) From: Kees Cook To: Jann Horn Cc: Kees Cook , Petr Mladek , Andrew Morton , tangmeng , "Guilherme G. Piccoli" , Sebastian Andrzej Siewior , Tiezhu Yang , Luis Chamberlain , Seth Jenkins , Greg KH , Linus Torvalds , Andy Lutomirski , "Eric W. Biederman" , Arnd Bergmann , Dmitry Vyukov , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Daniel Bristot de Oliveira , Valentin Schneider , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Vincenzo Frascino , David Gow , "Paul E. McKenney" , Jonathan Corbet , Baolin Wang , "Jason A. Donenfeld" , Eric Biggers , Huang Ying , Anton Vorontsov , Mauro Carvalho Chehab , Laurent Dufour , Rob Herring , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v3 6/6] panic: Expose "warn_count" to sysfs Date: Thu, 17 Nov 2022 15:43:26 -0800 Message-Id: <20221117234328.594699-6-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221117233838.give.484-kees@kernel.org> References: <20221117233838.give.484-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3097; h=from:subject; bh=D2z//ezLIcXAbCg09JRiGI8OFvfo+V6hl+TtnONC3LA=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjdsceSurFVH4Xz0byr7qjcNZv7p7TUAKJ01o1LaCS il+61kOJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCY3bHHgAKCRCJcvTf3G3AJrZqD/ 0XXgpqckv3Sl3gOzRU8XGOhhTKNCgley3+PyzCJRtiQH47toEntYyvD9vFmODaSLhG1FiyD30a+PUs G7BgQa2k5SXXu1y/m/LEYrgI+Ka82BZRjN3oncSn6Gj1sGbXDiyXNgFu2e7l3f5j0GuuPciyXT5UaC Whh7g6SSpQlWFg6h1VXkWltmzGxJmgVINVIrm35KuAdSyHO3fh2FDZDFbYgC7Zw5VEZQWZGwFRZKlq fZ2NQCYYViH28pOLbjsQelxISmwyjMc+u8Si72QGiSXyQDGontB6hLEn6ri71jOmtQC2fi1PaCVFse OlWZA3mp10sfh98TdxKylYukslvpvusA+K5MQpXzq1tksDtB8jEjaCMbaiVfi0VDO+HWdplKdRZ2+e n0Us8b6qHL08DRQD/d5Iyo3nKHoDU7W22eM6TKwdRh1VOt5OxabohHDHQQAQSKLRmVdRuK4voUVG2z WTiHCwgHCUaqjBbTFhP0qQEkOrInX+5FbG+pTGdqZYZkv2f092vx6VJEu8Z8BO3LF5bC2BFaiheOTK xh8e8bMHCJ2MM9mzid34rIfE7sSTbJVFhVblpoFmXm9S5J9GpgTITDTaHoCWUeeMuoxo3kOaCKuojk rVwdTZGGHPl+RyJg5fYfmDe+KCV0g0DLqAai97luhkgJ180YHwMEsAH3AtwQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668728613; a=rsa-sha256; cv=none; b=flVAGCMs4c0fXfk/9AMTwvwcdCWzDyMl3olAOlAuEIAjrGZFh9qPCwXYi7U2fOdyNmXyq0 hZc31N2bw98WHzOmgmx1F3bENa28AG/ABSny2dl9fYWFl6m3W0jQKXSIKqrQnx4qkKT2oj zYD1UTcL96vaEL7aL6PbsDkww1mo8zo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=CAnKSUlM; spf=pass (imf26.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.50 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668728613; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LPxyAZmVFIQ+hzeHNDklOMYnt0nT5zaSRXR3AKVl0no=; b=YQGdxEZ1LQn4C0h0EvtNHlbyLmD6zbKBy3KXwhmGP/6DJUkieIoYPcX240SQIKB2xn9Y66 iSK2afp62rzLiki0+qywLQZEm3z0TH2YH2DMd6A4ICGVmZPCcSx/c404CPwzgtb+tTV7av b+EZYLVJcydNXrigwVoq+UO9K+25Tf0= Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=CAnKSUlM; spf=pass (imf26.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.50 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7AC8814000C X-Rspam-User: X-Stat-Signature: kq37jn5r4jaj6om1qckdth7o9tsdtoyt X-HE-Tag: 1668728613-86700 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Since Warn count is now tracked and is a fairly interesting signal, add the entry /sys/kernel/warn_count to expose it to userspace. Cc: Petr Mladek Cc: Andrew Morton Cc: tangmeng Cc: "Guilherme G. Piccoli" Cc: Sebastian Andrzej Siewior Cc: Tiezhu Yang Reviewed-by: Luis Chamberlain Signed-off-by: Kees Cook --- .../ABI/testing/sysfs-kernel-warn_count | 6 +++++ MAINTAINERS | 1 + kernel/panic.c | 22 +++++++++++++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-kernel-warn_count diff --git a/Documentation/ABI/testing/sysfs-kernel-warn_count b/Documentation/ABI/testing/sysfs-kernel-warn_count new file mode 100644 index 000000000000..08f083d2fd51 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-kernel-warn_count @@ -0,0 +1,6 @@ +What: /sys/kernel/oops_count +Date: November 2022 +KernelVersion: 6.2.0 +Contact: Linux Kernel Hardening List +Description: + Shows how many times the system has Warned since last boot. diff --git a/MAINTAINERS b/MAINTAINERS index 0a1e95a58e54..282cd8a513fd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11107,6 +11107,7 @@ L: linux-hardening@vger.kernel.org S: Supported T: git git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/hardening F: Documentation/ABI/testing/sysfs-kernel-oops_count +F: Documentation/ABI/testing/sysfs-kernel-warn_count F: include/linux/overflow.h F: include/linux/randomize_kstack.h F: mm/usercopy.c diff --git a/kernel/panic.c b/kernel/panic.c index e5aab27496d7..d718531d8bf4 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -107,6 +108,25 @@ static __init int kernel_panic_sysctls_init(void) late_initcall(kernel_panic_sysctls_init); #endif +static atomic_t warn_count = ATOMIC_INIT(0); + +#ifdef CONFIG_SYSFS +static ssize_t warn_count_show(struct kobject *kobj, struct kobj_attribute *attr, + char *page) +{ + return sysfs_emit(page, "%d\n", atomic_read(&warn_count)); +} + +static struct kobj_attribute warn_count_attr = __ATTR_RO(warn_count); + +static __init int kernel_panic_sysfs_init(void) +{ + sysfs_add_file_to_group(kernel_kobj, &warn_count_attr.attr, NULL); + return 0; +} +late_initcall(kernel_panic_sysfs_init); +#endif + static long no_blink(int state) { return 0; @@ -211,8 +231,6 @@ static void panic_print_sys_info(bool console_flush) void check_panic_on_warn(const char *origin) { - static atomic_t warn_count = ATOMIC_INIT(0); - if (panic_on_warn) panic("%s: panic_on_warn set ...\n", origin);