unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer via Libc-alpha <libc-alpha@sourceware.org>
To: libc-alpha@sourceware.org
Subject: [PATCH] Linux: Use faccessat2 to implement faccessat (bug 18683)
Date: Fri, 07 Aug 2020 18:58:30 +0200	[thread overview]
Message-ID: <877dual7ex.fsf@oldenburg2.str.redhat.com> (raw)

This provides correct AT_EACCESS handling and also takes
Linux security modules into account.

Tested on i686-linux-gnu, x86_64-linux-gnu.  Built with
build-many-glibcs.py.

---
 sysdeps/unix/sysv/linux/faccessat.c       | 14 +++++++++++---
 sysdeps/unix/sysv/linux/kernel-features.h |  8 ++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/faccessat.c b/sysdeps/unix/sysv/linux/faccessat.c
index e4f18ab2db..56cb6dcc8b 100644
--- a/sysdeps/unix/sysv/linux/faccessat.c
+++ b/sysdeps/unix/sysv/linux/faccessat.c
@@ -30,6 +30,13 @@
 int
 faccessat (int fd, const char *file, int mode, int flag)
 {
+  int ret = INLINE_SYSCALL_CALL (faccessat2, fd, file, mode, flag);
+#if __ASSUME_FACCESSAT2
+  return ret;
+#else
+  if (ret == 0 || errno != ENOSYS)
+    return ret;
+
   if (flag & ~(AT_SYMLINK_NOFOLLOW | AT_EACCESS))
     return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL);
 
@@ -41,9 +48,9 @@ faccessat (int fd, const char *file, int mode, int flag)
     return -1;
 
   mode &= (X_OK | W_OK | R_OK);	/* Clear any bogus bits. */
-#if R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH
-# error Oops, portability assumptions incorrect.
-#endif
+# if R_OK != S_IROTH || W_OK != S_IWOTH || X_OK != S_IXOTH
+#  error Oops, portability assumptions incorrect.
+# endif
 
   if (mode == F_OK)
     return 0;			/* The file exists. */
@@ -68,4 +75,5 @@ faccessat (int fd, const char *file, int mode, int flag)
     return 0;
 
   return INLINE_SYSCALL_ERROR_RETURN_VALUE (EACCES);
+#endif /* !__ASSUME_FACCESSAT2 */
 }
diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h
index 32533e94cf..a6bbc3c94e 100644
--- a/sysdeps/unix/sysv/linux/kernel-features.h
+++ b/sysdeps/unix/sysv/linux/kernel-features.h
@@ -214,4 +214,12 @@
 # define __ASSUME_WAITID_PID0_P_PGID
 #endif
 
+/* The faccessat2 system call was introduced across all architectures
+   in Linux 5.8.  */
+#if __LINUX_KERNEL_VERSION >= 0x050800
+# define __ASSUME_FACCESSAT2 1
+#else
+# define __ASSUME_FACCESSAT2 0
+#endif
+
 #endif /* kernel-features.h */


             reply	other threads:[~2020-08-07 16:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-07 16:58 Florian Weimer via Libc-alpha [this message]
2020-08-07 19:58 ` [PATCH] Linux: Use faccessat2 to implement faccessat (bug 18683) Adhemerval Zanella via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877dual7ex.fsf@oldenburg2.str.redhat.com \
    --to=libc-alpha@sourceware.org \
    --cc=fweimer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).