X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=probes%2Flttng-events.h;h=d486994f3a0c2202741037c8ef68ffe5ebd16bc5;hb=c0be14c235542c5852d96b9b840c44a29349b002;hp=084666d56514520f7db875e6026bf538eef0cfbd;hpb=4ea00e4f764eb18686121161a98e4ef442fed2c0;p=lttng-modules.git diff --git a/probes/lttng-events.h b/probes/lttng-events.h index 084666d5..d486994f 100644 --- a/probes/lttng-events.h +++ b/probes/lttng-events.h @@ -188,6 +188,10 @@ void trace_##_name(void *__data); }, \ }, +#undef __string_from_user +#define __string_from_user(_item, _src) \ + __string(_item, _src) + #undef TP_STRUCT__entry #define TP_STRUCT__entry(args...) args /* Only one used in this phase */ @@ -336,6 +340,15 @@ static __used struct lttng_probe_desc TP_ID(__probe_desc___, TRACE_SYSTEM) = { #define __string(_item, _src) \ __event_len += __dynamic_len[__dynamic_len_idx++] = strlen(_src) + 1; +/* + * strlen_user includes \0. If returns 0, it faulted, so we set size to + * 1 (\0 only). + */ +#undef __string_from_user +#define __string_from_user(_item, _src) \ + __event_len += __dynamic_len[__dynamic_len_idx++] = \ + max_t(size_t, strlen_user(_src), 1); + #undef TP_PROTO #define TP_PROTO(args...) args @@ -383,6 +396,9 @@ static inline size_t __event_get_size__##_name(size_t *__dynamic_len, _proto) \ #undef __string #define __string(_item, _src) +#undef __string_from_user +#define __string_from_user(_item, _src) + #undef TP_PROTO #define TP_PROTO(args...) args @@ -424,7 +440,11 @@ static inline size_t __event_get_align__##_name(_proto) \ _type _item; #undef __string -#define __string(_item, _src) char _item; +#define __string(_item, _src) char _item; + +#undef __string_from_user +#define __string_from_user(_item, _src) \ + __string(_item, _src) #undef TP_STRUCT__entry #define TP_STRUCT__entry(args...) args @@ -473,6 +493,10 @@ __end_field_##_item##_2: goto __assign_##_item; \ __end_field_##_item: +#undef __string_from_user +#define __string_from_user(_item, _src) \ + __string(_item, _src) + /* * Macros mapping tp_assign() to "=", tp_memcpy() to memcpy() and tp_strcpy() to * strcpy(). @@ -510,6 +534,7 @@ __assign_##dest##_2: \ __chan->ops->event_write(&__ctx, src, \ sizeof(__typemap.dest) * __get_dynamic_array_len(dest));\ goto __end_field_##dest##_2; + #undef tp_memcpy_from_user #define tp_memcpy_from_user(dest, src, len) \ __assign_##dest: \ @@ -518,20 +543,27 @@ __assign_##dest##_2: \ lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ __chan->ops->event_write_from_user(&__ctx, src, len); \ goto __end_field_##dest; + /* - * tp_copy_string_from_user "len" parameter is the length of the string - * excluding the final \0. + * The string length including the final \0. */ #undef tp_copy_string_from_user -#define tp_copy_string_from_user(dest, src, len) \ +#define tp_copy_string_from_user(dest, src) \ __assign_##dest: \ - if (0) \ - (void) __typemap.dest; \ - lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest)); \ - __chan->ops->event_write_from_user(&__ctx, src, len); \ - __chan->ops->event_memset(&__ctx, 0, 1); \ + { \ + size_t __ustrlen; \ + \ + if (0) \ + (void) __typemap.dest; \ + lib_ring_buffer_align_ctx(&__ctx, ltt_alignof(__typemap.dest));\ + __ustrlen = __get_dynamic_array_len(dest); \ + if (likely(__ustrlen > 1)) { \ + __chan->ops->event_write_from_user(&__ctx, src, \ + __ustrlen - 1); \ + } \ + __chan->ops->event_memset(&__ctx, 0, 1); \ + } \ goto __end_field_##dest; - #undef tp_strcpy #define tp_strcpy(dest, src) \ tp_memcpy(dest, src, __get_dynamic_array_len(dest))