From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13737 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] Add missing __syscall_ret in dl_mmap Date: Sat, 9 Feb 2019 09:35:45 -0500 Message-ID: <20190209143545.GY23599@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="45131"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-13753-gllmg-musl=m.gmane.org@lists.openwall.com Sat Feb 09 15:36:02 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.89) (envelope-from ) id 1gsTjd-000Bd1-Fo for gllmg-musl@m.gmane.org; Sat, 09 Feb 2019 15:36:01 +0100 Original-Received: (qmail 17919 invoked by uid 550); 9 Feb 2019 14:35:59 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 17898 invoked from network); 9 Feb 2019 14:35:58 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:13737 Archived-At: On Sat, Feb 09, 2019 at 05:34:02PM +0400, Ilya Matveychikov wrote: > Signed-off-by: Ilya V. Matveychikov > --- > ldso/dynlink.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/ldso/dynlink.c b/ldso/dynlink.c > index ec921df..329b42a 100644 > --- a/ldso/dynlink.c > +++ b/ldso/dynlink.c > @@ -904,6 +904,7 @@ static void *dl_mmap(size_t n) > #else > p = (void *)__syscall(SYS_mmap, 0, n, prot, flags, -1, 0); > #endif > + p = (void *)__syscall_ret((unsigned long)p); > return p == MAP_FAILED ? 0 : p; > } I think you're right that the calling code expects dl_mmap to return 0, not a negative error code cast to an invalid pointer, on failure. However the change above is wrong. The whole reason the dl_mmap function exists is that it's used at a point at which non-static function calls can't be made (technically, calls to hidden functions probably work but it's not a property that we rely on), and at which accessing TLS (and thus errno in the error path) is not yet possible. The right fix would probably be something like: return (uintptr_t)p > -4096 ? 0 : p; Out of curiousity, how did you come across this? Rich