|
|
17b0f1 |
From 66d06bd0a577ddb2461e8d1e5c8c2fbf6845227d Mon Sep 17 00:00:00 2001
|
|
|
17b0f1 |
From: Lukas Nykryn <lnykryn@redhat.com>
|
|
|
17b0f1 |
Date: Wed, 19 Nov 2014 12:14:13 +0100
|
|
|
17b0f1 |
Subject: [PATCH] Revert "missing: remove fanotify"
|
|
|
17b0f1 |
|
|
|
17b0f1 |
This reverts commit c7e4a7bece7a5c4484d229dd5e8ff01a5d49c62e.
|
|
|
17b0f1 |
|
|
|
17b0f1 |
Conflicts:
|
|
|
17b0f1 |
src/shared/missing.h
|
|
|
17b0f1 |
---
|
|
|
17b0f1 |
Makefile.am | 1 +
|
|
|
17b0f1 |
configure.ac | 1 +
|
|
|
17b0f1 |
src/shared/linux/fanotify.h | 98 +++++++++++++++++++++++++++++++++++++
|
|
|
17b0f1 |
src/shared/missing.h | 64 ++++++++++++++++++++++++
|
|
|
17b0f1 |
4 files changed, 164 insertions(+)
|
|
|
17b0f1 |
create mode 100644 src/shared/linux/fanotify.h
|
|
|
17b0f1 |
|
|
|
17b0f1 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
17b0f1 |
index a734e9c486..70e4fbc6d4 100644
|
|
|
17b0f1 |
--- a/Makefile.am
|
|
|
17b0f1 |
+++ b/Makefile.am
|
|
|
17b0f1 |
@@ -749,6 +749,7 @@ libsystemd_shared_la_SOURCES = \
|
|
|
17b0f1 |
src/shared/capability.c \
|
|
|
17b0f1 |
src/shared/capability.h \
|
|
|
17b0f1 |
src/shared/linux/auto_dev-ioctl.h \
|
|
|
17b0f1 |
+ src/shared/linux/fanotify.h \
|
|
|
17b0f1 |
src/shared/ioprio.h \
|
|
|
17b0f1 |
src/shared/missing.h \
|
|
|
17b0f1 |
src/shared/initreq.h \
|
|
|
17b0f1 |
diff --git a/configure.ac b/configure.ac
|
|
|
17b0f1 |
index 97a29d63fd..3f50887a8d 100644
|
|
|
17b0f1 |
--- a/configure.ac
|
|
|
17b0f1 |
+++ b/configure.ac
|
|
|
17b0f1 |
@@ -310,6 +310,7 @@ RT_LIBS="$LIBS"
|
|
|
17b0f1 |
AC_SUBST(RT_LIBS)
|
|
|
17b0f1 |
LIBS="$save_LIBS"
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+AC_CHECK_FUNCS([fanotify_init fanotify_mark])
|
|
|
17b0f1 |
AC_CHECK_FUNCS([memfd_create])
|
|
|
17b0f1 |
AC_CHECK_FUNCS([__secure_getenv secure_getenv])
|
|
|
17b0f1 |
AC_CHECK_DECLS([gettid, pivot_root, name_to_handle_at, setns, getrandom, renameat2, kcmp, LO_FLAGS_PARTSCAN],
|
|
|
17b0f1 |
diff --git a/src/shared/linux/fanotify.h b/src/shared/linux/fanotify.h
|
|
|
17b0f1 |
new file mode 100644
|
|
|
17b0f1 |
index 0000000000..5cc1a7e676
|
|
|
17b0f1 |
--- /dev/null
|
|
|
17b0f1 |
+++ b/src/shared/linux/fanotify.h
|
|
|
17b0f1 |
@@ -0,0 +1,98 @@
|
|
|
17b0f1 |
+#ifndef _LINUX_FANOTIFY_H
|
|
|
17b0f1 |
+#define _LINUX_FANOTIFY_H
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#include <linux/types.h>
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/* the following events that user-space can register for */
|
|
|
17b0f1 |
+#define FAN_ACCESS 0x00000001 /* File was accessed */
|
|
|
17b0f1 |
+#define FAN_MODIFY 0x00000002 /* File was modified */
|
|
|
17b0f1 |
+#define FAN_CLOSE_WRITE 0x00000008 /* Unwrittable file closed */
|
|
|
17b0f1 |
+#define FAN_CLOSE_NOWRITE 0x00000010 /* Writtable file closed */
|
|
|
17b0f1 |
+#define FAN_OPEN 0x00000020 /* File was opened */
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/* FIXME currently Q's have no limit.... */
|
|
|
17b0f1 |
+#define FAN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#define FAN_OPEN_PERM 0x00010000 /* File open in perm check */
|
|
|
17b0f1 |
+#define FAN_ACCESS_PERM 0x00020000 /* File accessed in perm check */
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/* helper events */
|
|
|
17b0f1 |
+#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/* flags used for fanotify_init() */
|
|
|
17b0f1 |
+#define FAN_CLOEXEC 0x00000001
|
|
|
17b0f1 |
+#define FAN_NONBLOCK 0x00000002
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK)
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/* flags used for fanotify_modify_mark() */
|
|
|
17b0f1 |
+#define FAN_MARK_ADD 0x00000001
|
|
|
17b0f1 |
+#define FAN_MARK_REMOVE 0x00000002
|
|
|
17b0f1 |
+#define FAN_MARK_DONT_FOLLOW 0x00000004
|
|
|
17b0f1 |
+#define FAN_MARK_ONLYDIR 0x00000008
|
|
|
17b0f1 |
+#define FAN_MARK_MOUNT 0x00000010
|
|
|
17b0f1 |
+#define FAN_MARK_IGNORED_MASK 0x00000020
|
|
|
17b0f1 |
+#define FAN_MARK_IGNORED_SURV_MODIFY 0x00000040
|
|
|
17b0f1 |
+#define FAN_MARK_FLUSH 0x00000080
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD |\
|
|
|
17b0f1 |
+ FAN_MARK_REMOVE |\
|
|
|
17b0f1 |
+ FAN_MARK_DONT_FOLLOW |\
|
|
|
17b0f1 |
+ FAN_MARK_ONLYDIR |\
|
|
|
17b0f1 |
+ FAN_MARK_MOUNT |\
|
|
|
17b0f1 |
+ FAN_MARK_IGNORED_MASK |\
|
|
|
17b0f1 |
+ FAN_MARK_IGNORED_SURV_MODIFY)
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/*
|
|
|
17b0f1 |
+ * All of the events - we build the list by hand so that we can add flags in
|
|
|
17b0f1 |
+ * the future and not break backward compatibility. Apps will get only the
|
|
|
17b0f1 |
+ * events that they originally wanted. Be sure to add new events here!
|
|
|
17b0f1 |
+ */
|
|
|
17b0f1 |
+#define FAN_ALL_EVENTS (FAN_ACCESS |\
|
|
|
17b0f1 |
+ FAN_MODIFY |\
|
|
|
17b0f1 |
+ FAN_CLOSE |\
|
|
|
17b0f1 |
+ FAN_OPEN)
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/*
|
|
|
17b0f1 |
+ * All events which require a permission response from userspace
|
|
|
17b0f1 |
+ */
|
|
|
17b0f1 |
+#define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM |\
|
|
|
17b0f1 |
+ FAN_ACCESS_PERM)
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS |\
|
|
|
17b0f1 |
+ FAN_ALL_PERM_EVENTS |\
|
|
|
17b0f1 |
+ FAN_Q_OVERFLOW)
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#define FANOTIFY_METADATA_VERSION 2
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+struct fanotify_event_metadata {
|
|
|
17b0f1 |
+ __u32 event_len;
|
|
|
17b0f1 |
+ __u32 vers;
|
|
|
17b0f1 |
+ __u64 mask;
|
|
|
17b0f1 |
+ __s32 fd;
|
|
|
17b0f1 |
+ __s32 pid;
|
|
|
17b0f1 |
+} __attribute__ ((packed));
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+struct fanotify_response {
|
|
|
17b0f1 |
+ __s32 fd;
|
|
|
17b0f1 |
+ __u32 response;
|
|
|
17b0f1 |
+} __attribute__ ((packed));
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/* Legit userspace responses to a _PERM event */
|
|
|
17b0f1 |
+#define FAN_ALLOW 0x01
|
|
|
17b0f1 |
+#define FAN_DENY 0x02
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+/* Helper functions to deal with fanotify_event_metadata buffers */
|
|
|
17b0f1 |
+#define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, \
|
|
|
17b0f1 |
+ (struct fanotify_event_metadata*)(((char *)(meta)) + \
|
|
|
17b0f1 |
+ (meta)->event_len))
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && \
|
|
|
17b0f1 |
+ (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && \
|
|
|
17b0f1 |
+ (long)(meta)->event_len <= (long)(len))
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#endif /* _LINUX_FANOTIFY_H */
|
|
|
17b0f1 |
diff --git a/src/shared/missing.h b/src/shared/missing.h
|
|
|
17b0f1 |
index b33a70cb2c..06a55769a4 100644
|
|
|
17b0f1 |
--- a/src/shared/missing.h
|
|
|
17b0f1 |
+++ b/src/shared/missing.h
|
|
|
17b0f1 |
@@ -156,6 +156,70 @@ static inline int pivot_root(const char *new_root, const char *put_old) {
|
|
|
17b0f1 |
# endif
|
|
|
17b0f1 |
#endif
|
|
|
17b0f1 |
|
|
|
17b0f1 |
+#ifdef __x86_64__
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_init
|
|
|
17b0f1 |
+# define __NR_fanotify_init 300
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_mark
|
|
|
17b0f1 |
+# define __NR_fanotify_mark 301
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+#elif defined _MIPS_SIM
|
|
|
17b0f1 |
+# if _MIPS_SIM == _MIPS_SIM_ABI32
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_init
|
|
|
17b0f1 |
+# define __NR_fanotify_init 4336
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_mark
|
|
|
17b0f1 |
+# define __NR_fanotify_mark 4337
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+# elif _MIPS_SIM == _MIPS_SIM_NABI32
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_init
|
|
|
17b0f1 |
+# define __NR_fanotify_init 6300
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_mark
|
|
|
17b0f1 |
+# define __NR_fanotify_mark 6301
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+# elif _MIPS_SIM == _MIPS_SIM_ABI64
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_init
|
|
|
17b0f1 |
+# define __NR_fanotify_init 5295
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_mark
|
|
|
17b0f1 |
+# define __NR_fanotify_mark 5296
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+#else
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_init
|
|
|
17b0f1 |
+# define __NR_fanotify_init 338
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+# ifndef __NR_fanotify_mark
|
|
|
17b0f1 |
+# define __NR_fanotify_mark 339
|
|
|
17b0f1 |
+# endif
|
|
|
17b0f1 |
+#endif
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#ifndef HAVE_FANOTIFY_INIT
|
|
|
17b0f1 |
+static inline int fanotify_init(unsigned int flags, unsigned int event_f_flags) {
|
|
|
17b0f1 |
+ return syscall(__NR_fanotify_init, flags, event_f_flags);
|
|
|
17b0f1 |
+}
|
|
|
17b0f1 |
+#endif
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+#ifndef HAVE_FANOTIFY_MARK
|
|
|
17b0f1 |
+static inline int fanotify_mark(int fanotify_fd, unsigned int flags, uint64_t mask,
|
|
|
17b0f1 |
+ int dfd, const char *pathname) {
|
|
|
17b0f1 |
+#if defined _MIPS_SIM && _MIPS_SIM == _MIPS_SIM_ABI32 || defined __powerpc__ && !defined __powerpc64__ \
|
|
|
17b0f1 |
+ || defined __arm__ && !defined __aarch64__
|
|
|
17b0f1 |
+ union {
|
|
|
17b0f1 |
+ uint64_t _64;
|
|
|
17b0f1 |
+ uint32_t _32[2];
|
|
|
17b0f1 |
+ } _mask;
|
|
|
17b0f1 |
+ _mask._64 = mask;
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
+ return syscall(__NR_fanotify_mark, fanotify_fd, flags,
|
|
|
17b0f1 |
+ _mask._32[0], _mask._32[1], dfd, pathname);
|
|
|
17b0f1 |
+#else
|
|
|
17b0f1 |
+ return syscall(__NR_fanotify_mark, fanotify_fd, flags, mask, dfd, pathname);
|
|
|
17b0f1 |
+#endif
|
|
|
17b0f1 |
+}
|
|
|
17b0f1 |
+#endif
|
|
|
17b0f1 |
+
|
|
|
17b0f1 |
#ifndef HAVE_MEMFD_CREATE
|
|
|
17b0f1 |
static inline int memfd_create(const char *name, unsigned int flags) {
|
|
|
17b0f1 |
return syscall(__NR_memfd_create, name, flags);
|