From mboxrd@z Thu Jan 1 00:00:00 1970 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 877B6C433FE for ; Thu, 17 Nov 2022 23:28:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BA508E0001; Thu, 17 Nov 2022 18:28:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 16AF16B0072; Thu, 17 Nov 2022 18:28:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0328E8E0001; Thu, 17 Nov 2022 18:27:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E88616B0071 for ; Thu, 17 Nov 2022 18:27:59 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B5BC812125B for ; Thu, 17 Nov 2022 23:27:59 +0000 (UTC) X-FDA: 80144524278.14.95A5543 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) by imf18.hostedemail.com (Postfix) with ESMTP id 50A821C0015 for ; Thu, 17 Nov 2022 23:27:58 +0000 (UTC) Received: by mail-pj1-f43.google.com with SMTP id k2-20020a17090a4c8200b002187cce2f92so1570712pjh.2 for ; Thu, 17 Nov 2022 15:27:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=+zOnZ+iVEe8Qzy0xCfuCuxCEDTF24JR1bRlLbEe2Zd0=; b=lV/oOdWqej5RkQtxkQr7BqcpjgxET4zu2n3EB3MbJ/Mzt7OV7xFbi0S8yNY5S5knqW 4TtRGgV/rPxM3uAjyFZ0WjOKTxSfTSbu7+ShBacYWJZv7UMTP/J9oZp2lEAjLZ7QOiS+ S5qmYEpkNu7+FPF75+/tdNc0rtxKkt0tnxfOI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+zOnZ+iVEe8Qzy0xCfuCuxCEDTF24JR1bRlLbEe2Zd0=; b=1N+SCyB9o1zrrgSbCUEEBvLLylG/hTvpZqtAjta7jninlWmxhX39Ss7ngLZ5FjYxB7 yH+r5VS/5r2QugVSXmK6Xu9Y0PHEcj4iuXe6QC5yBGsYKrQQiltOyznKaP2POTFCxKQl OuimYSlWoBzMuRyAKnYHY7f0NjmUfIBF+a05yXXYuftJowGakN1k7AT/tSby8j3uiliq /YdTs2x4eF9lPkjFiL5kc0a4EmC8QuQEyNzQ0nddHHyqpT5V6MS3Zn52b6Rf3tM2UMGU SXLPbXbEITUhMLWcGWOZ3s1ZWt3Ahs0UfiJyjzA0pXFeyyjdJMhmiFcGm9ak/CxigVih 7FYw== X-Gm-Message-State: ANoB5pl8QMoSfD1uN5Is5Uv/xy0kVtvtZKmFg+PVN8od11guGzbpU7KT rO94WgGj6/k89xw+3jBxBjY5rw== X-Google-Smtp-Source: AA0mqf4N0rDT96rsS5N0QMBsicNjM1Eg3p/fTMT0yKfNf3Ol9BqUKC7VybTTGA+g9YUGGEAnaWzCzg== X-Received: by 2002:a17:90a:c901:b0:212:fe9a:5784 with SMTP id v1-20020a17090ac90100b00212fe9a5784mr4887578pjt.91.1668727677220; Thu, 17 Nov 2022 15:27:57 -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 o1-20020a170902d4c100b00186b1bfbe79sm2070434plg.66.2022.11.17.15.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 15:27:56 -0800 (PST) Date: Thu, 17 Nov 2022 15:27:55 -0800 From: Kees Cook To: Marco Elver Cc: Jann Horn , Jonathan Corbet , Andrew Morton , Baolin Wang , "Jason A. Donenfeld" , Eric Biggers , Huang Ying , Petr Mladek , tangmeng , "Guilherme G. Piccoli" , Tiezhu Yang , Sebastian Andrzej Siewior , linux-doc@vger.kernel.org, Greg KH , Linus Torvalds , Seth Jenkins , Andy Lutomirski , "Eric W. Biederman" , Arnd Bergmann , Dmitry Vyukov , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Vincenzo Frascino , Luis Chamberlain , David Gow , "Paul E. McKenney" , Anton Vorontsov , Mauro Carvalho Chehab , Laurent Dufour , Rob Herring , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 5/6] panic: Introduce warn_limit Message-ID: <202211171526.5F09B6D3D@keescook> References: <20221109194404.gonna.558-kees@kernel.org> <20221109200050.3400857-5-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668727678; a=rsa-sha256; cv=none; b=pdaHagFmBFtzcTo/6yUbb55XcKHoJu6ahsc3diaSJGdFjrY0on2qQ5JkOBcHMs2uZlpQpW IB+GlIZ+2Lq7B778Q+W4h0XOJvc5MITdo/v8yzarockWWGsgJztC24HEtako7unnfsUSHU 5Emb8iCOStj0h2yk5rPeqsrJQuUKtr4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="lV/oOdWq"; spf=pass (imf18.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.43 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=1668727678; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+zOnZ+iVEe8Qzy0xCfuCuxCEDTF24JR1bRlLbEe2Zd0=; b=bOyyQ7bYj0w+CQJrBAaSKjwun7K0fR6a4wD7NT3GzfgYK9BnKHUkhjwRjHvvIi1xlSXbVS Tk9VDNmO9/s8sMon5SHCk08VsgvLTJLMRgD1bcazRVVgtF68BXeaOv2Z4VNICqrFaVy8k8 3W1lGhUipRYZ34STV+Wz/Fgm+nJyj9g= X-Stat-Signature: 1qgnx6hk5h5wzkcwy6ri8rg7dfkwc45y X-Rspamd-Queue-Id: 50A821C0015 X-Rspamd-Server: rspam01 X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b="lV/oOdWq"; spf=pass (imf18.hostedemail.com: domain of keescook@chromium.org designates 209.85.216.43 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-HE-Tag: 1668727678-883426 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: On Mon, Nov 14, 2022 at 10:48:38AM +0100, Marco Elver wrote: > On Wed, 9 Nov 2022 at 21:00, Kees Cook wrote: > > > > Like oops_limit, add warn_limit for limiting the number of warnings when > > panic_on_warn is not set. > > > > Cc: Jonathan Corbet > > Cc: Andrew Morton > > Cc: Baolin Wang > > Cc: "Jason A. Donenfeld" > > Cc: Eric Biggers > > Cc: Huang Ying > > Cc: Petr Mladek > > Cc: tangmeng > > Cc: "Guilherme G. Piccoli" > > Cc: Tiezhu Yang > > Cc: Sebastian Andrzej Siewior > > Cc: linux-doc@vger.kernel.org > > Signed-off-by: Kees Cook > > --- > > Documentation/admin-guide/sysctl/kernel.rst | 9 +++++++++ > > kernel/panic.c | 13 +++++++++++++ > > 2 files changed, 22 insertions(+) > > > > diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst > > index 09f3fb2f8585..c385d5319cdf 100644 > > --- a/Documentation/admin-guide/sysctl/kernel.rst > > +++ b/Documentation/admin-guide/sysctl/kernel.rst > > @@ -1508,6 +1508,15 @@ entry will default to 2 instead of 0. > > 2 Unprivileged calls to ``bpf()`` are disabled > > = ============================================================= > > > > + > > +warn_limit > > +========== > > + > > +Number of kernel warnings after which the kernel should panic when > > +``panic_on_warn`` is not set. Setting this to 0 or 1 has the same effect > > +as setting ``panic_on_warn=1``. > > + > > + > > watchdog > > ======== > > > > diff --git a/kernel/panic.c b/kernel/panic.c > > index 3afd234767bc..b235fa4a6fc8 100644 > > --- a/kernel/panic.c > > +++ b/kernel/panic.c > > @@ -58,6 +58,7 @@ bool crash_kexec_post_notifiers; > > int panic_on_warn __read_mostly; > > unsigned long panic_on_taint; > > bool panic_on_taint_nousertaint = false; > > +static unsigned int warn_limit __read_mostly = 10000; > > > > int panic_timeout = CONFIG_PANIC_TIMEOUT; > > EXPORT_SYMBOL_GPL(panic_timeout); > > @@ -88,6 +89,13 @@ static struct ctl_table kern_panic_table[] = { > > .extra2 = SYSCTL_ONE, > > }, > > #endif > > + { > > + .procname = "warn_limit", > > + .data = &warn_limit, > > + .maxlen = sizeof(warn_limit), > > + .mode = 0644, > > + .proc_handler = proc_douintvec, > > + }, > > { } > > }; > > > > @@ -203,8 +211,13 @@ static void panic_print_sys_info(bool console_flush) > > > > void check_panic_on_warn(const char *reason) > > { > > + static atomic_t warn_count = ATOMIC_INIT(0); > > + > > if (panic_on_warn) > > panic("%s: panic_on_warn set ...\n", reason); > > + > > + if (atomic_inc_return(&warn_count) >= READ_ONCE(warn_limit)) > > + panic("Warned too often (warn_limit is %d)", warn_limit); > > Shouldn't this also include the "reason", like above? (Presumably a > warning had just been generated to console so the reason is easy > enough to infer from the log, although in that case "reason" also > seems redundant above.) Yeah, that makes sense. I had been thinking that since it was an action due to repeated prior actions, the current "reason" didn't matter here. But thinking about it more, I see what you mean. :) -- Kees Cook