Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2761426rwb; Thu, 17 Nov 2022 16:00:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7xaR7Sd3eM5Yz4zdvWtiwTFgIEkt70seulvsHY7I+OFc92vgNWcR44utGoKkkrBrv126qO X-Received: by 2002:a62:16d4:0:b0:572:6b5f:bdc2 with SMTP id 203-20020a6216d4000000b005726b5fbdc2mr5217994pfw.36.1668729601321; Thu, 17 Nov 2022 16:00:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668729601; cv=none; d=google.com; s=arc-20160816; b=xWQ2ohLaRNrc07mIJATqtZdTmG9wB0bCLl5cWI4U0w3Y8/vl1wUwmjE+Oa1oNnv8sv VPh1Lq43WfMQVa1V+kXDLfL/hS8GmzgT9YgG3Lk1KG48ZqxbYqHHFp8S5BIr0z90AZJf QmxCYTvrhHDIMpp68VUGNP4Q2bcnuK4W/Vm5OhM8gR3mGWcx6qql8DmTSiJMvpvJQ/IW JNX5lReVKYKkQAoWmg5c6JhaaeFv3pph2+f+9z2xzv6GxmJmZqYbZ+DFa8YABBs6/uDu 7HI8l1a1G1xAThSPKIkIRclI5u/6Yaa3dBTfDQYE6UYrWUjTZnNpXGWCTb6UMZquZ3bT 9SBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FcOLKLI7Dm9mEvWr+m80g8x+dHIAf7454LwMBIEgBJs=; b=INIcWGj1t/qMZEnTM3CtQge/nKMV7EyCBbYYYTDY5CnOc9GVgmuvY5EDVwA8XqCp8r kFLlwmvO9TOQ5fFS2Uw3qg2SENS/YRPTBUstiS0k5LkNpBEkkOx/pCMYVhK/cjOHy4nW jApmvt/E8yRr/Rc61Kyt9wFa2CLBAtTR3ChZbB4JwoZ7CImRkWskK6szY6f9eKkQZ8Dd uY7dTRwyLCxIgQ1r+6p5JtAxjvhQgASo5Vlix1k7elz4pgebRTh2onujS+5jtZ6KiUsQ AnyQ/1UOCZOyO30q/O72V6ths9r/RMuoviH61cWhwtkLoh3MXEypcR9G6OwX/40R79e1 l0LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lj3JmYhm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx3-20020a17090b4b0300b001fd7cab081bsi6657431pjb.125.2022.11.17.15.59.49; Thu, 17 Nov 2022 16:00:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lj3JmYhm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234850AbiKQX2s (ORCPT + 92 others); Thu, 17 Nov 2022 18:28:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234786AbiKQX2r (ORCPT ); Thu, 17 Nov 2022 18:28:47 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C515276155 for ; Thu, 17 Nov 2022 15:28:45 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id w15-20020a17090a380f00b0021873113cb4so3026800pjb.0 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=xUq9wpMw1MF4ohUe5Kzme1z702xTWd8d7st+Hj0h8zE59k1+E+L4QT4c3tC60MhpkQ eKLCL4YRvXw/qJraHxdI3oKvBhAPD4YEKMiK9j6g/Cl7FXQdCYjUmDFywwp6lO8aRAFN lXVhXUCV49gj1HG1tL7eFUUy49Ln7wjUhf998xIX3yILo0JwpJAvCCTF76G4lHTCdiyo QWYLhEAX4XIFfk5XusG0QF5yDtSVAYtKVbQEcHkxsCArpwEdMdLt+T7G93XzoHuhC3vz Nc/c+KEQlNEcbMB3CZ1G83FWdLog0R3IrryPGokrTfxMM3WE4mSXp+qsL2l61Q9yVEpB idqg== X-Gm-Message-State: ANoB5pk0STHB/u8FaZBdYqpDKIsC0nq8PHjZFNS24/J/7/J5HXgn4Cky XnmU/RCJ+j8yOsk5VZjvgzPA1Q== 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: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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