From patchwork Wed Nov 16 13:44:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 695561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tJlqv2SnVz9t2C for ; Thu, 17 Nov 2016 00:44:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="W22glyJR"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; q=dns; s=default; b=cbh8psRBu0nuTGeV 3qPVBUvFW7kobNEZ0uzRPIJux+4QupN9JH7bzp1nzjNLyd1o7rfqSbnz5MnvsWRH 0Wq2HLtRzR/Lj3aRobcs2rG8i9eey4Usv7isnbuVmVLoRTiP931lYguolbtN9sfB k86uBZ0jHpOJw+ARWeqYQjYlVJk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:subject:to:references:from:message-id:date :mime-version:in-reply-to:content-type :content-transfer-encoding; s=default; bh=pD6el4rwvNU5TGeWud2UXo DGZNE=; b=W22glyJRECUcOFXPqWYONdjXpZIbkiI/Szr5PjCWi3H4ayti1jGMSy B/gpHSiNMoHJnog6bWN6aMqFs2tRxKxEKgS+bUArJ1AzEFmYLeo1aTr3zfUARSiW GKwJuMVcBxPdzIYXWR3x1oQqO+QEe7T8xrMueoYolRu3WgADHAsAc= Received: (qmail 53419 invoked by alias); 16 Nov 2016 13:44:51 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 53405 invoked by uid 89); 16 Nov 2016 13:44:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=BAYES_50, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS, URIBL_RED autolearn=no version=3.3.2 spammy=2220, tunables, sk:develop, malloc_check_ X-HELO: mail-ua0-f178.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=YPlk9Dkd3LCLa78dG2+5Lz1LgReLzLbXLrOoW4RDMow=; b=lzx/SVSS3HxUrkJ3ha8NMbdtLHted8B5CrY2t5Iw1RlKOPFbNQwAaufoIFgNUmPfAW 9OY+FjcUSZi4+QMhTx9PLtPDtcWZAx+4+rcnBMdfcTqY+6xqFYnTSZOT+s+QSVoHG6Nz 9d5J1Knh+GL76iqRxaDc9GFWtbIGmwUQOLGPcbKcaiDMHfO4NmusZU5nbxXfuAnqjvoG ISbKS1mcP6WJFnDw17q7f32zmZmvYTrNxGPDxxBgZOCfRy1MTiy4pnjcPu7WxKKqZPSC cBlQ6wA6F4HKo/bH0YdE2nieoZqn/G5GliKd8pk0f3Fsl9YmHEcowVq2SP/4BDdCQqSm 4UcQ== X-Gm-Message-State: ABUngvdOBqaj5PrhS7hbwHBk0eT/A7SgCAtr1pmwKK/J4f83e2RKxb4DB7UtXDITDO2r2H4c X-Received: by 10.176.0.41 with SMTP id 38mr1653674uai.47.1479303878132; Wed, 16 Nov 2016 05:44:38 -0800 (PST) Subject: Re: [PATCH 2/2] New internal function __access_noerrno To: Siddhesh Poyarekar , libc-alpha@sourceware.org References: <1478797446-12213-1-git-send-email-adhemerval.zanella@linaro.org> <1478797446-12213-2-git-send-email-adhemerval.zanella@linaro.org> <083c6da8-5c67-acba-f7f0-79fb4253d7d2@gotplt.org> <23ef1354-7ade-70fe-46f0-59392798ef82@linaro.org> <60199742-d6f4-3f2a-ad38-619dcfdc7954@linaro.org> From: Adhemerval Zanella Message-ID: Date: Wed, 16 Nov 2016 11:44:35 -0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <60199742-d6f4-3f2a-ad38-619dcfdc7954@linaro.org> On 16/11/2016 11:27, Adhemerval Zanella wrote: > > > On 10/11/2016 16:31, Adhemerval Zanella wrote: >> >> >> On 10/11/2016 15:53, Siddhesh Poyarekar wrote: >>> On Thursday 10 November 2016 10:34 PM, Adhemerval Zanella wrote: >>>> This ia follow up patch for tunables requirement [1]. It Implement >>>> an internal version of __access called __access_noerrno that >>>> avoids setting errno. This is useful to check accessibility of files >>>> very early on in process startup i.e. before TLS setup. This allows >>>> tunables to replace MALLOC_CHECK_ safely (i.e. check existence of >>>> /etc/suid-debug to enable/disable MALLOC_CHECK) and at the same time >>>> initialize very early so that it can override IFUNCs. >>> >>> I think someone else should also review and ack this one, but I'll do a >>> review round anyway. >> >> Thanks, I fixes all my mistakes locally. It would be good to have a >> ack for nacl/hurd before pushing it. > > I tried both hurd [1] and nacl [2] environments to check the build but > without success. Hurd VM does not boot with a recent qemu (2.7.50) and > NaCL toolchain seems stuck in a ancient gcc version (4.4.7). Since I > this patch won't break any functionality (since it only adds a new > symbol), I see it should be safe to push. > > [1] https://people.debian.org/~sthibault/hurd-i386/README > [2] https://developer.chrome.com/native-client/sdk/download Updated version below: * hurd/hurd.h (__hurd_fail_noerrno): New function. * include/unistd.h [IS_IN (rtld) || !defined SHARED]: Declare __access_noerrno. * io/access.c (__access_noerrno): New function. * sysdeps/mach/hurd/access.c (hurd_fail_seterrno): New function. (hurd_fail_seterrno): Likewise. (access_common): Likewise. (__access_noerrno): Likewise. * sysdeps/nacl/access.c (__access_noerrno): Likewise. * sysdeps/unix/sysv/linux/access.c (__access_noerrno): Likewise. * sysdeps/nacl/nacl-interfaces.h (NACL_CALL_NOERRNO): New macro. --- ChangeLog | 15 +++++++++++++++ hurd/hurd.h | 29 +++++++++++++++++++++++++++++ include/unistd.h | 6 ++++++ io/access.c | 7 +++++++ sysdeps/mach/hurd/access.c | 37 +++++++++++++++++++++++++++++++------ sysdeps/nacl/access.c | 7 +++++++ sysdeps/nacl/nacl-interfaces.h | 4 ++++ sysdeps/unix/sysv/linux/access.c | 15 +++++++++++++++ 8 files changed, 114 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index dfa48e4..b2e5b68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2016-11-16 Adhemerval Zanella + + * hurd/hurd.h (__hurd_fail_noerrno): New function. + * include/unistd.h [IS_IN (rtld) || !defined SHARED]: Declare + __access_noerrno. + * io/access.c (__access_noerrno): New function. + * sysdeps/mach/hurd/access.c (hurd_fail_seterrno): New function. + (hurd_fail_seterrno): Likewise. + (access_common): Likewise. + (__access_noerrno): Likewise. + * sysdeps/nacl/access.c (__access_noerrno): Likewise. + * sysdeps/unix/sysv/linux/access.c (__access_noerrno): Likewise. + * sysdeps/nacl/nacl-interfaces.h (NACL_CALL_NOERRNO): New + macro. + 2016-11-16 Joseph Myers * sysdeps/unix/sysv/linux/sh/sh4/register-dump.h (register_dump): diff --git a/hurd/hurd.h b/hurd/hurd.h index ec07827..c089d4c 100644 --- a/hurd/hurd.h +++ b/hurd/hurd.h @@ -75,6 +75,35 @@ __hurd_fail (error_t err) errno = err; return -1; } + +_HURD_H_EXTERN_INLINE int +__hurd_fail_noerrno (error_t err) +{ + switch (err) + { + case EMACH_SEND_INVALID_DEST: + case EMIG_SERVER_DIED: + /* The server has disappeared! */ + err = EIEIO; + break; + + case KERN_NO_SPACE: + err = ENOMEM; + break; + + case KERN_INVALID_ARGUMENT: + err = EINVAL; + break; + + case 0: + return 0; + + default: + break; + } + + return -1; +} /* Basic ports and info, initialized by startup. */ diff --git a/include/unistd.h b/include/unistd.h index d2802b2..6144f41 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -181,6 +181,12 @@ extern int __getlogin_r_loginuid (char *name, size_t namesize) # include # endif +# if IS_IN (rtld) || !defined SHARED +/* __access variant that does not set errno. Used in very early initialization + code in libc.a and ld.so. */ +extern __typeof (__access) __access_noerrno attribute_hidden; +# endif + __END_DECLS # endif diff --git a/io/access.c b/io/access.c index 4534704..859cf75 100644 --- a/io/access.c +++ b/io/access.c @@ -19,6 +19,13 @@ #include #include +/* Test for access to FILE without setting errno. */ +int +__access_noerrno (const char *file, int type) +{ + return -1; +} + /* Test for access to FILE. */ int __access (const char *file, int type) diff --git a/sysdeps/mach/hurd/access.c b/sysdeps/mach/hurd/access.c index c308340..620acea 100644 --- a/sysdeps/mach/hurd/access.c +++ b/sysdeps/mach/hurd/access.c @@ -22,9 +22,20 @@ #include #include -/* Test for access to FILE by our real user and group IDs. */ -int -__access (const char *file, int type) +static int +hurd_fail_seterrno (error_t err) +{ + return __hurd_fail (err); +} + +static int +hurd_fail_noerrno (error_t err) +{ + return __hurd_fail_noerrno (err); +} + +static int +access_common (const char *file, int type, int (*errfunc) (error_t)) { error_t err; file_t rcrdir, rcwdir, io; @@ -120,13 +131,13 @@ __access (const char *file, int type) if (rcwdir != MACH_PORT_NULL) __mach_port_deallocate (__mach_task_self (), rcwdir); if (err) - return __hurd_fail (err); + return errfunc (err); /* Find out what types of access we are allowed to this file. */ err = __file_check_access (io, &allowed); __mach_port_deallocate (__mach_task_self (), io); if (err) - return __hurd_fail (err); + return errfunc (err); flags = 0; if (type & R_OK) @@ -138,9 +149,23 @@ __access (const char *file, int type) if (flags & ~allowed) /* We are not allowed all the requested types of access. */ - return __hurd_fail (EACCES); + return errfunc (EACESS); return 0; } +/* Test for access to FILE by our real user and group IDs without setting + errno. */ +int +__access_noerrno (const char *file, int type) +{ + return access_common (file, type, hurd_fail_noerrno); +} + +/* Test for access to FILE by our real user and group IDs. */ +int +__access (const char *file, int type) +{ + return access_common (file, type, hurd_fail); +} weak_alias (__access, access) diff --git a/sysdeps/nacl/access.c b/sysdeps/nacl/access.c index 95a0fb7..e07d558 100644 --- a/sysdeps/nacl/access.c +++ b/sysdeps/nacl/access.c @@ -19,6 +19,13 @@ #include #include +/* Test for access to FILE without setting errno. */ +int +__access_noerrno (const char *file, int type) +{ + return NACL_CALL_NOERRNO (__nacl_irt_dev_filename.access (file, type), 0); +} + /* Test for access to FILE. */ int __access (const char *file, int type) diff --git a/sysdeps/nacl/nacl-interfaces.h b/sysdeps/nacl/nacl-interfaces.h index b7b45bb..edd3217 100644 --- a/sysdeps/nacl/nacl-interfaces.h +++ b/sysdeps/nacl/nacl-interfaces.h @@ -113,4 +113,8 @@ __nacl_fail (int err) #define NACL_CALL(err, val) \ ({ int _err = (err); _err ? __nacl_fail (_err) : (val); }) +/* Same as NACL_CALL but without setting errno. */ +#define NACL_CALL_NOERRNO(err, val) \ + ({ int _err = (err); _err ? _err : (val); }) + #endif /* nacl-interfaces.h */ diff --git a/sysdeps/unix/sysv/linux/access.c b/sysdeps/unix/sysv/linux/access.c index 8f003df..adefbca 100644 --- a/sysdeps/unix/sysv/linux/access.c +++ b/sysdeps/unix/sysv/linux/access.c @@ -21,6 +21,21 @@ #include int +__access_noerrno (const char *file, int type) +{ + int res; + INTERNAL_SYSCALL_DECL (err); +#ifdef __NR_access + res = INTERNAL_SYSCALL_CALL (access, err, file, type); +#else + res = INTERNAL_SYSCALL_CALL (faccessat, err, AT_FDCWD, file, type); +#endif + if (INTERNAL_SYSCALL_ERROR_P (res, err)) + return INTERNAL_SYSCALL_ERRNO (res, err); + return 0; +} + +int __access (const char *file, int type) { #ifdef __NR_access