2 * Copyright (C) 2011 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 * There are a couple checks that try to see if a variable
20 * comes from the user. It would be better to unify them
21 * into one place. Also it we should follow the data down
22 * the call paths. Hence this file.
26 #include "smatch_slist.h"
27 #include "smatch_extra.h"
30 static int my_call_id
;
33 static bool func_gets_user_data
;
35 static const char * kstr_funcs
[] = {
36 "kstrtoull", "kstrtoll", "kstrtoul", "kstrtol", "kstrtouint",
37 "kstrtoint", "kstrtou64", "kstrtos64", "kstrtou32", "kstrtos32",
38 "kstrtou16", "kstrtos16", "kstrtou8", "kstrtos8", "kstrtoull_from_user"
39 "kstrtoll_from_user", "kstrtoul_from_user", "kstrtol_from_user",
40 "kstrtouint_from_user", "kstrtoint_from_user", "kstrtou16_from_user",
41 "kstrtos16_from_user", "kstrtou8_from_user", "kstrtos8_from_user",
42 "kstrtou64_from_user", "kstrtos64_from_user", "kstrtou32_from_user",
43 "kstrtos32_from_user",
46 static void set_points_to_user_data(struct expression
*expr
);
48 static struct stree
*start_states
;
49 static struct stree_stack
*saved_stack
;
50 static void save_start_states(struct statement
*stmt
)
52 start_states
= clone_stree(__get_cur_stree());
55 static void free_start_states(void)
57 free_stree(&start_states
);
60 static void match_save_states(struct expression
*expr
)
62 push_stree(&saved_stack
, start_states
);
66 static void match_restore_states(struct expression
*expr
)
68 free_stree(&start_states
);
69 start_states
= pop_stree(&saved_stack
);
72 static struct smatch_state
*empty_state(struct sm_state
*sm
)
74 return alloc_estate_empty();
77 static void pre_merge_hook(struct sm_state
*sm
)
79 struct smatch_state
*user
;
80 struct smatch_state
*extra
;
81 struct range_list
*rl
;
88 user
= get_state(my_id
, sm
->name
, sm
->sym
);
91 if (!estate_rl(sm
->state
)) {
93 * If the one side is capped and the other side is empty then
94 * let's just mark it as not-user data because the information
95 * isn't going to be useful. How this looks is:
97 * if (user_var > trusted)
98 * user_var = trusted; <-- empty state
102 * The problem is that sometimes things are capped to a literal
103 * and we'd like to keep the state in that case... Ugh. I've
104 * added a check which assumes that everything less than 100 is
105 * probably capped against a literal.
108 if (is_capped_var_sym(sm
->name
, sm
->sym
) &&
109 sval_cmp(estate_max(user
), sval_100
) > 0)
110 set_state(my_id
, sm
->name
, sm
->sym
, alloc_estate_empty());
113 extra
= get_state(SMATCH_EXTRA
, sm
->name
, sm
->sym
);
114 if (!extra
|| !estate_rl(extra
))
116 rl
= rl_intersection(estate_rl(user
), estate_rl(extra
));
117 if (rl_to_sval(rl
, &dummy
))
119 set_state(my_id
, sm
->name
, sm
->sym
, alloc_estate_rl(clone_rl(rl
)));
122 static void extra_nomod_hook(const char *name
, struct symbol
*sym
, struct expression
*expr
, struct smatch_state
*state
)
124 struct smatch_state
*user
;
125 struct range_list
*rl
;
127 user
= get_state(my_id
, name
, sym
);
130 rl
= rl_intersection(estate_rl(user
), estate_rl(state
));
131 if (rl_equiv(rl
, estate_rl(user
)))
133 set_state(my_id
, name
, sym
, alloc_estate_rl(rl
));
136 static void tag_inner_struct_members(struct expression
*expr
, struct symbol
*member
)
138 struct expression
*edge_member
;
139 struct symbol
*base
= get_real_base_type(member
);
143 expr
= member_expression(expr
, '.', member
->ident
);
145 FOR_EACH_PTR(base
->symbol_list
, tmp
) {
148 type
= get_real_base_type(tmp
);
152 if (type
->type
== SYM_UNION
|| type
->type
== SYM_STRUCT
) {
153 tag_inner_struct_members(expr
, tmp
);
160 edge_member
= member_expression(expr
, '.', tmp
->ident
);
161 set_state_expr(my_id
, edge_member
, alloc_estate_whole(type
));
162 } END_FOR_EACH_PTR(tmp
);
165 static void tag_struct_members(struct symbol
*type
, struct expression
*expr
)
168 struct expression
*member
;
171 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '&') {
172 expr
= strip_expr(expr
->unop
);
176 FOR_EACH_PTR(type
->symbol_list
, tmp
) {
177 type
= get_real_base_type(tmp
);
181 if (type
->type
== SYM_UNION
|| type
->type
== SYM_STRUCT
) {
182 tag_inner_struct_members(expr
, tmp
);
189 member
= member_expression(expr
, op
, tmp
->ident
);
190 set_state_expr(my_id
, member
, alloc_estate_whole(get_type(member
)));
192 if (type
->type
== SYM_ARRAY
)
193 set_points_to_user_data(member
);
194 } END_FOR_EACH_PTR(tmp
);
197 static void tag_base_type(struct expression
*expr
)
199 if (expr
->type
== EXPR_PREOP
&& expr
->op
== '&')
200 expr
= strip_expr(expr
->unop
);
202 expr
= deref_expression(expr
);
203 set_state_expr(my_id
, expr
, alloc_estate_whole(get_type(expr
)));
206 static void tag_as_user_data(struct expression
*expr
)
210 expr
= strip_expr(expr
);
212 type
= get_type(expr
);
213 if (!type
|| type
->type
!= SYM_PTR
)
215 type
= get_real_base_type(type
);
218 if (type
== &void_ctype
) {
219 set_state_expr(my_id
, deref_expression(expr
), alloc_estate_whole(&ulong_ctype
));
222 if (type
->type
== SYM_BASETYPE
)
224 if (type
->type
== SYM_STRUCT
|| type
->type
== SYM_UNION
) {
225 if (expr
->type
!= EXPR_PREOP
|| expr
->op
!= '&')
226 expr
= deref_expression(expr
);
228 set_state_expr(my_id
, deref_expression(expr
), alloc_estate_whole(&ulong_ctype
));
229 tag_struct_members(type
, expr
);
233 static void match_user_copy(const char *fn
, struct expression
*expr
, void *_param
)
235 int param
= PTR_INT(_param
);
236 struct expression
*dest
;
238 func_gets_user_data
= true;
240 dest
= get_argument_from_call_expr(expr
->args
, param
);
241 dest
= strip_expr(dest
);
244 tag_as_user_data(dest
);
247 static void match_sscanf(const char *fn
, struct expression
*expr
, void *unused
)
249 struct expression
*arg
;
252 func_gets_user_data
= true;
255 FOR_EACH_PTR(expr
->args
, arg
) {
259 tag_as_user_data(arg
);
260 } END_FOR_EACH_PTR(arg
);
263 static int is_skb_data(struct expression
*expr
)
270 if (expr
->type
== EXPR_BINOP
&& expr
->op
== '+')
271 return is_skb_data(expr
->left
);
273 expr
= strip_expr(expr
);
276 if (expr
->type
!= EXPR_DEREF
|| expr
->op
!= '.')
281 if (strcmp(expr
->member
->name
, "data") != 0)
284 sym
= expr_to_sym(expr
->deref
);
287 sym
= get_real_base_type(sym
);
288 if (!sym
|| sym
->type
!= SYM_PTR
)
290 sym
= get_real_base_type(sym
);
291 if (!sym
|| sym
->type
!= SYM_STRUCT
|| !sym
->ident
)
293 if (strcmp(sym
->ident
->name
, "sk_buff") != 0)
299 static int points_to_user_data(struct expression
*expr
)
301 struct smatch_state
*state
;
307 expr
= strip_expr(expr
);
310 if (is_skb_data(expr
))
313 if (expr
->type
== EXPR_BINOP
&& expr
->op
== '+') {
314 if (points_to_user_data(expr
->left
))
316 if (points_to_user_data(expr
->right
))
321 name
= expr_to_var_sym(expr
, &sym
);
324 snprintf(buf
, sizeof(buf
), "*%s", name
);
325 state
= get_state(my_id
, buf
, sym
);
326 if (state
&& estate_rl(state
))
333 static void set_points_to_user_data(struct expression
*expr
)
339 name
= expr_to_var_sym(expr
, &sym
);
342 snprintf(buf
, sizeof(buf
), "*%s", name
);
343 set_state(my_id
, buf
, sym
, alloc_estate_whole(&llong_ctype
));
348 static int comes_from_skb_data(struct expression
*expr
)
350 expr
= strip_expr(expr
);
351 if (!expr
|| expr
->type
!= EXPR_PREOP
|| expr
->op
!= '*')
354 expr
= strip_expr(expr
->unop
);
357 if (expr
->type
== EXPR_BINOP
&& expr
->op
== '+')
358 expr
= strip_expr(expr
->left
);
360 return is_skb_data(expr
);
363 static int handle_struct_assignment(struct expression
*expr
)
365 struct expression
*right
;
366 struct symbol
*left_type
, *right_type
;
368 left_type
= get_type(expr
->left
);
369 if (!left_type
|| left_type
->type
!= SYM_PTR
)
371 left_type
= get_real_base_type(left_type
);
374 if (left_type
->type
!= SYM_STRUCT
&&
375 left_type
->type
!= SYM_UNION
)
379 * Ignore struct to struct assignments because for those we look at the
380 * individual members.
382 right
= strip_expr(expr
->right
);
383 right_type
= get_type(right
);
384 if (!right_type
|| right_type
->type
!= SYM_PTR
)
387 /* If we are assigning struct members then normally that is handled
388 * by fake assignments, however if we cast one struct to a different
389 * of struct then we handle that here.
391 right_type
= get_real_base_type(right_type
);
392 if (right_type
== left_type
)
395 if (!points_to_user_data(right
))
398 tag_as_user_data(expr
->left
);
402 static int handle_get_user(struct expression
*expr
)
407 name
= get_macro_name(expr
->pos
);
408 if (!name
|| strcmp(name
, "get_user") != 0)
411 name
= expr_to_var(expr
->right
);
412 if (!name
|| strcmp(name
, "__val_gu") != 0)
414 set_state_expr(my_id
, expr
->left
, alloc_estate_whole(get_type(expr
->left
)));
421 static void match_assign(struct expression
*expr
)
423 struct range_list
*rl
;
425 if (is_fake_call(expr
->right
))
427 if (handle_get_user(expr
))
429 if (points_to_user_data(expr
->right
))
430 set_points_to_user_data(expr
->left
);
431 if (handle_struct_assignment(expr
))
434 if (!get_user_rl(expr
->right
, &rl
))
435 goto clear_old_state
;
437 rl
= cast_rl(get_type(expr
->left
), rl
);
438 set_state_expr(my_id
, expr
->left
, alloc_estate_rl(rl
));
443 if (get_state_expr(my_id
, expr
->left
))
444 set_state_expr(my_id
, expr
->left
, alloc_estate_empty());
447 static void handle_eq_noteq(struct expression
*expr
)
449 struct smatch_state
*left_orig
, *right_orig
;
451 left_orig
= get_state_expr(my_id
, expr
->left
);
452 right_orig
= get_state_expr(my_id
, expr
->right
);
454 if (!left_orig
&& !right_orig
)
456 if (left_orig
&& right_orig
)
460 set_true_false_states_expr(my_id
, expr
->left
,
461 expr
->op
== SPECIAL_EQUAL
? alloc_estate_empty() : NULL
,
462 expr
->op
== SPECIAL_EQUAL
? NULL
: alloc_estate_empty());
464 set_true_false_states_expr(my_id
, expr
->right
,
465 expr
->op
== SPECIAL_EQUAL
? alloc_estate_empty() : NULL
,
466 expr
->op
== SPECIAL_EQUAL
? NULL
: alloc_estate_empty());
470 static void handle_unsigned_lt_gt(struct expression
*expr
)
473 struct range_list
*left
;
474 struct range_list
*right
;
475 struct range_list
*non_negative
;
476 sval_t min
, minus_one
;
479 * conditions are mostly handled by smatch_extra.c. The special case
480 * here is that say you have if (user_int < unknown_u32) {
481 * In Smatch extra we say that, We have no idea what value
482 * unknown_u32 is so the only thin we can say for sure is that
483 * user_int is not -1 (UINT_MAX). But in check_user_data2.c we should
484 * assume that unless unknown_u32 is user data, it's probably less than
489 type
= get_type(expr
);
490 if (!type_unsigned(type
))
494 * Assume if (user < trusted) { ... because I am lazy and because this
495 * is the correct way to write code.
497 if (!get_user_rl(expr
->left
, &left
))
499 if (get_user_rl(expr
->right
, &right
))
502 if (!sval_is_negative(rl_min(left
)))
505 minus_one
.type
= rl_type(left
);
506 minus_one
.value
= -1;
507 non_negative
= remove_range(left
, min
, minus_one
);
511 case SPECIAL_UNSIGNED_LT
:
513 case SPECIAL_UNSIGNED_LTE
:
514 set_true_false_states_expr(my_id
, expr
->left
,
515 alloc_estate_rl(non_negative
), NULL
);
518 case SPECIAL_UNSIGNED_GT
:
520 case SPECIAL_UNSIGNED_GTE
:
521 set_true_false_states_expr(my_id
, expr
->left
,
522 NULL
, alloc_estate_rl(non_negative
));
527 static void match_condition(struct expression
*expr
)
529 if (expr
->type
!= EXPR_COMPARE
)
532 if (expr
->op
== SPECIAL_EQUAL
||
533 expr
->op
== SPECIAL_NOTEQUAL
) {
534 handle_eq_noteq(expr
);
538 handle_unsigned_lt_gt(expr
);
541 static void match_user_assign_function(const char *fn
, struct expression
*expr
, void *unused
)
543 func_gets_user_data
= true;
545 tag_as_user_data(expr
->left
);
546 set_points_to_user_data(expr
->left
);
549 static void match_simple_strtoul(const char *fn
, struct expression
*expr
, void *unused
)
551 func_gets_user_data
= true;
553 set_state_expr(my_id
, expr
->left
, alloc_estate_whole(get_type(expr
->left
)));
556 static int get_user_macro_rl(struct expression
*expr
, struct range_list
**rl
)
562 macro
= get_macro_name(expr
->pos
);
567 if (strcmp(macro
, "ntohl") == 0) {
568 *rl
= alloc_whole_rl(&uint_ctype
);
571 if (strcmp(macro
, "ntohs") == 0) {
572 *rl
= alloc_whole_rl(&ushort_ctype
);
579 struct range_list
*rl
;
580 struct expression
*call
;
582 static int returned_rl_callback(void *_info
, int argc
, char **argv
, char **azColName
)
584 struct db_info
*db_info
= _info
;
585 struct range_list
*rl
;
586 char *return_ranges
= argv
[0];
587 char *user_ranges
= argv
[1];
588 struct expression
*arg
;
594 call_results_to_rl(db_info
->call
, get_type(db_info
->call
), user_ranges
, &rl
);
595 if (str_to_comparison_arg(return_ranges
, db_info
->call
, &comparison
, &arg
) &&
596 comparison
== SPECIAL_EQUAL
) {
597 struct range_list
*orig_rl
;
599 if (!get_user_rl(arg
, &orig_rl
))
601 rl
= rl_intersection(rl
, orig_rl
);
605 db_info
->rl
= rl_union(db_info
->rl
, rl
);
610 static int has_user_data(struct symbol
*sym
)
612 struct sm_state
*tmp
;
614 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), tmp
) {
617 } END_FOR_EACH_SM(tmp
);
621 static int we_pass_user_data(struct expression
*call
)
623 struct expression
*arg
;
626 FOR_EACH_PTR(call
->args
, arg
) {
627 sym
= expr_to_sym(arg
);
630 if (has_user_data(sym
))
632 } END_FOR_EACH_PTR(arg
);
637 static int db_returned_user_rl(struct expression
*call
, struct range_list
**rl
)
639 struct db_info db_info
= {};
641 /* for function pointers assume everything is used */
642 if (call
->fn
->type
!= EXPR_SYMBOL
)
644 if (is_fake_call(call
))
648 run_sql(&returned_rl_callback
, &db_info
,
649 "select return, value from return_states where %s and type = %d and parameter = -1 and key = '$';",
650 get_static_filter(call
->fn
->symbol
), USER_DATA3_SET
);
652 func_gets_user_data
= true;
657 run_sql(&returned_rl_callback
, &db_info
,
658 "select return, value from return_states where %s and type = %d and parameter = -1 and key = '$';",
659 get_static_filter(call
->fn
->symbol
), USER_DATA3
);
661 if (!we_pass_user_data(call
))
670 static int user_data_flag
;
671 static struct range_list
*var_user_rl(struct expression
*expr
)
673 struct smatch_state
*state
;
674 struct range_list
*rl
;
675 struct range_list
*absolute_rl
;
677 if (expr
->type
== EXPR_BINOP
&& expr
->op
== '%') {
678 struct range_list
*left
, *right
;
680 if (!get_user_rl(expr
->right
, &right
))
682 get_absolute_rl(expr
->left
, &left
);
683 rl
= rl_binop(left
, '%', right
);
687 if (get_user_macro_rl(expr
, &rl
))
690 if (comes_from_skb_data(expr
)) {
691 rl
= alloc_whole_rl(get_type(expr
));
695 state
= get_state_expr(my_id
, expr
);
696 if (state
&& estate_rl(state
)) {
697 rl
= estate_rl(state
);
701 if (expr
->type
== EXPR_CALL
&& db_returned_user_rl(expr
, &rl
))
707 absolute_rl
= var_to_absolute_rl(expr
);
708 return clone_rl(rl_intersection(rl
, absolute_rl
));
711 int get_user_rl(struct expression
*expr
, struct range_list
**rl
)
715 custom_get_absolute_rl(expr
, &var_user_rl
, rl
);
716 if (!user_data_flag
|| !*rl
) {
723 int get_user_rl_var_sym(const char *name
, struct symbol
*sym
, struct range_list
**rl
)
725 struct smatch_state
*state
;
727 state
= get_state(my_id
, name
, sym
);
728 if (state
&& estate_rl(state
)) {
729 *rl
= estate_rl(state
);
735 static void match_call_info(struct expression
*expr
)
737 struct range_list
*rl
;
738 struct expression
*arg
;
742 FOR_EACH_PTR(expr
->args
, arg
) {
745 if (!get_user_rl(arg
, &rl
))
748 sql_insert_caller_info(expr
, USER_DATA3
, i
, "$", show_rl(rl
));
749 } END_FOR_EACH_PTR(arg
);
752 static void struct_member_callback(struct expression
*call
, int param
, char *printed_name
, struct sm_state
*sm
)
754 struct smatch_state
*state
;
755 struct range_list
*rl
;
757 if (strcmp(sm
->state
->name
, "") == 0)
760 state
= get_state(SMATCH_EXTRA
, sm
->name
, sm
->sym
);
761 if (!state
|| !estate_rl(state
))
762 rl
= estate_rl(sm
->state
);
764 rl
= rl_intersection(estate_rl(sm
->state
), estate_rl(state
));
766 sql_insert_caller_info(call
, USER_DATA3
, param
, printed_name
, show_rl(rl
));
769 static void set_param_user_data(const char *name
, struct symbol
*sym
, char *key
, char *value
)
771 struct range_list
*rl
= NULL
;
772 struct smatch_state
*state
;
776 if (strcmp(key
, "*$") == 0)
777 snprintf(fullname
, sizeof(fullname
), "*%s", name
);
778 else if (strncmp(key
, "$", 1) == 0)
779 snprintf(fullname
, 256, "%s%s", name
, key
+ 1);
783 type
= get_member_type_from_key(symbol_expression(sym
), key
);
785 /* if the caller passes a void pointer with user data */
786 if (strcmp(key
, "*$") == 0 && type
&& type
!= &void_ctype
) {
787 struct expression
*expr
= symbol_expression(sym
);
789 tag_as_user_data(expr
);
790 set_points_to_user_data(expr
);
793 str_to_rl(type
, value
, &rl
);
794 state
= alloc_estate_rl(rl
);
795 set_state(my_id
, fullname
, sym
, state
);
798 static void set_called(const char *name
, struct symbol
*sym
, char *key
, char *value
)
800 set_state(my_call_id
, "this_function", NULL
, &called
);
803 static void match_syscall_definition(struct symbol
*sym
)
810 macro
= get_macro_name(sym
->pos
);
812 (strncmp("SYSCALL_DEFINE", macro
, strlen("SYSCALL_DEFINE")) == 0 ||
813 strncmp("COMPAT_SYSCALL_DEFINE", macro
, strlen("COMPAT_SYSCALL_DEFINE")) == 0))
816 name
= get_function();
817 if (!option_no_db
&& get_state(my_call_id
, "this_function", NULL
) != &called
) {
818 if (name
&& strncmp(name
, "sys_", 4) == 0)
822 if (name
&& strncmp(name
, "compat_sys_", 11) == 0)
828 FOR_EACH_PTR(sym
->ctype
.base_type
->arguments
, arg
) {
829 set_state(my_id
, arg
->ident
->name
, arg
, alloc_estate_whole(get_real_base_type(arg
)));
830 } END_FOR_EACH_PTR(arg
);
833 static void set_to_user_data(struct expression
*expr
, char *key
, char *value
)
838 struct range_list
*rl
= NULL
;
840 type
= get_member_type_from_key(expr
, key
);
841 name
= get_variable_from_key(expr
, key
, &sym
);
845 call_results_to_rl(expr
, type
, value
, &rl
);
847 set_state(my_id
, name
, sym
, alloc_estate_rl(rl
));
853 static void returns_param_user_data(struct expression
*expr
, int param
, char *key
, char *value
)
855 struct expression
*arg
;
856 struct expression
*call
;
859 while (call
->type
== EXPR_ASSIGNMENT
)
860 call
= strip_expr(call
->right
);
861 if (call
->type
!= EXPR_CALL
)
864 if (!we_pass_user_data(call
))
868 if (expr
->type
!= EXPR_ASSIGNMENT
)
870 set_to_user_data(expr
->left
, key
, value
);
874 arg
= get_argument_from_call_expr(call
->args
, param
);
877 set_to_user_data(arg
, key
, value
);
880 static void returns_param_user_data_set(struct expression
*expr
, int param
, char *key
, char *value
)
882 struct expression
*arg
;
884 func_gets_user_data
= true;
887 if (expr
->type
!= EXPR_ASSIGNMENT
)
889 if (strcmp(key
, "*$") == 0) {
890 set_points_to_user_data(expr
->left
);
891 tag_as_user_data(expr
->left
);
893 set_to_user_data(expr
->left
, key
, value
);
898 while (expr
->type
== EXPR_ASSIGNMENT
)
899 expr
= strip_expr(expr
->right
);
900 if (expr
->type
!= EXPR_CALL
)
903 arg
= get_argument_from_call_expr(expr
->args
, param
);
906 set_to_user_data(arg
, key
, value
);
909 static int has_empty_state(struct sm_state
*sm
)
911 struct sm_state
*tmp
;
913 FOR_EACH_PTR(sm
->possible
, tmp
) {
914 if (!estate_rl(tmp
->state
))
916 } END_FOR_EACH_PTR(tmp
);
921 static void param_set_to_user_data(int return_id
, char *return_ranges
, struct expression
*expr
)
924 struct smatch_state
*start_state
;
925 struct range_list
*rl
;
928 const char *param_name
;
930 expr
= strip_expr(expr
);
931 return_str
= expr_to_str(expr
);
933 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), sm
) {
934 if (has_empty_state(sm
))
937 param
= get_param_num_from_sym(sm
->sym
);
939 if (expr_to_sym(expr
) == sm
->sym
)
945 /* The logic here was that if we were passed in a user data then
946 * we don't record that. It's like the difference between
947 * param_filter and param_set. When I think about it, I'm not
948 * sure it actually works. It's probably harmless because we
949 * checked earlier that we're not returning a parameter...
950 * Let's mark this as a TODO.
952 start_state
= get_state_stree(start_states
, my_id
, sm
->name
, sm
->sym
);
953 if (start_state
&& rl_equiv(estate_rl(sm
->state
), estate_rl(start_state
)))
957 param_name
= state_name_to_param_name(sm
->name
, return_str
);
959 param_name
= get_param_name(sm
);
962 if (strcmp(param_name
, "$") == 0) /* The -1 param is handled after the loop */
965 sql_insert_return_states(return_id
, return_ranges
,
966 func_gets_user_data
? USER_DATA3_SET
: USER_DATA3
,
967 param
, param_name
, show_rl(estate_rl(sm
->state
)));
968 } END_FOR_EACH_SM(sm
);
970 if (points_to_user_data(expr
)) {
971 sql_insert_return_states(return_id
, return_ranges
,
972 (is_skb_data(expr
) || !func_gets_user_data
) ?
973 USER_DATA3_SET
: USER_DATA3
,
975 } else if (get_user_rl(expr
, &rl
)) {
976 sql_insert_return_states(return_id
, return_ranges
,
977 func_gets_user_data
? USER_DATA3_SET
: USER_DATA3
,
978 -1, "$", show_rl(rl
));
981 free_string(return_str
);
984 static struct int_stack
*gets_data_stack
;
985 static void match_function_def(struct symbol
*sym
)
987 func_gets_user_data
= false;
990 static void match_inline_start(struct expression
*expr
)
992 push_int(&gets_data_stack
, func_gets_user_data
);
995 static void match_inline_end(struct expression
*expr
)
997 func_gets_user_data
= pop_int(&gets_data_stack
);
1000 void check_user_data2(int id
)
1006 if (option_project
!= PROJ_KERNEL
)
1009 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
1010 add_hook(&match_inline_start
, INLINE_FN_START
);
1011 add_hook(&match_inline_end
, INLINE_FN_END
);
1013 add_hook(&save_start_states
, AFTER_DEF_HOOK
);
1014 add_hook(&free_start_states
, AFTER_FUNC_HOOK
);
1015 add_hook(&match_save_states
, INLINE_FN_START
);
1016 add_hook(&match_restore_states
, INLINE_FN_END
);
1018 add_unmatched_state_hook(my_id
, &empty_state
);
1019 add_extra_nomod_hook(&extra_nomod_hook
);
1020 add_pre_merge_hook(my_id
, &pre_merge_hook
);
1021 add_merge_hook(my_id
, &merge_estates
);
1023 add_function_hook("copy_from_user", &match_user_copy
, INT_PTR(0));
1024 add_function_hook("__copy_from_user", &match_user_copy
, INT_PTR(0));
1025 add_function_hook("memcpy_fromiovec", &match_user_copy
, INT_PTR(0));
1026 for (i
= 0; i
< ARRAY_SIZE(kstr_funcs
); i
++)
1027 add_function_hook(kstr_funcs
[i
], &match_user_copy
, INT_PTR(2));
1029 add_function_assign_hook("simple_strtol", &match_simple_strtoul
, NULL
);
1030 add_function_assign_hook("simple_strtoll", &match_simple_strtoul
, NULL
);
1031 add_function_assign_hook("simple_strtoul", &match_simple_strtoul
, NULL
);
1032 add_function_assign_hook("simple_strtoull", &match_simple_strtoul
, NULL
);
1034 add_function_hook("sscanf", &match_sscanf
, NULL
);
1036 add_function_assign_hook("memdup_user", &match_user_assign_function
, NULL
);
1037 add_function_assign_hook("kmap_atomic", &match_user_assign_function
, NULL
);
1038 add_function_assign_hook("skb_network_header", &match_user_assign_function
, NULL
);
1040 add_hook(&match_syscall_definition
, AFTER_DEF_HOOK
);
1042 add_hook(&match_assign
, ASSIGNMENT_HOOK
);
1043 add_hook(&match_condition
, CONDITION_HOOK
);
1045 add_hook(&match_call_info
, FUNCTION_CALL_HOOK
);
1046 add_member_info_callback(my_id
, struct_member_callback
);
1047 select_caller_info_hook(set_param_user_data
, USER_DATA3
);
1048 select_return_states_hook(USER_DATA3
, &returns_param_user_data
);
1049 select_return_states_hook(USER_DATA3_SET
, &returns_param_user_data_set
);
1050 add_split_return_callback(¶m_set_to_user_data
);
1053 void check_user_data3(int id
)
1057 if (option_project
!= PROJ_KERNEL
)
1059 select_caller_info_hook(set_called
, INTERNAL
);