Bug 1598502
Summary: | tcsh corrupt history file results in rapid memory consumption until memory exhausted | |||
---|---|---|---|---|
Product: | Red Hat Enterprise Linux 7 | Reporter: | afox <afox> | |
Component: | tcsh | Assignee: | Jan Macku <jamacku> | |
Status: | CLOSED ERRATA | QA Contact: | Karel Volný <kvolny> | |
Severity: | medium | Docs Contact: | ||
Priority: | medium | |||
Version: | 7.5 | CC: | afox, darren.lavender, dkaylor, fkrska, fsumsal, jamacku, jhuo, kdudka, klaas, kvolny, lnykryn, msekleta, pdwyer, svashisht | |
Target Milestone: | rc | |||
Target Release: | --- | |||
Hardware: | x86_64 | |||
OS: | Linux | |||
Whiteboard: | ||||
Fixed In Version: | tcsh-6.18.01-16.el7 | Doc Type: | If docs needed, set a value | |
Doc Text: | Story Points: | --- | ||
Clone Of: | ||||
: | 1765649 1765659 1846271 (view as bug list) | Environment: | ||
Last Closed: | 2020-03-31 20:09:46 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: | ||||
Bug Blocks: | 1643104, 1765649, 1818766, 1846271 |
Description
afox@redhat.com
2018-07-05 15:58:18 UTC
David, dkaspar is currently on PTO, so I had a look at this bug. I will try to summarize it here: This is the backtrace when tcsh exits when it can not allocate memory: #0 out_of_memory () at tc.alloc.c:69 #1 0x000000000044c2ad in smalloc (n=578604348) at tc.alloc.c:530 #2 0x00000000004553bf in s_strsave ( s=0x7fff46e4c010 L"VA\xf000009d\xf000009a\xf000009d\xf000009a\xf00000d1\xf00000cb\021\xf00000fd\001`\023\xf00000fd\001 ; 1\004\001\001\001\001\001\001\001\001\xf00000c0\021\xf00000fd\001!\xf00000ff\a < \xf000009e\xf000009a\xf00000d1\xf00000cb\177!\xf000009e\xf000009a\xf00000d1\xf00000cb\177!\xf000009e\xf000009a\xf00000d1\xf00000cb\177!\xf000009e\xf000009a\xf00000d1\xf00000cb\177\022\xf00000fd\001\xf00000e0\021\xf00000fdist$HOME/stop_start/lis\xf00000c1\xf000009e\xf000009a\xf00000d1\xf00000cb\177կ\xf000009a\xf00000d1\xf00000cb\020U\xf000009e\xf000009a\xf00000d1\xf00000cbop_start/listener \177\xf00000ff\xf00000ff\xf00000ff\xf00000ff\002 \xf000009e\xf000009a\xf00000d1\003!\"${VALUE_GREP_OUT}\"!\020\021\xf00000fd\xf000009e\xf000009a\xf00000d1\xf00000cb\177կ\xf000009a\xf00000d1\xf00000cb\177\xf00000ff\xf00000ff\xf00000ff\xf00000ff\006\xf0000083\xf00000b3\xf000009a\xf00000d1\xf00000cb\177!\xf000009e\xf000009a\xf00000d1\xf00000cb\177!\xf000009e\xf000009a\xf00000d1E/stop_sta"...) at tc.str.c:458 #3 0x000000000041c231 in enthist (event=7, lp=0x682ed0 <paraml>, docopy=1, mflg=0, hlen=100) at sh.hist.c:985 #4 0x000000000041b1ce in savehist (sp=0x682ed0 <paraml>, mflg=0) at sh.hist.c:150 #5 0x0000000000406f00 in process (catch=0) at sh.c:2091 #6 0x0000000000406544 in srcunit (unit=6, onlyown=0, hflg=1, av=0x6b6eb0) at sh.c:1761 #7 0x0000000000405c98 in srcfile (f=0x6bb7f0 "/home/situ/.history", onlyown=0, flag=1, av=0x6b6eb0) at sh.c:1553 #8 0x0000000000407330 in dosource (t=0x6b6eb0, c=0x0) at sh.c:2201 #9 0x000000000041cdbf in loadhist (fname=0x670b50 <STRNULL> L"", mflg=0) at sh.hist.c:1341 #10 0x0000000000405683 in main (argc=0, argv=0x7fffffffdee8) at sh.c:1362 This is the block of code in tc.str.c which is trying to allocate memory to copy a string from history: (gdb) l 453 size_t size; 454 455 if (s == NULL) 456 s = STRNULL; 457 size = (Strlen(s) + 1) * sizeof(*n); 458 n = xmalloc(size); 459 memcpy(n, s, size); 460 return (n); 461 } 462 String that is being saved is arbitrarily long: (gdb) p wcslen(s) $1 = 144651086 So this line: 457 size = (Strlen(s) + 1) * sizeof(*n); evaluates to: (gdb) p size $2 = 578604348 On my system, malloc fails while trying to allocate a chunk of this size. I think tcsh should put some limiations on length of string that is being saved. I would let dkaspar follow up on it when he is back from holidays. Right now we don't a proper fix there, postponing to 7.8. 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://access.redhat.com/errata/RHBA-2020:1177 Hi, this update lead to problems within one of our important production systems. [For the Red Hat people: Customer Case #02690226 with the corrupt .history file] We had a corrupt .history file (it included a line with thousands of characters). It is unclear what caused that corrupt file, but in any case -- tcsh should not write that corrupt file. Now with the corrupt file starting a shell will show a very unspecific error message: "$< line too long." and under certain conditions (which are not clear to us yet) will even lead to the shell not exiting properly. This in turn lead to the cron scripts that use tcsh to spawn process and not exit them anymore which lead to a monitoring script causing a process exhaustion for the application user. So there are three issues that need addressing: 1) do not write a corrupt history file 2) deal with a corrupt history file properly and not create hung processes 3) make the error message more clear, my first instinct was to search all files like .cshrc for a command that is too long :) Greetings Klaas Hi Klaas, I'm sorry for inconvenience. I'm working on fix. Please follow clone of this bug at rhbz #1846271 if possible. Thank you Greetings Jan |