[Crash-utility] Crash-utility Digest, Vol 179, Issue 4

lijiang lijiang at redhat.com
Thu Aug 13 13:08:11 UTC 2020


在 2020年08月13日 16:33, David Wysochanski 写道:
> Hi Lianbo
> 
> On Sat, Aug 8, 2020 at 10:46 PM lijiang <lijiang at redhat.com> wrote:
>>
>> 在 2020年08月07日 00:00, crash-utility-request at redhat.com 写道:
>>> Message: 5
>>> Date: Thu,  6 Aug 2020 09:30:22 -0400
>>> From: Dave Wysochanski <dwysocha at redhat.com>
>>> To: crash-utility at redhat.com
>>> Subject: [Crash-utility] [PATCH v3] Fix "log" command when crash is
>>>       started with "--minimal" option
>>> Message-ID: <20200806133022.2127538-1-dwysocha at redhat.com>
>>>
>>> Commit c86250bce29f introduced the useful '-T' option to print the
>>> log timestamp in human-readable form.  However, this option does
>>> not work when crash is invoked with '--minimal' mode, and if tried,
>>> crash will spin at 100% and continuously crash at a divide by 0
>>> because machdep->hz == 0.
>>>
>>> Fix this by disallowing this option in minimal mode.  In addition,
>>> only calculate the logic to calculate kt->boot_date.tv_sec
>>> when this option is enabled.
>>>
>> Hi, Dave Wysochanski
>>
>> Thank you for the patch.
>>
>>> Fixes: c86250bce29f ("Introduction of the "log -T" option...")
>>> Signed-off-by: Dave Wysochanski <dwysocha at redhat.com>
>>> Reviewed-by: Wang Long <w at laoqinren.net>
>>> Tested-by: Mathias Krause <minipli at grsecurity.net>
>>> ---
>>>  kernel.c | 5 ++++-
>>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/kernel.c b/kernel.c
>>> index 5ed6021..95119f3 100644
>>> --- a/kernel.c
>>> +++ b/kernel.c
>>> @@ -4939,7 +4939,10 @@ cmd_log(void)
>>>          if (argerrs)
>>>                  cmd_usage(pc->curcmd, SYNOPSIS);
>>>
>>> -     if (kt->boot_date.tv_sec == 0) {
>>> +     if (msg_flags & SHOW_LOG_CTIME && pc->flags & MINIMAL_MODE)
>>> +             error(FATAL, "log: option 'T' not available in minimal mode\n");
>>> +
>>> +     if (msg_flags & SHOW_LOG_CTIME && kt->boot_date.tv_sec == 0) {
>>
>> The above two 'if' statements have the same checking condition, would you mind putting them together
>> as a statement block? E.g:
>>
> Sure I can resubmit a fixup of v4 patch once there are no more changes needed.
> 
>> +       if (msg_flags & SHOW_LOG_CTIME) {
>> +               if (pc->flags & MINIMAL_MODE) {
>> +                       error(WARNING, "the option '-T' not available in minimal mode\n");
>> +                       return;
>> +               }
>> +
>> +               if (kt->boot_date.tv_sec == 0) {
>> ...
>> +               }
>>         }
>>
>> In addition, might it be more reasonable to issue a warning instead of a fatal error?
>>
> 
> If you use WARNING it will not fix the infinite loop / CPU spin at
> 100%.  You have to CTRL-C the crash program to get the prompt back.
> So I do not think this is a good idea.
> 
How did you reproduce it? Can you help to confirm if you have applied the correct patch
as below?

[root at intel-sharkbay-mb-03 crash]# git diff kernel.c 
diff --git a/kernel.c b/kernel.c
index 5ed6021..6375b24 100644
--- a/kernel.c
+++ b/kernel.c
@@ -4939,13 +4939,20 @@ cmd_log(void)
         if (argerrs)
                 cmd_usage(pc->curcmd, SYNOPSIS);
 
-       if (kt->boot_date.tv_sec == 0) {
-               ulonglong uptime_jiffies;
-               ulong  uptime_sec;
-               get_uptime(NULL, &uptime_jiffies);
-               uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz;
-               kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
-               kt->boot_date.tv_nsec = 0;
+       if (msg_flags & SHOW_LOG_CTIME) {
+               if (pc->flags & MINIMAL_MODE) {
+                       error(WARNING, "the option '-T' not available in minimal mode\n");
+                       return;
+               }
+
+               if (kt->boot_date.tv_sec == 0) {
+                       ulonglong uptime_jiffies;
+                       ulong  uptime_sec;
+                       get_uptime(NULL, &uptime_jiffies);
+                       uptime_sec = (uptime_jiffies)/(ulonglong)machdep->hz;
+                       kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
+                       kt->boot_date.tv_nsec = 0;
+               }
        }
 
        if (msg_flags & SHOW_LOG_AUDIT) {


I didn't see any problems, it's strange, this is my test steps.

[root at intel-sharkbay-mb-03 crash]# ./crash vmlinux /var/crash/vmcore --minimal
crash 7.2.8++
Copyright (C) 2002-2020  Red Hat, Inc.
Copyright (C) 2004, 2005, 2006, 2010  IBM Corporation
Copyright (C) 1999-2006  Hewlett-Packard Co
Copyright (C) 2005, 2006, 2011, 2012  Fujitsu Limited
Copyright (C) 2006, 2007  VA Linux Systems Japan K.K.
Copyright (C) 2005, 2011  NEC Corporation
Copyright (C) 1999, 2002, 2007  Silicon Graphics, Inc.
Copyright (C) 1999, 2000, 2001, 2002  Mission Critical Linux, Inc.
This program is free software, covered by the GNU General Public License,
and you are welcome to change it and/or distribute copies of it under
certain conditions.  Enter "help copying" to see the conditions.
This program has absolutely no warranty.  Enter "help warranty" for details.
 
GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu"...

WARNING: kernel relocated [160MB]: patching 98187 gdb minimal_symbol values

NOTE: minimal mode commands: log, dis, rd, sym, eval, set, extend and exit

crash> log -T
log: WARNING: the option '-T' not available in minimal mode
crash> 

Tasks: 183 total,   1 running, 182 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   3527.0 total,    359.8 free,    682.5 used,   2484.7 buff/cache
MiB Swap:   3816.0 total,   3804.2 free,     11.8 used.   2563.1 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                          
      1 root      20   0  245500  13888   8968 S   0.0   0.4   0:04.86 systemd                                                          
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.06 kthreadd                                                         
      3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp                                                           
      4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp                                                       
      6 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 kworker/0:0H-kblockd                                             
      9 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 mm_percpu_wq                                                     
     10 root      20   0       0      0      0 S   0.0   0.0   0:00.00 ksoftirqd/0                                                      
     11 root      20   0       0      0      0 I   0.0   0.0   1:24.46 rcu_sched                                                        
     12 root      rt   0       0      0      0 S   0.0   0.0   0:00.03 migration/0                                                      
     13 root      rt   0       0      0      0 S   0.0   0.0   0:00.00 watchdog/0                                                       
     14 root      20   0       0      0      0 S   0.0   0.0   0:00.02 cpuhp/0 


Thanks.
Lianbo

> This is easily reproducible on any vmcore you can see for yourself if
> you want.   But here is the backtrace in GDB:
> 
> crash> log -T
> [Detaching after fork from child process 2669642]
> log: WARNING: log: option 'T' not available in minimal mode
> 
> Program received signal SIGFPE, Arithmetic exception.
> 0x00000000004e5ecf in cmd_log () at kernel.c:4950
> 4950                    kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
> Missing separate debuginfos, use: yum debuginfo-install
> zlib-1.2.11-13.el8.x86_64
> (gdb) bt
> #0  0x00000000004e5ecf in cmd_log () at kernel.c:4950
> #1  0x0000000000463ea9 in exec_command () at main.c:880
> #2  0x00000000004640da in main_loop () at main.c:827
> #3  0x00000000006c0ce3 in captured_command_loop (data=<optimized out>)
> at main.c:258
> #4  0x00000000006bf5ce in catch_errors (func=0x6c0cd0
> <captured_command_loop>, func_args=0x0, errstring=0x91b926 "", mask=6)
> at exceptions.c:557
> #5  0x00000000006c1bb6 in captured_main (data=<optimized out>) at main.c:1064
> #6  0x00000000006bf5ce in catch_errors (func=0x6c0df0 <captured_main>,
> func_args=0x7fffffffe260, errstring=0x91b926 "", mask=6) at
> exceptions.c:557
> #7  0x00000000006c0ae4 in gdb_main (args=<optimized out>) at main.c:1079
> #8  0x00000000006c0b1e in gdb_main_entry (argc=<optimized out>,
> argv=<optimized out>, argv at entry=0x7fffffffe3c8) at main.c:1099
> #9  0x00000000004f86d4 in gdb_main_loop (argc=<optimized out>,
> argc at entry=4, argv=argv at entry=0x7fffffffe3c8) at gdb_interface.c:76
> #10 0x0000000000462707 in main (argc=4, argv=0x7fffffffe3c8) at main.c:708
> (gdb) c
> Continuing.
> 
> Program received signal SIGFPE, Arithmetic exception.
> 0x00000000004e5ecf in cmd_log () at kernel.c:4950
> 4950                    kt->boot_date.tv_sec = kt->date.tv_sec - uptime_sec;
> (gdb) bt
> #0  0x00000000004e5ecf in cmd_log () at kernel.c:4950
> #1  0x0000000000463ea9 in exec_command () at main.c:880
> #2  0x00000000004640da in main_loop () at main.c:827
> #3  0x00000000006c0ce3 in captured_command_loop (data=<optimized out>)
> at main.c:258
> #4  0x00000000006bf5ce in catch_errors (func=0x6c0cd0
> <captured_command_loop>, func_args=0x0, errstring=0x91b926 "", mask=6)
> at exceptions.c:557
> #5  0x00000000006c1bb6 in captured_main (data=<optimized out>) at main.c:1064
> #6  0x00000000006bf5ce in catch_errors (func=0x6c0df0 <captured_main>,
> func_args=0x7fffffffe260, errstring=0x91b926 "", mask=6) at
> exceptions.c:557
> #7  0x00000000006c0ae4 in gdb_main (args=<optimized out>) at main.c:1079
> #8  0x00000000006c0b1e in gdb_main_entry (argc=<optimized out>,
> argv=<optimized out>, argv at entry=0x7fffffffe3c8) at main.c:1099
> #9  0x00000000004f86d4 in gdb_main_loop (argc=<optimized out>,
> argc at entry=4, argv=argv at entry=0x7fffffffe3c8) at gdb_interface.c:76
> #10 0x0000000000462707 in main (argc=4, argv=0x7fffffffe3c8) at main.c:708
> (gdb) quit
> A debugging session is active.
> 
>         Inferior 1 [process 2669636] will be killed.
> 
> Quit anyway? (y or n) y
> 




More information about the Crash-utility mailing list