[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH] xen/flask: estimate max sidtable size


  • To: Sergiy Kibrik <Sergiy_Kibrik@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 1 Jul 2025 12:42:34 +0200
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 01 Jul 2025 10:42:54 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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_Kibrik@xxxxxxxx>
> ---
> 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?

> --- a/xen/xsm/flask/Makefile
> +++ b/xen/xsm/flask/Makefile
> @@ -14,7 +14,7 @@ AV_H_DEPEND := $(srcdir)/policy/access_vectors
>  
>  FLASK_H_FILES := flask.h class_to_string.h initial_sid_to_string.h
>  AV_H_FILES := av_perm_to_string.h av_permissions.h
> -ALL_H_FILES := $(addprefix include/,$(FLASK_H_FILES) $(AV_H_FILES))
> +ALL_H_FILES := $(addprefix include/,$(FLASK_H_FILES) $(AV_H_FILES) 
> se_limits.h)

As a nit: Dashes in preference to underscores please in any new files'
names.

> @@ -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 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.)

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.