Warn and return on fd overflow fdt master
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 29 May 2024 19:02:15 +0000 (15:02 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 9 Jun 2024 12:04:39 +0000 (08:04 -0400)
The fdt should only grow and iterate_fd() holds file_lock, which should
ensure the fdt does not change while the lock is taken but be cautious
and check anyway.

Change-Id: Icd6a3263026734cbe3f296f6087f79add4148a8f
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/instrumentation/events/btrfs.h
include/instrumentation/events/mm_vmscan.h
include/instrumentation/events/udp.h
include/instrumentation/syscalls/arm-32-syscalls_pointers_override.h
include/instrumentation/syscalls/powerpc-32-syscalls_pointers_override.h
include/instrumentation/syscalls/syscalls_pointers_override.h
include/instrumentation/syscalls/x86-32-syscalls_pointers_override.h
include/instrumentation/syscalls/x86-64-syscalls_pointers_override.h
include/wrapper/fdtable.h
src/lttng-statedump-impl.c
tools/syscalls/lttng-get-syscall-inout.sh

index 4d286ef4e87d9e71a5f254f7f91fcdfa657fcba2..88709cfe04d58f8665a95f7e93c01170bd304155 100644 (file)
@@ -958,7 +958,51 @@ LTTNG_TRACEPOINT_EVENT(btrfs_add_block_group,
 )
 #endif
 
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0) || \
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,10,0))
+LTTNG_TRACEPOINT_EVENT_CLASS(btrfs_delayed_tree_ref,
+
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_delayed_ref_node *ref),
+
+       TP_ARGS(fs_info, ref),
+
+       TP_FIELDS(
+               ctf_array(u8, fsid, lttng_fs_info_fsid, BTRFS_UUID_SIZE)
+               ctf_integer(u64, bytenr, ref->bytenr)
+               ctf_integer(u64, num_bytes, ref->num_bytes)
+               ctf_integer(int, action, ref->action)
+               ctf_integer(u64, parent, ref->parent)
+               ctf_integer(u64, ref_root, ref->ref_root)
+               ctf_integer(int, level, ref->tree_ref.level)
+               ctf_integer(int, type, ref->type)
+               ctf_integer(u64, seq, ref->seq)
+       )
+)
+
+LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(btrfs_delayed_tree_ref,
+
+       add_delayed_tree_ref,
+
+       btrfs_add_delayed_tree_ref,
+
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_delayed_ref_node *ref),
+
+       TP_ARGS(fs_info, ref)
+)
+
+LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(btrfs_delayed_tree_ref,
+
+       run_delayed_tree_ref,
+
+       btrfs_run_delayed_tree_ref,
+
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_delayed_ref_node *ref),
+
+       TP_ARGS(fs_info, ref)
+)
+#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0) || \
        LTTNG_SLE_KERNEL_RANGE(4,4,73,5,0,0, 4,4,73,6,0,0) || \
        LTTNG_SLE_KERNEL_RANGE(4,4,82,6,0,0, 4,4,82,7,0,0) || \
        LTTNG_SLE_KERNEL_RANGE(4,4,92,6,0,0, 4,4,92,7,0,0) || \
@@ -1159,7 +1203,53 @@ LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(btrfs_delayed_tree_ref,
 )
 #endif
 
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0) || \
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,10,0))
+LTTNG_TRACEPOINT_EVENT_CLASS(btrfs_delayed_data_ref,
+
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_delayed_ref_node *ref),
+
+       TP_ARGS(fs_info, ref),
+
+       TP_FIELDS(
+               ctf_array(u8, fsid, lttng_fs_info_fsid, BTRFS_UUID_SIZE)
+               ctf_integer(u64, bytenr, ref->bytenr)
+               ctf_integer(u64, num_bytes, ref->num_bytes)
+               ctf_integer(int, action, ref->action)
+               ctf_integer(u64, parent, ref->parent)
+               ctf_integer(u64, ref_root, ref->ref_root)
+               ctf_integer(u64, owner, ref->data_ref.objectid)
+               ctf_integer(u64, offset, ref->data_ref.offset)
+               ctf_integer(int, type, ref->type)
+               ctf_integer(u64, seq, ref->seq)
+       )
+)
+
+LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(btrfs_delayed_data_ref,
+
+       add_delayed_data_ref,
+
+       btrfs_add_delayed_data_ref,
+
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_delayed_ref_node *ref),
+
+       TP_ARGS(fs_info, ref)
+)
+
+LTTNG_TRACEPOINT_EVENT_INSTANCE_MAP(btrfs_delayed_data_ref,
+
+       run_delayed_data_ref,
+
+       btrfs_run_delayed_data_ref,
+
+       TP_PROTO(const struct btrfs_fs_info *fs_info,
+                const struct btrfs_delayed_ref_node *ref),
+
+       TP_ARGS(fs_info, ref)
+)
+
+#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,14,0) || \
        LTTNG_SLE_KERNEL_RANGE(4,4,73,5,0,0, 4,4,73,6,0,0) || \
        LTTNG_SLE_KERNEL_RANGE(4,4,82,6,0,0, 4,4,82,7,0,0) || \
        LTTNG_SLE_KERNEL_RANGE(4,4,92,6,0,0, 4,4,92,7,0,0) || \
index 90addbf3cc04f14f025d5f953789293719120307..66eb490cc5288217f1a597fdf0f8648c3ddb42c4 100644 (file)
@@ -334,7 +334,8 @@ LTTNG_TRACEPOINT_EVENT_MAP(mm_shrink_slab_end,
        )
 )
 
-#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,7,0))
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,7,0) || \
+     LTTNG_RHEL_KERNEL_RANGE(5,14,0,427,16,1, 5,15,0,0,0,0))
 LTTNG_TRACEPOINT_EVENT(mm_vmscan_lru_isolate,
 
        TP_PROTO(int classzone_idx,
index b63a1bb5dcb3a0f0f4d25415e0a6ccc5f96af50a..0a94b46631292cbd7b3ba91d0a33fa9b0c47e516 100644 (file)
@@ -7,7 +7,36 @@
 
 #include <lttng/tracepoint-event.h>
 #include <linux/udp.h>
+#include <lttng/kernel-version.h>
 
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,10,0))
+LTTNG_TRACEPOINT_ENUM(lttng_sk_family,
+       TP_ENUM_VALUES(
+               ctf_enum_value("AF_INET", AF_INET)
+               ctf_enum_value("AF_INET6", AF_INET6)
+       )
+)
+
+LTTNG_TRACEPOINT_EVENT(udp_fail_queue_rcv_skb,
+
+       TP_PROTO(int rc, struct sock *sk, struct sk_buff *skb),
+
+       TP_ARGS(rc, sk, skb),
+
+       TP_FIELDS(
+               ctf_integer(int, rc, rc)
+               ctf_integer(__u16, sport, ntohs(udp_hdr(skb)->source))
+               ctf_integer(__u16, dport, ntohs(udp_hdr(skb)->dest))
+               ctf_enum(lttng_sk_family, __u16, family, sk->sk_family)
+               /*
+                * The 'saddr' and 'daddr' fields from the upstream tracepoint
+                * are currently not extracted. It is recommended to use a
+                * tracepoint from the 'net' probe instead which includes all
+                * fields from the IP header.
+                */
+       )
+)
+#else
 LTTNG_TRACEPOINT_EVENT(udp_fail_queue_rcv_skb,
 
        TP_PROTO(int rc, struct sock *sk),
@@ -19,6 +48,7 @@ LTTNG_TRACEPOINT_EVENT(udp_fail_queue_rcv_skb,
                ctf_integer(__u16, lport, inet_sk(sk)->inet_num)
        )
 )
+#endif
 
 #endif /* LTTNG_TRACE_UDP_H */
 
index 96fb731f7212a5e025a059f498e3f6d94315f7cd..6c08b79435165b96e77f21fe5999f118751660cf 100644 (file)
 #endif /* CONFIG_COMPAT_OLD_SIGACTION */
 #endif
 
+/*
+ * Override 'pipe' to set the output field 'fildes' to an array of 2 integers
+ * instead of the default integer pointer.
+ */
 #define OVERRIDE_32_pipe
 SC_LTTNG_TRACEPOINT_EVENT(pipe,
        TP_PROTO(sc_exit(long ret,) int * fildes),
index fde30d270ff2cdbaf1307c331997077b0e830475..b0006833b2923b3a73da32bb30a1e6563b40a23d 100644 (file)
@@ -4,6 +4,10 @@
 
 #ifndef CREATE_SYSCALL_TABLE
 
+/*
+ * Override 'pipe' to set the output field 'fildes' to an array of 2 integers
+ * instead of the default integer pointer.
+ */
 #define OVERRIDE_32_pipe
 SC_LTTNG_TRACEPOINT_EVENT(pipe,
        TP_PROTO(sc_exit(long ret,) int * fildes),
index 924677491b12b343c096eeaa486c4c6228162f42..b3647ecd27c7378d3960512809318f779e2ef731 100644 (file)
@@ -193,6 +193,10 @@ SC_LTTNG_TRACEPOINT_EVENT(getcpu,
        )
 )
 
+/*
+ * Override 'pipe2' to set the output field 'fildes' to an array of 2 integers
+ * instead of the default integer pointer.
+ */
 #define OVERRIDE_32_pipe2
 #define OVERRIDE_64_pipe2
 SC_LTTNG_TRACEPOINT_EVENT(pipe2,
index bd63ed09ceebda18410da8f6dcd076060f329589..63a900f619b2ac5b5b96eb0991c410462384f8b5 100644 (file)
 #endif /* CONFIG_COMPAT_OLD_SIGACTION */
 #endif
 
+/*
+ * Override 'pipe' to set the output field 'fildes' to an array of 2 integers
+ * instead of the default integer pointer.
+ */
 #define OVERRIDE_32_pipe
 #define OVERRIDE_64_pipe
 SC_LTTNG_TRACEPOINT_EVENT(pipe,
index bd88945124285608df97c82dc4325c574169ce91..e88a97aa3addbf3fbe9abba8a930b0a014fcba4f 100644 (file)
@@ -155,6 +155,10 @@ SC_LTTNG_TRACEPOINT_EVENT_CODE(accept4,
        TP_code_post()
 )
 
+/*
+ * Override 'pipe' to set the output field 'fildes' to an array of 2 integers
+ * instead of the default integer pointer.
+ */
 #define OVERRIDE_64_pipe
 SC_LTTNG_TRACEPOINT_EVENT(pipe,
        TP_PROTO(sc_exit(long ret,) int * fildes),
index 46fc3f33dddef766d7dfea8e71f7a8711b956b74..d81b4f0b4c8404107e41f42b0862209ed7827daf 100644 (file)
@@ -41,4 +41,18 @@ struct file *lttng_lookup_fdget_rcu(unsigned int fd)
 }
 #endif
 
+#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(6,10,0))
+static inline
+bool lttng_close_on_exec(unsigned int fd, const struct files_struct *files)
+{
+       return close_on_exec(fd, files);
+}
+#else
+static inline
+bool lttng_close_on_exec(unsigned int fd, const struct files_struct *files)
+{
+       return close_on_exec(fd, files_fdtable(files));
+}
+#endif
+
 #endif /* _LTTNG_WRAPPER_FDTABLE_H */
index a0e97e1ca5a53a0f5975f31aa46bbccc2cff1b34..5ea790f59a1d26e2e889766a54a439f454203d83 100644 (file)
@@ -42,7 +42,6 @@
 #include <wrapper/fdtable.h>
 #include <wrapper/tracepoint.h>
 #include <wrapper/blkdev.h>
-#include <wrapper/fdtable.h>
 #include <wrapper/sched.h>
 
 /* Define the tracepoints, but do not build the probes */
@@ -436,17 +435,22 @@ int lttng_dump_one_fd(const void *p, struct file *file, unsigned int fd)
         */
        flags &= ~FMODE_NONOTIFY;
        fdt = files_fdtable(ctx->files);
+
        /*
-        * We need to check here again whether fd is within the fdt
-        * max_fds range, because we might be seeing a different
-        * files_fdtable() than iterate_fd(), assuming only RCU is
-        * protecting the read. In reality, iterate_fd() holds
-        * file_lock, which should ensure the fdt does not change while
-        * the lock is taken, but we are not aware whether this is
-        * guaranteed or not, so play safe.
+        * The fdt should only grow and iterate_fd() holds file_lock, which
+        * should ensure the fdt does not change while the lock is taken but be
+        * cautious and check anyway.
         */
-       if (fd < fdt->max_fds && close_on_exec(fd, fdt))
+       if (WARN_ON_ONCE(fd >= fdt->max_fds))
+               return 0;
+
+       if (lttng_close_on_exec(fd, ctx->files))
                flags |= O_CLOEXEC;
+
+       /*
+        * If d_path() failed to get a full path for the file, use the dentry
+        * name instead to at least get a filename.
+        */
        if (IS_ERR(s)) {
                struct dentry *dentry = file->f_path.dentry;
 
index 1cf963944655e3a9b99f77551dd5a22f9712c22d..e4c55e9dfabcba6b6657247d800d4c0af669d208 100755 (executable)
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
 
 # example usage:
-# lttng-get-syscall-inout.sh table-syscall-inout.txt select 1
+# lttng-get-syscall-inout.sh arm-64 select 5 1
 
 ARCH_NAME=$1
 SYSCALL_NAME=$2
@@ -14,18 +14,23 @@ GENERIC_INOUT_DESCRIPTION_FILE="$(dirname "$0")/table-syscall-inout.txt"
 # Delete temp file on exit
 trap 'rm -f "$TMPFILE"' EXIT
 
-if [ "${GENERIC_INOUT_DESCRIPTION_FILE}" = "" ]; then
-       echo "Error: Please specify input file name as first argument" >&2
+if [ "${ARCH_NAME}" = "" ]; then
+       echo "Error: Please specify the arch name as first argument" >&2
        exit 1
 fi
 
 if [ "${SYSCALL_NAME}" = "" ]; then
-       echo "Error: Please specify system call name as second argument" >&2
+       echo "Error: Please specify the system call name as second argument" >&2
+       exit 1
+fi
+
+if [[ "${NB_ARGS}" = "" ]]; then
+       echo "Error: Please specify a number of arguments as third argument" >&2
        exit 1
 fi
 
 if [[ "${ARG_NR}" = "" || ${ARG_NR} == 0 ]]; then
-       echo "Error: Please specify argument number larger than 0 as third argument" >&2
+       echo "Error: Please specify an argument number larger than 0 as fourth argument" >&2
        exit 1
 fi
 
This page took 0.034605 seconds and 4 git commands to generate.