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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DE95C43217 for ; Thu, 17 Nov 2022 23:28:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231274AbiKQX2B (ORCPT ); Thu, 17 Nov 2022 18:28:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234884AbiKQX17 (ORCPT ); Thu, 17 Nov 2022 18:27:59 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAEEA2BFA for ; Thu, 17 Nov 2022 15:27:57 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso6748797pjg.5 for ; Thu, 17 Nov 2022 15:27:57 -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=DnQNC98czj7nFFYoszoobSu964b2tOJVfbfE4+Fu8ECv5MWG3oauQ06n/n+jDcU89A hdwnVbOy8tyNV8BzPfeHLhlezauL6AON0rDNuHm1FaxIHgot0gtW+n+/dVUYcnhQZH43 kC1ZytjiQ37UvEcTFC1Vt5a219GoYSpToO/CyiQNuKlB6Z5RLfUutwGNSGmyHO57W+GI HcwCznRt3FRm18mNVDpTESzxauLbzBPdZLurzKuoYOzjoqvC2TbEg2FwdjB+mvPb97QQ M3j7VFVbdtmOvcmdsLT7W/hugq6l63fmGYGF5gcOLZL7tQhPv0Buxh+Czu+Jdm22H4Bq Ph2w== X-Gm-Message-State: ANoB5plSPJx+tC5YPRoRfRmy1dbRRYA3EPwKW9705LQMZqiRMsZWhQph ZHUKm1k1AHm2Pvek8zpWE6QObw== 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: Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org 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