Skip to contentSkip to conversation

dbus-daemon patches review

PATCH Laurent Bigonville 3 participants 8 messages Mar 21, 2018 – Mar 23, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

Hello,

Could somebody have a quick look at the two patches that I opened for two dbus bugs:

https://bugs.freedesktop.org/show_bug.cgi?id=92831 (stop using avc_init())

https://bugs.freedesktop.org/attachment.cgi?id=138021 (stop using selinux_set_mapping())

I'm also wondering whether the call to avc_add_callback() shouldn't be replaced by selinux_set_callback(), an opinion on this?

Kind regards,

Laurent Bigonville

Quoted 1 line

From 1299035853924131d40d1033ce367153933d4a84 Mon Sep 17 00:00:00 2001

From: Laurent Bigonville <[email protected]>
Date: Sat, 3 Mar 2018 13:15:17 +0100
Subject: [PATCH 1/2] Stop using avc_init() which is deprecated

Stop using avc_init() and use avc_open() instead. With this commit dbus-daemon will stop using a thread to monitor the avc netlink and will poll it instead.

https://bugs.freedesktop.org/show_bug.cgi?id=92831

---
 bus/bus.c       |   2 +-
 bus/selinux.c   | 213 +++++++++++++++++++++++++++-----------------------------
 bus/selinux.h   |   2 +-
 bus/test-main.c |   6 --
 bus/test.c      |   9 +++
 5 files changed, 113 insertions(+), 119 deletions(-)
bus/bus.c +1 -1
index 9fd9820b..5b59ed45 100644
@@ -995,7 +995,7 @@ bus_context_new (const DBusString *config_file,
    */
   bus_audit_init (context);
 
-  if (!bus_selinux_full_init ())
+  if (!bus_selinux_full_init (context, error))
     {
       bus_context_log (context, DBUS_SYSTEM_LOG_ERROR,
                        "SELinux enabled but D-Bus initialization failed; "
bus/selinux.c +102 -111

303 lines not on this page · raw message

bus/selinux.h +1 -1
index a0383cdd..53de1a84 100644
@@ -28,7 +28,7 @@
 #include "services.h"
 
 dbus_bool_t bus_selinux_pre_init (void);
-dbus_bool_t bus_selinux_full_init(void);
+dbus_bool_t bus_selinux_full_init(BusContext *context, DBusError *error);
 void        bus_selinux_shutdown (void);
 
 dbus_bool_t bus_selinux_enabled  (void);
bus/test-main.c +0 -6
index 400ea423..ba73a1b4 100644
@@ -47,12 +47,6 @@ static DBusString test_data_dir;
 static void
 test_pre_hook (void)
 {
-  
-  if (_dbus_getenv ("DBUS_TEST_SELINUX")
-      && (!bus_selinux_pre_init ()
-	  || !bus_selinux_full_init ()))
-    _dbus_test_fatal ("Could not init selinux support");
-
   initial_fds = _dbus_check_fdleaks_enter ();
 }
 
bus/test.c +9 -0
index 76960a30..730cd64a 100644
@@ -28,6 +28,8 @@
 #include <dbus/dbus-internals.h>
 #include <dbus/dbus-list.h>
 #include <dbus/dbus-sysdeps.h>
+#include <dbus/dbus-test-tap.h>
+#include "selinux.h"
 
 /* The "debug client" watch/timeout handlers don't dispatch messages,
  * as we manually pull them in order to verify them. This is why they
@@ -307,6 +309,13 @@ bus_context_new_test (const DBusString *test_data_dir,
       return NULL;
     }
 
+    if (_dbus_getenv ("DBUS_TEST_SELINUX")
+      && (!bus_selinux_pre_init ()
+	  || !bus_selinux_full_init (context, &error)))
+    _dbus_test_fatal ("Could not init selinux support");
+
+  dbus_error_free (&error);
+
   _dbus_string_free (&config_file);
 
   return context;
Signature · 1 line
2.16.2
Quoted 1 line

From 94889d438c81f001d4716d11df8a55a3706e45b0 Mon Sep 17 00:00:00 2001

From: Laurent Bigonville <[email protected]>
Date: Sat, 3 Mar 2018 11:15:23 +0100
Subject: [PATCH 2/2] Stop using selinux_set_mapping() function

Currently, if the "dbus" security class or the associated AV doesn't exist, dbus-daemon fails to initialize and exits immediately. Also the security classes or access vector cannot be reordered in the policy. This can be a problem for people developping their own policy or trying to access a machine where, for some reasons, there is not policy defined at all.

The code here copy the behaviour of the selinux_check_access() function. We cannot use this function here as it doesn't allow us to define a cache.

https://bugs.freedesktop.org/show_bug.cgi?id=105330

---
 bus/selinux.c | 75 ++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 43 insertions(+), 32 deletions(-)
bus/selinux.c +43 -32

115 lines not on this page · raw message

Signature · 1 line
2.16.2
#1 lore raw
Quoted 9 lines · Laurent Bigonville

Hello,

Could somebody have a quick look at the two patches that I opened for two dbus bugs:

https://bugs.freedesktop.org/show_bug.cgi?id=92831 (stop using avc_init())

https://bugs.freedesktop.org/attachment.cgi?id=138021 (stop using selinux_set_mapping())

I'm also wondering whether the call to avc_add_callback() shouldn't be replaced by selinux_set_callback(), an opinion on this?

Patches look sane to me although I'm not really familiar with dbus code.

Looks like the callback is only used to trigger a reload of the dbus configuration (for dbus_contexts updates), and thus selinux_set_callback(SELINUX_CB_POLICYLOAD) is more appropriate than avc_add_callback(AVC_CALLBACK_RESET), since the latter is called upon setenforce 1 as well. However, if it were truly only for that purpose, one might argue that it ought to be a watch on the dbus_contexts file instead and not be tied to selinux at all.

NB This still won't fix the case where dbusd has already performed a string_to_security_class/av_perm lookup and the result has been cached by the libselinux class cache and then a subsequent policy update alters those values. That is what was fixed for systemd's usage of selinux_check_access() by selinux commit b408d72ca9104cb0c1bc4e154d8732cc7c0a9190. Offhand, I'm now wondering why I didn't just call flush_class_cache() from avc_reset() itself. That would fix it for other users of the AVC. You can't directly call flush_class_cache() from the dbus selinux policyload callback because it is hidden presently. If we can fix it directly in libselinux, then that is better. If not, we'd need to export it and probably give it a more unique name, ala selinux_flush_class_cache().

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

Hello,

Could somebody have a quick look at the two patches that I opened for two dbus bugs:

https://bugs.freedesktop.org/show_bug.cgi?id=92831 (stop using avc_init())

https://bugs.freedesktop.org/attachment.cgi?id=138021 (stop using selinux_set_mapping())

Quoted 7 lines
Quoted 1 line

I'm also wondering whether the call to avc_add_callback() shouldn't be replaced by selinux_set_callback(), an opinion on this?

Patches look sane to me although I'm not really familiar with dbus code.

Looks like the callback is only used to trigger a reload of the dbus configuration (for dbus_contexts updates), and thus selinux_set_callback(SELINUX_CB_POLICYLOAD) is more appropriate than avc_add_callback(AVC_CALLBACK_RESET), since the latter is called upon setenforce 1 as well. However, if it were truly only for that purpose, one might argue that it ought to be a watch on the dbus_contexts file instead and not be tied to selinux at all.

NB This still won't fix the case where dbusd has already performed a string_to_security_class/av_perm lookup and the result has been cached by the libselinux class cache and then a subsequent policy update alters those values. That is what was fixed for systemd's usage of selinux_check_access() by selinux commit b408d72ca9104cb0c1bc4e154d8732cc7c0a9190. Offhand, I'm now wondering why I didn't just call flush_class_cache() from avc_reset() itself. That would fix it for other users of the AVC. You can't directly call flush_class_cache() from the dbus selinux policyload callback because it is hidden presently. If we can fix it directly in libselinux, then that is better. If not, we'd need to export it and probably give it a more unique name, ala selinux_flush_class_cache().

dbus-broker also uses selinux_access_check: https://github.com/bus1/dbus-broker/issues/16

Quoted 2 lines
Signature · 3 lines
Key fingerprint = 5F4D 3CDB D3F8 3652 FBD8  02D5 3B6C 5F1D 2C7B 6B02
https://sks-keyservers.net/pks/lookup?op=get&search=0x3B6C5F1D2C7B6B02
Dominick Grift
#3 lore raw
In reply to Stephen Smalley

Le 22/03/18 à 17:09, Stephen Smalley a écrit :

Quoted 11 lines · Laurent Bigonville
Quoted 9 lines

Hello,

Could somebody have a quick look at the two patches that I opened for two dbus bugs:

https://bugs.freedesktop.org/show_bug.cgi?id=92831 (stop using avc_init())

https://bugs.freedesktop.org/attachment.cgi?id=138021 (stop using selinux_set_mapping())

I'm also wondering whether the call to avc_add_callback() shouldn't be replaced by selinux_set_callback(), an opinion on this?

Patches look sane to me although I'm not really familiar with dbus code.

Thanks for the review, Simon already had a look at the dbus part of the code

Quoted 1 line

Looks like the callback is only used to trigger a reload of the dbus configuration (for dbus_contexts updates), and thus selinux_set_callback(SELINUX_CB_POLICYLOAD) is more appropriate than avc_add_callback(AVC_CALLBACK_RESET), since the latter is called upon setenforce 1 as well. However, if it were truly only for that purpose, one might argue that it ought to be a watch on the dbus_contexts file instead and not be tied to selinux at all.

I really don't know the original rational of this. But I guess that if somebody is modifying dbus_contexts file, there are big chances that he will reload the policy as well(?).

I'll change avc_add_callback() by selinux_set_callback(), we could say that as the file is in the SELinux path it's its responsibility.

Quoted 1 line

NB This still won't fix the case where dbusd has already performed a string_to_security_class/av_perm lookup and the result has been cached by the libselinux class cache and then a subsequent policy update alters those values. That is what was fixed for systemd's usage of selinux_check_access() by selinux commit b408d72ca9104cb0c1bc4e154d8732cc7c0a9190. Offhand, I'm now wondering why I didn't just call flush_class_cache() from avc_reset() itself. That would fix it for other users of the AVC. You can't directly call flush_class_cache() from the dbus selinux policyload callback because it is hidden presently. If we can fix it directly in libselinux, then that is better. If not, we'd need to export it and probably give it a more unique name, ala selinux_flush_class_cache().

Right, that's a really good point, that I apparently overlooked...

Is that cache really supposed to substantially speedup things? Would it be possible to create a version of selinux_check_access() that allows to pass a reference the cache or let selinux_check_access() create that cache itself? If it's the case I guess that dbus-broker would benefit of that as well as they are using selinux_check_access().

Otherwise we can indeed clean up the cache our self, but wasn't the goal of selinux_check_access() to be an "easy" interface to use, asking the applications to do this kind of housekeeping is defeating that purpose, isn't it?

#4 lore raw
Quoted 18 lines · Laurent Bigonville

Le 22/03/18 à 17:09, Stephen Smalley a écrit :

Quoted 11 lines · Laurent Bigonville
Quoted 9 lines

Hello,

Could somebody have a quick look at the two patches that I opened for two dbus bugs:

https://bugs.freedesktop.org/show_bug.cgi?id=92831  (stop using avc_init())

https://bugs.freedesktop.org/attachment.cgi?id=138021  (stop using selinux_set_mapping())

I'm also wondering whether the call to avc_add_callback() shouldn't be replaced by selinux_set_callback(), an opinion on this?

Patches look sane to me although I'm not really familiar with dbus code.

Thanks for the review, Simon already had a look at the dbus part of the code

Quoted 1 line

Looks like the callback is only used to trigger a reload of the dbus configuration (for dbus_contexts updates), and thus selinux_set_callback(SELINUX_CB_POLICYLOAD) is more appropriate than avc_add_callback(AVC_CALLBACK_RESET), since the latter is called upon setenforce 1 as well.  However, if it were truly only for that purpose, one might argue that it ought to be a watch on the dbus_contexts file instead and not be tied to selinux at all.

I really don't know the original rational of this. But I guess that if somebody is modifying dbus_contexts file, there are big chances that he will reload the policy as well(?).

Quoted 8 lines

I'll change avc_add_callback() by selinux_set_callback(), we could say that as the file is in the SELinux path it's its responsibility.

Quoted 1 line

NB This still won't fix the case where dbusd has already performed a string_to_security_class/av_perm lookup and the result has been cached by the libselinux class cache and then a subsequent policy update alters those values.  That is what was fixed for systemd's usage of selinux_check_access() by selinux commit b408d72ca9104cb0c1bc4e154d8732cc7c0a9190.  Offhand, I'm now wondering why I didn't just call flush_class_cache() from avc_reset() itself.  That would fix it for other users of the AVC.  You can't directly call flush_class_cache() from the dbus selinux policyload callback because it is hidden presently.  If we can fix it directly in libselinux, then that is better.  If not, we'd need to export it and probably give it a more unique name, ala selinux_flush_class_cache().

Right, that's a really good point, that I apparently overlooked...

Is that cache really supposed to substantially speedup things? Would it be possible to create a version of selinux_check_access() that allows to pass a reference the cache or let selinux_check_access() create that cache itself? If it's the case I guess that dbus-broker would benefit of that as well as they are using selinux_check_access().

Otherwise we can indeed clean up the cache our self, but wasn't the goal of selinux_check_access() to be an "easy" interface to use, asking the applications to do this kind of housekeeping is defeating that purpose, isn't it?

If you use selinux_check_access(), then the class cache is already flushed for you upon an AVC reset; that is what the commit I referenced above did. The problem in the case of dbusd is that it is not using selinux_check_access() but rather its own direct usage of string_to_security_class/av_perm() and avc_has_perm(). That's why we need to either take the call to flush_class_cache() in libselinux to avc_reset() so that it is done for all users of the AVC, or we need to export it and have dbusd call it from its policy reload callback.

#5 lore raw

Le 23/03/18 à 13:26, Stephen Smalley a écrit :

Quoted 20 lines · Laurent Bigonville
Quoted 19 lines

Le 22/03/18 à 17:09, Stephen Smalley a écrit :

Quoted 11 lines · Laurent Bigonville
Quoted 9 lines

Hello,

Could somebody have a quick look at the two patches that I opened for two dbus bugs:

https://bugs.freedesktop.org/show_bug.cgi?id=92831  (stop using avc_init())

https://bugs.freedesktop.org/attachment.cgi?id=138021  (stop using selinux_set_mapping())

I'm also wondering whether the call to avc_add_callback() shouldn't be replaced by selinux_set_callback(), an opinion on this?

Patches look sane to me although I'm not really familiar with dbus code.

Thanks for the review, Simon already had a look at the dbus part of the code

Quoted 1 line

Looks like the callback is only used to trigger a reload of the dbus configuration (for dbus_contexts updates), and thus selinux_set_callback(SELINUX_CB_POLICYLOAD) is more appropriate than avc_add_callback(AVC_CALLBACK_RESET), since the latter is called upon setenforce 1 as well.  However, if it were truly only for that purpose, one might argue that it ought to be a watch on the dbus_contexts file instead and not be tied to selinux at all.

I really don't know the original rational of this. But I guess that if somebody is modifying dbus_contexts file, there are big chances that he will reload the policy as well(?).

I'll change avc_add_callback() by selinux_set_callback(), we could say that as the file is in the SELinux path it's its responsibility.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

NB This still won't fix the case where dbusd has already performed a string_to_security_class/av_perm lookup and the result has been cached by the libselinux class cache and then a subsequent policy update alters those values.  That is what was fixed for systemd's usage of selinux_check_access() by selinux commit b408d72ca9104cb0c1bc4e154d8732cc7c0a9190.  Offhand, I'm now wondering why I didn't just call flush_class_cache() from avc_reset() itself.  That would fix it for other users of the AVC.  You can't directly call flush_class_cache() from the dbus selinux policyload callback because it is hidden presently.  If we can fix it directly in libselinux, then that is better.  If not, we'd need to export it and probably give it a more unique name, ala selinux_flush_class_cache().

Right, that's a really good point, that I apparently overlooked...

Is that cache really supposed to substantially speedup things? Would it be possible to create a version of selinux_check_access() that allows to pass a reference the cache or let selinux_check_access() create that cache itself? If it's the case I guess that dbus-broker would benefit of that as well as they are using selinux_check_access().

Otherwise we can indeed clean up the cache our self, but wasn't the goal of selinux_check_access() to be an "easy" interface to use, asking the applications to do this kind of housekeeping is defeating that purpose, isn't it?

If you use selinux_check_access(), then the class cache is already flushed for you upon an AVC reset; that is what the commit I referenced above did. The problem in the case of dbusd is that it is not using selinux_check_access() but rather its own direct usage of string_to_security_class/av_perm() and avc_has_perm(). That's why we need to either take the call to flush_class_cache() in libselinux to avc_reset() so that it is done for all users of the AVC, or we need to export it and have dbusd call it from its policy reload callback.

No, I meant the decision cache used by avc_has_perm(). dbus is not using selinux_check_access() because there is no way to set that decision cache (the 5th parameter of avc_has_perm() is NULL)

#6 lore raw
Quoted 22 lines · Laurent Bigonville

Le 23/03/18 à 13:26, Stephen Smalley a écrit :

Quoted 21 lines · Laurent Bigonville
Quoted 20 lines

Le 22/03/18 à 17:09, Stephen Smalley a écrit :

Quoted 11 lines · Laurent Bigonville
Quoted 9 lines

Hello,

Could somebody have a quick look at the two patches that I opened for two dbus bugs:

https://bugs.freedesktop.org/show_bug.cgi?id=92831  (stop using avc_init())

https://bugs.freedesktop.org/attachment.cgi?id=138021  (stop using selinux_set_mapping())

I'm also wondering whether the call to avc_add_callback() shouldn't be replaced by selinux_set_callback(), an opinion on this?

Patches look sane to me although I'm not really familiar with dbus code.

Thanks for the review, Simon already had a look at the dbus part of the code

Quoted 1 line

Looks like the callback is only used to trigger a reload of the dbus configuration (for dbus_contexts updates), and thus selinux_set_callback(SELINUX_CB_POLICYLOAD) is more appropriate than avc_add_callback(AVC_CALLBACK_RESET), since the latter is called upon setenforce 1 as well.  However, if it were truly only for that purpose, one might argue that it ought to be a watch on the dbus_contexts file instead and not be tied to selinux at all.

I really don't know the original rational of this. But I guess that if somebody is modifying dbus_contexts file, there are big chances that he will reload the policy as well(?).

I'll change avc_add_callback() by selinux_set_callback(), we could say that as the file is in the SELinux path it's its responsibility.

Quoted 1 line

NB This still won't fix the case where dbusd has already performed a string_to_security_class/av_perm lookup and the result has been cached by the libselinux class cache and then a subsequent policy update alters those values.  That is what was fixed for systemd's usage of selinux_check_access() by selinux commit b408d72ca9104cb0c1bc4e154d8732cc7c0a9190.  Offhand, I'm now wondering why I didn't just call flush_class_cache() from avc_reset() itself.  That would fix it for other users of the AVC.  You can't directly call flush_class_cache() from the dbus selinux policyload callback because it is hidden presently.  If we can fix it directly in libselinux, then that is better.  If not, we'd need to export it and probably give it a more unique name, ala selinux_flush_class_cache().

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

Right, that's a really good point, that I apparently overlooked...

Is that cache really supposed to substantially speedup things? Would it be possible to create a version of selinux_check_access() that allows to pass a reference the cache or let selinux_check_access() create that cache itself? If it's the case I guess that dbus-broker would benefit of that as well as they are using selinux_check_access().

Otherwise we can indeed clean up the cache our self, but wasn't the goal of selinux_check_access() to be an "easy" interface to use, asking the applications to do this kind of housekeeping is defeating that purpose, isn't it?

If you use selinux_check_access(), then the class cache is already flushed for you upon an AVC reset; that is what the commit I referenced above did.  The problem in the case of dbusd is that it is not using selinux_check_access() but rather its own direct usage of string_to_security_class/av_perm() and avc_has_perm().  That's why we need to either take the call to flush_class_cache() in libselinux to avc_reset() so that it is done for all users of the AVC, or we need to export it and have dbusd call it from its policy reload callback.

No, I meant the decision cache used by avc_has_perm(). dbus is not using selinux_check_access() because there is no way to set that decision cache (the 5th parameter of avc_has_perm() is NULL)

Oh, you mean the AVC entry reference. Usually that would be cached in a per-object structure of some sort, e.g. in the kernel, there used to be an AVC entry reference cached in the task, inode, and other security structures. However, the AVC entry references were dropped from the kernel altogether when the kernel AVC was converted to using RCU. They are still used in the libselinux AVC, but I wouldn't expect dbusd is gaining much from using it especially since dbusd is only storing a single reference globally rather than any kind of per-object one. The larger cost of switching to using selinux_check_access() is probably the avc_context_to_sid() lookups since you already have the SIDs available to you.

You don't necessarily have to switch to selinux_check_access(). But we do need to ensure that the class cache is flushed, either by adding a call to avc_reset() in libselinux if that is possible, or by exporting flush_class_cache() and calling it from the dbusd policy reload callback.

#7 lore raw
Quoted 27 lines · Stephen Smalley
Quoted 26 lines · Laurent Bigonville

Le 23/03/18 à 13:26, Stephen Smalley a écrit :

Quoted 25 lines · Laurent Bigonville
Quoted 24 lines

Le 22/03/18 à 17:09, Stephen Smalley a écrit :

Quoted 11 lines · Laurent Bigonville
Quoted 9 lines

Hello,

Could somebody have a quick look at the two patches that I opened for two dbus bugs:

https://bugs.freedesktop.org/show_bug.cgi?id=92831  (stop using avc_init())

https://bugs.freedesktop.org/attachment.cgi?id=138021  (stop using selinux_set_mapping())

I'm also wondering whether the call to avc_add_callback() shouldn't be replaced by selinux_set_callback(), an opinion on this?

Patches look sane to me although I'm not really familiar with dbus code.

Thanks for the review, Simon already had a look at the dbus part of the code

Quoted 1 line

Looks like the callback is only used to trigger a reload of the dbus configuration (for dbus_contexts updates), and thus selinux_set_callback(SELINUX_CB_POLICYLOAD) is more appropriate than avc_add_callback(AVC_CALLBACK_RESET), since the latter is called upon setenforce 1 as well.  However, if it were truly only for that purpose, one might argue that it ought to be a watch on the dbus_contexts file instead and not be tied to selinux at all.

I really don't know the original rational of this. But I guess that if somebody is modifying dbus_contexts file, there are big chances that he will reload the policy as well(?).

I'll change avc_add_callback() by selinux_set_callback(), we could say that as the file is in the SELinux path it's its responsibility.

Quoted 1 line

NB This still won't fix the case where dbusd has already performed a string_to_security_class/av_perm lookup and the result has been cached by the libselinux class cache and then a subsequent policy update alters those values.  That is what was fixed for systemd's usage of selinux_check_access() by selinux commit b408d72ca9104cb0c1bc4e154d8732cc7c0a9190.  Offhand, I'm now wondering why I didn't just call flush_class_cache() from avc_reset() itself.  That would fix it for other users of the AVC.  You can't directly call flush_class_cache() from the dbus selinux policyload callback because it is hidden presently.  If we can fix it directly in libselinux, then that is better.  If not, we'd need to export it and probably give it a more unique name, ala selinux_flush_class_cache().

Right, that's a really good point, that I apparently overlooked...

Is that cache really supposed to substantially speedup things? Would it be possible to create a version of selinux_check_access() that allows to pass a reference the cache or let selinux_check_access() create that cache itself? If it's the case I guess that dbus-broker would benefit of that as well as they are using selinux_check_access().

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Otherwise we can indeed clean up the cache our self, but wasn't the goal of selinux_check_access() to be an "easy" interface to use, asking the applications to do this kind of housekeeping is defeating that purpose, isn't it?

If you use selinux_check_access(), then the class cache is already flushed for you upon an AVC reset; that is what the commit I referenced above did.  The problem in the case of dbusd is that it is not using selinux_check_access() but rather its own direct usage of string_to_security_class/av_perm() and avc_has_perm().  That's why we need to either take the call to flush_class_cache() in libselinux to avc_reset() so that it is done for all users of the AVC, or we need to export it and have dbusd call it from its policy reload callback.

No, I meant the decision cache used by avc_has_perm(). dbus is not using selinux_check_access() because there is no way to set that decision cache (the 5th parameter of avc_has_perm() is NULL)

Oh, you mean the AVC entry reference. Usually that would be cached in a per-object structure of some sort, e.g. in the kernel, there used to be an AVC entry reference cached in the task, inode, and other security structures. However, the AVC entry references were dropped from the kernel altogether when the kernel AVC was converted to using RCU. They are still used in the libselinux AVC, but I wouldn't expect dbusd is gaining much from using it especially since dbusd is only storing a single reference globally rather than any kind of per-object one. The larger cost of switching to using selinux_check_access() is probably the avc_context_to_sid() lookups since you already have the SIDs available to you.

You don't necessarily have to switch to selinux_check_access(). But we do need to ensure that the class cache is flushed, either by adding a call to avc_reset() in libselinux if that is possible, or by exporting flush_class_cache() and calling it from the dbusd policy reload callback.

Sorry, to be clear, the first option is to add a call to flush_class_cache() from avc_reset() in libselinux, so that it is always called upon an AVC reset (and dropping the custom avc reset callback from selinux_check_access).