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

[RFC] Add support for gen_system_context #299

Draft
wants to merge 1 commit into
base: main
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 src/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ fs_use_task { return FS_USE_TASK; }
define { return DEFINE; }
gen_user { return GEN_USER; }
gen_context { return GEN_CONTEXT; }
gen_system_context { return GEN_SYSTEM_CONTEXT; }
permissive { return PERMISSIVE; }
typebounds { return TYPEBOUNDS; }
interface { return INTERFACE; }
Expand Down
7 changes: 7 additions & 0 deletions src/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
%token DEFINE;
%token GEN_USER;
%token GEN_CONTEXT;
%token GEN_SYSTEM_CONTEXT;
%token PERMISSIVE;
%token TYPEBOUNDS;
%token INTERFACE;
Expand Down Expand Up @@ -993,6 +994,12 @@ context:
GEN_CONTEXT OPEN_PAREN raw_context COMMA mls_range COMMA mls_range CLOSE_PAREN { free($5); free($7); }
|
GEN_CONTEXT OPEN_PAREN raw_context COMMA mls_range COMMA CLOSE_PAREN { free($5); }
|
GEN_SYSTEM_CONTEXT OPEN_PAREN STRING CLOSE_PAREN { free($3); }
|
GEN_SYSTEM_CONTEXT OPEN_PAREN STRING COMMA mls_range CLOSE_PAREN { free($3); free($5); }
|
GEN_SYSTEM_CONTEXT OPEN_PAREN STRING COMMA mls_range COMMA mls_range CLOSE_PAREN { free($3); free($5); free($7); }
;

raw_context:
Expand Down
8 changes: 5 additions & 3 deletions src/parse_fc.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ bool check_for_fc_macro(const char *line, const struct string_list *custom_fc_ma
if (line_len <= custom_fc_len) {
continue;
}
if (line[custom_fc_len] != '(') {
const char *begin = strstr(line, custom_fc_macros->string);
if (!begin) {
continue;
}
if (0 == strncmp(line, custom_fc_macros->string, custom_fc_len)) {
return true;
if (begin[custom_fc_len] != '(') {
continue;
}
return true;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/end-to-end.bats
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ test_report_format_impl() {
run ${SELINT_PATH} -c configs/default.conf -s policies/misc/fc_macros.fc
count=$(echo ${output} | grep -o "E-002" | wc -l)
echo ${output}
[ "$count" -eq 1 ]
[ "$count" -eq 2 ]
run ${SELINT_PATH} -c configs/fc_macros.conf -s policies/misc/fc_macros.fc
count=$(echo ${output} | grep -o "E-002" | wc -l)
echo ${output}
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/policies/misc/fc_macros.fc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
my_custom_macro(`foo')

/foo -- gen_context(system_u:object_r:foo_t, s0)

/foo/bar my_custom_macro(foo_t)
1 change: 1 addition & 0 deletions tests/sample_policy_files/uncommon.te
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type this_shouldnt_be_allowed_t alias other_name_t, attr_name;
permissive foo_t;

sid netmsg gen_context(system_u:object_r:netlabel_peer_t,mls_systemhigh)
sid netmsg gen_system_context(netlabel_peer_t,mls_systemhigh)

portcon udp 7007 gen_context(system_u:object_r:afs_bos_port_t,s0)
portcon udp 7007 gen_context(system_u:object_r:afs_bos_port_t,s0:c2)
Expand Down
Loading