Skip to content

Commit 2d15ea1

Browse files
Add support for using FAN_MARK_FILESYSTEM to see bind mounted accesses
1 parent 67c116d commit 2d15ea1

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed

ChangeLog

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Update filesystems we dont care about
44
- Add --check-path to fapolicyd-cli to locate missed files
55
- Detect trusted static apps running programs by ld.so
6+
- Add support for using FAN_MARK_FILESYSTEM to see bind mounted accesses
67

78
1.1.4
89
- Fix descriptor leak on enqueue failure (Steven Brzozowski)

configure.ac

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ AC_CHECK_DECLS([FAN_OPEN_EXEC_PERM], [perm=yes], [perm=no], [[#include <linux/fa
5656
if test $perm = "no"; then
5757
AC_MSG_ERROR([FAN_OPEN_EXEC_PERM is not defined in linux/fanotify.h. It is required for the kernel to support it])
5858
fi
59+
AC_CHECK_DECLS([FAN_MARK_FILESYSTEM], [], [], [[#include <linux/fanotify.h>]])
5960

6061
withval=""
6162
AC_ARG_WITH(rpm,

doc/fapolicyd.conf.5

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH FAPOLICYD.CONF: "6" "October 2021" "Red Hat" "System Administration Utilities"
1+
.TH FAPOLICYD.CONF: "6" "September 2022" "Red Hat" "System Administration Utilities"
22
.SH NAME
33
fapolicyd.conf \- fapolicyd configuration file
44
.SH DESCRIPTION
@@ -87,6 +87,9 @@ Example:
8787
.B rpm_sha256_only
8888
The option set to 1 forces the daemon to work only with SHA256 hashes. This is useful on the systems where the integrity is set to SHA256 or IMA and some rpms were originally built with e.g. SHA1. The daemon will ingore these SHA1 entries therefore they can be added manually via CLI with correct SHA256 to a trust file later. If set to 0 the daemon stores SHA1 in trustdb as well. This is compatible with older behavior which works with the integrity set to NONE and SIZE. The NONE or SIZE integrity setting considers the files installed via rpm as trusted and it does not care about their hashes at all. On the other hand the integrity set to SHA256 or IMA will never consider a file with SHA1 in trustdb as trusted. The default value is 0.
8989

90+
.TP
91+
.B allow_filesystem_mark
92+
When this option is set to 1, it allows fapolicyd to monitor file access events on the underlying file system when they are bind mounted or are overlayed (e.g. the overlayfs). Normally they block fapolicyd from seeing events on the underlying file systems. This may or may not be desirable. For example, you might start seeing containers accessing things outside of the container but there is no source of trust for the container. In that case you probably do not want to see access from the container. Or maybe you do not use containers but want to control anything run by systemd-run when dynamic users are allowed. In that case you probably want to turn it on. Not all kernel's supoport this option. Therefore the default value is 0.
9093

9194
.SH "SEE ALSO"
9295
.BR fapolicyd (8),

init/fapolicyd.conf

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ trust = rpmdb,file
1818
integrity = none
1919
syslog_format = rule,dec,perm,auid,pid,exe,:,path,ftype,trust
2020
rpm_sha256_only = 0
21+
allow_filesystem_mark = 0

src/daemon/notify.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,16 @@ int init_fanotify(const conf_t *conf, mlist *m)
123123
path = mlist_first(m);
124124
while (path) {
125125
retry_mark:
126-
if (fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_MOUNT,
127-
mask, -1, path) == -1) {
126+
unsigned int flags = FAN_MARK_ADD;
127+
#ifdef HAVE_DECL_FAN_MARK_FILESYSTEM
128+
if (conf->allow_filesystem_mark)
129+
flags |= FAN_MARK_FILESYSTEM;
130+
#else
131+
if (conf->allow_filesystem_mark)
132+
msg(LOG_ERR,
133+
"allow_filesystem_mark is unsupported for this kernel - ignoring");
134+
#endif
135+
if (fanotify_mark(fd, flags, mask, -1, path) == -1) {
128136
/*
129137
* The FAN_OPEN_EXEC_PERM mask is not supported by
130138
* all kernel releases prior to 5.0. Retry setting

src/library/conf.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* conf.h configuration structure
2-
* Copyright 2018-20 Red Hat Inc.
2+
* Copyright 2018-20,22 Red Hat Inc.
33
* All Rights Reserved.
44
*
55
* This program is free software; you can redistribute it and/or modify
@@ -45,6 +45,7 @@ typedef struct conf
4545
integrity_t integrity;
4646
const char *syslog_format;
4747
unsigned int rpm_sha256_only;
48+
unsigned int allow_filesystem_mark;
4849
} conf_t;
4950

5051
#endif

src/library/daemon-config.c

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* daemon-config.c - This is a config file parser
33
*
4-
* Copyright 2018-21 Red Hat Inc.
4+
* Copyright 2018-22 Red Hat Inc.
55
* All Rights Reserved.
66
*
77
* This library is free software; you can redistribute it and/or
@@ -92,6 +92,8 @@ static int syslog_format_parser(const struct nv_pair *nv, int line,
9292
conf_t *config);
9393
static int rpm_sha256_only_parser(const struct nv_pair *nv, int line,
9494
conf_t *config);
95+
static int fs_mark_parser(const struct nv_pair *nv, int line,
96+
conf_t *config);
9597

9698
static const struct kw_pair keywords[] =
9799
{
@@ -110,6 +112,7 @@ static const struct kw_pair keywords[] =
110112
{"integrity", integrity_parser },
111113
{"syslog_format", syslog_format_parser },
112114
{"rpm_sha256_only", rpm_sha256_only_parser},
115+
{"allow_filesystem_mark", fs_mark_parser },
113116
{ NULL, NULL }
114117
};
115118

@@ -138,6 +141,7 @@ static void clear_daemon_config(conf_t *config)
138141
config->syslog_format =
139142
strdup("rule,dec,perm,auid,pid,exe,:,path,ftype");
140143
config->rpm_sha256_only = 0;
144+
config->allow_filesystem_mark = 0;
141145
}
142146

143147
int load_daemon_config(conf_t *config)
@@ -590,6 +594,7 @@ static int syslog_format_parser(const struct nv_pair *nv, int line,
590594
return 1;
591595
}
592596

597+
593598
static int rpm_sha256_only_parser(const struct nv_pair *nv, int line,
594599
conf_t *config)
595600
{
@@ -607,3 +612,24 @@ static int rpm_sha256_only_parser(const struct nv_pair *nv, int line,
607612

608613
return rc;
609614
}
615+
616+
617+
static int fs_mark_parser(const struct nv_pair *nv, int line,
618+
conf_t *config)
619+
{
620+
int rc = 0;
621+
#ifndef HAVE_DECL_FAN_MARK_FILESYSTEM
622+
msg(LOG_WARNING,
623+
"allow_filesystem_mark is unsupported on this kernel - ignoring");
624+
#else
625+
rc = unsigned_int_parser(&(config->allow_filesystem_mark), nv->value, line);
626+
627+
if (rc == 0 && config->allow_filesystem_mark > 1) {
628+
msg(LOG_WARNING,
629+
"allow_filesystem_mark value reset to 0 - line %d", line);
630+
config->allow_filesystem_mark = 0;
631+
}
632+
#endif
633+
634+
return rc;
635+
}

0 commit comments

Comments
 (0)