[lttng-dev] [PATCH lttng-modules v3 2/5] Extract the FD sets in select and pselect6

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Fri Apr 15 19:41:51 UTC 2016


----- On Apr 15, 2016, at 3:31 PM, Julien Desfossez jdesfossez at efficios.com wrote:

> 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  | 218 +++++++++++++++++++++
> 1 file changed, 218 insertions(+)
> 
> diff --git a/instrumentation/syscalls/headers/syscalls_pointers_override.h
> b/instrumentation/syscalls/headers/syscalls_pointers_override.h
> index bf5c632..64c0474 100644
> --- a/instrumentation/syscalls/headers/syscalls_pointers_override.h
> +++ b/instrumentation/syscalls/headers/syscalls_pointers_override.h
> @@ -53,4 +53,222 @@ 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[__FD_SETSIZE / (8 * sizeof(uint8_t))],
> +			fds_out[__FD_SETSIZE / (8 * sizeof(uint8_t))],
> +			fds_ex[__FD_SETSIZE / (8 * sizeof(uint8_t))];

3 * 1024 * 8 seems to possibly overflow the kernel stack. Should be
dynamically allocated.

> +		int nb_in, nb_out, nb_ex;
> +	),
> +	TP_code_pre(
> +		sc_in(
> +		{
> +			unsigned long nr_bytes;
> +			int err;
> +
> +			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;
> +				}
> +			}
> +			tp_locvar->nb_in = 0;
> +			tp_locvar->nb_out = 0;
> +			tp_locvar->nb_ex = 0;
> +			if (inp) {
> +				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) {
> +				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) {
> +				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->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) {
> +				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) {
> +				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) {
> +				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()
> +)
> +#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[__FD_SETSIZE / (8 * sizeof(uint8_t))],
> +			fds_out[__FD_SETSIZE / (8 * sizeof(uint8_t))],
> +			fds_ex[__FD_SETSIZE / (8 * sizeof(uint8_t))];

Same here about stack size.

Thanks,

Mathieu

> +		int nb_in, nb_out, nb_ex;
> +	),
> +	TP_code_pre(
> +		sc_in(
> +		{
> +			unsigned long nr_bytes;
> +			int err;
> +
> +			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;
> +				}
> +			}
> +			tp_locvar->nb_in = 0;
> +			tp_locvar->nb_out = 0;
> +			tp_locvar->nb_ex = 0;
> +			if (inp) {
> +				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) {
> +				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) {
> +				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->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) {
> +				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) {
> +				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) {
> +				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()
> +)
> +#endif /* defined(CONFIG_X86_32) || defined(CONFIG_X86_64) ||
> defined(CONFIG_ARM64) || defined(CONFIG_ARM) */
> +
> #endif /* CREATE_SYSCALL_TABLE */
> --
> 1.9.1

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com


More information about the lttng-dev mailing list