Skip to content

Commit

Permalink
netlabel: handle sparse category maps in netlbl_catmap_getlong()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
pcmoore committed Jun 9, 2016
1 parent 8bebe88 commit 50b8629
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions net/netlabel/netlabel_kapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 50b8629

Please sign in to comment.