Skip to content

Commit eead1c2

Browse files
Paolo Abenidavem330
authored andcommitted
netlabel: cope with NULL catmap
The cipso and calipso code can set the MLS_CAT attribute on successful parsing, even if the corresponding catmap has not been allocated, as per current configuration and external input. Later, selinux code tries to access the catmap if the MLS_CAT flag is present via netlbl_catmap_getlong(). That may cause null ptr dereference while processing incoming network traffic. Address the issue setting the MLS_CAT flag only if the catmap is really allocated. Additionally let netlbl_catmap_getlong() cope with NULL catmap. Reported-by: Matthew Sheets <[email protected]> Fixes: 4b8feff ("netlabel: fix the horribly broken catmap functions") Fixes: ceba183 ("calipso: Set the calipso socket label to match the secattr.") Signed-off-by: Paolo Abeni <[email protected]> Acked-by: Paul Moore <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 24adbc1 commit eead1c2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

net/ipv4/cipso_ipv4.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,8 @@ static int cipso_v4_parsetag_rbm(const struct cipso_v4_doi *doi_def,
12581258
return ret_val;
12591259
}
12601260

1261-
secattr->flags |= NETLBL_SECATTR_MLS_CAT;
1261+
if (secattr->attr.mls.cat)
1262+
secattr->flags |= NETLBL_SECATTR_MLS_CAT;
12621263
}
12631264

12641265
return 0;
@@ -1439,7 +1440,8 @@ static int cipso_v4_parsetag_rng(const struct cipso_v4_doi *doi_def,
14391440
return ret_val;
14401441
}
14411442

1442-
secattr->flags |= NETLBL_SECATTR_MLS_CAT;
1443+
if (secattr->attr.mls.cat)
1444+
secattr->flags |= NETLBL_SECATTR_MLS_CAT;
14431445
}
14441446

14451447
return 0;

net/ipv6/calipso.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,8 @@ static int calipso_opt_getattr(const unsigned char *calipso,
10471047
goto getattr_return;
10481048
}
10491049

1050-
secattr->flags |= NETLBL_SECATTR_MLS_CAT;
1050+
if (secattr->attr.mls.cat)
1051+
secattr->flags |= NETLBL_SECATTR_MLS_CAT;
10511052
}
10521053

10531054
secattr->type = NETLBL_NLTYPE_CALIPSO;

net/netlabel/netlabel_kapi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,12 @@ int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap,
734734
if ((off & (BITS_PER_LONG - 1)) != 0)
735735
return -EINVAL;
736736

737+
/* a null catmap is equivalent to an empty one */
738+
if (!catmap) {
739+
*offset = (u32)-1;
740+
return 0;
741+
}
742+
737743
if (off < catmap->startbit) {
738744
off = catmap->startbit;
739745
*offset = off;

0 commit comments

Comments
 (0)