2 * lttng-filter-validator.c
4 * LTTng modules filter bytecode validator.
6 * Copyright (C) 2010-2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/jhash.h>
24 #include <linux/slab.h>
26 #include "wrapper/list.h"
27 #include "lttng-filter.h"
29 #define MERGE_POINT_TABLE_BITS 7
30 #define MERGE_POINT_TABLE_SIZE (1U << MERGE_POINT_TABLE_BITS)
32 /* merge point table node */
34 struct hlist_node node
;
36 /* Context at merge point */
38 unsigned long target_pc
;
42 struct hlist_head mp_head
[MERGE_POINT_TABLE_SIZE
];
46 int lttng_hash_match(struct mp_node
*mp_node
, unsigned long key_pc
)
48 if (mp_node
->target_pc
== key_pc
)
55 int merge_points_compare(const struct vstack
*stacka
,
56 const struct vstack
*stackb
)
60 if (stacka
->top
!= stackb
->top
)
62 len
= stacka
->top
+ 1;
63 WARN_ON_ONCE(len
< 0);
64 for (i
= 0; i
< len
; i
++) {
65 if (stacka
->e
[i
].type
!= stackb
->e
[i
].type
)
72 int merge_point_add_check(struct mp_table
*mp_table
, unsigned long target_pc
,
73 const struct vstack
*stack
)
75 struct mp_node
*mp_node
;
76 unsigned long hash
= jhash_1word(target_pc
, 0);
77 struct hlist_head
*head
;
78 struct mp_node
*lookup_node
;
81 dbg_printk("Filter: adding merge point at offset %lu, hash %lu\n",
83 mp_node
= kzalloc(sizeof(struct mp_node
), GFP_KERNEL
);
86 mp_node
->target_pc
= target_pc
;
87 memcpy(&mp_node
->stack
, stack
, sizeof(mp_node
->stack
));
89 head
= &mp_table
->mp_head
[hash
& (MERGE_POINT_TABLE_SIZE
- 1)];
90 lttng_hlist_for_each_entry(lookup_node
, head
, node
) {
91 if (lttng_hash_match(lookup_node
, target_pc
)) {
97 /* Key already present */
98 dbg_printk("Filter: compare merge points for offset %lu, hash %lu\n",
101 if (merge_points_compare(stack
, &lookup_node
->stack
)) {
102 printk(KERN_WARNING
"Merge points differ for offset %lu\n",
107 hlist_add_head(&mp_node
->node
, head
);
112 * Binary comparators use top of stack and top of stack -1.
115 int bin_op_compare_check(struct vstack
*stack
, const char *str
)
117 if (unlikely(!vstack_ax(stack
) || !vstack_bx(stack
)))
120 switch (vstack_ax(stack
)->type
) {
126 switch (vstack_bx(stack
)->type
) {
138 switch (vstack_bx(stack
)->type
) {
157 printk(KERN_WARNING
"type mismatch for '%s' binary operator\n", str
);
162 * Validate bytecode range overflow within the validation pass.
163 * Called for each instruction encountered.
166 int bytecode_validate_overflow(struct bytecode_runtime
*bytecode
,
167 void *start_pc
, void *pc
)
171 switch (*(filter_opcode_t
*) pc
) {
172 case FILTER_OP_UNKNOWN
:
175 printk(KERN_WARNING
"unknown bytecode op %u\n",
176 (unsigned int) *(filter_opcode_t
*) pc
);
181 case FILTER_OP_RETURN
:
183 if (unlikely(pc
+ sizeof(struct return_op
)
184 > start_pc
+ bytecode
->len
)) {
195 case FILTER_OP_MINUS
:
196 case FILTER_OP_RSHIFT
:
197 case FILTER_OP_LSHIFT
:
198 case FILTER_OP_BIN_AND
:
199 case FILTER_OP_BIN_OR
:
200 case FILTER_OP_BIN_XOR
:
201 case FILTER_OP_EQ_DOUBLE
:
202 case FILTER_OP_NE_DOUBLE
:
203 case FILTER_OP_GT_DOUBLE
:
204 case FILTER_OP_LT_DOUBLE
:
205 case FILTER_OP_GE_DOUBLE
:
206 case FILTER_OP_LE_DOUBLE
:
208 case FILTER_OP_EQ_DOUBLE_S64
:
209 case FILTER_OP_NE_DOUBLE_S64
:
210 case FILTER_OP_GT_DOUBLE_S64
:
211 case FILTER_OP_LT_DOUBLE_S64
:
212 case FILTER_OP_GE_DOUBLE_S64
:
213 case FILTER_OP_LE_DOUBLE_S64
:
214 case FILTER_OP_EQ_S64_DOUBLE
:
215 case FILTER_OP_NE_S64_DOUBLE
:
216 case FILTER_OP_GT_S64_DOUBLE
:
217 case FILTER_OP_LT_S64_DOUBLE
:
218 case FILTER_OP_GE_S64_DOUBLE
:
219 case FILTER_OP_LE_S64_DOUBLE
:
220 case FILTER_OP_LOAD_FIELD_REF_DOUBLE
:
221 case FILTER_OP_GET_CONTEXT_REF_DOUBLE
:
222 case FILTER_OP_LOAD_DOUBLE
:
223 case FILTER_OP_CAST_DOUBLE_TO_S64
:
224 case FILTER_OP_UNARY_PLUS_DOUBLE
:
225 case FILTER_OP_UNARY_MINUS_DOUBLE
:
226 case FILTER_OP_UNARY_NOT_DOUBLE
:
228 printk(KERN_WARNING
"unsupported bytecode op %u\n",
229 (unsigned int) *(filter_opcode_t
*) pc
);
240 case FILTER_OP_EQ_STRING
:
241 case FILTER_OP_NE_STRING
:
242 case FILTER_OP_GT_STRING
:
243 case FILTER_OP_LT_STRING
:
244 case FILTER_OP_GE_STRING
:
245 case FILTER_OP_LE_STRING
:
246 case FILTER_OP_EQ_S64
:
247 case FILTER_OP_NE_S64
:
248 case FILTER_OP_GT_S64
:
249 case FILTER_OP_LT_S64
:
250 case FILTER_OP_GE_S64
:
251 case FILTER_OP_LE_S64
:
253 if (unlikely(pc
+ sizeof(struct binary_op
)
254 > start_pc
+ bytecode
->len
)) {
261 case FILTER_OP_UNARY_PLUS
:
262 case FILTER_OP_UNARY_MINUS
:
263 case FILTER_OP_UNARY_NOT
:
264 case FILTER_OP_UNARY_PLUS_S64
:
265 case FILTER_OP_UNARY_MINUS_S64
:
266 case FILTER_OP_UNARY_NOT_S64
:
268 if (unlikely(pc
+ sizeof(struct unary_op
)
269 > start_pc
+ bytecode
->len
)) {
279 if (unlikely(pc
+ sizeof(struct logical_op
)
280 > start_pc
+ bytecode
->len
)) {
287 case FILTER_OP_LOAD_FIELD_REF
:
289 printk(KERN_WARNING
"Unknown field ref type\n");
293 /* get context ref */
294 case FILTER_OP_GET_CONTEXT_REF
:
296 printk(KERN_WARNING
"Unknown field ref type\n");
300 case FILTER_OP_LOAD_FIELD_REF_STRING
:
301 case FILTER_OP_LOAD_FIELD_REF_SEQUENCE
:
302 case FILTER_OP_LOAD_FIELD_REF_USER_STRING
:
303 case FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE
:
304 case FILTER_OP_LOAD_FIELD_REF_S64
:
305 case FILTER_OP_GET_CONTEXT_REF_STRING
:
306 case FILTER_OP_GET_CONTEXT_REF_S64
:
308 if (unlikely(pc
+ sizeof(struct load_op
) + sizeof(struct field_ref
)
309 > start_pc
+ bytecode
->len
)) {
315 /* load from immediate operand */
316 case FILTER_OP_LOAD_STRING
:
318 struct load_op
*insn
= (struct load_op
*) pc
;
319 uint32_t str_len
, maxlen
;
321 if (unlikely(pc
+ sizeof(struct load_op
)
322 > start_pc
+ bytecode
->len
)) {
327 maxlen
= start_pc
+ bytecode
->len
- pc
- sizeof(struct load_op
);
328 str_len
= strnlen(insn
->data
, maxlen
);
329 if (unlikely(str_len
>= maxlen
)) {
330 /* Final '\0' not found within range */
336 case FILTER_OP_LOAD_S64
:
338 if (unlikely(pc
+ sizeof(struct load_op
) + sizeof(struct literal_numeric
)
339 > start_pc
+ bytecode
->len
)) {
345 case FILTER_OP_CAST_TO_S64
:
346 case FILTER_OP_CAST_NOP
:
348 if (unlikely(pc
+ sizeof(struct cast_op
)
349 > start_pc
+ bytecode
->len
)) {
361 unsigned long delete_all_nodes(struct mp_table
*mp_table
)
363 struct mp_node
*mp_node
;
364 struct hlist_node
*tmp
;
365 unsigned long nr_nodes
= 0;
368 for (i
= 0; i
< MERGE_POINT_TABLE_SIZE
; i
++) {
369 struct hlist_head
*head
;
371 head
= &mp_table
->mp_head
[i
];
372 lttng_hlist_for_each_entry_safe(mp_node
, tmp
, head
, node
) {
386 int validate_instruction_context(struct bytecode_runtime
*bytecode
,
387 struct vstack
*stack
,
393 switch (*(filter_opcode_t
*) pc
) {
394 case FILTER_OP_UNKNOWN
:
397 printk(KERN_WARNING
"unknown bytecode op %u\n",
398 (unsigned int) *(filter_opcode_t
*) pc
);
403 case FILTER_OP_RETURN
:
413 case FILTER_OP_MINUS
:
414 case FILTER_OP_RSHIFT
:
415 case FILTER_OP_LSHIFT
:
416 case FILTER_OP_BIN_AND
:
417 case FILTER_OP_BIN_OR
:
418 case FILTER_OP_BIN_XOR
:
420 case FILTER_OP_EQ_DOUBLE
:
421 case FILTER_OP_NE_DOUBLE
:
422 case FILTER_OP_GT_DOUBLE
:
423 case FILTER_OP_LT_DOUBLE
:
424 case FILTER_OP_GE_DOUBLE
:
425 case FILTER_OP_LE_DOUBLE
:
426 case FILTER_OP_EQ_DOUBLE_S64
:
427 case FILTER_OP_NE_DOUBLE_S64
:
428 case FILTER_OP_GT_DOUBLE_S64
:
429 case FILTER_OP_LT_DOUBLE_S64
:
430 case FILTER_OP_GE_DOUBLE_S64
:
431 case FILTER_OP_LE_DOUBLE_S64
:
432 case FILTER_OP_EQ_S64_DOUBLE
:
433 case FILTER_OP_NE_S64_DOUBLE
:
434 case FILTER_OP_GT_S64_DOUBLE
:
435 case FILTER_OP_LT_S64_DOUBLE
:
436 case FILTER_OP_GE_S64_DOUBLE
:
437 case FILTER_OP_LE_S64_DOUBLE
:
438 case FILTER_OP_UNARY_PLUS_DOUBLE
:
439 case FILTER_OP_UNARY_MINUS_DOUBLE
:
440 case FILTER_OP_UNARY_NOT_DOUBLE
:
441 case FILTER_OP_LOAD_FIELD_REF_DOUBLE
:
442 case FILTER_OP_LOAD_DOUBLE
:
443 case FILTER_OP_CAST_DOUBLE_TO_S64
:
444 case FILTER_OP_GET_CONTEXT_REF_DOUBLE
:
446 printk(KERN_WARNING
"unsupported bytecode op %u\n",
447 (unsigned int) *(filter_opcode_t
*) pc
);
454 ret
= bin_op_compare_check(stack
, "==");
461 ret
= bin_op_compare_check(stack
, "!=");
468 ret
= bin_op_compare_check(stack
, ">");
475 ret
= bin_op_compare_check(stack
, "<");
482 ret
= bin_op_compare_check(stack
, ">=");
489 ret
= bin_op_compare_check(stack
, "<=");
495 case FILTER_OP_EQ_STRING
:
496 case FILTER_OP_NE_STRING
:
497 case FILTER_OP_GT_STRING
:
498 case FILTER_OP_LT_STRING
:
499 case FILTER_OP_GE_STRING
:
500 case FILTER_OP_LE_STRING
:
502 if (!vstack_ax(stack
) || !vstack_bx(stack
)) {
503 printk(KERN_WARNING
"Empty stack\n");
507 if (vstack_ax(stack
)->type
!= REG_STRING
508 || vstack_bx(stack
)->type
!= REG_STRING
) {
509 printk(KERN_WARNING
"Unexpected register type for string comparator\n");
516 case FILTER_OP_EQ_S64
:
517 case FILTER_OP_NE_S64
:
518 case FILTER_OP_GT_S64
:
519 case FILTER_OP_LT_S64
:
520 case FILTER_OP_GE_S64
:
521 case FILTER_OP_LE_S64
:
523 if (!vstack_ax(stack
) || !vstack_bx(stack
)) {
524 printk(KERN_WARNING
"Empty stack\n");
528 if (vstack_ax(stack
)->type
!= REG_S64
529 || vstack_bx(stack
)->type
!= REG_S64
) {
530 printk(KERN_WARNING
"Unexpected register type for s64 comparator\n");
538 case FILTER_OP_UNARY_PLUS
:
539 case FILTER_OP_UNARY_MINUS
:
540 case FILTER_OP_UNARY_NOT
:
542 if (!vstack_ax(stack
)) {
543 printk(KERN_WARNING
"Empty stack\n");
547 switch (vstack_ax(stack
)->type
) {
550 printk(KERN_WARNING
"unknown register type\n");
555 printk(KERN_WARNING
"Unary op can only be applied to numeric or floating point registers\n");
564 case FILTER_OP_UNARY_PLUS_S64
:
565 case FILTER_OP_UNARY_MINUS_S64
:
566 case FILTER_OP_UNARY_NOT_S64
:
568 if (!vstack_ax(stack
)) {
569 printk(KERN_WARNING
"Empty stack\n");
573 if (vstack_ax(stack
)->type
!= REG_S64
) {
574 printk(KERN_WARNING
"Invalid register type\n");
585 struct logical_op
*insn
= (struct logical_op
*) pc
;
587 if (!vstack_ax(stack
)) {
588 printk(KERN_WARNING
"Empty stack\n");
592 if (vstack_ax(stack
)->type
!= REG_S64
) {
593 printk(KERN_WARNING
"Logical comparator expects S64 register\n");
598 dbg_printk("Validate jumping to bytecode offset %u\n",
599 (unsigned int) insn
->skip_offset
);
600 if (unlikely(start_pc
+ insn
->skip_offset
<= pc
)) {
601 printk(KERN_WARNING
"Loops are not allowed in bytecode\n");
609 case FILTER_OP_LOAD_FIELD_REF
:
611 printk(KERN_WARNING
"Unknown field ref type\n");
615 case FILTER_OP_LOAD_FIELD_REF_STRING
:
616 case FILTER_OP_LOAD_FIELD_REF_SEQUENCE
:
617 case FILTER_OP_LOAD_FIELD_REF_USER_STRING
:
618 case FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE
:
620 struct load_op
*insn
= (struct load_op
*) pc
;
621 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
623 dbg_printk("Validate load field ref offset %u type string\n",
627 case FILTER_OP_LOAD_FIELD_REF_S64
:
629 struct load_op
*insn
= (struct load_op
*) pc
;
630 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
632 dbg_printk("Validate load field ref offset %u type s64\n",
637 /* load from immediate operand */
638 case FILTER_OP_LOAD_STRING
:
643 case FILTER_OP_LOAD_S64
:
648 case FILTER_OP_CAST_TO_S64
:
650 struct cast_op
*insn
= (struct cast_op
*) pc
;
652 if (!vstack_ax(stack
)) {
653 printk(KERN_WARNING
"Empty stack\n");
657 switch (vstack_ax(stack
)->type
) {
660 printk(KERN_WARNING
"unknown register type\n");
665 printk(KERN_WARNING
"Cast op can only be applied to numeric or floating point registers\n");
671 if (insn
->op
== FILTER_OP_CAST_DOUBLE_TO_S64
) {
672 if (vstack_ax(stack
)->type
!= REG_DOUBLE
) {
673 printk(KERN_WARNING
"Cast expects double\n");
680 case FILTER_OP_CAST_NOP
:
685 /* get context ref */
686 case FILTER_OP_GET_CONTEXT_REF
:
688 printk(KERN_WARNING
"Unknown get context ref type\n");
692 case FILTER_OP_GET_CONTEXT_REF_STRING
:
694 struct load_op
*insn
= (struct load_op
*) pc
;
695 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
697 dbg_printk("Validate get context ref offset %u type string\n",
701 case FILTER_OP_GET_CONTEXT_REF_S64
:
703 struct load_op
*insn
= (struct load_op
*) pc
;
704 struct field_ref
*ref
= (struct field_ref
*) insn
->data
;
706 dbg_printk("Validate get context ref offset %u type s64\n",
722 int validate_instruction_all_contexts(struct bytecode_runtime
*bytecode
,
723 struct mp_table
*mp_table
,
724 struct vstack
*stack
,
729 unsigned long target_pc
= pc
- start_pc
;
731 struct hlist_head
*head
;
732 struct mp_node
*mp_node
;
734 /* Validate the context resulting from the previous instruction */
735 ret
= validate_instruction_context(bytecode
, stack
, start_pc
, pc
);
739 /* Validate merge points */
740 hash
= jhash_1word(target_pc
, 0);
741 head
= &mp_table
->mp_head
[hash
& (MERGE_POINT_TABLE_SIZE
- 1)];
742 lttng_hlist_for_each_entry(mp_node
, head
, node
) {
743 if (lttng_hash_match(mp_node
, target_pc
)) {
749 dbg_printk("Filter: validate merge point at offset %lu\n",
751 if (merge_points_compare(stack
, &mp_node
->stack
)) {
752 printk(KERN_WARNING
"Merge points differ for offset %lu\n",
756 /* Once validated, we can remove the merge point */
757 dbg_printk("Filter: remove merge point at offset %lu\n",
759 hlist_del(&mp_node
->node
);
766 * >0: going to next insn.
767 * 0: success, stop iteration.
771 int exec_insn(struct bytecode_runtime
*bytecode
,
772 struct mp_table
*mp_table
,
773 struct vstack
*stack
,
778 void *next_pc
= *_next_pc
;
780 switch (*(filter_opcode_t
*) pc
) {
781 case FILTER_OP_UNKNOWN
:
784 printk(KERN_WARNING
"unknown bytecode op %u\n",
785 (unsigned int) *(filter_opcode_t
*) pc
);
790 case FILTER_OP_RETURN
:
792 if (!vstack_ax(stack
)) {
793 printk(KERN_WARNING
"Empty stack\n");
806 case FILTER_OP_MINUS
:
807 case FILTER_OP_RSHIFT
:
808 case FILTER_OP_LSHIFT
:
809 case FILTER_OP_BIN_AND
:
810 case FILTER_OP_BIN_OR
:
811 case FILTER_OP_BIN_XOR
:
813 case FILTER_OP_EQ_DOUBLE
:
814 case FILTER_OP_NE_DOUBLE
:
815 case FILTER_OP_GT_DOUBLE
:
816 case FILTER_OP_LT_DOUBLE
:
817 case FILTER_OP_GE_DOUBLE
:
818 case FILTER_OP_LE_DOUBLE
:
819 case FILTER_OP_EQ_DOUBLE_S64
:
820 case FILTER_OP_NE_DOUBLE_S64
:
821 case FILTER_OP_GT_DOUBLE_S64
:
822 case FILTER_OP_LT_DOUBLE_S64
:
823 case FILTER_OP_GE_DOUBLE_S64
:
824 case FILTER_OP_LE_DOUBLE_S64
:
825 case FILTER_OP_EQ_S64_DOUBLE
:
826 case FILTER_OP_NE_S64_DOUBLE
:
827 case FILTER_OP_GT_S64_DOUBLE
:
828 case FILTER_OP_LT_S64_DOUBLE
:
829 case FILTER_OP_GE_S64_DOUBLE
:
830 case FILTER_OP_LE_S64_DOUBLE
:
831 case FILTER_OP_UNARY_PLUS_DOUBLE
:
832 case FILTER_OP_UNARY_MINUS_DOUBLE
:
833 case FILTER_OP_UNARY_NOT_DOUBLE
:
834 case FILTER_OP_LOAD_FIELD_REF_DOUBLE
:
835 case FILTER_OP_GET_CONTEXT_REF_DOUBLE
:
836 case FILTER_OP_LOAD_DOUBLE
:
837 case FILTER_OP_CAST_DOUBLE_TO_S64
:
839 printk(KERN_WARNING
"unsupported bytecode op %u\n",
840 (unsigned int) *(filter_opcode_t
*) pc
);
851 case FILTER_OP_EQ_STRING
:
852 case FILTER_OP_NE_STRING
:
853 case FILTER_OP_GT_STRING
:
854 case FILTER_OP_LT_STRING
:
855 case FILTER_OP_GE_STRING
:
856 case FILTER_OP_LE_STRING
:
857 case FILTER_OP_EQ_S64
:
858 case FILTER_OP_NE_S64
:
859 case FILTER_OP_GT_S64
:
860 case FILTER_OP_LT_S64
:
861 case FILTER_OP_GE_S64
:
862 case FILTER_OP_LE_S64
:
865 if (vstack_pop(stack
)) {
869 if (!vstack_ax(stack
)) {
870 printk(KERN_WARNING
"Empty stack\n");
874 vstack_ax(stack
)->type
= REG_S64
;
875 next_pc
+= sizeof(struct binary_op
);
880 case FILTER_OP_UNARY_PLUS
:
881 case FILTER_OP_UNARY_MINUS
:
882 case FILTER_OP_UNARY_NOT
:
883 case FILTER_OP_UNARY_PLUS_S64
:
884 case FILTER_OP_UNARY_MINUS_S64
:
885 case FILTER_OP_UNARY_NOT_S64
:
888 if (!vstack_ax(stack
)) {
889 printk(KERN_WARNING
"Empty stack\n");
893 vstack_ax(stack
)->type
= REG_S64
;
894 next_pc
+= sizeof(struct unary_op
);
902 struct logical_op
*insn
= (struct logical_op
*) pc
;
905 /* Add merge point to table */
906 merge_ret
= merge_point_add_check(mp_table
,
907 insn
->skip_offset
, stack
);
912 /* Continue to next instruction */
913 /* Pop 1 when jump not taken */
914 if (vstack_pop(stack
)) {
918 next_pc
+= sizeof(struct logical_op
);
923 case FILTER_OP_LOAD_FIELD_REF
:
925 printk(KERN_WARNING
"Unknown field ref type\n");
929 /* get context ref */
930 case FILTER_OP_GET_CONTEXT_REF
:
932 printk(KERN_WARNING
"Unknown get context ref type\n");
936 case FILTER_OP_LOAD_FIELD_REF_STRING
:
937 case FILTER_OP_LOAD_FIELD_REF_SEQUENCE
:
938 case FILTER_OP_GET_CONTEXT_REF_STRING
:
939 case FILTER_OP_LOAD_FIELD_REF_USER_STRING
:
940 case FILTER_OP_LOAD_FIELD_REF_USER_SEQUENCE
:
942 if (vstack_push(stack
)) {
946 vstack_ax(stack
)->type
= REG_STRING
;
947 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
950 case FILTER_OP_LOAD_FIELD_REF_S64
:
951 case FILTER_OP_GET_CONTEXT_REF_S64
:
953 if (vstack_push(stack
)) {
957 vstack_ax(stack
)->type
= REG_S64
;
958 next_pc
+= sizeof(struct load_op
) + sizeof(struct field_ref
);
962 /* load from immediate operand */
963 case FILTER_OP_LOAD_STRING
:
965 struct load_op
*insn
= (struct load_op
*) pc
;
967 if (vstack_push(stack
)) {
971 vstack_ax(stack
)->type
= REG_STRING
;
972 next_pc
+= sizeof(struct load_op
) + strlen(insn
->data
) + 1;
976 case FILTER_OP_LOAD_S64
:
978 if (vstack_push(stack
)) {
982 vstack_ax(stack
)->type
= REG_S64
;
983 next_pc
+= sizeof(struct load_op
)
984 + sizeof(struct literal_numeric
);
988 case FILTER_OP_CAST_TO_S64
:
991 if (!vstack_ax(stack
)) {
992 printk(KERN_WARNING
"Empty stack\n");
996 vstack_ax(stack
)->type
= REG_S64
;
997 next_pc
+= sizeof(struct cast_op
);
1000 case FILTER_OP_CAST_NOP
:
1002 next_pc
+= sizeof(struct cast_op
);
1008 *_next_pc
= next_pc
;
1013 * Never called concurrently (hash seed is shared).
1015 int lttng_filter_validate_bytecode(struct bytecode_runtime
*bytecode
)
1017 struct mp_table
*mp_table
;
1018 void *pc
, *next_pc
, *start_pc
;
1020 struct vstack stack
;
1022 vstack_init(&stack
);
1024 mp_table
= kzalloc(sizeof(*mp_table
), GFP_KERNEL
);
1026 printk(KERN_WARNING
"Error allocating hash table for bytecode validation\n");
1029 start_pc
= &bytecode
->data
[0];
1030 for (pc
= next_pc
= start_pc
; pc
- start_pc
< bytecode
->len
;
1032 ret
= bytecode_validate_overflow(bytecode
, start_pc
, pc
);
1035 printk(KERN_WARNING
"filter bytecode overflow\n");
1038 dbg_printk("Validating op %s (%u)\n",
1039 lttng_filter_print_op((unsigned int) *(filter_opcode_t
*) pc
),
1040 (unsigned int) *(filter_opcode_t
*) pc
);
1043 * For each instruction, validate the current context
1044 * (traversal of entire execution flow), and validate
1045 * all merge points targeting this instruction.
1047 ret
= validate_instruction_all_contexts(bytecode
, mp_table
,
1048 &stack
, start_pc
, pc
);
1051 ret
= exec_insn(bytecode
, mp_table
, &stack
, &next_pc
, pc
);
1056 if (delete_all_nodes(mp_table
)) {
1058 printk(KERN_WARNING
"Unexpected merge points\n");