[PATCH 3/5] libselinux: matchpathcon: make filespec table per thread and bound specind
Stephen Smalley <[email protected]>
| Newsgroups | org.kernel.vger.selinux |
|---|---|
| Message-ID | <[email protected]> |
The context array (con_array) that specind indexes is per-thread but the inode association table (fl_head) is process-wide. Give each thread its own fl_head to match con_array. There are no in-tree callers of this deprecated interface and single-threaded callers will see no change. Also bounds check specind in matchpathcon_filespec_add() to ensure it is a valid index previously returned by matchpathcon_index(). Signed-off-by: Stephen Smalley <[email protected]> --- libselinux/src/matchpathcon.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libselinux/src/matchpathcon.c b/libselinux/src/matchpathcon.c index 80de61a0..9a45dbd5 100644 --- a/libselinux/src/matchpathcon.c +++ b/libselinux/src/matchpathcon.c @@ -212,7 +212,7 @@ typedef struct file_spec { #define HASH_BITS 16 #define HASH_BUCKETS (1 << HASH_BITS) #define HASH_MASK (HASH_BUCKETS - 1) -static file_spec_t *fl_head; +static __thread file_spec_t *fl_head; /* * Try to add an association between an inode and @@ -227,6 +227,11 @@ int matchpathcon_filespec_add(ino_t ino, int specind, const char *file) int h, ret; struct stat sb; + if (specind < 0 || specind >= con_array_used) { + errno = EINVAL; + return -1; + } + if (!fl_head) { fl_head = calloc(HASH_BUCKETS, sizeof(file_spec_t)); if (!fl_head) -- 2.55.0