1 /* 2 * Copyright (C) 2010 Dan Carpenter. 3 * 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. 8 * 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. 13 * 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 16 */ 17 18 #include "smatch.h" 19 20 static int my_id; 21 22 static struct { 23 int name_param; 24 int mode_param; 25 } param_index[] = { 26 {.name_param = 0, .mode_param = 1}, 27 {.name_param = 1, .mode_param = 2}, 28 }; 29 30 #define S_IWOTH 00002 31 32 static void match_create(const char *fn, struct expression *expr, void *_param_type) 33 { 34 struct expression *arg_expr; 35 sval_t sval; 36 char *name; 37 int idx = PTR_INT(_param_type); 38 39 arg_expr = get_argument_from_call_expr(expr->args, param_index[idx].mode_param); 40 if (!get_implied_value(arg_expr, &sval)) 41 return; 42 if (!(sval.uvalue & S_IWOTH)) 43 return; 44 arg_expr = get_argument_from_call_expr(expr->args, param_index[idx].name_param); 45 name = expr_to_var(arg_expr); 46 sm_warning("proc file '%s' is world writable", name); 47 free_string(name); 48 } 49 50 void check_proc_create(int id) 51 { 52 my_id = id; 53 if (option_project != PROJ_KERNEL) 54 return; 55 56 add_function_hook("proc_create", &match_create, INT_PTR(0)); 57 add_function_hook("create_proc_entry", &match_create, INT_PTR(0)); 58 add_function_hook("proc_create_data", &match_create, INT_PTR(0)); 59 add_function_hook("proc_net_fops_create", match_create, INT_PTR(1)); 60 } 61