Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 227812
b: refs/heads/master
c: 73ff5fc
h: refs/heads/master
v: v3
  • Loading branch information
Eric Paris committed Dec 7, 2010
1 parent e784f0a commit 8b313b9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 415103f9932d45f7927f4b17e3a9a13834cdb9a1
refs/heads/master: 73ff5fc0a86b28b77e02a6963b388d1dbfa0a263
39 changes: 37 additions & 2 deletions trunk/security/selinux/ss/sidtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ int sidtab_map(struct sidtab *s,
return rc;
}

static void sidtab_update_cache(struct sidtab *s, struct sidtab_node *n, int loc)
{
BUG_ON(loc >= SIDTAB_CACHE_LEN);

while (loc > 0) {
s->cache[loc] = s->cache[loc - 1];
loc--;
}
s->cache[0] = n;
}

static inline u32 sidtab_search_context(struct sidtab *s,
struct context *context)
{
Expand All @@ -156,14 +167,33 @@ static inline u32 sidtab_search_context(struct sidtab *s,
for (i = 0; i < SIDTAB_SIZE; i++) {
cur = s->htable[i];
while (cur) {
if (context_cmp(&cur->context, context))
if (context_cmp(&cur->context, context)) {
sidtab_update_cache(s, cur, SIDTAB_CACHE_LEN - 1);
return cur->sid;
}
cur = cur->next;
}
}
return 0;
}

static inline u32 sidtab_search_cache(struct sidtab *s, struct context *context)
{
int i;
struct sidtab_node *node;

for (i = 0; i < SIDTAB_CACHE_LEN; i++) {
node = s->cache[i];
if (unlikely(!node))
return 0;
if (context_cmp(&node->context, context)) {
sidtab_update_cache(s, node, i);
return node->sid;
}
}
return 0;
}

int sidtab_context_to_sid(struct sidtab *s,
struct context *context,
u32 *out_sid)
Expand All @@ -174,7 +204,9 @@ int sidtab_context_to_sid(struct sidtab *s,

*out_sid = SECSID_NULL;

sid = sidtab_search_context(s, context);
sid = sidtab_search_cache(s, context);
if (!sid)
sid = sidtab_search_context(s, context);
if (!sid) {
spin_lock_irqsave(&s->lock, flags);
/* Rescan now that we hold the lock. */
Expand Down Expand Up @@ -259,12 +291,15 @@ void sidtab_destroy(struct sidtab *s)
void sidtab_set(struct sidtab *dst, struct sidtab *src)
{
unsigned long flags;
int i;

spin_lock_irqsave(&src->lock, flags);
dst->htable = src->htable;
dst->nel = src->nel;
dst->next_sid = src->next_sid;
dst->shutdown = 0;
for (i = 0; i < SIDTAB_CACHE_LEN; i++)
dst->cache[i] = NULL;
spin_unlock_irqrestore(&src->lock, flags);
}

Expand Down
2 changes: 2 additions & 0 deletions trunk/security/selinux/ss/sidtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct sidtab {
unsigned int nel; /* number of elements */
unsigned int next_sid; /* next SID to allocate */
unsigned char shutdown;
#define SIDTAB_CACHE_LEN 3
struct sidtab_node *cache[SIDTAB_CACHE_LEN];
spinlock_t lock;
};

Expand Down

0 comments on commit 8b313b9

Please sign in to comment.