Bug 1369242

Summary: logrotate crash when using long dateformat [el6]
Product: Red Hat Enterprise Linux 6 Reporter: Peter Edwards <thatsafunnyname>
Component: logrotateAssignee: Kamil Dudka <kdudka>
Status: CLOSED ERRATA QA Contact: Vaclav Danek <vdanek>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 6.7CC: kdudka, psklenar, vdanek
Target Milestone: rcKeywords: EasyFix, Patch
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: logrotate-3.7.8-28.el6 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1369438 (view as bug list) Environment:
Last Closed: 2017-03-21 09:44:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1369438    
Bug Blocks:    

Description Peter Edwards 2016-08-22 19:43:20 UTC
Description of problem:

logrotate crash when using long dateformat

Version-Release number of selected component (if applicable):

Seen using logrotate-3.7.8-23.el6.x86_64 but also I could not see the (Fedora and upstream) patch to fix this in -26.

How reproducible:

valgrind reports errors every time, crashes are sporadic and not seen on every run.

Steps to Reproduce:
1. Use a logrotate conf file with the following parameters for a file:
    dateext
    dateformat -alonghostname01-%Y%m%d-%s
2. Run logrotate under valgrind when the file is rotated.
3. Or run logrotate to rotate the file repeatedly and generate a backtrace from the core.

Actual results:

valgrind /usr/sbin/logrotate -v -s ~/logrotate/test.status ~/logrotate/test.conf
...
reading config file ~/logrotate/test.conf
reading config info for ~/logrotate/test/*.log
compress_options is now -1
Handling 1 logs
rotating pattern: ~/logrotate/test/*.log  1048576 bytes (14 rotations)
empty log files are not rotated, old logs are removed
considering log ~/logrotate/test/file.log
  log needs rotating
rotating log ~/logrotate/test/file.log, log->rotateCount is 14
Converted ' -alonghostname01-%Y-%s' -> '-alonghostname01-%Y-%s'
dateext suffix '-alonghostname01-2016-1471886664'
glob pattern '-alonghostname-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
glob finding logs to compress failed
glob finding old rotated logs failed
==29193== Invalid write of size 1
==29193==    at 0x316D2FFAC2: __vsprintf_chk (in /lib64/libc-2.12.so)
==29193==    by 0x316D2FF9FE: __sprintf_chk (in /lib64/libc-2.12.so)
==29193==    by 0x4059D5: ??? (in /usr/sbin/logrotate)
==29193==    by 0x40644F: ??? (in /usr/sbin/logrotate)
==29193==    by 0x406B6E: ??? (in /usr/sbin/logrotate)
==29193==    by 0x316D21ED1C: (below main) (in /lib64/libc-2.12.so)
==29193==  Address 0x4c4819b is 0 bytes after a block of size 75 alloc'd
==29193==    at 0x4A06A2E: malloc (vg_replace_malloc.c:270)
==29193==    by 0x404FF3: ??? (in /usr/sbin/logrotate)
==29193==    by 0x40644F: ??? (in /usr/sbin/logrotate)
==29193==    by 0x406B6E: ??? (in /usr/sbin/logrotate)
==29193==    by 0x316D21ED1C: (below main) (in /lib64/libc-2.12.so)
 
 
gdb -c core.1471881601_62_62_6_52839_logrotate /usr/sbin/logrotate
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-83.el6)
Copyright (C) 2010 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/sbin/logrotate...(no debugging symbols found)...done.
[New Thread 52839]
Reading symbols from /lib64/libpopt.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib64/libpopt.so.0
Reading symbols from /lib64/libselinux.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libselinux.so.1
Reading symbols from /lib64/libacl.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libacl.so.1
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libattr.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libattr.so.1
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
Core was generated by `/usr/sbin/logrotate -s /var/run/logrotate.status REMOVED'.
Program terminated with signal 6, Aborted.
#0  0x0000003df1e325e5 in raise () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install logrotate-3.7.8-23.el6.x86_64
(gdb) symbol-file /usr/lib/debug/usr/sbin/logrotate.debug
Reading symbols from /usr/lib/debug/usr/sbin/logrotate.debug...done.
(gdb) bt
#0  0x0000003df1e325e5 in raise () from /lib64/libc.so.6
#1  0x0000003df1e33dc5 in abort () from /lib64/libc.so.6
#2  0x0000003df1e704f7 in __libc_message () from /lib64/libc.so.6
#3  0x0000003df1e75f3e in malloc_printerr () from /lib64/libc.so.6
#4  0x0000003df1e78dd0 in _int_free () from /lib64/libc.so.6
#5  0x00000000004060bf in rotateLogSet (log=<value optimized out>, force=<value optimized out>) at logrotate.c:1573
#6  0x0000000000406b6f in main (argc=<value optimized out>, argv=<value optimized out>) at logrotate.c:2017

/usr/src/debug/logrotate-3.7.8/logrotate.c
 
    for (i = 0; i < log->numFiles; i++) {
        free(rotNames[i]->firstRotated);    <- line 1573
        free(rotNames[i]->disposeName);
        free(rotNames[i]->finalName);
        free(rotNames[i]->dirName);
        free(rotNames[i]->baseName);
        free(rotNames[i]);
    }

Expected results:

No valgrind errors.
No heap corruption due to too small memory allocation.
Does not crash.

Additional info:

Fix:

https://fedorahosted.org/logrotate/ticket/50
https://fedorahosted.org/logrotate/changeset/474
https://github.com/logrotate/logrotate/commit/768b23c0bd94f973abf108f6e2cf4138c426f140
https://fedorahosted.org/logrotate/browser/tags/r3-9-1/CHANGES#L4
 
Workaround:
 
Use shorter dateformat.

Comment 8 errata-xmlrpc 2017-03-21 09:44:03 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2017-0625.html