Skip to contentSkip to conversation

setsebool: report errors from commit phase

PATCH In review Topi Miettinen 2 participants 3 messages Apr 26, 2020 – Apr 28, 2020 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 setsebool: report errors from commit phase

In case there are errors when committing changes to booleans, the errors may not be reported to user except by nonzero exit status. With "setsebool -V" it's possible to see errors from commit phase, but otherwise the unfixed command is silent:

 # setsebool -V -P secure_mode_insmod=off
libsemanage.semanage_install_final_tmp: Could not copy /var/lib/selinux/final/default/contexts/files/file_contexts to /etc/selinux/default/contexts/files/file_contexts. (Read-only file system).
libsemanage.semanage_install_final_tmp: Could not copy /var/lib/selinux/final/default/contexts/files/file_contexts to /etc/selinux/default/contexts/files/file_contexts. (Read-only file system).

Fixed version alerts the user about problems even without -V:

 # setsebool -P secure_mode_insmod=off
Failed to commit changes to booleans: Read-only file system
---
 policycoreutils/setsebool/setsebool.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
policycoreutils/setsebool/setsebool.c +3 -1
index 9d8abfac..60da5df1 100644
@@ -200,8 +200,10 @@ static int semanage_set_boolean_list(size_t boolcnt,
 
        if (no_reload)
                semanage_set_reload(handle, 0);
-       if (semanage_commit(handle) < 0)
+       if (semanage_commit(handle) < 0) {
+               fprintf(stderr, "Failed to commit changes to booleans: %m\n");
                goto err;
+       }
 
        semanage_disconnect(handle);
        semanage_handle_destroy(handle);
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Topi Miettinen

In case there are errors when committing changes to booleans, the errors may not be reported to user except by nonzero exit status. With "setsebool -V" it's possible to see errors from commit phase, but otherwise the unfixed command is silent:

  # setsebool -V -P secure_mode_insmod=off
libsemanage.semanage_install_final_tmp: Could not copy
/var/lib/selinux/final/default/contexts/files/file_contexts to
/etc/selinux/default/contexts/files/file_contexts. (Read-only file system).
libsemanage.semanage_install_final_tmp: Could not copy
/var/lib/selinux/final/default/contexts/files/file_contexts to
/etc/selinux/default/contexts/files/file_contexts. (Read-only file system).
Quoted 5 lines

Fixed version alerts the user about problems even without -V:

  # setsebool -P secure_mode_insmod=off
Failed to commit changes to booleans: Read-only file system

Looks good to me. The patch below has been mangled (tabs have been replaced by spaces) but I took the patch from your Pull Request
(https://github.com/SELinuxProject/selinux/pull/227.patch) and it applied cleanly.

If nobody raises an objection, I will merge the patch tomorrow.

Thanks,
Nicolas

Quoted 24 lines
---
  policycoreutils/setsebool/setsebool.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
policycoreutils/setsebool/setsebool.c +3 -1
index 9d8abfac..60da5df1 100644
@@ -200,8 +200,10 @@ static int semanage_set_boolean_list(size_t boolcnt,
 
         if (no_reload)
                 semanage_set_reload(handle, 0);
-       if (semanage_commit(handle) < 0)
+       if (semanage_commit(handle) < 0) {
+               fprintf(stderr, "Failed to commit changes to booleans:
 %m\n");
                 goto err;
+       }
 
         semanage_disconnect(handle);
         semanage_handle_destroy(handle);

--
2.26.2

#2 lore raw
Quoted 22 lines · Nicolas Iooss
Quoted 14 lines · Topi Miettinen

In case there are errors when committing changes to booleans, the errors may not be reported to user except by nonzero exit status. With "setsebool -V" it's possible to see errors from commit phase, but otherwise the unfixed command is silent:

  # setsebool -V -P secure_mode_insmod=off
libsemanage.semanage_install_final_tmp: Could not copy
/var/lib/selinux/final/default/contexts/files/file_contexts to
/etc/selinux/default/contexts/files/file_contexts. (Read-only file system).
libsemanage.semanage_install_final_tmp: Could not copy
/var/lib/selinux/final/default/contexts/files/file_contexts to
/etc/selinux/default/contexts/files/file_contexts. (Read-only file system).
Quoted 5 lines

Fixed version alerts the user about problems even without -V:

  # setsebool -P secure_mode_insmod=off
Failed to commit changes to booleans: Read-only file system
Quoted 8 lines

Looks good to me. The patch below has been mangled (tabs have been replaced by spaces) but I took the patch from your Pull Request
(https://github.com/SELinuxProject/selinux/pull/227.patch) and it applied cleanly.

If nobody raises an objection, I will merge the patch tomorrow.

Merged.

Thanks,
Nicolas

Quoted 25 lines
Quoted 25 lines
---
  policycoreutils/setsebool/setsebool.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
policycoreutils/setsebool/setsebool.c +3 -1
index 9d8abfac..60da5df1 100644
@@ -200,8 +200,10 @@ static int semanage_set_boolean_list(size_t boolcnt,
 
         if (no_reload)
                 semanage_set_reload(handle, 0);
-       if (semanage_commit(handle) < 0)
+       if (semanage_commit(handle) < 0) {
+               fprintf(stderr, "Failed to commit changes to booleans:
 %m\n");
                 goto err;
+       }
 
         semanage_disconnect(handle);
         semanage_handle_destroy(handle);

--
2.26.2