From patchwork Sat Aug 6 12:23:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 12938015 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 31739C19F2D for ; Sat, 6 Aug 2022 12:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Bb9Ki0Ei9EMUZmisp8l4+bMifICoQKI9u5eejzF8sCs=; b=axp6YK7ILhKowV qe8l/25pWOqG1mx0jv5MoqnN6nLDeL3bqt4IeHMgbY7ydal4/sbcgeX8YlJz3LODaLjieC2cKc2yy 6LxEzpJ6tTCJB8KZtNWiS/nhx39WSjvCW8cTxg5xmNqiqUFw62tFx7FU9JbleaGk14SC+AGbd1u2d NvPjc8gIKjdnFVp8t/b2Z5ClCMqmT+y68wOM3dgq4mAj9cuqFKXf6095Q9A+a2p2xseppRslRKttY rtdPQqj0nspymanD7I3198Af4p3XfehKv/yYWIGClbKSMr7bVo5OzdtcH0kiAn2jpqaFmhFyUuCyr MCZKS4O5/qu5HYg5GwUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKIqr-00AuzN-Gl; Sat, 06 Aug 2022 12:24:21 +0000 Received: from mout.gmx.net ([212.227.15.15]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oKIqX-00AtiE-6d for linux-arm-kernel@lists.infradead.org; Sat, 06 Aug 2022 12:24:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1659788631; bh=lELR8WYbBOTLMAY/ROaaXRuZyiwAFpzcRRcD1yGmR+U=; h=X-UI-Sender-Class:From:To:Subject:Date:In-Reply-To:References; b=WyehE8w1Jhfb7cmxf4r8c8mKj31OCf5NW+Kp+QP2am6/6DhXUOSZw6s6+iTRK7i2Y rKVfEXTH4O+4nNKfRWQgZAkHpLLJBZgCFcKMPhi/WxHeQTnOnEkSIkhhZTq3wwtXE/ mm6hPmTT8zmbcf70eNsaPwtINlweqRt9dNU09GSQ= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from p100.fritz.box ([92.116.170.46]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MyKDe-1nUe3m3znY-00ygrT; Sat, 06 Aug 2022 14:23:51 +0200 From: Helge Deller To: linux-s390@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, Josh Triplett , linux-fsdevel@vger.kernel.org Subject: [PATCH v2 2/3] lib/dump_stack: Add dump_stack_print_cmdline() and wire up in dump_stack_print_info() Date: Sat, 6 Aug 2022 14:23:47 +0200 Message-Id: <20220806122348.82584-3-deller@gmx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220806122348.82584-1-deller@gmx.de> References: <20220806122348.82584-1-deller@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BialK5Gr6LY7i1wCJNhco7oXVVXlstreH3iQsxuzTtOakZOQe2F vaS/im2YcOCpaEPRnRhbwzns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kDqbvn xA7eCe8GI2Joh0+2BMUgtSKu1XfhCHqcC5zelbtBbVeDy5PhRQeEdy4rzboIJY858SUbhW4hd v9L+dcswOxIb0oqxLDTt/mbcoN8sCX2AT3rZhm5cPExW8CZ9ySXty/4T1m8y+wXqvidb1V+NU ZNTqb++QElDkvaqYPdVPEIykOMOFxhJoq60pwhPvyQWxpsJ+VdeRkkGeKcHPnvNig4OdOYE4n xrTh+fgGdUpSiwelgs2BCsT+uZSzLwxcWMD7hETBr1lt8oOULoacU/zYg== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220806_052401_571368_17612742 X-CRM114-Status: GOOD ( 17.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add the function dump_stack_print_cmdline() which can be used by arch code to print the command line of the current processs. This function is useful in arch code when dumping information for a faulting process. Wire this function up in the dump_stack_print_info() function to include the dumping of the command line for architectures which use dump_stack_print_info(). As an example, with this patch a failing glibc testcase (which uses ld.so.1 as starting program) up to now reported just "ld.so.1" failing: do_page_fault() command='ld.so.1' type=15 address=0x565921d8 in libc.so[f7339000+1bb000] trap #15: Data TLB miss fault, vm_start = 0x0001a000, vm_end = 0x0001b000 and now it reports in addition: ld.so.1[1151] cmdline: /home/gnu/glibc/objdir/elf/ld.so.1 --library-path /home/gnu/glibc/objdir:/home/gnu/glibc/objdir/math:/home/gnu/ /home/gnu/glibc/objdir/malloc/tst-safe-linking-malloc-hugetlb1 Josh Triplett noted that dumping such command line parameters into syslog may theoretically lead to information disclosure. That's why this patch checks the value of the kptr_restrict sysctl variable and will not print any information if kptr_restrict==2, and will not show the program parameters if kptr_restrict==1. Signed-off-by: Helge Deller --- include/linux/printk.h | 5 +++++ lib/dump_stack.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) -- 2.37.1 diff --git a/include/linux/printk.h b/include/linux/printk.h index cf7d666ab1f8..5290a32a197d 100644 --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -191,6 +191,7 @@ u32 log_buf_len_get(void); void log_buf_vmcoreinfo_setup(void); void __init setup_log_buf(int early); __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...); +void dump_stack_print_cmdline(const char *log_lvl); void dump_stack_print_info(const char *log_lvl); void show_regs_print_info(const char *log_lvl); extern asmlinkage void dump_stack_lvl(const char *log_lvl) __cold; @@ -262,6 +263,10 @@ static inline __printf(1, 2) void dump_stack_set_arch_desc(const char *fmt, ...) { } +static inline void dump_stack_print_cmdline(const char *log_lvl) +{ +} + static inline void dump_stack_print_info(const char *log_lvl) { } diff --git a/lib/dump_stack.c b/lib/dump_stack.c index 83471e81501a..38ef1067c7eb 100644 --- a/lib/dump_stack.c +++ b/lib/dump_stack.c @@ -14,6 +14,7 @@ #include #include #include +#include static char dump_stack_arch_desc_str[128]; @@ -45,6 +46,37 @@ void __init dump_stack_set_arch_desc(const char *fmt, ...) #define BUILD_ID_VAL "" #endif +/** + * dump_stack_print_cmdline - print the command line of current process + * @log_lvl: log level + */ +void dump_stack_print_cmdline(const char *log_lvl) +{ + char cmdline[256]; + + if (kptr_restrict >= 2) + return; /* never show command line */ + + /* get command line */ + get_task_cmdline_kernel(current, cmdline, sizeof(cmdline)); + + if (kptr_restrict == 1) { + char *p; + + /* if restricted show program path only */ + p = strchr(cmdline, ' '); + if (p) { + *p = 0; + strlcat(cmdline, + " ... [parameters hidden due to kptr_restrict]", + sizeof(cmdline)); + } + } + + printk("%s%s[%d] cmdline: %s\n", log_lvl, current->comm, + current->pid, cmdline); +} + /** * dump_stack_print_info - print generic debug info for dump_stack() * @log_lvl: log level @@ -62,6 +94,8 @@ void dump_stack_print_info(const char *log_lvl) (int)strcspn(init_utsname()->version, " "), init_utsname()->version, BUILD_ID_VAL); + dump_stack_print_cmdline(log_lvl); + if (dump_stack_arch_desc_str[0] != '\0') printk("%sHardware name: %s\n", log_lvl, dump_stack_arch_desc_str);