From patchwork Thu Nov 10 17:04:06 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: 81708 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp832607qge; Thu, 10 Nov 2016 09:04:45 -0800 (PST) X-Received: by 10.99.133.200 with SMTP id u191mr25186646pgd.28.1478797485327; Thu, 10 Nov 2016 09:04:45 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id i27si5851085pgn.68.2016.11.10.09.04.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Nov 2016 09:04:45 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-74651-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-74651-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-74651-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=N5O3+eoWNi1ST7lOHW9NDTBJDXmHgWg 0saTMBjm/6N2EyIEBpSgf9q/GFL9Ww72s9rMlRZSXdgJryEoa2Q3QlL8CDgZrlyA kFh9gbY3gj9fqoaHDvVgNUT2cM5cVLYG/Bq8Uhpr9WYXLhFEiPXYODDOLJtMhjDM 1FO7EtAbcqXY= 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:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=hRYcqXxNO2Ogq9OUb60qnuNq0sc=; b=VOJ+X hCD2JF4V7cirXXt/VtY3GfQQu+L/WB4OEZwKXVIw5rMF4XpAvMCLrQU5YyY6GxhL MLCfR79gpUjXj0Bb3vktebhlVQ2ZwGb5tx3dH21jJ22FIkqYGz1d23mS5eaj+Una sEuGJaFbKXp9iAmDFGX+rkecv2byZMH3/1hFoo= Received: (qmail 46548 invoked by alias); 10 Nov 2016 17:04:27 -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 46449 invoked by uid 89); 10 Nov 2016 17:04:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=siddheshsourcewareorg, siddhesh@sourceware.org, U*siddhesh, sk:siddhes X-HELO: mail-vk0-f45.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=BK87pY+qVUNUGonQVh+yCL6GCQRNlAMHESf0iY+bOKs=; b=I2thL6UqiNb0XEZB46zQD8ysvEcB87O9P79hH64QgD8s7D5DJHzqQVRqlKDJuT3wOE L1+288e+FfDaHQtezHl5CDcnrxI5WF4okL9k+t1WljvFPhRZozE7CCLl+c7jNMuPBsQF 1YupkqGrvtSJkqucHLaAlllskrUEypzyGffmvCcnZCWxS07i4Hw2mIRD+XdHK2vbK1cY u5f9nsYwlQmNMV49YeudvP27LEC2Smma3wjGLF7S6H8P++3/3LPKfA1T8MKW3ZdXKrBE GWhc83dNd3hnnebwmCJpS5+IpxsxqLDJ7McGAF/KLhwDLsD6op/xmWlGSqQ4UWqHxsOJ 9FRw== X-Gm-Message-State: ABUngvdLGOnnmatUIzGOTxwIPZL132HxbF9ym9U64+xsEnT2ZK2n/md86hTPAU7CbtcH1RCt X-Received: by 10.31.86.132 with SMTP id k126mr4156661vkb.11.1478797454765; Thu, 10 Nov 2016 09:04:14 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/2] New internal function __access_noerrno Date: Thu, 10 Nov 2016 15:04:06 -0200 Message-Id: <1478797446-12213-2-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1478797446-12213-1-git-send-email-adhemerval.zanella@linaro.org> References: <1478797446-12213-1-git-send-email-adhemerval.zanella@linaro.org> 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. Checked on x86_64. Siddhesh Poyarekar 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. [1] https://sourceware.org/ml/libc-alpha/2016-11/msg00399.html --- ChangeLog | 13 +++++++++++++ hurd/hurd.h | 30 ++++++++++++++++++++++++++++++ include/unistd.h | 6 ++++++ io/access.c | 8 +++++++- 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, 113 insertions(+), 7 deletions(-) -- 2.7.4 diff --git a/hurd/hurd.h b/hurd/hurd.h index ec07827..8bcb1ec 100644 --- a/hurd/hurd.h +++ b/hurd/hurd.h @@ -75,6 +75,36 @@ __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; + } + + errno = err; + 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..68b49ca 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) @@ -33,5 +40,4 @@ __access (const char *file, int type) return -1; } stub_warning (access) - weak_alias (__access, access) 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..4266d63 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 (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 cdb7908..004da1b 100644 --- a/sysdeps/unix/sysv/linux/access.c +++ b/sysdeps/unix/sysv/linux/access.c @@ -19,6 +19,21 @@ #include #include +int +__access_noerro (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; +} + /* Test for access to FILE. */ int __access (const char *file, int type)