Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broken setting of log level in libsepol? #176

Closed
mikhailnov opened this issue Sep 17, 2019 · 3 comments
Closed

broken setting of log level in libsepol? #176

mikhailnov opened this issue Sep 17, 2019 · 3 comments

Comments

@mikhailnov
Copy link
Contributor

I wanted to set maximum log level in semodule (libsepol). Grepped the source code and it seemed me that lvl is always 1 and there is no way to change it via cli.

So I had to patch it to get maximum log level.

diff --git a/libsepol/cil/src/cil_log.c b/libsepol/cil/src/cil_log.c
index b222b155..82dc56f3 100644
--- a/libsepol/cil/src/cil_log.c
+++ b/libsepol/cil/src/cil_log.c
@@ -51,11 +51,11 @@ void cil_set_log_handler(void (*handler)(int lvl, char *msg))
 
 __attribute__ ((format (printf, 2, 0))) void cil_vlog(enum cil_log_level lvl, const char *msg, va_list args)
 {
-	if (cil_log_level >= lvl) {
+	//if (cil_log_level >= lvl) {
 		char buff[MAX_LOG_SIZE];
 		vsnprintf(buff, MAX_LOG_SIZE, msg, args);
 		(*cil_log_handler)(cil_log_level, buff);
-	}
+	//}
 }
 
 __attribute__ ((format (printf, 2, 3))) void cil_log(enum cil_log_level lvl, const char *msg, ...)

Please correct me if I'm wrong.

@stephensmalley
Copy link
Member

cil_set_log_level(), called by secilc or secil2conf with a level that can be incremented by passing one or more -v options?

@mikhailnov
Copy link
Contributor Author

I needed it from semodule, not secil

@stephensmalley
Copy link
Member

Probably semodule should be patched to call cil_set_log_level() with a value based on its existing -v option, which presently only controls its own logging.

perfinion added a commit to perfinion/selinux that referenced this issue Oct 21, 2019
semodule -v will turn on semodule's own verbose logging but not logging
from CIL. This change makes the verbose flag also set cil's log level.

By default (ie no -v flag), this will enable CIL_ERR, and each -v will
increase the level from there.

Tested with a duplicated fcontext in the policy.
Before this change:
    # semodule -v -B
    Committing changes:
    Problems processing filecon rules
    Failed post db handling
    semodule:  Failed!

After this change:
    # semodule -v -B
    [ ... snip ... ]
    Found conflicting filecon rules
      at /var/lib/selinux/mcs/tmp/modules/400/mycustom/cil:159
      at /var/lib/selinux/mcs/tmp/modules/400/mycustom/cil:158
    Problems processing filecon rules
    Failed post db handling
    semodule:  Failed!

Closes: SELinuxProject#176
Signed-off-by: Jason Zaman <jason@perfinion.com>
stephensmalley pushed a commit to stephensmalley/selinux that referenced this issue Oct 21, 2019
semodule -v will turn on semodule's own verbose logging but not logging
from CIL. This change makes the verbose flag also set cil's log level.

By default (ie no -v flag), this will enable CIL_ERR, and each -v will
increase the level from there.

Tested with a duplicated fcontext in the policy.
Before this change:
    # semodule -v -B
    Committing changes:
    Problems processing filecon rules
    Failed post db handling
    semodule:  Failed!

After this change:
    # semodule -v -B
    [ ... snip ... ]
    Found conflicting filecon rules
      at /var/lib/selinux/mcs/tmp/modules/400/mycustom/cil:159
      at /var/lib/selinux/mcs/tmp/modules/400/mycustom/cil:158
    Problems processing filecon rules
    Failed post db handling
    semodule:  Failed!

Closes: SELinuxProject#176
Signed-off-by: Jason Zaman <jason@perfinion.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants