Skip to content

Commit 8278569

Browse files
rwmjonesstephensmalley
authored andcommitted
setfiles: Add -A option to disable SELINUX_RESTORECON_ADD_ASSOC
SELINUX_RESTORECON_ADD_ASSOC tracks conflicts between inodes with multiple hard links or bind mounts that have differing contexts. However doing this involves building a large internal hashtable that stores the full path of every file examined by setfiles. For filesystems that have very large numbers of files or long pathnames, this uses a lot of memory, which makes SELinux relabelling in constrained memory environments infeasible. This adds a new setfiles -A option that disables this tracking. For example, using setfiles to relabel a filesystem with 15 million files took 3.7GB of RAM. Using this option, the same filesystem can be relabelled in 121MB (albeit with no warnings or errors possible for conflicting labels, but for our use case we don't care about that.) Fixes: https://issues.redhat.com/browse/RHEL-111505 Signed-off-by: Richard W.M. Jones <[email protected]> Acked-by: Stephen Smalley <[email protected]>
1 parent cc8c4a5 commit 8278569

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

policycoreutils/setfiles/setfiles.8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ setfiles \- set SELinux file security contexts.
2323
.RB [ \-I | \-D ]
2424
.RB [ \-T
2525
.IR nthreads ]
26+
.RB [ \-A ]
2627
.I spec_file
2728
.IR pathname \ ...
2829

@@ -187,6 +188,10 @@ use up to
187188
threads. Specify 0 to create as many threads as there are available
188189
CPU cores; 1 to use only a single thread (default); or any positive
189190
number to use the given number of threads (if possible).
191+
.TP
192+
.B \-A
193+
do not track inodes with multiple hard links or bind mounts that would
194+
match different contexts (saves memory)
190195

191196
.SH "ARGUMENTS"
192197
.TP

policycoreutils/setfiles/setfiles.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ static __attribute__((__noreturn__)) void usage(const char *const name)
4040
name, name);
4141
} else {
4242
fprintf(stderr,
43-
"usage: %s [-diIDlmnpqvCEFUWT] [-e excludedir] [-r alt_root_path] [-c policyfile] spec_file pathname...\n"
44-
"usage: %s [-diIDlmnpqvCEFUWT] [-e excludedir] [-r alt_root_path] [-c policyfile] spec_file -f filename\n"
45-
"usage: %s -s [-diIDlmnpqvFUWT] spec_file\n",
43+
"usage: %s [-diIDlmnpqvACEFUWT] [-e excludedir] [-r alt_root_path] [-c policyfile] spec_file pathname...\n"
44+
"usage: %s [-diIDlmnpqvACEFUWT] [-e excludedir] [-r alt_root_path] [-c policyfile] spec_file -f filename\n"
45+
"usage: %s -s [-diIDlmnpqvAFUWT] spec_file\n",
4646
name, name, name);
4747
}
4848
exit(-1);
@@ -147,7 +147,7 @@ int main(int argc, char **argv)
147147
const char *base;
148148
int errors = 0;
149149
const char *ropts = "e:f:hiIDlmno:pqrsvFURW0xT:";
150-
const char *sopts = "c:de:f:hiIDlmno:pqr:svCEFUR:W0T:";
150+
const char *sopts = "c:de:f:hiIDlmno:pqr:svACEFUR:W0T:";
151151
const char *opts;
152152
union selinux_callback cb;
153153
long unsigned skipped_errors;
@@ -375,6 +375,9 @@ int main(int argc, char **argv)
375375
if (*optarg == '\0' || *endptr != '\0')
376376
usage(argv[0]);
377377
break;
378+
case 'A':
379+
r_opts.add_assoc = 0;
380+
break;
378381
case 'h':
379382
case '?':
380383
usage(argv[0]);

0 commit comments

Comments
 (0)