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 54AE9C43219 for ; Thu, 17 Nov 2022 23:28:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234932AbiKQX2s (ORCPT ); Thu, 17 Nov 2022 18:28:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234850AbiKQX2r (ORCPT ); Thu, 17 Nov 2022 18:28:47 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C696076160 for ; Thu, 17 Nov 2022 15:28:45 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id b1-20020a17090a7ac100b00213fde52d49so3455442pjl.3 for ; Thu, 17 Nov 2022 15:28:45 -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=FcOLKLI7Dm9mEvWr+m80g8x+dHIAf7454LwMBIEgBJs=; b=lj3JmYhmFP49enZ7BxP/5GWppKnAj8SCgQGp6xPE+6+tFUOgdM7wDLFEj70QX9lmbX yGcp5CKcwqVjrv/Mk2mtpSyahI9rVFSpvCnHXYBUYU8FPmUKWsFrnsXv8zBXVi5jSr/l mKjLka+gt5yA5FVG5FscBRzNyfWnHm2lnmqbw= 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=FcOLKLI7Dm9mEvWr+m80g8x+dHIAf7454LwMBIEgBJs=; b=QFU/gkgS9ExkNKaMVf0dTes4fW4ZgCc7NF4qGS8MGF/ZvIMfjr5Wf5wqJ8Rgqra1GH 2/+iEYK4ews8YhIH+dnXCSRzQ3iB0qGNkf/RuowN/2LvGTrqbcRBfaHVH+NxMQS6MlQs yjQvZbtYSF6mKfECC1yXtMVaJfw0EDuIrQTLeOJzDYI03gb5K2XvVCY2nyp2WNBb3faZ M/tb5gBv4iziGpnBY0lG/Dr+iGT1v07KjRa2OVEL74VojgrX/RpdFO6BwdLmvqyiOl1O qGI9Ud1DpHfVtWOMwYtDmamFPAKq1CuXH5irU87q902ZJ2l6/w0OUsY/K6prSYsYIz2U oEpg== X-Gm-Message-State: ANoB5pm06smdjrxqcEIPjr44ziborVBLunCHvRTc/QgoHAcz8KCusNYd vFaOmAkciWZ/Fb9i1mozrYyqEw== X-Google-Smtp-Source: AA0mqf58Ma7eiUSU1v06lTRmXyRIaf5qGvRu9GMxwZP155Uu9IDglDpTru83Stj4Ke9kGjDXEKX0gg== X-Received: by 2002:a17:902:f651:b0:186:b5c8:4c8f with SMTP id m17-20020a170902f65100b00186b5c84c8fmr4827739plg.124.1668727725304; Thu, 17 Nov 2022 15:28:45 -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 y15-20020a656c0f000000b0046f7e1ca434sm1643826pgu.0.2022.11.17.15.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 15:28:44 -0800 (PST) Date: Thu, 17 Nov 2022 15:28:44 -0800 From: Kees Cook To: Marco Elver Cc: Jann Horn , 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 , Andrew Morton , Luis Chamberlain , David Gow , tangmeng , Petr Mladek , "Paul E. McKenney" , Sebastian Andrzej Siewior , "Guilherme G. Piccoli" , Tiezhu Yang , kasan-dev@googlegroups.com, linux-mm@kvack.org, Greg KH , Linus Torvalds , Seth Jenkins , Andy Lutomirski , "Eric W. Biederman" , Arnd Bergmann , 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, linux-doc@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2 4/6] panic: Consolidate open-coded panic_on_warn checks Message-ID: <202211171528.DF818B1CB6@keescook> References: <20221109194404.gonna.558-kees@kernel.org> <20221109200050.3400857-4-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:57:15AM +0100, Marco Elver wrote: > On Wed, 9 Nov 2022 at 21:00, Kees Cook wrote: > > > > Several run-time checkers (KASAN, UBSAN, KFENCE, KCSAN, sched) roll > > their own warnings, and each check "panic_on_warn". Consolidate this > > into a single function so that future instrumentation can be added in > > a single location. > > > > Cc: Marco Elver > > Cc: Dmitry Vyukov > > Cc: Peter Zijlstra > > Cc: Juri Lelli > > Cc: Vincent Guittot > > Cc: Dietmar Eggemann > > Cc: Steven Rostedt > > Cc: Ben Segall > > Cc: Mel Gorman > > Cc: Daniel Bristot de Oliveira > > Cc: Valentin Schneider > > Cc: Andrey Ryabinin > > Cc: Alexander Potapenko > > Cc: Andrey Konovalov > > Cc: Vincenzo Frascino > > Cc: Andrew Morton > > Cc: Luis Chamberlain > > Cc: David Gow > > Cc: tangmeng > > Cc: Jann Horn > > Cc: Petr Mladek > > Cc: "Paul E. McKenney" > > Cc: Sebastian Andrzej Siewior > > Cc: "Guilherme G. Piccoli" > > Cc: Tiezhu Yang > > Cc: kasan-dev@googlegroups.com > > Cc: linux-mm@kvack.org > > Signed-off-by: Kees Cook > > --- > > include/linux/panic.h | 1 + > > kernel/kcsan/report.c | 3 +-- > > kernel/panic.c | 9 +++++++-- > > kernel/sched/core.c | 3 +-- > > lib/ubsan.c | 3 +-- > > mm/kasan/report.c | 4 ++-- > > mm/kfence/report.c | 3 +-- > > 7 files changed, 14 insertions(+), 12 deletions(-) > > > > diff --git a/include/linux/panic.h b/include/linux/panic.h > > index c7759b3f2045..1702aeb74927 100644 > > --- a/include/linux/panic.h > > +++ b/include/linux/panic.h > > @@ -11,6 +11,7 @@ extern long (*panic_blink)(int state); > > __printf(1, 2) > > void panic(const char *fmt, ...) __noreturn __cold; > > void nmi_panic(struct pt_regs *regs, const char *msg); > > +void check_panic_on_warn(const char *reason); > > extern void oops_enter(void); > > extern void oops_exit(void); > > extern bool oops_may_print(void); > > diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c > > index 67794404042a..e95ce7d7a76e 100644 > > --- a/kernel/kcsan/report.c > > +++ b/kernel/kcsan/report.c > > @@ -492,8 +492,7 @@ static void print_report(enum kcsan_value_change value_change, > > dump_stack_print_info(KERN_DEFAULT); > > pr_err("==================================================================\n"); > > > > - if (panic_on_warn) > > - panic("panic_on_warn set ...\n"); > > + check_panic_on_warn("KCSAN"); > > } > > > > static void release_report(unsigned long *flags, struct other_info *other_info) > > diff --git a/kernel/panic.c b/kernel/panic.c > > index 129936511380..3afd234767bc 100644 > > --- a/kernel/panic.c > > +++ b/kernel/panic.c > > @@ -201,6 +201,12 @@ static void panic_print_sys_info(bool console_flush) > > ftrace_dump(DUMP_ALL); > > } > > > > +void check_panic_on_warn(const char *reason) > > +{ > > + if (panic_on_warn) > > + panic("%s: panic_on_warn set ...\n", reason); > > +} > > + > > /** > > * panic - halt the system > > * @fmt: The text string to print > > @@ -619,8 +625,7 @@ void __warn(const char *file, int line, void *caller, unsigned taint, > > if (regs) > > show_regs(regs); > > > > - if (panic_on_warn) > > - panic("panic_on_warn set ...\n"); > > + check_panic_on_warn("kernel"); > > What is the reason "kernel" in this context? The real reason is a WARN > - so would the reason "WARNING" be more intuitive? I'll rename "reason" to "origin" or something -- it's mainly to see who was calling this when it's not core kernel logic. -- Kees Cook