[lttng-dev] [PATCH lttng-modules v4 2/5] Extract the FD sets in select and pselect6
Julien Desfossez
jdesfossez at efficios.com
Fri Apr 15 20:37:18 UTC 2016
Instead of extracting the user-space pointers of the 3 fd_set, we now
extract the bitmask of the FDs in the sets (in, out, ex) in the form of
an array of uint8_t (1024 FDs is the limit in the kernel).
In this example, we select in input FDs 5 to 19 (0xFFFF0), it returns
that one FD is ready: FD 12 (0x1000).
syscall_entry_select: {
n = 20,
_fdset_in_length = 3, fdset_in = [ [0] = 0xF0, [1] = 0xFF, [2] = 0xF ],
_fdset_out_length = 0, fdset_out = [ ],
_fdset_ex_length = 0, fdset_ex = [ ],
tvp = 0
}
syscall_exit_select: {
ret = 1,
_fdset_in_length = 3, fdset_in = [ [0] = 0x0, [1] = 0x10, [2] = 0x0 ],
_fdset_out_length = 0, fdset_out = [ ],
_fdset_ex_length = 0, fdset_ex = [ ],
tvp = 0
}
Signed-off-by: Julien Desfossez <jdesfossez at efficios.com>
---
.../syscalls/headers/syscalls_pointers_override.h | 287 +++++++++++++++++++++
1 file changed, 287 insertions(+)
diff --git a/instrumentation/syscalls/headers/syscalls_pointers_override.h b/instrumentation/syscalls/headers/syscalls_pointers_override.h
index bf5c632..debd4b2 100644
--- a/instrumentation/syscalls/headers/syscalls_pointers_override.h
+++ b/instrumentation/syscalls/headers/syscalls_pointers_override.h
@@ -53,4 +53,291 @@ SC_LTTNG_TRACEPOINT_EVENT(pipe2,
)
)
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64)
+#define OVERRIDE_32_select
+#define OVERRIDE_64_select
+SC_LTTNG_TRACEPOINT_EVENT_CODE(select,
+ TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+ fd_set __user * exp, struct timeval * tvp),
+ TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp),
+ TP_locvar(
+ uint8_t *fds_in, *fds_out, *fds_ex;
+ int nb_in, nb_out, nb_ex;
+ ),
+ TP_code_pre(
+ sc_in(
+ {
+ unsigned long nr_bytes;
+ int err;
+
+ tp_locvar->fds_in = NULL;
+ tp_locvar->fds_out = NULL;
+ tp_locvar->fds_ex = NULL;
+
+ tp_locvar->nb_in = 0;
+ tp_locvar->nb_out = 0;
+ tp_locvar->nb_ex = 0;
+
+ if (n <= 0) {
+ nr_bytes = 0;
+ } else {
+ nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+ /* On error or bogus input, don't copy anything. */
+ if (nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {
+ nr_bytes = 0;
+ }
+ }
+ if (inp) {
+ tp_locvar->fds_in = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_in)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_in, inp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_in = nr_bytes;
+ }
+ if (outp) {
+ tp_locvar->fds_out = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_out)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_out, outp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_out = nr_bytes;
+ }
+ if (exp) {
+ tp_locvar->fds_ex = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_ex)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_ex, exp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_ex = nr_bytes;
+ }
+ }
+ skip_code:
+ )
+ sc_out(
+ {
+ unsigned long nr_bytes;
+ int err;
+
+ tp_locvar->fds_in = NULL;
+ tp_locvar->fds_out = NULL;
+ tp_locvar->fds_ex = NULL;
+
+ tp_locvar->nb_in = 0;
+ tp_locvar->nb_out = 0;
+ tp_locvar->nb_ex = 0;
+
+ if (ret <= 0)
+ goto skip_code;
+
+ if (n <= 0) {
+ nr_bytes = 0;
+ } else {
+ nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+ /* On error or bogus input, don't copy anything. */
+ if (nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {
+ nr_bytes = 0;
+ }
+ }
+ if (inp && tp_locvar->fds_in) {
+ err = copy_from_user(tp_locvar->fds_in, inp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_in = nr_bytes;
+ }
+ if (outp && tp_locvar->fds_out) {
+ err = copy_from_user(tp_locvar->fds_out, outp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_out = nr_bytes;
+ }
+ if (exp && tp_locvar->fds_ex) {
+ err = copy_from_user(tp_locvar->fds_ex, exp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_ex = nr_bytes;
+ }
+ }
+ skip_code:
+ )
+ ),
+ TP_FIELDS(
+ sc_exit(ctf_integer(long, ret, ret))
+ sc_in(ctf_integer(int, n, n))
+ sc_inout(ctf_sequence_hex(uint8_t, fdset_in,
+ tp_locvar->fds_in, uint8_t, tp_locvar->nb_in))
+ sc_inout(ctf_sequence_hex(uint8_t, fdset_out,
+ tp_locvar->fds_out, uint8_t, tp_locvar->nb_out))
+ sc_inout(ctf_sequence_hex(uint8_t, fdset_ex,
+ tp_locvar->fds_ex, uint8_t, tp_locvar->nb_ex))
+ sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+ ),
+ TP_code_post(
+ kfree(tp_locvar->fds_in);
+ kfree(tp_locvar->fds_out);
+ kfree(tp_locvar->fds_ex);
+ )
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) */
+
+#if defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM)
+#define OVERRIDE_32_pselect6
+#define OVERRIDE_64_pselect6
+SC_LTTNG_TRACEPOINT_EVENT_CODE(pselect6,
+ TP_PROTO(sc_exit(long ret,) int n, fd_set __user * inp, fd_set __user * outp,
+ fd_set __user * exp, struct timeval * tvp, void * sig),
+ TP_ARGS(sc_exit(ret,) n, inp, outp, exp, tvp, sig),
+ TP_locvar(
+ uint8_t *fds_in, *fds_out, *fds_ex;
+ int nb_in, nb_out, nb_ex;
+ ),
+ TP_code_pre(
+ sc_in(
+ {
+ unsigned long nr_bytes;
+ int err;
+
+ tp_locvar->fds_in = NULL;
+ tp_locvar->fds_out = NULL;
+ tp_locvar->fds_ex = NULL;
+
+ tp_locvar->nb_in = 0;
+ tp_locvar->nb_out = 0;
+ tp_locvar->nb_ex = 0;
+
+ if (n <= 0) {
+ nr_bytes = 0;
+ } else {
+ nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+ /* On error or bogus input, don't copy anything. */
+ if (nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {
+ nr_bytes = 0;
+ }
+ }
+ if (inp) {
+ tp_locvar->fds_in = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_in)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_in, inp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_in = nr_bytes;
+ }
+ if (outp) {
+ tp_locvar->fds_out = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_out)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_out, outp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_out = nr_bytes;
+ }
+ if (exp) {
+ tp_locvar->fds_ex = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_ex)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_ex, exp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_ex = nr_bytes;
+ }
+ }
+ skip_code:
+ )
+ sc_out(
+ {
+ unsigned long nr_bytes;
+ int err;
+
+ tp_locvar->fds_in = NULL;
+ tp_locvar->fds_out = NULL;
+ tp_locvar->fds_ex = NULL;
+
+ tp_locvar->nb_in = 0;
+ tp_locvar->nb_out = 0;
+ tp_locvar->nb_ex = 0;
+
+ if (ret <= 0)
+ goto skip_code;
+
+ if (n <= 0) {
+ nr_bytes = 0;
+ } else {
+ nr_bytes = DIV_ROUND_UP((unsigned int) n, BITS_PER_BYTE);
+ /* On error or bogus input, don't copy anything. */
+ if (nr_bytes > (__FD_SETSIZE / (8 * sizeof(uint8_t)))) {
+ nr_bytes = 0;
+ }
+ }
+ if (inp) {
+ tp_locvar->fds_in = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_in)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_in, inp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_in = nr_bytes;
+ }
+ if (outp) {
+ tp_locvar->fds_out = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_out)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_out, outp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_out = nr_bytes;
+ }
+ if (exp) {
+ tp_locvar->fds_ex = kmalloc((__FD_SETSIZE / (8 * sizeof(uint8_t))) *
+ sizeof(uint8_t), GFP_KERNEL);
+ if (!tp_locvar->fds_ex)
+ goto skip_code;
+
+ err = copy_from_user(tp_locvar->fds_ex, exp, nr_bytes);
+ if (err < 0)
+ goto skip_code;
+ tp_locvar->nb_ex = nr_bytes;
+ }
+ }
+ skip_code:
+ )
+ ),
+ TP_FIELDS(
+ sc_exit(ctf_integer(long, ret, ret))
+ sc_in(ctf_integer(int, n, n))
+ sc_inout(ctf_sequence_hex(uint8_t, fdset_in,
+ tp_locvar->fds_in, uint8_t, tp_locvar->nb_in))
+ sc_inout(ctf_sequence_hex(uint8_t, fdset_out,
+ tp_locvar->fds_out, uint8_t, tp_locvar->nb_out))
+ sc_inout(ctf_sequence_hex(uint8_t, fdset_ex,
+ tp_locvar->fds_ex, uint8_t, tp_locvar->nb_ex))
+ sc_inout(ctf_integer(struct timeval *, tvp, tvp))
+ ),
+ TP_code_post(
+ kfree(tp_locvar->fds_in);
+ kfree(tp_locvar->fds_out);
+ kfree(tp_locvar->fds_ex);
+ )
+)
+#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) || defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
+
#endif /* CREATE_SYSCALL_TABLE */
--
1.9.1
More information about the lttng-dev
mailing list