Skip to content

Commit d04f6fe

Browse files
DaanDeMeyeryuwata
authored andcommitted
selinux: Disable selinux logging in mac_init() as well
We currently only disable selinux logging in mac_selinux_setup(), but not in mac_init(). We don't want libraries we use to log unless we tell them to, so disable selinux's logging in mac_init() as well.
1 parent 3a4aa7f commit d04f6fe

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/core/selinux-setup.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,13 @@
1919
#include "string-util.h"
2020
#include "time-util.h"
2121

22-
#if HAVE_SELINUX
23-
_printf_(2,3)
24-
static int null_log(int type, const char *fmt, ...) {
25-
return 0;
26-
}
27-
#endif
28-
2922
int mac_selinux_setup(bool *loaded_policy) {
3023
assert(loaded_policy);
3124

3225
#if HAVE_SELINUX
3326
int r;
3427

35-
/* Turn off all of SELinux' own logging, we want to do that ourselves */
36-
selinux_set_callback(SELINUX_CB_LOG, (const union selinux_callback) { .func_log = null_log });
28+
mac_selinux_disable_logging();
3729

3830
/* Don't load policy in the initrd if we don't appear to have it. For the real root, we check below
3931
* if we've already loaded policy, and return gracefully. */

src/shared/selinux-util.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ static int selinux_init(bool force) {
167167
if (!force && initialized != LAZY_INITIALIZED)
168168
return 1;
169169

170+
mac_selinux_disable_logging();
171+
170172
r = selinux_status_open(/* netlink fallback= */ 1);
171173
if (r < 0) {
172174
if (!ERRNO_IS_PRIVILEGE(errno))
@@ -263,6 +265,20 @@ void mac_selinux_finish(void) {
263265
#endif
264266
}
265267

268+
#if HAVE_SELINUX
269+
_printf_(2,3)
270+
static int selinux_log_glue(int type, const char *fmt, ...) {
271+
return 0;
272+
}
273+
#endif
274+
275+
void mac_selinux_disable_logging(void) {
276+
#if HAVE_SELINUX
277+
/* Turn off all of SELinux' own logging, we want to do that ourselves */
278+
selinux_set_callback(SELINUX_CB_LOG, (const union selinux_callback) { .func_log = selinux_log_glue });
279+
#endif
280+
}
281+
266282
#if HAVE_SELINUX
267283
static int selinux_fix_fd(
268284
int fd,

src/shared/selinux-util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ int mac_selinux_init_lazy(void);
3232
void mac_selinux_maybe_reload(void);
3333
void mac_selinux_finish(void);
3434

35+
void mac_selinux_disable_logging(void);
36+
3537
int mac_selinux_fix_full(int atfd, const char *inode_path, const char *label_path, LabelFixFlags flags);
3638

3739
int mac_selinux_apply(const char *path, const char *label);

0 commit comments

Comments
 (0)