@@ -2547,50 +2547,10 @@ void selinux_audit_set_callback(int (*callback)(void))
25472547}
25482548
25492549#ifdef CONFIG_NETLABEL
2550- /*
2551- * NetLabel cache structure
2552- */
2553- #define NETLBL_CACHE (x ) ((struct selinux_netlbl_cache *)(x))
2554- #define NETLBL_CACHE_T_NONE 0
2555- #define NETLBL_CACHE_T_SID 1
2556- #define NETLBL_CACHE_T_MLS 2
2557- struct selinux_netlbl_cache {
2558- u32 type ;
2559- union {
2560- u32 sid ;
2561- struct mls_range mls_label ;
2562- } data ;
2563- };
2564-
2565- /**
2566- * security_netlbl_cache_free - Free the NetLabel cached data
2567- * @data: the data to free
2568- *
2569- * Description:
2570- * This function is intended to be used as the free() callback inside the
2571- * netlbl_lsm_cache structure.
2572- *
2573- */
2574- static void security_netlbl_cache_free (const void * data )
2575- {
2576- struct selinux_netlbl_cache * cache ;
2577-
2578- if (data == NULL )
2579- return ;
2580-
2581- cache = NETLBL_CACHE (data );
2582- switch (cache -> type ) {
2583- case NETLBL_CACHE_T_MLS :
2584- ebitmap_destroy (& cache -> data .mls_label .level [0 ].cat );
2585- break ;
2586- }
2587- kfree (data );
2588- }
2589-
25902550/**
25912551 * security_netlbl_cache_add - Add an entry to the NetLabel cache
25922552 * @secattr: the NetLabel packet security attributes
2593- * @ctx : the SELinux context
2553+ * @sid : the SELinux SID
25942554 *
25952555 * Description:
25962556 * Attempt to cache the context in @ctx, which was derived from the packet in
@@ -2599,60 +2559,46 @@ static void security_netlbl_cache_free(const void *data)
25992559 *
26002560 */
26012561static void security_netlbl_cache_add (struct netlbl_lsm_secattr * secattr ,
2602- struct context * ctx )
2562+ u32 sid )
26032563{
2604- struct selinux_netlbl_cache * cache = NULL ;
2564+ u32 * sid_cache ;
26052565
2606- secattr -> cache = netlbl_secattr_cache_alloc (GFP_ATOMIC );
2607- if (secattr -> cache == NULL )
2608- return ;
2609-
2610- cache = kzalloc (sizeof (* cache ), GFP_ATOMIC );
2611- if (cache == NULL )
2566+ sid_cache = kmalloc (sizeof (* sid_cache ), GFP_ATOMIC );
2567+ if (sid_cache == NULL )
26122568 return ;
2613-
2614- cache -> type = NETLBL_CACHE_T_MLS ;
2615- if (ebitmap_cpy (& cache -> data .mls_label .level [0 ].cat ,
2616- & ctx -> range .level [0 ].cat ) != 0 ) {
2617- kfree (cache );
2569+ secattr -> cache = netlbl_secattr_cache_alloc (GFP_ATOMIC );
2570+ if (secattr -> cache == NULL ) {
2571+ kfree (sid_cache );
26182572 return ;
26192573 }
2620- cache -> data .mls_label .level [1 ].cat .highbit =
2621- cache -> data .mls_label .level [0 ].cat .highbit ;
2622- cache -> data .mls_label .level [1 ].cat .node =
2623- cache -> data .mls_label .level [0 ].cat .node ;
2624- cache -> data .mls_label .level [0 ].sens = ctx -> range .level [0 ].sens ;
2625- cache -> data .mls_label .level [1 ].sens = ctx -> range .level [0 ].sens ;
26262574
2627- secattr -> cache -> free = security_netlbl_cache_free ;
2628- secattr -> cache -> data = (void * )cache ;
2575+ * sid_cache = sid ;
2576+ secattr -> cache -> free = kfree ;
2577+ secattr -> cache -> data = sid_cache ;
26292578 secattr -> flags |= NETLBL_SECATTR_CACHE ;
26302579}
26312580
26322581/**
26332582 * security_netlbl_secattr_to_sid - Convert a NetLabel secattr to a SELinux SID
26342583 * @secattr: the NetLabel packet security attributes
2635- * @base_sid: the SELinux SID to use as a context for MLS only attributes
26362584 * @sid: the SELinux SID
26372585 *
26382586 * Description:
26392587 * Convert the given NetLabel security attributes in @secattr into a
26402588 * SELinux SID. If the @secattr field does not contain a full SELinux
2641- * SID/context then use the context in @base_sid as the foundation. If
2642- * possibile the 'cache' field of @secattr is set and the CACHE flag is set;
2643- * this is to allow the @secattr to be used by NetLabel to cache the secattr to
2644- * SID conversion for future lookups. Returns zero on success, negative
2645- * values on failure.
2589+ * SID/context then use SECINITSID_NETMSG as the foundation. If possibile the
2590+ * 'cache' field of @secattr is set and the CACHE flag is set; this is to
2591+ * allow the @secattr to be used by NetLabel to cache the secattr to SID
2592+ * conversion for future lookups. Returns zero on success, negative values on
2593+ * failure.
26462594 *
26472595 */
26482596int security_netlbl_secattr_to_sid (struct netlbl_lsm_secattr * secattr ,
2649- u32 base_sid ,
26502597 u32 * sid )
26512598{
26522599 int rc = - EIDRM ;
26532600 struct context * ctx ;
26542601 struct context ctx_new ;
2655- struct selinux_netlbl_cache * cache ;
26562602
26572603 if (!ss_initialized ) {
26582604 * sid = SECSID_NULL ;
@@ -2662,43 +2608,13 @@ int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
26622608 POLICY_RDLOCK ;
26632609
26642610 if (secattr -> flags & NETLBL_SECATTR_CACHE ) {
2665- cache = NETLBL_CACHE (secattr -> cache -> data );
2666- switch (cache -> type ) {
2667- case NETLBL_CACHE_T_SID :
2668- * sid = cache -> data .sid ;
2669- rc = 0 ;
2670- break ;
2671- case NETLBL_CACHE_T_MLS :
2672- ctx = sidtab_search (& sidtab , base_sid );
2673- if (ctx == NULL )
2674- goto netlbl_secattr_to_sid_return ;
2675-
2676- ctx_new .user = ctx -> user ;
2677- ctx_new .role = ctx -> role ;
2678- ctx_new .type = ctx -> type ;
2679- ctx_new .range .level [0 ].sens =
2680- cache -> data .mls_label .level [0 ].sens ;
2681- ctx_new .range .level [0 ].cat .highbit =
2682- cache -> data .mls_label .level [0 ].cat .highbit ;
2683- ctx_new .range .level [0 ].cat .node =
2684- cache -> data .mls_label .level [0 ].cat .node ;
2685- ctx_new .range .level [1 ].sens =
2686- cache -> data .mls_label .level [1 ].sens ;
2687- ctx_new .range .level [1 ].cat .highbit =
2688- cache -> data .mls_label .level [1 ].cat .highbit ;
2689- ctx_new .range .level [1 ].cat .node =
2690- cache -> data .mls_label .level [1 ].cat .node ;
2691-
2692- rc = sidtab_context_to_sid (& sidtab , & ctx_new , sid );
2693- break ;
2694- default :
2695- goto netlbl_secattr_to_sid_return ;
2696- }
2611+ * sid = * (u32 * )secattr -> cache -> data ;
2612+ rc = 0 ;
26972613 } else if (secattr -> flags & NETLBL_SECATTR_SECID ) {
26982614 * sid = secattr -> attr .secid ;
26992615 rc = 0 ;
27002616 } else if (secattr -> flags & NETLBL_SECATTR_MLS_LVL ) {
2701- ctx = sidtab_search (& sidtab , base_sid );
2617+ ctx = sidtab_search (& sidtab , SECINITSID_NETMSG );
27022618 if (ctx == NULL )
27032619 goto netlbl_secattr_to_sid_return ;
27042620
@@ -2725,7 +2641,7 @@ int security_netlbl_secattr_to_sid(struct netlbl_lsm_secattr *secattr,
27252641 if (rc != 0 )
27262642 goto netlbl_secattr_to_sid_return_cleanup ;
27272643
2728- security_netlbl_cache_add (secattr , & ctx_new );
2644+ security_netlbl_cache_add (secattr , * sid );
27292645
27302646 ebitmap_destroy (& ctx_new .range .level [0 ].cat );
27312647 } else {
0 commit comments