Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infer interface parameter types and check for interface-template mis-declarations #206

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ tests/check_startup
tests/check_te_checks
tests/check_ordering
tests/check_perm_macro
tests/check_infer
tests/functional/policies/parse_errors/test3_tmp.if
tests/functional/policies/parse_errors/test5_tmp.te
tests/functional/policies/parse_errors/test6_tmp.if
Expand Down
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ CHECK IDS
S-008: Unquoted gen_require block
S-009: Permission macro suffix does not match class name
S-010: Permission macro usage suggested
S-011: Interface should be declared as template
S-012: Template can be declared as interface

W-001: Type or attribute referenced without explicit declaration
W-002: Type, attribute or role used but not listed in require block in interface
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

bin_PROGRAMS = selint
selint_SOURCES = main.c lex.l parse.y tree.c tree.h selint_error.h parse_functions.c parse_functions.h maps.c maps.h runner.c runner.h parse_fc.c parse_fc.h template.c template.h file_list.c file_list.h check_hooks.c check_hooks.h fc_checks.c fc_checks.h util.c util.h if_checks.c if_checks.h selint_config.c selint_config.h string_list.c string_list.h startup.c startup.h te_checks.c te_checks.h ordering.c ordering.h color.c color.h perm_macro.c perm_macro.h
selint_SOURCES = main.c lex.l parse.y tree.c tree.h selint_error.h parse_functions.c parse_functions.h maps.c maps.h runner.c runner.h parse_fc.c parse_fc.h template.c template.h file_list.c file_list.h check_hooks.c check_hooks.h fc_checks.c fc_checks.h util.c util.h if_checks.c if_checks.h selint_config.c selint_config.h string_list.c string_list.h startup.c startup.h te_checks.c te_checks.h ordering.c ordering.h color.c color.h perm_macro.c perm_macro.h infer.c infer.h
BUILT_SOURCES = parse.h
AM_YFLAGS = -d -Wno-yacc -Werror=conflicts-rr -Werror=conflicts-sr

Expand Down
2 changes: 2 additions & 0 deletions src/check_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ enum style_ids {
S_ID_UNQUOTE_GENREQ = 8,
S_ID_PERM_SUFFIX = 9,
S_ID_PERMMACRO = 10,
S_ID_TEXT_IF_PARAM = 11,
S_ID_VOID_TEMP_DECL = 12,
S_END
};

Expand Down
74 changes: 74 additions & 0 deletions src/if_checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,80 @@ struct check_result *check_unquoted_gen_require_block(__attribute__((unused)) co
return NULL;
}

struct check_result *check_text_param_in_interface(__attribute__((unused)) const struct
check_data *data,
const struct
policy_node *node)
{
const char *if_name = node->data.str;
const struct interface_trait *trait = look_up_in_if_traits_map(if_name);
if (!trait || !trait->is_inferred) {
return NULL;
}

for (int i = 0; i < TRAIT_MAX_PARAMETERS; i++) {
if (trait->parameters[i] == PARAM_TEXT) {
return make_check_result('S', S_ID_TEXT_IF_PARAM,
"Interface %s should be a template, due to parameter %d",
if_name,
i + 1);
}

if (trait->parameters[i] == PARAM_INITIAL) {
break;
}
}

return NULL;
}

struct check_result *check_unnecessary_template_definition(__attribute__((unused)) const struct
check_data *data,
const struct
policy_node *node)
{
const char *temp_name = node->data.str;
const struct interface_trait *trait = look_up_in_if_traits_map(temp_name);
if (!trait || !trait->is_inferred) {
return NULL;
}

for (int i = 0; i < TRAIT_MAX_PARAMETERS; i++) {
if (trait->parameters[i] == PARAM_TEXT) {
return NULL;
}

if (trait->parameters[i] == PARAM_INITIAL) {
break;
}
}

for (const struct policy_node *cur = node->first_child; cur; cur = dfs_next(cur)) {
if (cur == node || cur == node->next) {
break;
}

if (cur->flavor == NODE_GEN_REQ || cur->flavor == NODE_REQUIRE) {
cur = cur->next;
}

if (cur->flavor == NODE_DECL) {
return NULL;
}

if (cur->flavor == NODE_IF_CALL) {
const struct if_call_data *ic_data = cur->data.ic_data;
if (look_up_in_template_map(ic_data->name)) {
return NULL;
}
}
}

return make_check_result('S', S_ID_VOID_TEMP_DECL,
"Template %s might be declared as an interface",
temp_name);
}

struct check_result *check_name_used_but_not_required_in_if(const struct
check_data *data,
const struct
Expand Down
24 changes: 24 additions & 0 deletions src/if_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ struct check_result *check_unquoted_gen_require_block(const struct
const struct
policy_node *node);

/*********************************************
* Check that an interface has no text parameter
* Called on NODE_INTERFACE_DEF nodes
* data - metadata about the file
* node - the node to check
* returns NULL if passed or check_result for issue S-011
*********************************************/
struct check_result *check_text_param_in_interface(const struct
check_data *data,
const struct
policy_node *node);

/*********************************************
* Check for templates that can be declared as interface
* Called on NODE_TEMP_DEF nodes
* data - metadata about the file
* node - the node to check
* returns NULL if passed or check_result for issue S-012
*********************************************/
struct check_result *check_unnecessary_template_definition(const struct
check_data *data,
const struct
policy_node *node);

/*********************************************
* Check that all names referenced in interface are listed in its require block
* (or declared in that template)
Expand Down
Loading