diff options
| author | Stefan Metzmacher <metze@samba.org> | 2021-02-17 12:29:27 +0100 |
|---|---|---|
| committer | Andreas Schneider <asn@samba.org> | 2021-03-15 08:04:58 +0100 |
| commit | ba970e5d32cceb0750eaa71fb83da3e2eef881d5 (patch) | |
| tree | 6c7b485096014361c8dff27ca42cd1626ed53621 /src | |
| parent | efd2967e060a3a7ca3de589a23511bb38151ed8b (diff) | |
| download | socket_wrapper-ba970e5d32cceb0750eaa71fb83da3e2eef881d5.tar.gz socket_wrapper-ba970e5d32cceb0750eaa71fb83da3e2eef881d5.tar.xz socket_wrapper-ba970e5d32cceb0750eaa71fb83da3e2eef881d5.zip | |
swrap: export a public socket_wrapper_indicate_no_inet_fd() helper function
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14640
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/socket_wrapper.c | 22 | ||||
| -rw-r--r-- | src/socket_wrapper.h | 25 | ||||
| -rw-r--r-- | src/socket_wrapper_noop.c | 6 |
3 files changed, 53 insertions, 0 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 63de148..714cd25 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -7456,6 +7456,28 @@ static void swrap_remove_stale(int fd) swrap_remove_wrapper(__func__, swrap_noop_close, fd); } +/* + * This allows socket_wrapper aware applications to + * indicate that the given fd does not belong to + * an inet socket. + * + * We already overload a lot of unrelated functions + * like eventfd(), timerfd_create(), ... in order to + * call swrap_remove_stale() on the returned fd, but + * we'll never be able to handle all possible syscalls. + * + * socket_wrapper_indicate_no_inet_fd() gives them a way + * to do the same. + * + * We don't export swrap_remove_stale() in order to + * make it easier to analyze SOCKET_WRAPPER_DEBUGLEVEL=3 + * log files. + */ +void socket_wrapper_indicate_no_inet_fd(int fd) +{ + swrap_remove_wrapper(__func__, swrap_noop_close, fd); +} + static int swrap_close(int fd) { return swrap_remove_wrapper(__func__, libc_close, fd); diff --git a/src/socket_wrapper.h b/src/socket_wrapper.h index f1a97e8..3ec5031 100644 --- a/src/socket_wrapper.h +++ b/src/socket_wrapper.h @@ -61,4 +61,29 @@ */ bool socket_wrapper_enabled(void); +/* + * This allows socket_wrapper aware applications to + * indicate that the given fd does not belong to + * an inet socket. + * + * socket_wrapper may not be able to intercept the __close_nocancel() + * syscall made from within libc.so. As result it's possible + * that the in memory meta date of socket_wrapper references + * stale file descriptors, which are already reused for unrelated + * kernel objects, e.g. files, directories, ... + * + * Socket wrapper already intercepts a lot of unrelated + * functions like eventfd(), timerfd_create(), ... in order + * to remove stale meta data for the returned fd, but + * it will never be able to handle all possible syscalls. + * + * socket_wrapper_indicate_no_inet_fd() gives applications a way + * to do the same, explicitly without waiting for new syscalls to + * be added to libsocket_wrapper.so. + * + * This is a no-op if socket_wrapper is not in use or + * if the there is no in memory meta data for the given fd. + */ +void socket_wrapper_indicate_no_inet_fd(int fd); + #endif /* __SOCKET_WRAPPER_H__ */ diff --git a/src/socket_wrapper_noop.c b/src/socket_wrapper_noop.c index 45aff8f..aadf350 100644 --- a/src/socket_wrapper_noop.c +++ b/src/socket_wrapper_noop.c @@ -55,3 +55,9 @@ bool socket_wrapper_enabled(void) { return false; } + +void socket_wrapper_indicate_no_inet_fd(int fd) +{ + (void) fd; /* unused */ + return; +} |
