Skip to content

Commit

Permalink
Merge branch 'smack-for-3.12' of git://git.gitorious.org/smack-next/k…
Browse files Browse the repository at this point in the history
…ernel into ra-next
  • Loading branch information
James Morris committed Aug 22, 2013
2 parents f8eb8a1 + 10289b0 commit 7320336
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 114 deletions.
13 changes: 11 additions & 2 deletions security/smack/smack.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
*/
struct smack_known {
struct list_head list;
struct hlist_node smk_hashed;
char *smk_known;
u32 smk_secid;
struct netlbl_lsm_secattr smk_netlabel; /* on wire labels */
Expand Down Expand Up @@ -167,9 +168,13 @@ struct smk_port_label {
#define SMACK_CIPSO_DOI_INVALID -1 /* Not a DOI */
#define SMACK_CIPSO_DIRECT_DEFAULT 250 /* Arbitrary */
#define SMACK_CIPSO_MAPPED_DEFAULT 251 /* Also arbitrary */
#define SMACK_CIPSO_MAXCATVAL 63 /* Bigger gets harder */
#define SMACK_CIPSO_MAXLEVEL 255 /* CIPSO 2.2 standard */
#define SMACK_CIPSO_MAXCATNUM 239 /* CIPSO 2.2 standard */
/*
* CIPSO 2.2 standard is 239, but Smack wants to use the
* categories in a structured way that limits the value to
* the bits in 23 bytes, hence the unusual number.
*/
#define SMACK_CIPSO_MAXCATNUM 184 /* 23 * 8 */

/*
* Flag for transmute access
Expand Down Expand Up @@ -222,6 +227,7 @@ char *smk_parse_smack(const char *string, int len);
int smk_netlbl_mls(int, char *, struct netlbl_lsm_secattr *, int);
char *smk_import(const char *, int);
struct smack_known *smk_import_entry(const char *, int);
void smk_insert_entry(struct smack_known *skp);
struct smack_known *smk_find_entry(const char *);
u32 smack_to_secid(const char *);

Expand All @@ -247,6 +253,9 @@ extern struct list_head smk_netlbladdr_list;

extern struct security_operations smack_ops;

#define SMACK_HASH_SLOTS 16
extern struct hlist_head smack_known_hash[SMACK_HASH_SLOTS];

/*
* Is the directory transmuting?
*/
Expand Down
29 changes: 26 additions & 3 deletions security/smack/smack_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,25 @@ void smack_log(char *subject_label, char *object_label, int request,

DEFINE_MUTEX(smack_known_lock);

struct hlist_head smack_known_hash[SMACK_HASH_SLOTS];

/**
* smk_insert_entry - insert a smack label into a hash map,
*
* this function must be called under smack_known_lock
*/
void smk_insert_entry(struct smack_known *skp)
{
unsigned int hash;
struct hlist_head *head;

hash = full_name_hash(skp->smk_known, strlen(skp->smk_known));
head = &smack_known_hash[hash & (SMACK_HASH_SLOTS - 1)];

hlist_add_head_rcu(&skp->smk_hashed, head);
list_add_rcu(&skp->list, &smack_known_list);
}

/**
* smk_find_entry - find a label on the list, return the list entry
* @string: a text string that might be a Smack label
Expand All @@ -334,12 +353,16 @@ DEFINE_MUTEX(smack_known_lock);
*/
struct smack_known *smk_find_entry(const char *string)
{
unsigned int hash;
struct hlist_head *head;
struct smack_known *skp;

list_for_each_entry_rcu(skp, &smack_known_list, list) {
hash = full_name_hash(string, strlen(string));
head = &smack_known_hash[hash & (SMACK_HASH_SLOTS - 1)];

hlist_for_each_entry_rcu(skp, head, smk_hashed)
if (strcmp(skp->smk_known, string) == 0)
return skp;
}

return NULL;
}
Expand Down Expand Up @@ -475,7 +498,7 @@ struct smack_known *smk_import_entry(const char *string, int len)
* Make sure that the entry is actually
* filled before putting it on the list.
*/
list_add_rcu(&skp->list, &smack_known_list);
smk_insert_entry(skp);
goto unlockout;
}
/*
Expand Down
42 changes: 30 additions & 12 deletions security/smack/smack_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3063,6 +3063,8 @@ static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap,
{
struct smack_known *skp;
int found = 0;
int acat;
int kcat;

if ((sap->flags & NETLBL_SECATTR_MLS_LVL) != 0) {
/*
Expand All @@ -3079,12 +3081,28 @@ static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap,
list_for_each_entry(skp, &smack_known_list, list) {
if (sap->attr.mls.lvl != skp->smk_netlabel.attr.mls.lvl)
continue;
if (memcmp(sap->attr.mls.cat,
skp->smk_netlabel.attr.mls.cat,
SMK_CIPSOLEN) != 0)
continue;
found = 1;
break;
/*
* Compare the catsets. Use the netlbl APIs.
*/
if ((sap->flags & NETLBL_SECATTR_MLS_CAT) == 0) {
if ((skp->smk_netlabel.flags &
NETLBL_SECATTR_MLS_CAT) == 0)
found = 1;
break;
}
for (acat = -1, kcat = -1; acat == kcat; ) {
acat = netlbl_secattr_catmap_walk(
sap->attr.mls.cat, acat + 1);
kcat = netlbl_secattr_catmap_walk(
skp->smk_netlabel.attr.mls.cat,
kcat + 1);
if (acat < 0 || kcat < 0)
break;
}
if (acat == kcat) {
found = 1;
break;
}
}
rcu_read_unlock();

Expand Down Expand Up @@ -3876,12 +3894,12 @@ static __init void init_smack_known_list(void)
/*
* Create the known labels list
*/
list_add(&smack_known_huh.list, &smack_known_list);
list_add(&smack_known_hat.list, &smack_known_list);
list_add(&smack_known_star.list, &smack_known_list);
list_add(&smack_known_floor.list, &smack_known_list);
list_add(&smack_known_invalid.list, &smack_known_list);
list_add(&smack_known_web.list, &smack_known_list);
smk_insert_entry(&smack_known_huh);
smk_insert_entry(&smack_known_hat);
smk_insert_entry(&smack_known_star);
smk_insert_entry(&smack_known_floor);
smk_insert_entry(&smack_known_invalid);
smk_insert_entry(&smack_known_web);
}

/**
Expand Down
Loading

0 comments on commit 7320336

Please sign in to comment.