Skip to contentSkip to conversation

(Userspace) AVC denial generated even if allowed by the policy?

DISCUSSION Laurent Bigonville 3 participants 10 messages Nov 23, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I'm still looking at adding SELinux support in the "at" daemon and I now have the following patch[0].

With this patch, at seems to behave like the cron daemon, as explained in the commit log:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For confined user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes are run under the user default context.

But every time an AVC denial is generated (with cron_userdomain_transition set to off and the user running as staff_u, in permissive with unmodified refpolicy):

avc: denied { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:staff_r:cronjob_t:s0

But audit2{allow,why} are saying that this is already allowed in the policy

Setting the cron_userdomain_transition boolean to on, I have the following avc:

avc: denied { entrypoint } for scontext=staff_u:sysadm_r:sysadm_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:sysadm_r:sysadm_t:s0

So as said it seems to work, but I'm not sure why this AVC denial is generated.

sesearch shows:

$ sesearch -ATSC  -t user_cron_spool_t -c file -p entrypoint
Found 6 semantic av rules:
   allow files_unconfined_type file_type : file { ioctl read write 
create getattr setattr lock relabelfrom relabelto append unlink link rename execute swapon quotaon mounton execute_no_trans entrypoint open audit_access } ;
DT allow unconfined_t user_cron_spool_t : file entrypoint ; [ cron_userdomain_transition ]
DT allow user_t user_cron_spool_t : file entrypoint ; [ cron_userdomain_transition ]
EF allow cronjob_t user_cron_spool_t : file entrypoint ; [ cron_userdomain_transition ]
DT allow staff_t user_cron_spool_t : file entrypoint ; [ cron_userdomain_transition ]
DT allow sysadm_t user_cron_spool_t : file entrypoint ; [ cron_userdomain_transition ]

Did I overlooked something?

Cheers,

Laurent Bigonville

[0] https://anonscm.debian.org/cgit/users/bigon/at.git/commit/?h=selinux&id=0112f006b74a36f7200e315575fd25d78e11b170

#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Quoted 24 lines · Laurent Bigonville

Hi,

I'm still looking at adding SELinux support in the "at" daemon and I now have the following patch[0].

With this patch, at seems to behave like the cron daemon, as explained in the commit log:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For confined user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes are run under the user default context.

But every time an AVC denial is generated (with cron_userdomain_transition set to off and the user running as staff_u, in permissive with unmodified refpolicy):

avc: denied { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:staff_r:cronjob_t:s0

Quoted 7 lines

But audit2{allow,why} are saying that this is already allowed in the policy

Setting the cron_userdomain_transition boolean to on, I have the following avc:

avc: denied { entrypoint } for scontext=staff_u:sysadm_r:sysadm_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

I think this is weird as well since user_cron_spool_t is not actually
executed as far as i know (and thus is not actually an entrypoint). The entrypoint permission is merely allowed so that crond_t/atd_t can calculate access to the target domains.

So i do not see why these entrypoint events are hit in the first place

Quoted 30 lines

The job runs as (id -Z): staff_u:sysadm_r:sysadm_t:s0

So as said it seems to work, but I'm not sure why this AVC denial is generated.

sesearch shows:

$ sesearch -ATSC  -t user_cron_spool_t -c file -p entrypoint
Found 6 semantic av rules:
   allow files_unconfined_type file_type : file { ioctl read write create
getattr setattr lock relabelfrom relabelto append unlink link rename execute
swapon quotaon mounton execute_no_trans entrypoint open audit_access } ;
DT allow unconfined_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow user_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
EF allow cronjob_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow staff_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow sysadm_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]

Did I overlooked something?

Cheers,

Laurent Bigonville

Quoted 7 lines

[0] https://anonscm.debian.org/cgit/users/bigon/at.git/commit/?h=selinux&id=0112f006b74a36f7200e315575fd25d78e11b170

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

- --
02DFF788
4D30 903A 1CF3 B756 FB48 1514 3148 83A2 02DF F788
https://sks-keyservers.net/pks/lookup?op=get&search=0x314883A202DFF788
Dominick Grift
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQGcBAEBCgAGBQJWUsliAAoJENAR6kfG5xmceAcL/jHlL/Ru8AeJ0kciGQoBfNHQ KszDv3fv5x3l1qlN9311Do8mnjVedZS+7fucA+AaXT1R/EpSdVlZZsf5fXaIhPc3 k28niDSGIWrLypLsjlEbkZ/KgIZNuMOnmIVmfuhakVlyZmdq/VFmd6wQb1xuIoet ZrPclGtiXbKljkKbXTlMWEioMf1mM1CRUWuekZu2ViGWbBRCAOvl+qbWQzRgW5Xy QWk4U29wXLHlhr3UYIdiZcR7avprY3e6xhb+KmL6Q7smfuIsV8iLT3qIy1r/9nLb cotbilVVnBdJYZxuTqZxe7nZpCl2tY9ScYtgarljqBWanOG1Qt8jPLgIVdyXDYZs 64vfPoBuAj/XaKxoiffm3U4xuMSfQOJKkEA0VGWjvz2P2f9qWXw5Qwrfb6IxQKkP TjAB+E1kauzvrVzXaw1vbgYOfrggcl4dGoSaA347C4KxAa/BXh76Cj23DfWeF82P 799SMSSzLZQGQKCOhArW7I0ZwFSRAXQtaX2LqH11Yw==
=g861
-----END PGP SIGNATURE-----

#2 lore raw
Quoted 30 lines · Dominick Grift
Quoted 29 lines · Laurent Bigonville

Hi,

I'm still looking at adding SELinux support in the "at" daemon and I now have the following patch[0].

With this patch, at seems to behave like the cron daemon, as explained in the commit log:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For confined user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes are run under the user default context.

But every time an AVC denial is generated (with cron_userdomain_transition set to off and the user running as staff_u, in permissive with unmodified refpolicy):

avc: denied { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:staff_r:cronjob_t:s0

But audit2{allow,why} are saying that this is already allowed in the policy

Setting the cron_userdomain_transition boolean to on, I have the following avc:

Quoted 7 lines
Quoted 2 lines

avc: denied { entrypoint } for scontext=staff_u:sysadm_r:sysadm_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

I think this is weird as well since user_cron_spool_t is not actually
executed as far as i know (and thus is not actually an entrypoint). The entrypoint permission is merely allowed so that crond_t/atd_t can calculate access to the target domains.

So i do not see why these entrypoint events are hit in the first place

The code is explicitly doing that, I guess it's the design decision from the original writer of the patch:

/*
* Since crontab files are not directly executed,
* crond must ensure that the crontab file has
* a context that is appropriate for the context of
* the user cron job. It performs an entrypoint
* permission check for this purpose.
*/

And that's why there is a entrypoint check:

selinux_check_access(user_context, file_context, "file", "entrypoint", NULL);

#3 lore raw
In reply to Laurent Bigonville
Quoted 58 lines · Laurent Bigonville

Hi,

I'm still looking at adding SELinux support in the "at" daemon and I now have the following patch[0].

With this patch, at seems to behave like the cron daemon, as explained in the commit log:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For
confined
user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes are run under the user default context.

But every time an AVC denial is generated (with cron_userdomain_transition set to off and the user running as staff_u, in permissive with unmodified refpolicy):

avc: denied { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:staff_r:cronjob_t:s0

But audit2{allow,why} are saying that this is already allowed in the policy

Setting the cron_userdomain_transition boolean to on, I have the following avc:

avc: denied { entrypoint } for scontext=staff_u:sysadm_r:sysadm_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:sysadm_r:sysadm_t:s0

So as said it seems to work, but I'm not sure why this AVC denial is generated.

sesearch shows:

$ sesearch -ATSC  -t user_cron_spool_t -c file -p entrypoint
Found 6 semantic av rules:
   allow files_unconfined_type file_type : file { ioctl read write
create getattr setattr lock relabelfrom relabelto append unlink link
rename execute swapon quotaon mounton execute_no_trans entrypoint open
audit_access } ;
DT allow unconfined_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow user_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
EF allow cronjob_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow staff_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow sysadm_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
Quoted 8 lines

Did I overlooked something?

Cheers,

Laurent Bigonville

[0]
https://anonscm.debian.org/cgit/users/bigon/at.git/commit/?h=selinux&id=0112f006b74a36f7200e315575fd25d78e11b170

I'm attaching the patch to this mail for the people that cannot access the website and FTR.

Cheers,

Laurent Bigonville

Quoted 1 line

From c8aa69e51d8781da782a50dbdf20b258288093d4 Mon Sep 17 00:00:00 2001

From: Laurent Bigonville <[email protected]>
Date: Mon, 23 Nov 2015 12:25:13 +0100
Subject: [PATCH] Allow the user cronjobs to run in their userdomain

When cron_userdomain_transition boolean is set to on, the user cronjobs are supposed to run in their domains. Without this patch the default context is not properly computed:

    $ /usr/sbin/getdefaultcon user_u system_u:system_r:crond_t:s0
    /usr/sbin/getdefaultcon: Invalid argument
    $ /usr/sbin/getdefaultcon staff_u system_u:system_r:crond_t:s0
    staff_u:sysadm_r:sysadm_t:s0

With this patch applied:

    $ /usr/sbin/getdefaultcon user_u system_u:system_r:crond_t:s0
    user_u:user_r:user_t:s0
    $ /usr/sbin/getdefaultcon staff_ system_u:system_r:crond_t:s0
    staff_u:staff_r:staff_t:s0
---
 config/appconfig-mcs/staff_u_default_contexts      | 2 +-
 config/appconfig-mcs/user_u_default_contexts       | 2 +-
 config/appconfig-mls/staff_u_default_contexts      | 2 +-
 config/appconfig-mls/user_u_default_contexts       | 2 +-
 config/appconfig-standard/staff_u_default_contexts | 2 +-
 config/appconfig-standard/user_u_default_contexts  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
config/appconfig-mcs/staff_u_default_contexts +1 -1
index 881a292..5606c4e 100644
@@ -1,7 +1,7 @@
 system_r:local_login_t:s0	staff_r:staff_t:s0 sysadm_r:sysadm_t:s0
 system_r:remote_login_t:s0	staff_r:staff_t:s0
 system_r:sshd_t:s0		staff_r:staff_t:s0 sysadm_r:sysadm_t:s0
-system_r:crond_t:s0		staff_r:cronjob_t:s0
+system_r:crond_t:s0		staff_r:staff_t:s0 staff_r:cronjob_t:s0
 system_r:xdm_t:s0		staff_r:staff_t:s0
 staff_r:staff_su_t:s0		staff_r:staff_t:s0
 staff_r:staff_sudo_t:s0		staff_r:staff_t:s0
config/appconfig-mcs/user_u_default_contexts +1 -1
index cacbc93..56d6071 100644
@@ -1,7 +1,7 @@
 system_r:local_login_t:s0	user_r:user_t:s0
 system_r:remote_login_t:s0	user_r:user_t:s0
 system_r:sshd_t:s0		user_r:user_t:s0
-system_r:crond_t:s0		user_r:cronjob_t:s0
+system_r:crond_t:s0		user_r:user_t:s0 user_r:cronjob_t:s0
 system_r:xdm_t:s0		user_r:user_t:s0
 user_r:user_su_t:s0		user_r:user_t:s0
 user_r:user_sudo_t:s0		user_r:user_t:s0
config/appconfig-mls/staff_u_default_contexts +1 -1
index 881a292..5606c4e 100644
@@ -1,7 +1,7 @@
 system_r:local_login_t:s0	staff_r:staff_t:s0 sysadm_r:sysadm_t:s0
 system_r:remote_login_t:s0	staff_r:staff_t:s0
 system_r:sshd_t:s0		staff_r:staff_t:s0 sysadm_r:sysadm_t:s0
-system_r:crond_t:s0		staff_r:cronjob_t:s0
+system_r:crond_t:s0		staff_r:staff_t:s0 staff_r:cronjob_t:s0
 system_r:xdm_t:s0		staff_r:staff_t:s0
 staff_r:staff_su_t:s0		staff_r:staff_t:s0
 staff_r:staff_sudo_t:s0		staff_r:staff_t:s0
config/appconfig-mls/user_u_default_contexts +1 -1
index cacbc93..56d6071 100644
@@ -1,7 +1,7 @@
 system_r:local_login_t:s0	user_r:user_t:s0
 system_r:remote_login_t:s0	user_r:user_t:s0
 system_r:sshd_t:s0		user_r:user_t:s0
-system_r:crond_t:s0		user_r:cronjob_t:s0
+system_r:crond_t:s0		user_r:user_t:s0 user_r:cronjob_t:s0
 system_r:xdm_t:s0		user_r:user_t:s0
 user_r:user_su_t:s0		user_r:user_t:s0
 user_r:user_sudo_t:s0		user_r:user_t:s0
config/appconfig-standard/staff_u_default_contexts +1 -1
index c2a5ea8..300694c 100644
@@ -1,7 +1,7 @@
 system_r:local_login_t		staff_r:staff_t sysadm_r:sysadm_t
 system_r:remote_login_t		staff_r:staff_t
 system_r:sshd_t			staff_r:staff_t sysadm_r:sysadm_t
-system_r:crond_t		staff_r:cronjob_t
+system_r:crond_t		staff_r:staff_t staff_r:cronjob_t
 system_r:xdm_t			staff_r:staff_t
 staff_r:staff_su_t		staff_r:staff_t
 staff_r:staff_sudo_t		staff_r:staff_t
config/appconfig-standard/user_u_default_contexts +1 -1
index f5bfac3..63b7eec 100644
@@ -1,7 +1,7 @@
 system_r:local_login_t		user_r:user_t
 system_r:remote_login_t		user_r:user_t
 system_r:sshd_t			user_r:user_t
-system_r:crond_t		user_r:cronjob_t
+system_r:crond_t		user_r:user_t user_r:cronjob_t
 system_r:xdm_t			user_r:user_t
 user_r:user_su_t		user_r:user_t
 user_r:user_sudo_t		user_r:user_t
Signature · 1 line
2.6.2
#4 lore raw
Quoted 66 lines · Laurent Bigonville
Quoted 65 lines · Laurent Bigonville

Hi,

I'm still looking at adding SELinux support in the "at" daemon and I now have the following patch[0].

With this patch, at seems to behave like the cron daemon, as explained in the commit log:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For
confined
user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes are
run
under the user default context.

But every time an AVC denial is generated (with cron_userdomain_transition set to off and the user running as staff_u, in permissive with unmodified refpolicy):

avc: denied { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:staff_r:cronjob_t:s0

But audit2{allow,why} are saying that this is already allowed in the policy

Setting the cron_userdomain_transition boolean to on, I have the following avc:

avc: denied { entrypoint } for scontext=staff_u:sysadm_r:sysadm_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:sysadm_r:sysadm_t:s0

So as said it seems to work, but I'm not sure why this AVC denial is generated.

sesearch shows:

$ sesearch -ATSC  -t user_cron_spool_t -c file -p entrypoint
Found 6 semantic av rules:
   allow files_unconfined_type file_type : file { ioctl read write
create getattr setattr lock relabelfrom relabelto append unlink link
rename execute swapon quotaon mounton execute_no_trans entrypoint
open audit_access } ;
DT allow unconfined_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow user_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
EF allow cronjob_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow staff_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow sysadm_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]

Did I overlooked something?

Cheers,

Quoted 7 lines
Quoted 4 lines

Laurent Bigonville

[0]
https://anonscm.debian.org/cgit/users/bigon/at.git/commit/?h=selinux&id=0112f006b74a36f7200e315575fd25d78e11b170

I'm attaching the patch to this mail for the people that cannot access the website and FTR.

And it was of course the wrong one...

Quoted 1 line

From 0112f006b74a36f7200e315575fd25d78e11b170 Mon Sep 17 00:00:00 2001

From: Laurent Bigonville <[email protected]>
Date: Thu, 16 Jul 2015 01:06:06 +0200
Subject: [PATCH] Add SELinux support to run jobs in the proper domain
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Currently, jobs run by at are run in the crond_t domain and not transitioned outside of it.

With this patch, the jobs are transitioned in the same domain as the jobs that are run by the cron daemon:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For confined user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes are run under the user default context.

This patch is based on Marcela Mašláňová <[email protected]> work

---
 Makefile.in  |  3 ++-
 atd.c        | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 config.h.in  |  3 +++
 configure.ac |  8 ++++++
 daemon.c     | 16 +++++++++++
 daemon.h     |  3 +++
 6 files changed, 119 insertions(+), 1 deletion(-)
Makefile.in +2 -1
index 06544f9..dd3c2f8 100644
@@ -40,6 +40,7 @@ LIBS		= @LIBS@
 LIBOBJS		= @LIBOBJS@
 INSTALL		= @INSTALL@
 PAMLIB          = @PAMLIB@
+SELINUXLIB      = @SELINUXLIB@
 
 CLONES		= atq atrm
 ATOBJECTS	= at.o panic.o perm.o posixtm.o y.tab.o lex.yy.o
@@ -73,7 +74,7 @@ at: $(ATOBJECTS)
 	$(LN_S) -f at atrm
 
 atd: $(RUNOBJECTS)
-	$(CC) $(LDFLAGS) -o atd $(RUNOBJECTS) $(LIBS) $(PAMLIB)
+	$(CC) $(LDFLAGS) -o atd $(RUNOBJECTS) $(LIBS) $(PAMLIB) $(SELINUXLIB)
 
 y.tab.c y.tab.h: parsetime.y
 	$(YACC) -d parsetime.y
atd.c +87 -0

111 lines not on this page · raw message

config.h.in +3 -0
index 4d7dc91..681d68e 100644
@@ -192,6 +192,9 @@
    <sys/cpustats.h>. */
 #undef UMAX4_3
 
+/* Define if you are building with_selinux */
+#undef WITH_SELINUX
+
 /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
    `char[]'. */
 #undef YYTEXT_POINTER
configure.ac +8 -0
index bcd3ec6..0321a02 100644
@@ -239,6 +239,14 @@ AC_ARG_WITH(daemon_username,
 )
 AC_SUBST(DAEMON_USERNAME)
 
+AC_ARG_WITH(selinux,
+[ --with-selinux       Define to run with selinux],
+AC_DEFINE(WITH_SELINUX, 1, [Define if you are building with_selinux]),
+)
+AC_CHECK_LIB(selinux, is_selinux_enabled, SELINUXLIB=-lselinux)
+AC_SUBST(SELINUXLIB)
+AC_SUBST(WITH_SELINUX)
+
 AC_MSG_CHECKING(groupname to run under)
 AC_ARG_WITH(daemon_groupname,
 [ --with-daemon_groupname=DAEMON_GROUPNAME	Groupname to run under (default daemon) ],
daemon.c +16 -0
index 8be40d4..f9d25e7 100644
@@ -83,6 +83,22 @@ perr(const char *fmt,...)
 }
 
 void
+lerr(const char *fmt,...)
+{
+    char buf[1024];
+    va_list args;
+
+    va_start(args, fmt);
+    vsnprintf(buf, sizeof(buf), fmt, args);
+    va_end(args);
+
+    if (daemon_debug) {
+	perror(buf);
+    } else
+	syslog(LOG_ERR, "%s: %m", buf);
+}
+
+void
 pabort(const char *fmt,...)
 {
     char buf[1024];
daemon.h +3 -0
index c4507ae..f44ccd1 100644
@@ -13,5 +13,8 @@ __attribute__((noreturn))
 #endif
 perr (const char *fmt, ...);
 
+void
+lerr (const char *fmt, ...);
+
 extern int daemon_debug;
 extern int daemon_foreground;

--
2.6.2

#5 lore raw
In reply to Laurent Bigonville
Quoted 57 lines · Laurent Bigonville

Hi,

I'm still looking at adding SELinux support in the "at" daemon and I now have the following patch[0].

With this patch, at seems to behave like the cron daemon, as explained in the commit log:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For
confined
user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes are run under the user default context.

But every time an AVC denial is generated (with cron_userdomain_transition set to off and the user running as staff_u, in permissive with unmodified refpolicy):

avc: denied { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:staff_r:cronjob_t:s0

But audit2{allow,why} are saying that this is already allowed in the policy

Setting the cron_userdomain_transition boolean to on, I have the following avc:

avc: denied { entrypoint } for scontext=staff_u:sysadm_r:sysadm_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:sysadm_r:sysadm_t:s0

So as said it seems to work, but I'm not sure why this AVC denial is generated.

sesearch shows:

$ sesearch -ATSC  -t user_cron_spool_t -c file -p entrypoint
Found 6 semantic av rules:
    allow files_unconfined_type file_type : file { ioctl read write
create getattr setattr lock relabelfrom relabelto append unlink link
rename execute swapon quotaon mounton execute_no_trans entrypoint open
audit_access } ;
DT allow unconfined_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow user_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
EF allow cronjob_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow staff_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow sysadm_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
Quoted 1 line

Did I overlooked something?

What output do you get from:

$ compute_av staff_u:staff_r:cronjob_t:s0 staff_u:object_r:user_cron_spool_t:s0 file

Likewise, for the attached trivial program, what output do you get from:

$ ./check_access staff_u:staff_r:cronjob_t:s0 staff_u:object_r:cronjob_t:s0 file entrypoint

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <selinux/selinux.h>

int main(int argc, char **argv)

{
	int ret;

	if (argc != 5) {
		fprintf(stderr, "usage:  %s scontext tcontext tclass permission\n",
			argv[0]);
		exit(1);
	}

	ret = selinux_check_access(argv[1], argv[2], argv[3], argv[4], NULL);
	if (ret < 0) {
		fprintf(stderr, "selinux_check_access failed: %s\n", strerror(errno));
		exit(2);
	}

	printf("allowed\n");
	exit(0);
}
#6 lore raw
Quoted 59 lines · Stephen Smalley
Quoted 58 lines · Laurent Bigonville

Hi,

I'm still looking at adding SELinux support in the "at" daemon and I now have the following patch[0].

With this patch, at seems to behave like the cron daemon, as explained in the commit log:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For
confined
user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes
are run
under the user default context.

But every time an AVC denial is generated (with cron_userdomain_transition set to off and the user running as staff_u, in permissive with unmodified refpolicy):

avc: denied { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:staff_r:cronjob_t:s0

But audit2{allow,why} are saying that this is already allowed in the policy

Setting the cron_userdomain_transition boolean to on, I have the following avc:

avc: denied { entrypoint } for scontext=staff_u:sysadm_r:sysadm_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:sysadm_r:sysadm_t:s0

So as said it seems to work, but I'm not sure why this AVC denial is generated.

sesearch shows:

$ sesearch -ATSC  -t user_cron_spool_t -c file -p entrypoint
Found 6 semantic av rules:
    allow files_unconfined_type file_type : file { ioctl read write
create getattr setattr lock relabelfrom relabelto append unlink link
rename execute swapon quotaon mounton execute_no_trans entrypoint open
audit_access } ;
DT allow unconfined_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow user_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
EF allow cronjob_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow staff_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow sysadm_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
Quoted 5 lines
Quoted 1 line

Did I overlooked something?

What output do you get from:

$ compute_av staff_u:staff_r:cronjob_t:s0 staff_u:object_r:user_cron_spool_t:s0 file
$ /usr/sbin/compute_av staff_u:staff_r:cronjob_t:s0 staff_u:object_r:user_cron_spool_t:s0 file
allowed= { entrypoint }
Quoted 2 lines

Likewise, for the attached trivial program, what output do you get from:

$ ./check_access staff_u:staff_r:cronjob_t:s0 staff_u:object_r:cronjob_t:s0 file entrypoint
$ ./check_access staff_u:staff_r:cronjob_t:s0 staff_u:object_r:cronjob_t:s0 file entrypoint
avc:  denied  { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:cronjob_t:s0 tclass=file
allowed
$ ./check_access staff_u:staff_r:cronjob_t:s0 staff_u:object_r:user_cron_spool_t:s0 file entrypoint
allowed

The above result is what I get with debian unstable and the kernel 4.2

BUT with the kernel 4.3 from experimental (same machine, just updated kernel), I get:

$ /usr/sbin/compute_av staff_u:staff_r:cronjob_t:s0 staff_u:object_r:user_cron_spool_t:s0 file
allowed= null
$ ./check_access staff_u:staff_r:cronjob_t:s0 staff_u:object_r:cronjob_t:s0 file entrypoint
avc:  denied  { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:cronjob_t:s0 tclass=file
allowed
$ ./check_access staff_u:staff_r:cronjob_t:s0 staff_u:object_r:user_cron_spool_t:s0 file entrypoint
avc:  denied  { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file
allowed

As you can see the results are different... So this seems to be regression at the kernel level.

Cheers,

Laurent Bigonville

#7 lore raw
Quoted 103 lines · Laurent Bigonville
Quoted 60 lines · Stephen Smalley
Quoted 59 lines · Laurent Bigonville

Hi,

I'm still looking at adding SELinux support in the "at" daemon and I now have the following patch[0].

With this patch, at seems to behave like the cron daemon, as explained in the commit log:

- When cron_userdomain_transition is set to off, a process for an unconfined user will transition to unconfined_cronjob_t. For
confined
user, the job is run as cronjob_t.

- When cron_userdomain_transition is set to on, the processes
are run
under the user default context.

But every time an AVC denial is generated (with cron_userdomain_transition set to off and the user running as staff_u, in permissive with unmodified refpolicy):

avc: denied { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:staff_r:cronjob_t:s0

But audit2{allow,why} are saying that this is already allowed in the policy

Setting the cron_userdomain_transition boolean to on, I have the following avc:

avc: denied { entrypoint } for scontext=staff_u:sysadm_r:sysadm_t:s0 tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file

The job runs as (id -Z): staff_u:sysadm_r:sysadm_t:s0

So as said it seems to work, but I'm not sure why this AVC denial is generated.

sesearch shows:

$ sesearch -ATSC  -t user_cron_spool_t -c file -p entrypoint
Found 6 semantic av rules:
    allow files_unconfined_type file_type : file { ioctl read write
create getattr setattr lock relabelfrom relabelto append unlink link
rename execute swapon quotaon mounton execute_no_trans entrypoint open
audit_access } ;
DT allow unconfined_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow user_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
EF allow cronjob_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow staff_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
DT allow sysadm_t user_cron_spool_t : file entrypoint ; [
cron_userdomain_transition ]
Quoted 6 lines
Quoted 1 line

Did I overlooked something?

What output do you get from:

$ compute_av staff_u:staff_r:cronjob_t:s0
staff_u:object_r:user_cron_spool_t:s0 file
$ /usr/sbin/compute_av staff_u:staff_r:cronjob_t:s0
staff_u:object_r:user_cron_spool_t:s0 file
allowed= { entrypoint }
Quoted 3 lines

Likewise, for the attached trivial program, what output do you get from:

$ ./check_access staff_u:staff_r:cronjob_t:s0
staff_u:object_r:cronjob_t:s0 file entrypoint
$ ./check_access staff_u:staff_r:cronjob_t:s0
staff_u:object_r:cronjob_t:s0 file entrypoint
avc:  denied  { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0
tcontext=staff_u:object_r:cronjob_t:s0 tclass=file
allowed
$ ./check_access staff_u:staff_r:cronjob_t:s0
staff_u:object_r:user_cron_spool_t:s0 file entrypoint
allowed

The above result is what I get with debian unstable and the kernel 4.2

BUT with the kernel 4.3 from experimental (same machine, just updated kernel), I get:

$ /usr/sbin/compute_av staff_u:staff_r:cronjob_t:s0
staff_u:object_r:user_cron_spool_t:s0 file
allowed= null
$ ./check_access staff_u:staff_r:cronjob_t:s0
staff_u:object_r:cronjob_t:s0 file entrypoint
avc:  denied  { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0
tcontext=staff_u:object_r:cronjob_t:s0 tclass=file
allowed
$ ./check_access staff_u:staff_r:cronjob_t:s0
staff_u:object_r:user_cron_spool_t:s0 file entrypoint
avc:  denied  { entrypoint } for scontext=staff_u:staff_r:cronjob_t:s0
tcontext=staff_u:object_r:user_cron_spool_t:s0 tclass=file
allowed
Quoted 2 lines

As you can see the results are different... So this seems to be regression at the kernel level.

Well, that depends - are you loading the same policy into both? What do you have in /etc/selinux/targeted/policy? A policy.29 and a policy.30?
What does your libsepol/checkpolicy support?

Or, alternatively, are you toggling cron_userdomain_transition and thereby changing the result?

#8 lore raw
Quoted 10 lines · Stephen Smalley
Quoted 2 lines · Laurent Bigonville

As you can see the results are different... So this seems to be regression at the kernel level.

Well, that depends - are you loading the same policy into both? What do you have in /etc/selinux/targeted/policy? A policy.29 and a policy.30? What does your libsepol/checkpolicy support?

Or, alternatively, are you toggling cron_userdomain_transition and thereby changing the result?

It's the same policy loaded, for both kernel version (I'm just choosing an other kernel in grub), I only have one policy file.

# ls /etc/selinux/refpolicy/policy/
policy.29

I've the latest released userspace (2.4), policydb.h shows max version being 29.

The policyvers utility shows: 30 with 4.3 and 29 with 4.2

#9 lore raw
Quoted 15 lines · Laurent Bigonville
Quoted 10 lines · Stephen Smalley
Quoted 2 lines · Laurent Bigonville

As you can see the results are different... So this seems to be regression at the kernel level.

Well, that depends - are you loading the same policy into both? What do you have in /etc/selinux/targeted/policy? A policy.29 and a policy.30? What does your libsepol/checkpolicy support?

Or, alternatively, are you toggling cron_userdomain_transition and thereby changing the result?

It's the same policy loaded, for both kernel version (I'm just choosing an other kernel in grub), I only have one policy file.

Quoted 7 lines
# ls /etc/selinux/refpolicy/policy/
policy.29

I've the latest released userspace (2.4), policydb.h shows max version being 29.

The policyvers utility shows: 30 with 4.3 and 29 with 4.2

You are correct - this is a kernel bug. Hidden on Fedora because these rules are unconditional there...