Skip to content

Commit bfe3f88

Browse files
committed
forcing old genfscon behavior for time being
1 parent a74ad71 commit bfe3f88

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

data/expected_cil/fs_context.cil

-5
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@
109109
(handleunknown allow)
110110
(typeattribute domain)
111111
(typeattribute resource)
112-
(type bar)
113-
(roletype object_r bar)
114-
(typeattributeset resource (bar))
115112
(type foo)
116113
(roletype object_r foo)
117114
(typeattributeset resource (foo))
@@ -130,8 +127,6 @@
130127
(fsuse trans tmpfs (system_u object_r foo ((s0) (s0))))
131128
(genfscon cgroup "/" (system_u object_r foo ((s0) (s0))))
132129
(genfscon proc "/" (system_u object_r foo ((s0) (s0))))
133-
(genfscon sysfs "/zap" dir (system_u object_r foo ((s0) (s0))))
134-
(genfscon sysfs "/zap/baa" file (system_u object_r bar ((s0) (s0))))
135130
(sid kernel)
136131
(sidcontext kernel (system_u system_r kernel_sid ((s0) (s0))))
137132
(sid security)

data/policies/fs_context.cas

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ resource foo {
77
fs_context(this, "proc", genfscon, "/");
88
fs_context(this, "proc", genfscon, "/");
99
fs_context(this, "cgroup", genfscon);
10-
fs_context(this, "sysfs", genfscon, "/zap", [dir]);
10+
// TODO re-add when secilc check is in place
11+
// fs_context(this, "sysfs", genfscon, "/zap", [dir]);
1112

1213
// Policies must include at least one av rule
1314
allow(domain, foo, file, [read]);
1415
}
1516

16-
resource bar {
17-
fs_context(this, "sysfs", genfscon, "/zap/baa", [file]);
18-
}
17+
// TODO re-add when secilc check is in place
18+
// resource bar {
19+
// fs_context(this, "sysfs", genfscon, "/zap/baa", [file]);
20+
//}

src/internal_rep.rs

+25-16
Original file line numberDiff line numberDiff line change
@@ -1404,28 +1404,37 @@ impl From<&FileSystemContextRule<'_>> for sexp::Sexp {
14041404
Sexp::from(&f.context),
14051405
]),
14061406
FSContextType::GenFSCon => {
1407-
// Since path is an optional arg and I dont want to get
1407+
// Since path is an optional arg and I don't want to get
14081408
// into unwrap issue we are doing an 'if let' here. The lack
1409-
// of path should be caught ealier, so if we dont have a path
1409+
// of path should be caught earlier, so if we don't have a path
14101410
// we will return an empty list. The more correct way to fix this
14111411
// is convert this to a try_from, but this causes issues with some
14121412
// of our match statements and mixing returns.
14131413
if let Some(p) = &f.path {
1414-
match &f.file_type {
1415-
Some(file_type) => list(&[
1416-
atom_s("genfscon"),
1417-
atom_s(f.fs_name.trim_matches('"')),
1418-
atom_s(p.as_ref()),
1419-
Sexp::Atom(Atom::S(file_type.to_string())),
1420-
Sexp::from(&f.context),
1421-
]),
1422-
None => list(&[
1423-
atom_s("genfscon"),
1424-
atom_s(f.fs_name.trim_matches('"')),
1425-
atom_s(p.as_ref()),
1426-
Sexp::from(&f.context),
1427-
]),
1414+
if let Some(file_type) = &f.file_type {
1415+
// TODO add secilc check here. Right now our github pipeline
1416+
// supports an older version of secilc. So to get things moving forward
1417+
// we are forcing the old behavior. The new behavior has been tested locally.
1418+
// REMEMBER TO UPDATE THE TESTS
1419+
// if secilc/libsepol version is new enough {
1420+
if false {
1421+
return list(&[
1422+
atom_s("genfscon"),
1423+
atom_s(f.fs_name.trim_matches('"')),
1424+
atom_s(p.as_ref()),
1425+
Sexp::Atom(Atom::S(file_type.to_string())),
1426+
Sexp::from(&f.context),
1427+
]);
1428+
}
14281429
}
1430+
// We are purposefully falling through without an else to
1431+
// reduce redundant lines of code
1432+
list(&[
1433+
atom_s("genfscon"),
1434+
atom_s(f.fs_name.trim_matches('"')),
1435+
atom_s(p.as_ref()),
1436+
Sexp::from(&f.context),
1437+
])
14291438
} else {
14301439
list(&[])
14311440
}

src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,9 @@ mod tests {
11471147
"fsuse task sockfs (system_u object_r foo ((s0) (s0)))",
11481148
"fsuse trans tmpfs (system_u object_r foo ((s0) (s0)))",
11491149
"genfscon proc \"/\" (system_u object_r foo ((s0) (s0)))",
1150-
"genfscon sysfs \"/zap\" dir (system_u object_r foo ((s0) (s0)))",
1151-
"genfscon sysfs \"/zap/baa\" file (system_u object_r bar ((s0) (s0)))",
1150+
// TODO re-add when secilc check is in place
1151+
// "genfscon sysfs \"/zap\" dir (system_u object_r foo ((s0) (s0)))",
1152+
// "genfscon sysfs \"/zap/baa\" file (system_u object_r bar ((s0) (s0)))",
11521153
"genfscon cgroup \"/\" (system_u object_r foo ((s0) (s0)))",
11531154
],
11541155
&[],

0 commit comments

Comments
 (0)