From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id e035ee94 for ; Fri, 13 Dec 2019 10:32:34 +0000 (UTC) Received: (qmail 8638 invoked by alias); 13 Dec 2019 10:32:29 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45016 Received: (qmail 25311 invoked by uid 1010); 13 Dec 2019 10:32:29 -0000 X-Qmail-Scanner-Diagnostics: from mailout1.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25656. spamassassin: 3.4.2. Clear:RC:0(210.118.77.11):SA:0(-7.0/5.0):. Processed in 2.842655 secs); 13 Dec 2019 10:32:29 -0000 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.samsung.com designates 210.118.77.11 as permitted sender) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20191213103150euoutp0157c62d05989640268fcce30aad24bacb~f56mVk0Mn2395723957euoutp01v X-AuditID: cbfec7f5-a0fff7000001ed1a-e4-5df36895bdbb Message-ID: <1576233108.5214.5.camel@samsung.com> Subject: Re: [BUG] Crash due to malloc call in signal handler From: Peter Stephenson To: Zsh hackers list Date: Fri, 13 Dec 2019 10:31:48 +0000 In-Reply-To: X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: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S/ZAPjae4uRk4OCQETiZ3tMxm7GLk4hASWMkrMvfiTHSIhI/HpykcoW1ji z7UuNoiibiaJV+unMUM4ZxglLvyaCOVcYJR4unIN0CwODl4BQ4mmjYog3cICthJbJs9hBLHZ gMJTN80Gs0UEtCR2nDzJBGKzCKhKNLZOZQOxOQUCJT60HYeaOYlZ4n3rR1aQBLOApkTr9t9Q J2lIbLh5DKyZV0BQ4uTMJywQNfISzVtnM09gFJqFpGUWkrJZSMoWMDKvYhRJLS3OTc8tNtIr TswtLs1L10vOz93ECAz+bcd+btnB2PUu+BCjAAejEg/visRPsUKsiWXFlbmHGCU4mJVEeFO1 P8cK8aYkVlalFuXHF5XmpBYfYjQF+mgis5Rocj4wMvNK4g1NDc0tLA3Njc2NzSyUxHk7BA7G CAmkJ5akZqemFqQWwfQxcXBKNTDuzbq7eef/6FCf399/hS51vqBw7M5ut0XTNXamel+66XVR SKjoour82DULjE42zdn/kz3qNe+cRfaSJldffn7ygqc3RNruUlqs4UNF7R9XX1lkP2L6Gj5h tvrOJN5TPnGnir9yHHmyc+m+9YeOTd8o5NX9Sq9m+wSFspz9L6f5GJ0oWS57p+r3cSWW4oxE Qy3mouJEAN9TGdeUAgAA X-CMS-MailID: 20191213103149eucas1p14b3d89d6bc21267f7da12b065fc28def X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20191212182957epcas5p48645aa560e781ac1c34f00662a6d6176 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20191212182957epcas5p48645aa560e781ac1c34f00662a6d6176 References: <2022943386.989309814.1576175339554.JavaMail.root@zimbra62-e11.priv.proxad.net> <1576230001.5214.1.camel@samsung.com> <1576232178.5214.2.camel@samsung.com> On Fri, 2019-12-13 at 11:19 +0100, Roman Perepelitsa wrote: > On Fri, Dec 13, 2019 at 11:17 AM Peter Stephenson > wrote: > >  > >  > > On Fri, 2019-12-13 at 10:45 +0100, Roman Perepelitsa wrote: > > >  > > > On Fri, Dec 13, 2019 at 10:40 AM Peter Stephenson > > > wrote: > > > >  > > > >  > > > > The main shell is suspended, waiting for a child to finish, so the fact > > > > it's in the signal handler isn't saying anything. > > > >  > > > > From the look of it, some memory corruption must already have occurred > > > > at this point to get the malloc to fail. > > > malloc is not async signal safe. It's illegal to call it from a signal > > > handler. I'm not saying this is what's causing a crash. > > In zsh, this is handled by queuing interrupts and only allowing them to > > run in a few places in the code.  Obviously, waiting for a child to > > exit is one of those places. > The stack trace shows malloc being called zhandler. zhandler is a > signal handler. What am I missing? You're not missing anything there, that's how it works. Interrupts are queued so they don't normally go off. In certain places they are allowed to take place; one of these is when we are sitting waiting for a child to exit. At this point the signal handler will then run. Thus the signal handler is supposed not to be running when any memory management is taking place underneath.  So it's not asynchronous with respect to code actually running in the main shell (despite being run from a signal handler which can formally occur anywhere, but we make sure it doesn't). Of course, there's the possibility of bugs in this, but the stack in this case doesn't show evidence of that at the point in question. You'll find long discussions of this in the mail archive going back some years. pws