Skip to content

Commit c4fbe0d

Browse files
committed
Implementation of mountpoint blacklist
Signed-off-by: Radovan Sroka <rsroka@redhat.com>
1 parent f76484b commit c4fbe0d

File tree

4 files changed

+46
-27
lines changed

4 files changed

+46
-27
lines changed

init/fapolicyd.conf

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ syslog_format = rule,dec,perm,auid,pid,exe,:,path,ftype,trust
2020
rpm_sha256_only = 0
2121
allow_filesystem_mark = 0
2222
report_interval = 0
23+
ignore_mounts = /run,/sys

src/daemon/fapolicyd.c

+29-27
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ volatile atomic_bool stop = false, hup = false, run_stats = false;
7272
// Local variables
7373
static conf_t config;
7474
// This holds info about all file systems to watch
75-
struct fs_avl {
75+
typedef struct fs_avl {
7676
avl_tree_t index;
77-
};
77+
} fs_avl;
7878
// This is the data about a specific file system to watch
7979
typedef struct fs_data {
8080
avl_t avl; // This has to be first
8181
const char *fs_name;
8282
} fs_data_t;
83-
static struct fs_avl filesystems;
83+
static fs_avl filesystems;
84+
static fs_avl ignored_mounts;
8485

8586
// List of mounts being watched
8687
static mlist *m = NULL;
@@ -141,27 +142,27 @@ static void free_filesystem(fs_data_t *s)
141142
}
142143

143144

144-
static void destroy_filesystem(void)
145+
static void destroy_filesystem(fs_avl* fs)
145146
{
146-
avl_t *cur = filesystems.index.root;
147+
avl_t *cur = fs->index.root;
147148

148-
fs_data_t *tmp =(fs_data_t *)avl_remove(&filesystems.index, cur);
149+
fs_data_t *tmp =(fs_data_t *)avl_remove(&fs->index, cur);
149150
if ((avl_t *)tmp != cur)
150151
msg(LOG_DEBUG, "filesystem: removal of invalid node");
151152
free_filesystem(tmp);
152153
}
153154

154155

155-
static void destroy_fs_list(void)
156+
static void destroy_fs_list(fs_avl* fs)
156157
{
157-
while (filesystems.index.root)
158-
destroy_filesystem();
158+
while (fs->index.root)
159+
destroy_filesystem(fs);
159160
}
160161

161162

162-
static int add_filesystem(fs_data_t *f)
163+
static int add_filesystem(fs_avl* fs, fs_data_t *f)
163164
{
164-
fs_data_t *tmp=(fs_data_t *)avl_insert(&filesystems.index,(avl_t *)(f));
165+
fs_data_t *tmp=(fs_data_t *)avl_insert(&fs->index,(avl_t *)(f));
165166
if (tmp) {
166167
if (tmp != f) {
167168
msg(LOG_DEBUG, "fs_list: duplicate filesystem found");
@@ -173,40 +174,40 @@ static int add_filesystem(fs_data_t *f)
173174
}
174175

175176

176-
static fs_data_t *new_filesystem(const char *fs)
177+
static fs_data_t *new_filesystem(fs_avl* fs, const char * f)
177178
{
178179
fs_data_t *tmp = malloc(sizeof(fs_data_t));
179180
if (tmp) {
180-
tmp->fs_name = fs ? strdup(fs) : strdup("");
181-
if (add_filesystem(tmp) != 0)
181+
tmp->fs_name = fs ? strdup(f) : strdup("");
182+
if (add_filesystem(fs,tmp) != 0)
182183
return NULL;
183184
}
184185
return tmp;
185186
}
186187

187188

188-
static fs_data_t *find_filesystem(const char *f)
189+
static fs_data_t *find_filesystem(fs_avl* fs, const char *f)
189190
{
190191
fs_data_t tmp;
191192

192193
tmp.fs_name = f;
193-
return (fs_data_t *)avl_search(&filesystems.index, (avl_t *) &tmp);
194+
return (fs_data_t *)avl_search(&fs->index, (avl_t *) &tmp);
194195
}
195196

196197

197-
static void init_fs_list(const char *watch_fs)
198+
static void init_fs_list(fs_avl* fs, const char *watch_fs)
198199
{
199200
if (watch_fs == NULL) {
200201
msg(LOG_ERR, "File systems to watch is empty");
201202
exit(1);
202203
}
203-
avl_init(&filesystems.index, cmp_fs);
204+
avl_init(&fs->index, cmp_fs);
204205

205206
// Now parse up list and push into avl
206207
char *ptr, *saved, *tmp = strdup(watch_fs);
207208
ptr = strtok_r(tmp, ",", &saved);
208209
while (ptr) {
209-
new_filesystem(ptr);
210+
new_filesystem(fs, ptr);
210211
ptr = strtok_r(NULL, ",", &saved);
211212
}
212213
free(tmp);
@@ -344,13 +345,12 @@ static int become_daemon(void)
344345
// Returns 1 if we care about the entry and 0 if we do not
345346
static int check_mount_entry(const char *point, const char *type)
346347
{
347-
// Some we know we don't want
348-
if (strcmp(point, "/run") == 0)
349-
return 0;
350-
if (strncmp(point, "/sys", 4) == 0)
348+
// ignored mount points
349+
if (find_filesystem(&ignored_mounts, point))
351350
return 0;
352351

353-
if (find_filesystem(type))
352+
// wanted filesystems
353+
if (find_filesystem(&filesystems, type))
354354
return 1;
355355
else
356356
return 0;
@@ -640,7 +640,8 @@ int main(int argc, const char *argv[])
640640
}
641641

642642
// Setup filesystem to watch list
643-
init_fs_list(config.watch_fs);
643+
init_fs_list(&filesystems, config.watch_fs);
644+
init_fs_list(&ignored_mounts, config.ignore_mounts);
644645

645646
// Write the pid file for the init system
646647
write_pid_file();
@@ -678,7 +679,7 @@ int main(int argc, const char *argv[])
678679
if (init_database(&config)) {
679680
destroy_event_system();
680681
destroy_rules();
681-
destroy_fs_list();
682+
destroy_fs_list(&filesystems);
682683
free_daemon_config(&config);
683684
unlink(pidfile);
684685
exit(1);
@@ -757,7 +758,8 @@ int main(int argc, const char *argv[])
757758
}
758759
destroy_event_system();
759760
destroy_rules();
760-
destroy_fs_list();
761+
destroy_fs_list(&filesystems);
762+
destroy_fs_list(&ignored_mounts);
761763
free_daemon_config(&config);
762764

763765
return 0;

src/library/conf.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ typedef struct conf
4747
unsigned int rpm_sha256_only;
4848
unsigned int allow_filesystem_mark;
4949
unsigned int report_interval;
50+
const char *ignore_mounts;
5051
} conf_t;
5152

5253
#endif

src/library/daemon-config.c

+15
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ static int fs_mark_parser(const struct nv_pair *nv, int line,
9696
conf_t *config);
9797
static int report_interval_parser(const struct nv_pair *nv, int line,
9898
conf_t *config);
99+
static int ignore_mounts_parser(const struct nv_pair *nv, int line,
100+
conf_t *config);
99101

100102
static const struct kw_pair keywords[] =
101103
{
@@ -116,6 +118,7 @@ static const struct kw_pair keywords[] =
116118
{"rpm_sha256_only", rpm_sha256_only_parser},
117119
{"allow_filesystem_mark", fs_mark_parser },
118120
{"report_interval", report_interval_parser },
121+
{"ignore_mounts", ignore_mounts_parser },
119122
{ NULL, NULL }
120123
};
121124

@@ -146,6 +149,7 @@ static void clear_daemon_config(conf_t *config)
146149
config->rpm_sha256_only = 0;
147150
config->allow_filesystem_mark = 0;
148151
config->report_interval = 0;
152+
config->ignore_mounts = strdup("/run,/sys");
149153
}
150154

151155
int load_daemon_config(conf_t *config)
@@ -645,3 +649,14 @@ static int fs_mark_parser(const struct nv_pair *nv, int line,
645649

646650
return rc;
647651
}
652+
653+
static int ignore_mounts_parser(const struct nv_pair *nv, int line,
654+
conf_t *config)
655+
{
656+
free((void *)config->ignore_mounts);
657+
config->ignore_mounts = strdup(nv->value);
658+
if (config->ignore_mounts)
659+
return 0;
660+
msg(LOG_ERR, "Could not store value line %d", line);
661+
return 1;
662+
}

0 commit comments

Comments
 (0)