01.07.25 13:42, Jan Beulich:
On 30.06.2025 10:55, Sergiy Kibrik wrote:
Currently Xen lacks a defined largest number of security IDs it can potentially
use. The number of SIDs are naturally limited by number of security contexts
provided by a given security policy, i.e. how many combination of user, role
and type there can be, and is dependant on the policy being used.
Thus in Xen the number of allocated entries in sidtable is hard-limited by
UINT_MAX.
However in the embedded environment configured for safety it is desirable to
avoid guest-triggered dynamic memory allocations at runtime, or at least limit
them to some decent amounts. So we seek to estimate this limit.
This patch suggests one way to do it using Xen's flask policy.
List of users, roles and types is read from binary policy using setools utils,
then it is used to count the No. of combinations these values can give.
This No. of combinations then can be used in code as a practical replacement
of UINT_MAX limit. Also it can be used later to pre-allocate sidtable at boot
and avoid runtime entries allocation altogether.
Signed-off-by: Sergiy Kibrik <sergiy_kib...@epam.com>
---
This RFC presents a concept of estimating a max possible sidtable size.
Can we discuss how valid this concept is? Currently it yields 420 as max SID,
is it a reasonable number?
As this is policy dependent - what policy did you use to obtain that 420?
it's actually from my custom extended policy, for policy in Xen master
branch it's 384.
@@ -54,4 +54,7 @@ $(obj)/policy.bin: FORCE
FLASK_BUILD_DIR=$(FLASK_BUILD_DIR) POLICY_FILENAME=$(POLICY_SRC)
cmp -s $(POLICY_SRC) $@ || cp $(POLICY_SRC) $@
+$(obj)/%/se_limits.h: $(obj)/policy.bin
+ $(srcdir)/policy/mkselim.sh $^ $@
Hmm, that's using the built-in policy, isn't it? What if later another
policy is loaded? Wouldn't it be possible to have ...
--- a/xen/xsm/flask/ss/sidtab.c
+++ b/xen/xsm/flask/ss/sidtab.c
@@ -13,6 +13,7 @@
#include "flask.h"
#include "security.h"
#include "sidtab.h"
+#include "se_limits.h"
#define SIDTAB_HASH(sid) ((sid) & SIDTAB_HASH_MASK)
@@ -228,7 +229,7 @@ int sidtab_context_to_sid(struct sidtab *s, struct context *context,
if ( sid )
goto unlock_out;
/* No SID exists for the context. Allocate a new one. */
- if ( s->next_sid == UINT_MAX || s->shutdown )
+ if ( s->next_sid == SEPOL_SID_LIMIT || s->shutdown )
... more than this many SIDs? What if CONFIG_XSM_FLASK_POLICY isn't even set?
It's using a policy from tools/flask/policy, yes. But not a built-in
policy, just reusing a bit of code from that code. The idea is that we
can have CONFIG_XSM_FLASK_POLICY option disabled yet still be able to
calculate SEPOL_SID_LIMIT.
As for loading another policy at runtime -- the calculated
SEPOL_SID_LIMIT=384 for current master flask policy is still pretty big
limit. From what I can see -- much less No. contexts are being used on a
running system, because most of calculated combinations of
user/role/type are not really usable (e.g. contexts with xen_t or
xenboot_t types and user_1 user are not expected etc). So there should
be enough room even for more complex custom policies.
It also doesn't really become clear to me how you avoid or even (meaningfully)
bound memory allocation here. A table of several hundred entries is still a
decent size. If you really knew the max size up front, why couldn't the table
be allocated statically. (Sadly the table allocation isn't in context, as you
don't even touch that code, wherever it lives.)
As said before, this limit is crude and still far from the number of
actually usable contexts. So allocating this memory beforehand can be
kind of wasteful, as most of it will probably never be used.
-Sergiy