Skip to contentSkip to conversation

netlabel: handle sparse category maps in netlbl_catmap_getlong()

PATCH In review Paul Moore 1 participant 2 messages Jun 13, 2016

Subsystems (4)
lore
Share & tools
lore

Paul Moore

author
#0 lore raw

PATCH 1/1 netlabel: handle sparse category maps in netlbl_catmap_getlong()

From: Paul Moore <[email protected]>

In cases where the category bitmap is sparse enough that gaps exist between netlbl_lsm_catmap structs, callers to netlbl_catmap_getlong() could find themselves prematurely ending their search through the category bitmap. Further, the methods used to calculate the 'idx' and 'off' values were incorrect for bitmaps this large. This patch changes the netlbl_catmap_getlong() behavior so that it always skips over gaps and calculates the index and offset values correctly.

---
 net/netlabel/netlabel_kapi.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
net/netlabel/netlabel_kapi.c +4 -5
index bd007a9..3c070f2 100644
@@ -609,20 +609,19 @@ int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap,
 		off = catmap->startbit;
 		*offset = off;
 	}
-	iter = _netlbl_catmap_getnode(&catmap, off, _CM_F_NONE, 0);
+	iter = _netlbl_catmap_getnode(&catmap, off, _CM_F_WALK, 0);
 	if (iter == NULL) {
 		*offset = (u32)-1;
 		return 0;
 	}
 
 	if (off < iter->startbit) {
-		off = iter->startbit;
-		*offset = off;
+		*offset = iter->startbit;
+		off = 0;
 	} else
 		off -= iter->startbit;
-
 	idx = off / NETLBL_CATMAP_MAPSIZE;
-	*bitmap = iter->bitmap[idx] >> (off % NETLBL_CATMAP_SIZE);
+	*bitmap = iter->bitmap[idx] >> (off % NETLBL_CATMAP_MAPSIZE);
 
 	return 0;
 }
author
#1 lore raw
Quoted 10 lines · Paul Moore

From: Paul Moore <[email protected]>

In cases where the category bitmap is sparse enough that gaps exist between netlbl_lsm_catmap structs, callers to netlbl_catmap_getlong() could find themselves prematurely ending their search through the category bitmap. Further, the methods used to calculate the 'idx' and 'off' values were incorrect for bitmaps this large. This patch changes the netlbl_catmap_getlong() behavior so that it always skips over gaps and calculates the index and offset values correctly.

Quoted 4 lines
---
 net/netlabel/netlabel_kapi.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Another relatively small fix that I've merged into selinux#next, if anyone has any objections, let me know.

Quoted 30 lines
net/netlabel/netlabel_kapi.c +4 -5
index bd007a9..3c070f2 100644
@@ -609,20 +609,19 @@ int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap,
                off = catmap->startbit;
                *offset = off;
        }
-       iter = _netlbl_catmap_getnode(&catmap, off, _CM_F_NONE, 0);
+       iter = _netlbl_catmap_getnode(&catmap, off, _CM_F_WALK, 0);
        if (iter == NULL) {
                *offset = (u32)-1;
                return 0;
        }
 
        if (off < iter->startbit) {
-               off = iter->startbit;
-               *offset = off;
+               *offset = iter->startbit;
+               off = 0;
        } else
                off -= iter->startbit;
-
        idx = off / NETLBL_CATMAP_MAPSIZE;
-       *bitmap = iter->bitmap[idx] >> (off % NETLBL_CATMAP_SIZE);
+       *bitmap = iter->bitmap[idx] >> (off % NETLBL_CATMAP_MAPSIZE);
 
        return 0;
 }
Signature · 2 lines
paul moore
security @ redhat