From patchwork Fri May 15 18:44:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 200460 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0481EC433DF for ; Fri, 15 May 2020 18:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D863F2070A for ; Fri, 15 May 2020 18:44:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="dJGXyum4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbgEOSoq (ORCPT ); Fri, 15 May 2020 14:44:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726725AbgEOSom (ORCPT ); Fri, 15 May 2020 14:44:42 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51CECC05BD0C for ; Fri, 15 May 2020 11:44:42 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id n11so1386716pgl.9 for ; Fri, 15 May 2020 11:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0jdcunXv3pqO3EZGEjVZoYTNjFacyriadazWIgCIza0=; b=dJGXyum44KSJaIJ6ilVk6F+MrANEv/lMa+3vHZEw+Ee/F1S+Khae+6am+JJqjUAiur xBltba6noayGshrr5DxfoWxBOGFddZ2Q6/7usxSbkmXzsQ6VuUbv+3k9rY0wEFNMFtsi hEwaIVZ0ywvmhwEBIyI/X+3TR4cdCOeMAROUM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0jdcunXv3pqO3EZGEjVZoYTNjFacyriadazWIgCIza0=; b=V1d6SzkYVfgz5WwKDWgwsbA18j8Y+xX4pe8wMxufblUiYQCr9OcjWBfJBYMGBxpmQX 4WTX7QOIyuH4ZB7QeeXEDK9BnYhB8RhycMuej9mCUUSd7+iQq42wLFE45dF9p0IWEqvB Ihi5tbmS3z0q8F8y5M02TVKphcLTOOCaKST+bv6fEQsBfer2uzYnFLrKPrZdwADOTLPT p+h+BTW29ACUJQiE/5/A2a7YT1x6yZ3jcGddPnqaU1A89poWKUdV50JQVuByouUT5snS mVXvNGKHc0d2m0Kl20Nymq8sqOEiR0dS6IiGVbWI/qHWrJi1xMR8r9CTVbp2F6cfkBIO uwCw== X-Gm-Message-State: AOAM533LmcXuQBmwqZM2y93bankLKPfgXTm3b01BmhaMx5KMcecRXr1c 5rcNfDJW1hbHlt+ZvlDxX06qrg== X-Google-Smtp-Source: ABdhPJzok71/4xx3xqYrVEUNk01rjmmUYSquuxTkQe96RfbVBWJ4Kp4ARtspqkm/dg5KXVU82P9AJA== X-Received: by 2002:a63:d60a:: with SMTP id q10mr4555654pgg.37.1589568281921; Fri, 15 May 2020 11:44:41 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id mu17sm2243430pjb.53.2020.05.15.11.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 May 2020 11:44:38 -0700 (PDT) From: Kees Cook To: Pavel Tatashin Cc: Kees Cook , Petr Mladek , Anton Vorontsov , Colin Cross , Tony Luck , Jonathan Corbet , Benson Leung , Rob Herring , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Enric Balletbo i Serra , Sergey Senozhatsky , Steven Rostedt , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v4 2/6] printk: honor the max_reason field in kmsg_dumper Date: Fri, 15 May 2020 11:44:30 -0700 Message-Id: <20200515184434.8470-3-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200515184434.8470-1-keescook@chromium.org> References: <20200515184434.8470-1-keescook@chromium.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Pavel Tatashin kmsg_dump() allows to dump kmesg buffer for various system events: oops, panic, reboot, etc. It provides an interface to register a callback call for clients, and in that callback interface there is a field "max_reason" which gets ignored unless always_kmsg_dump is passed as kernel parameter. Allow clients to decide max_reason, and keep the current behavior when max_reason is not set. Signed-off-by: Pavel Tatashin Link: https://lore.kernel.org/lkml/20200506211523.15077-2-keescook@chromium.org/ Signed-off-by: Kees Cook --- include/linux/kmsg_dump.h | 1 + kernel/printk/printk.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/linux/kmsg_dump.h b/include/linux/kmsg_dump.h index 3f82b5cb2d82..9826014771ab 100644 --- a/include/linux/kmsg_dump.h +++ b/include/linux/kmsg_dump.h @@ -26,6 +26,7 @@ enum kmsg_dump_reason { KMSG_DUMP_OOPS, KMSG_DUMP_EMERG, KMSG_DUMP_SHUTDOWN, + KMSG_DUMP_MAX }; /** diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 9a9b6156270b..a121c2255737 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3157,12 +3157,19 @@ void kmsg_dump(enum kmsg_dump_reason reason) struct kmsg_dumper *dumper; unsigned long flags; - if ((reason > KMSG_DUMP_OOPS) && !always_kmsg_dump) - return; - rcu_read_lock(); list_for_each_entry_rcu(dumper, &dump_list, list) { - if (dumper->max_reason && reason > dumper->max_reason) + enum kmsg_dump_reason max_reason = dumper->max_reason; + + /* + * If client has not provided a specific max_reason, default + * to KMSG_DUMP_OOPS, unless always_kmsg_dump was set. + */ + if (max_reason == KMSG_DUMP_UNDEF) { + max_reason = always_kmsg_dump ? KMSG_DUMP_MAX : + KMSG_DUMP_OOPS; + } + if (reason > max_reason) continue; /* initialize iterator with data about the stored records */