Message ID | 07d99ae197bfdb2964931201db67b6cd0b38db5b.1589276729.git.pabeni@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [net] netlabel: cope with NULL catmap | expand |
On Tue, May 12, 2020 at 8:44 AM Paolo Abeni <pabeni@redhat.com> wrote: > > 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 <matthew.sheets@gd-ms.com> > Fixes: 4b8feff251da ("netlabel: fix the horribly broken catmap functions") > Fixes: ceba1832b1b2 ("calipso: Set the calipso socket label to match the secattr.") > Signed-off-by: Paolo Abeni <pabeni@redhat.com> > --- > net/ipv4/cipso_ipv4.c | 6 ++++-- > net/ipv6/calipso.c | 3 ++- > net/netlabel/netlabel_kapi.c | 6 ++++++ > 3 files changed, 12 insertions(+), 3 deletions(-) Seems reasonable to me, thanks Paolo. Acked-by: Paul Moore <paul@paul-moore.com>
From: Paolo Abeni <pabeni@redhat.com> Date: Tue, 12 May 2020 14:43:14 +0200 > 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 <matthew.sheets@gd-ms.com> > Fixes: 4b8feff251da ("netlabel: fix the horribly broken catmap functions") > Fixes: ceba1832b1b2 ("calipso: Set the calipso socket label to match the secattr.") > Signed-off-by: Paolo Abeni <pabeni@redhat.com> Applied and queued up for -stable, thanks.
diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index 0bd10a1f477f..a23094b050f8 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c @@ -1258,7 +1258,8 @@ static int cipso_v4_parsetag_rbm(const struct cipso_v4_doi *doi_def, return ret_val; } - secattr->flags |= NETLBL_SECATTR_MLS_CAT; + if (secattr->attr.mls.cat) + secattr->flags |= NETLBL_SECATTR_MLS_CAT; } return 0; @@ -1439,7 +1440,8 @@ static int cipso_v4_parsetag_rng(const struct cipso_v4_doi *doi_def, return ret_val; } - secattr->flags |= NETLBL_SECATTR_MLS_CAT; + if (secattr->attr.mls.cat) + secattr->flags |= NETLBL_SECATTR_MLS_CAT; } return 0; diff --git a/net/ipv6/calipso.c b/net/ipv6/calipso.c index 221c81f85cbf..8d3f66c310db 100644 --- a/net/ipv6/calipso.c +++ b/net/ipv6/calipso.c @@ -1047,7 +1047,8 @@ static int calipso_opt_getattr(const unsigned char *calipso, goto getattr_return; } - secattr->flags |= NETLBL_SECATTR_MLS_CAT; + if (secattr->attr.mls.cat) + secattr->flags |= NETLBL_SECATTR_MLS_CAT; } secattr->type = NETLBL_NLTYPE_CALIPSO; diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c index 409a3ae47ce2..5e1239cef000 100644 --- a/net/netlabel/netlabel_kapi.c +++ b/net/netlabel/netlabel_kapi.c @@ -734,6 +734,12 @@ int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap, if ((off & (BITS_PER_LONG - 1)) != 0) return -EINVAL; + /* a null catmap is equivalent to an empty one */ + if (!catmap) { + *offset = (u32)-1; + return 0; + } + if (off < catmap->startbit) { off = catmap->startbit; *offset = off;
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 <matthew.sheets@gd-ms.com> Fixes: 4b8feff251da ("netlabel: fix the horribly broken catmap functions") Fixes: ceba1832b1b2 ("calipso: Set the calipso socket label to match the secattr.") Signed-off-by: Paolo Abeni <pabeni@redhat.com> --- net/ipv4/cipso_ipv4.c | 6 ++++-- net/ipv6/calipso.c | 3 ++- net/netlabel/netlabel_kapi.c | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-)