From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RDNS_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 28261 invoked from network); 11 Mar 2020 00:47:45 -0000 Received-SPF: pass (mother.openwall.net: domain of lists.openwall.com designates 195.42.179.200 as permitted sender) receiver=inbox.vuxu.org; client-ip=195.42.179.200 envelope-from= Received: from unknown (HELO mother.openwall.net) (195.42.179.200) by inbox.vuxu.org with ESMTP; 11 Mar 2020 00:47:45 -0000 Received: (qmail 8151 invoked by uid 550); 11 Mar 2020 00:47:42 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 8133 invoked from network); 11 Mar 2020 00:47:41 -0000 Date: Tue, 10 Mar 2020 20:47:29 -0400 From: Rich Felker To: Pirmin Walthert , musl@lists.openwall.com Message-ID: <20200311004729.GD11469@brightrain.aerifal.cx> References: <41ea935d-39e4-1460-e502-5c82d7dd6a4d@wwcom.ch> <20200309171227.GY11469@brightrain.aerifal.cx> <82b69741-72e6-ab53-c523-ce4e1e7dc98e@wwcom.ch> <20200309185536.GI14278@port70.net> <5957e47c-50c6-0ae1-3e5c-32fd96c756eb@wwcom.ch> <20200310100657.GK14278@port70.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200310100657.GK14278@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] Re: FYI: some observations when testing next-gen malloc On Tue, Mar 10, 2020 at 11:06:57AM +0100, Szabolcs Nagy wrote: > * Pirmin Walthert [2020-03-10 10:44:46 +0100]: > > Am 09.03.20 um 19:55 schrieb Szabolcs Nagy: > > > * Pirmin Walthert [2020-03-09 19:14:59 +0100]: > > > > Am 09.03.20 um 18:12 schrieb Rich Felker: > > > > > It's not described very rigorously, but effectively it's in an async > > > > > signal context and can only call functions which are AS-safe. > > > > > > > > > > A future version of the standard is expected to drop the requirement > > > > > that fork itself be async-signal-safe, and may thereby add > > > > > requirements to synchronize against some or all internal locks so that > > > > > the child can inherit a working context. But the right solution here is > > > > > always to stop using fork without exec. > > > > > > > > > > Rich > > > > Well, I have now changed the code a bit to make sure that no > > > > async-signal-unsafe command is being executed before execl. Things I've > > > > removed: > > > > > > > > a call to cap_from_text, cap_set_proc and cap_free has been removed as well > > > > as sched_setscheduler. Now the only thing being executed before execl in the > > > > child process is closefrom() > > > > > > closefrom is not as-safe. > > > > > > i think it reads /proc/self/fd directory to close fds. > > > (haven't checked the specific asterisk version) > > > opendir calls malloc so it can deadlock. > > > > > Indeed I am not able to reproduce the problem any longer with a modified > > version of asterisk. What I've changed is: > > > > Removed some code that sets the capabilities after fork() (with > > cap_from_text, cap_set_proc, cap_free) and closefrom replaced with a thumb > > loop over all possible fds up to sysconf(_SC_OPEN_MAX). With this > > modification the fd closing procedure with max open files set to 21471 now > > needs 7ms instead of 70ns (so a slowdown by times 100), however this is not > > critical in our environment... > > > > Will discuss the findings with the asterisk developers. > > > > Thanks for your hints! > > good. > > ideally they would use close-on-exec fds and then > you don't need such ugliness. > > please don't drop the list from replies. While indeed the right thing is not to do is a closefrom/closeall hack at all, if you really can't fix the fd leaks and need to, there is a fast but safe version that doesn't require listing /proc/self/fd. Instead, call poll() with a large array of pollfd with .events = 0 for each element, and zero timeout, and check the .revents of each for POLLNVAL. This will tell you with very few syscalls (probably just 1) which file descriptors are open. Rich