1*1f5207b7SJohn Levon /*
2*1f5207b7SJohn Levon * Copyright (C) 2010 Dan Carpenter.
3*1f5207b7SJohn Levon *
4*1f5207b7SJohn Levon * This program is free software; you can redistribute it and/or
5*1f5207b7SJohn Levon * modify it under the terms of the GNU General Public License
6*1f5207b7SJohn Levon * as published by the Free Software Foundation; either version 2
7*1f5207b7SJohn Levon * of the License, or (at your option) any later version.
8*1f5207b7SJohn Levon *
9*1f5207b7SJohn Levon * This program is distributed in the hope that it will be useful,
10*1f5207b7SJohn Levon * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*1f5207b7SJohn Levon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*1f5207b7SJohn Levon * GNU General Public License for more details.
13*1f5207b7SJohn Levon *
14*1f5207b7SJohn Levon * You should have received a copy of the GNU General Public License
15*1f5207b7SJohn Levon * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16*1f5207b7SJohn Levon */
17*1f5207b7SJohn Levon
18*1f5207b7SJohn Levon #include "smatch.h"
19*1f5207b7SJohn Levon
20*1f5207b7SJohn Levon static int my_id;
21*1f5207b7SJohn Levon
22*1f5207b7SJohn Levon static struct {
23*1f5207b7SJohn Levon int name_param;
24*1f5207b7SJohn Levon int mode_param;
25*1f5207b7SJohn Levon } param_index[] = {
26*1f5207b7SJohn Levon {.name_param = 0, .mode_param = 1},
27*1f5207b7SJohn Levon {.name_param = 1, .mode_param = 2},
28*1f5207b7SJohn Levon };
29*1f5207b7SJohn Levon
30*1f5207b7SJohn Levon #define S_IWOTH 00002
31*1f5207b7SJohn Levon
match_create(const char * fn,struct expression * expr,void * _param_type)32*1f5207b7SJohn Levon static void match_create(const char *fn, struct expression *expr, void *_param_type)
33*1f5207b7SJohn Levon {
34*1f5207b7SJohn Levon struct expression *arg_expr;
35*1f5207b7SJohn Levon sval_t sval;
36*1f5207b7SJohn Levon char *name;
37*1f5207b7SJohn Levon int idx = PTR_INT(_param_type);
38*1f5207b7SJohn Levon
39*1f5207b7SJohn Levon arg_expr = get_argument_from_call_expr(expr->args, param_index[idx].mode_param);
40*1f5207b7SJohn Levon if (!get_implied_value(arg_expr, &sval))
41*1f5207b7SJohn Levon return;
42*1f5207b7SJohn Levon if (!(sval.uvalue & S_IWOTH))
43*1f5207b7SJohn Levon return;
44*1f5207b7SJohn Levon arg_expr = get_argument_from_call_expr(expr->args, param_index[idx].name_param);
45*1f5207b7SJohn Levon name = expr_to_var(arg_expr);
46*1f5207b7SJohn Levon sm_warning("proc file '%s' is world writable", name);
47*1f5207b7SJohn Levon free_string(name);
48*1f5207b7SJohn Levon }
49*1f5207b7SJohn Levon
check_proc_create(int id)50*1f5207b7SJohn Levon void check_proc_create(int id)
51*1f5207b7SJohn Levon {
52*1f5207b7SJohn Levon my_id = id;
53*1f5207b7SJohn Levon if (option_project != PROJ_KERNEL)
54*1f5207b7SJohn Levon return;
55*1f5207b7SJohn Levon
56*1f5207b7SJohn Levon add_function_hook("proc_create", &match_create, INT_PTR(0));
57*1f5207b7SJohn Levon add_function_hook("create_proc_entry", &match_create, INT_PTR(0));
58*1f5207b7SJohn Levon add_function_hook("proc_create_data", &match_create, INT_PTR(0));
59*1f5207b7SJohn Levon add_function_hook("proc_net_fops_create", match_create, INT_PTR(1));
60*1f5207b7SJohn Levon }
61