Skip to content

Commit 50b8629

Browse files
committed
netlabel: handle sparse category maps in netlbl_catmap_getlong()
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. Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 8bebe88 commit 50b8629

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

net/netlabel/netlabel_kapi.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,20 +609,19 @@ int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap,
609609
off = catmap->startbit;
610610
*offset = off;
611611
}
612-
iter = _netlbl_catmap_getnode(&catmap, off, _CM_F_NONE, 0);
612+
iter = _netlbl_catmap_getnode(&catmap, off, _CM_F_WALK, 0);
613613
if (iter == NULL) {
614614
*offset = (u32)-1;
615615
return 0;
616616
}
617617

618618
if (off < iter->startbit) {
619-
off = iter->startbit;
620-
*offset = off;
619+
*offset = iter->startbit;
620+
off = 0;
621621
} else
622622
off -= iter->startbit;
623-
624623
idx = off / NETLBL_CATMAP_MAPSIZE;
625-
*bitmap = iter->bitmap[idx] >> (off % NETLBL_CATMAP_SIZE);
624+
*bitmap = iter->bitmap[idx] >> (off % NETLBL_CATMAP_MAPSIZE);
626625

627626
return 0;
628627
}

0 commit comments

Comments
 (0)