@@ -776,7 +776,7 @@ static int security_compute_validatetrans(struct selinux_state *state,
776776 read_lock (& state -> ss -> policy_rwlock );
777777
778778 policydb = & state -> ss -> policydb ;
779- sidtab = & state -> ss -> sidtab ;
779+ sidtab = state -> ss -> sidtab ;
780780
781781 if (!user )
782782 tclass = unmap_class (& state -> ss -> map , orig_tclass );
@@ -876,7 +876,7 @@ int security_bounded_transition(struct selinux_state *state,
876876 read_lock (& state -> ss -> policy_rwlock );
877877
878878 policydb = & state -> ss -> policydb ;
879- sidtab = & state -> ss -> sidtab ;
879+ sidtab = state -> ss -> sidtab ;
880880
881881 rc = - EINVAL ;
882882 old_context = sidtab_search (sidtab , old_sid );
@@ -1034,7 +1034,7 @@ void security_compute_xperms_decision(struct selinux_state *state,
10341034 goto allow ;
10351035
10361036 policydb = & state -> ss -> policydb ;
1037- sidtab = & state -> ss -> sidtab ;
1037+ sidtab = state -> ss -> sidtab ;
10381038
10391039 scontext = sidtab_search (sidtab , ssid );
10401040 if (!scontext ) {
@@ -1123,7 +1123,7 @@ void security_compute_av(struct selinux_state *state,
11231123 goto allow ;
11241124
11251125 policydb = & state -> ss -> policydb ;
1126- sidtab = & state -> ss -> sidtab ;
1126+ sidtab = state -> ss -> sidtab ;
11271127
11281128 scontext = sidtab_search (sidtab , ssid );
11291129 if (!scontext ) {
@@ -1177,7 +1177,7 @@ void security_compute_av_user(struct selinux_state *state,
11771177 goto allow ;
11781178
11791179 policydb = & state -> ss -> policydb ;
1180- sidtab = & state -> ss -> sidtab ;
1180+ sidtab = state -> ss -> sidtab ;
11811181
11821182 scontext = sidtab_search (sidtab , ssid );
11831183 if (!scontext ) {
@@ -1315,7 +1315,7 @@ static int security_sid_to_context_core(struct selinux_state *state,
13151315 }
13161316 read_lock (& state -> ss -> policy_rwlock );
13171317 policydb = & state -> ss -> policydb ;
1318- sidtab = & state -> ss -> sidtab ;
1318+ sidtab = state -> ss -> sidtab ;
13191319 if (force )
13201320 context = sidtab_search_force (sidtab , sid );
13211321 else
@@ -1483,7 +1483,7 @@ static int security_context_to_sid_core(struct selinux_state *state,
14831483 }
14841484 read_lock (& state -> ss -> policy_rwlock );
14851485 policydb = & state -> ss -> policydb ;
1486- sidtab = & state -> ss -> sidtab ;
1486+ sidtab = state -> ss -> sidtab ;
14871487 rc = string_to_context_struct (policydb , sidtab , scontext2 ,
14881488 & context , def_sid );
14891489 if (rc == - EINVAL && force ) {
@@ -1668,7 +1668,7 @@ static int security_compute_sid(struct selinux_state *state,
16681668 }
16691669
16701670 policydb = & state -> ss -> policydb ;
1671- sidtab = & state -> ss -> sidtab ;
1671+ sidtab = state -> ss -> sidtab ;
16721672
16731673 scontext = sidtab_search (sidtab , ssid );
16741674 if (!scontext ) {
@@ -1925,10 +1925,7 @@ static int convert_context(u32 key,
19251925 struct user_datum * usrdatum ;
19261926 char * s ;
19271927 u32 len ;
1928- int rc = 0 ;
1929-
1930- if (key <= SECINITSID_NUM )
1931- goto out ;
1928+ int rc ;
19321929
19331930 args = p ;
19341931
@@ -2090,9 +2087,8 @@ static int security_preserve_bools(struct selinux_state *state,
20902087int security_load_policy (struct selinux_state * state , void * data , size_t len )
20912088{
20922089 struct policydb * policydb ;
2093- struct sidtab * sidtab ;
2090+ struct sidtab * oldsidtab , * newsidtab ;
20942091 struct policydb * oldpolicydb , * newpolicydb ;
2095- struct sidtab oldsidtab , newsidtab ;
20962092 struct selinux_mapping * oldmapping ;
20972093 struct selinux_map newmap ;
20982094 struct convert_context_args args ;
@@ -2108,27 +2104,37 @@ int security_load_policy(struct selinux_state *state, void *data, size_t len)
21082104 newpolicydb = oldpolicydb + 1 ;
21092105
21102106 policydb = & state -> ss -> policydb ;
2111- sidtab = & state -> ss -> sidtab ;
2107+
2108+ newsidtab = kmalloc (sizeof (* newsidtab ), GFP_KERNEL );
2109+ if (!newsidtab ) {
2110+ rc = - ENOMEM ;
2111+ goto out ;
2112+ }
21122113
21132114 if (!state -> initialized ) {
21142115 rc = policydb_read (policydb , fp );
2115- if (rc )
2116+ if (rc ) {
2117+ kfree (newsidtab );
21162118 goto out ;
2119+ }
21172120
21182121 policydb -> len = len ;
21192122 rc = selinux_set_mapping (policydb , secclass_map ,
21202123 & state -> ss -> map );
21212124 if (rc ) {
2125+ kfree (newsidtab );
21222126 policydb_destroy (policydb );
21232127 goto out ;
21242128 }
21252129
2126- rc = policydb_load_isids (policydb , sidtab );
2130+ rc = policydb_load_isids (policydb , newsidtab );
21272131 if (rc ) {
2132+ kfree (newsidtab );
21282133 policydb_destroy (policydb );
21292134 goto out ;
21302135 }
21312136
2137+ state -> ss -> sidtab = newsidtab ;
21322138 security_load_policycaps (state );
21332139 state -> initialized = 1 ;
21342140 seqno = ++ state -> ss -> latest_granting ;
@@ -2141,13 +2147,17 @@ int security_load_policy(struct selinux_state *state, void *data, size_t len)
21412147 goto out ;
21422148 }
21432149
2150+ oldsidtab = state -> ss -> sidtab ;
2151+
21442152#if 0
2145- sidtab_hash_eval (sidtab , "sids" );
2153+ sidtab_hash_eval (oldsidtab , "sids" );
21462154#endif
21472155
21482156 rc = policydb_read (newpolicydb , fp );
2149- if (rc )
2157+ if (rc ) {
2158+ kfree (newsidtab );
21502159 goto out ;
2160+ }
21512161
21522162 newpolicydb -> len = len ;
21532163 /* If switching between different policy types, log MLS status */
@@ -2156,10 +2166,11 @@ int security_load_policy(struct selinux_state *state, void *data, size_t len)
21562166 else if (!policydb -> mls_enabled && newpolicydb -> mls_enabled )
21572167 pr_info ("SELinux: Enabling MLS support...\n" );
21582168
2159- rc = policydb_load_isids (newpolicydb , & newsidtab );
2169+ rc = policydb_load_isids (newpolicydb , newsidtab );
21602170 if (rc ) {
21612171 pr_err ("SELinux: unable to load the initial SIDs\n" );
21622172 policydb_destroy (newpolicydb );
2173+ kfree (newsidtab );
21632174 goto out ;
21642175 }
21652176
@@ -2180,7 +2191,7 @@ int security_load_policy(struct selinux_state *state, void *data, size_t len)
21802191 args .state = state ;
21812192 args .oldp = policydb ;
21822193 args .newp = newpolicydb ;
2183- rc = sidtab_convert (sidtab , & newsidtab , convert_context , & args );
2194+ rc = sidtab_convert (oldsidtab , newsidtab , convert_context , & args );
21842195 if (rc ) {
21852196 pr_err ("SELinux: unable to convert the internal"
21862197 " representation of contexts in the new SID"
@@ -2190,12 +2201,11 @@ int security_load_policy(struct selinux_state *state, void *data, size_t len)
21902201
21912202 /* Save the old policydb and SID table to free later. */
21922203 memcpy (oldpolicydb , policydb , sizeof (* policydb ));
2193- sidtab_set (& oldsidtab , sidtab );
21942204
21952205 /* Install the new policydb and SID table. */
21962206 write_lock_irq (& state -> ss -> policy_rwlock );
21972207 memcpy (policydb , newpolicydb , sizeof (* policydb ));
2198- sidtab_set ( sidtab , & newsidtab ) ;
2208+ state -> ss -> sidtab = newsidtab ;
21992209 security_load_policycaps (state );
22002210 oldmapping = state -> ss -> map .mapping ;
22012211 state -> ss -> map .mapping = newmap .mapping ;
@@ -2205,7 +2215,8 @@ int security_load_policy(struct selinux_state *state, void *data, size_t len)
22052215
22062216 /* Free the old policydb and SID table. */
22072217 policydb_destroy (oldpolicydb );
2208- sidtab_destroy (& oldsidtab );
2218+ sidtab_destroy (oldsidtab );
2219+ kfree (oldsidtab );
22092220 kfree (oldmapping );
22102221
22112222 avc_ss_reset (state -> avc , seqno );
@@ -2219,7 +2230,8 @@ int security_load_policy(struct selinux_state *state, void *data, size_t len)
22192230
22202231err :
22212232 kfree (newmap .mapping );
2222- sidtab_destroy (& newsidtab );
2233+ sidtab_destroy (newsidtab );
2234+ kfree (newsidtab );
22232235 policydb_destroy (newpolicydb );
22242236
22252237out :
@@ -2256,7 +2268,7 @@ int security_port_sid(struct selinux_state *state,
22562268 read_lock (& state -> ss -> policy_rwlock );
22572269
22582270 policydb = & state -> ss -> policydb ;
2259- sidtab = & state -> ss -> sidtab ;
2271+ sidtab = state -> ss -> sidtab ;
22602272
22612273 c = policydb -> ocontexts [OCON_PORT ];
22622274 while (c ) {
@@ -2302,7 +2314,7 @@ int security_ib_pkey_sid(struct selinux_state *state,
23022314 read_lock (& state -> ss -> policy_rwlock );
23032315
23042316 policydb = & state -> ss -> policydb ;
2305- sidtab = & state -> ss -> sidtab ;
2317+ sidtab = state -> ss -> sidtab ;
23062318
23072319 c = policydb -> ocontexts [OCON_IBPKEY ];
23082320 while (c ) {
@@ -2348,7 +2360,7 @@ int security_ib_endport_sid(struct selinux_state *state,
23482360 read_lock (& state -> ss -> policy_rwlock );
23492361
23502362 policydb = & state -> ss -> policydb ;
2351- sidtab = & state -> ss -> sidtab ;
2363+ sidtab = state -> ss -> sidtab ;
23522364
23532365 c = policydb -> ocontexts [OCON_IBENDPORT ];
23542366 while (c ) {
@@ -2394,7 +2406,7 @@ int security_netif_sid(struct selinux_state *state,
23942406 read_lock (& state -> ss -> policy_rwlock );
23952407
23962408 policydb = & state -> ss -> policydb ;
2397- sidtab = & state -> ss -> sidtab ;
2409+ sidtab = state -> ss -> sidtab ;
23982410
23992411 c = policydb -> ocontexts [OCON_NETIF ];
24002412 while (c ) {
@@ -2459,7 +2471,7 @@ int security_node_sid(struct selinux_state *state,
24592471 read_lock (& state -> ss -> policy_rwlock );
24602472
24612473 policydb = & state -> ss -> policydb ;
2462- sidtab = & state -> ss -> sidtab ;
2474+ sidtab = state -> ss -> sidtab ;
24632475
24642476 switch (domain ) {
24652477 case AF_INET : {
@@ -2559,7 +2571,7 @@ int security_get_user_sids(struct selinux_state *state,
25592571 read_lock (& state -> ss -> policy_rwlock );
25602572
25612573 policydb = & state -> ss -> policydb ;
2562- sidtab = & state -> ss -> sidtab ;
2574+ sidtab = state -> ss -> sidtab ;
25632575
25642576 context_init (& usercon );
25652577
@@ -2661,7 +2673,7 @@ static inline int __security_genfs_sid(struct selinux_state *state,
26612673 u32 * sid )
26622674{
26632675 struct policydb * policydb = & state -> ss -> policydb ;
2664- struct sidtab * sidtab = & state -> ss -> sidtab ;
2676+ struct sidtab * sidtab = state -> ss -> sidtab ;
26652677 int len ;
26662678 u16 sclass ;
26672679 struct genfs * genfs ;
@@ -2747,7 +2759,7 @@ int security_fs_use(struct selinux_state *state, struct super_block *sb)
27472759 read_lock (& state -> ss -> policy_rwlock );
27482760
27492761 policydb = & state -> ss -> policydb ;
2750- sidtab = & state -> ss -> sidtab ;
2762+ sidtab = state -> ss -> sidtab ;
27512763
27522764 c = policydb -> ocontexts [OCON_FSUSE ];
27532765 while (c ) {
@@ -2953,7 +2965,7 @@ int security_sid_mls_copy(struct selinux_state *state,
29532965 u32 sid , u32 mls_sid , u32 * new_sid )
29542966{
29552967 struct policydb * policydb = & state -> ss -> policydb ;
2956- struct sidtab * sidtab = & state -> ss -> sidtab ;
2968+ struct sidtab * sidtab = state -> ss -> sidtab ;
29572969 struct context * context1 ;
29582970 struct context * context2 ;
29592971 struct context newcon ;
@@ -3044,7 +3056,7 @@ int security_net_peersid_resolve(struct selinux_state *state,
30443056 u32 * peer_sid )
30453057{
30463058 struct policydb * policydb = & state -> ss -> policydb ;
3047- struct sidtab * sidtab = & state -> ss -> sidtab ;
3059+ struct sidtab * sidtab = state -> ss -> sidtab ;
30483060 int rc ;
30493061 struct context * nlbl_ctx ;
30503062 struct context * xfrm_ctx ;
@@ -3405,7 +3417,7 @@ int selinux_audit_rule_match(u32 sid, u32 field, u32 op, void *vrule,
34053417 goto out ;
34063418 }
34073419
3408- ctxt = sidtab_search (& state -> ss -> sidtab , sid );
3420+ ctxt = sidtab_search (state -> ss -> sidtab , sid );
34093421 if (unlikely (!ctxt )) {
34103422 WARN_ONCE (1 , "selinux_audit_rule_match: unrecognized SID %d\n" ,
34113423 sid );
@@ -3568,7 +3580,7 @@ int security_netlbl_secattr_to_sid(struct selinux_state *state,
35683580 u32 * sid )
35693581{
35703582 struct policydb * policydb = & state -> ss -> policydb ;
3571- struct sidtab * sidtab = & state -> ss -> sidtab ;
3583+ struct sidtab * sidtab = state -> ss -> sidtab ;
35723584 int rc ;
35733585 struct context * ctx ;
35743586 struct context ctx_new ;
@@ -3646,7 +3658,7 @@ int security_netlbl_sid_to_secattr(struct selinux_state *state,
36463658 read_lock (& state -> ss -> policy_rwlock );
36473659
36483660 rc = - ENOENT ;
3649- ctx = sidtab_search (& state -> ss -> sidtab , sid );
3661+ ctx = sidtab_search (state -> ss -> sidtab , sid );
36503662 if (ctx == NULL )
36513663 goto out ;
36523664
0 commit comments