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 659B0C4332F for ; Thu, 17 Nov 2022 23:28:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB2368E0002; Thu, 17 Nov 2022 18:28:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E62826B0072; Thu, 17 Nov 2022 18:28:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D03BF8E0002; Thu, 17 Nov 2022 18:28:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C1B126B0071 for ; Thu, 17 Nov 2022 18:28:46 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 96F7D4131F for ; Thu, 17 Nov 2022 23:28:46 +0000 (UTC) X-FDA: 80144526252.02.53BC25A Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf19.hostedemail.com (Postfix) with ESMTP id 4F56E1A0007 for ; Thu, 17 Nov 2022 23:28:46 +0000 (UTC) Received: by mail-pl1-f182.google.com with SMTP id y10so1866991plp.3 for ; Thu, 17 Nov 2022 15:28:46 -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=AJiBnlBB2J8GuUoUmkPgUBKXdkHeD1M5eYMwLJnf/Zo2rfmgr0RSS4u2G8WL6gWuqC CuQ1aNHcXCf2SR5hQZRDMxpEe+viL56vYjIoWa7sK/MYqbeW1Xjv9fJBxNxM+9ttLVk8 hopytJ1S8rqNSQYmVpqaDtxf5wF2MM/H+xEVO7uWoWJLhmAZv2QWG5CLy8be8Zb/Chxy Kb4HFr45g5utrFCszK0eKlrV5h4/jmllRLVT1kDtqlhQT7wZcu5epPtCSPb6HdVyTMQE +QRVSrwOhFlvKY0dKDb7YTzMRPplwEx36jD5pw4+qaBTtl3yMMtX3yqpJXFnSZTP/ScG kyWw== X-Gm-Message-State: ANoB5pkVfnoANLCrbGt8HEo6hPq/2pf+B/wsD4lRvg7kUCKul6cs4vzX eFvkLIeuGsjLrFxpyl/aNsNtpA== 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: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668727726; a=rsa-sha256; cv=none; b=fBRg2Xg77JkF7tMqTZa6SxniNCw7xgqkV+xhPQ0+zQaMztWOKfViOaQuc7uxK3JNVugG5g +cTQtAe8HPO1MS3vH3GeN0VxoJXRD9rjPpekQsIuS2GDF5xkSjxzpSCY+vy0L7DThaBJyo vONgA9qsgagfRzj+qRaS58w3rDWpNeA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=lj3JmYhm; spf=pass (imf19.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.182 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=1668727726; 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=FcOLKLI7Dm9mEvWr+m80g8x+dHIAf7454LwMBIEgBJs=; b=fzQ55Id7J2DEXWAr+297puELzhGQZkXxBYGCKPy9Sx+u9HmFpDMQz7FwyRv23DOe/Plp9Z +c6ceUgkC2zvp6TnJyeAHoWeK9tziAbtmZTvPhJCe7IlFmWaTYshN2fMT4otnKVgHgHY/e 3qavhPqlGzo15wTk7MshQCqRsQ0NzBA= X-Stat-Signature: mpj8uqxt9tma576qi9rr7j3sijznsft1 X-Rspamd-Queue-Id: 4F56E1A0007 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=lj3JmYhm; spf=pass (imf19.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.182 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1668727726-530161 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: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