Skip to contentSkip to conversation

convert smack_known list to a standard linux list.

PATCH In review etienne 3 participants 5 messages Feb 22, 2009 – Feb 24, 2009

Subsystems (2)
lore
Share & tools
lore

etienne

author
#0 lore raw

PATCH 1/1 convert smack_known list to a standard linux list.

hello,

this patch on top of [PATCH][SMACK] convert smack rule list to linux list V2 converts "smack_known" to a regular linux list. (rcu variant)

regards,
Etienne

Signed-off-by <[email protected]>

---

security/smack/smack.h +1 -3
index 0dcb907..64164f8 100644
@@ -109,7 +109,6 @@ struct smk_netlbladdr {
  */
 struct smack_known {
 	struct list_head	list;
-	struct smack_known	*smk_next;
 	char			smk_known[SMK_LABELLEN];
 	u32			smk_secid;
 	struct smack_cipso	*smk_cipso;
@@ -202,7 +201,6 @@ extern int smack_cipso_direct;
 extern char *smack_net_ambient;
 extern char *smack_onlycap;
 
-extern struct smack_known *smack_known;
 extern struct smack_known smack_known_floor;
 extern struct smack_known smack_known_hat;
 extern struct smack_known smack_known_huh;
@@ -210,7 +208,7 @@ extern struct smack_known smack_known_invalid;
 extern struct smack_known smack_known_star;
 extern struct smack_known smack_known_web;
 
-extern struct list_head smack_know_list;
+extern struct list_head smack_known_list;
 extern struct list_head smack_rule_list;
 extern struct list_head smk_netlbladdr_list;
 
security/smack/smack_access.c +35 -20

153 lines not on this page · raw message

security/smack/smack_lsm.c +13 -0
index 65a4a8a..e6f89d6 100644
@@ -2935,6 +2935,17 @@ struct security_operations smack_ops = {
 	.release_secctx = 		smack_release_secctx,
 };
 
+
+static __init init_smack_know_list(void)
+{
+	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);
+}
+
 /**
  * smack_init - initialize the smack system
  *
@@ -2955,6 +2966,8 @@ static __init int smack_init(void)
 	cred = (struct cred *) current->cred;
 	cred->security = &smack_known_floor.smk_known;
 
+	/* initilize the smack_know_list */
+	init_smack_know_list();
 	/*
 	 * Initialize locks
 	 */
security/smack/smackfs.c +12 -10
index 771e452..665e2cc 100644
@@ -84,7 +84,6 @@ char *smack_onlycap;
 LIST_HEAD(smk_netlbladdr_list);
 LIST_HEAD(smack_rule_list);
 
-
 static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
 
 #define	SEQ_READ_FINISHED	1
@@ -436,24 +435,26 @@ static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
 {
 	if (*pos == SEQ_READ_FINISHED)
 		return NULL;
+	if (list_empty(&smack_known_list))
+		return NULL;
 
-	return smack_known;
+	return &smack_known_list;
 }
 
 static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
 {
-	struct smack_known *skp = ((struct smack_known *) v)->smk_next;
+	struct list_head  *list = v;
 
 	/*
-	 * Omit labels with no associated cipso value
+	 * labels with no associated cipso value wont be printed
+	 * in cipso_seq_show
 	 */
-	while (skp != NULL && !skp->smk_cipso)
-		skp = skp->smk_next;
-
-	if (skp == NULL)
+	if (list_is_last(list->next, &smack_known_list)) {
 		*pos = SEQ_READ_FINISHED;
+		return NULL;
+	}
 
-	return skp;
+	return list->next;
 }
 
 /*
@@ -462,7 +463,8 @@ static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
  */
 static int cipso_seq_show(struct seq_file *s, void *v)
 {
-	struct smack_known *skp = (struct smack_known *) v;
+	struct list_head  *list = v;
+	struct smack_known *skp = container_of(list->next, struct smack_known, list);
 	struct smack_cipso *scp = skp->smk_cipso;
 	char *cbp;
 	char sep = '/';
maintainer
#1 lore raw
Quoted 6 lines · etienne

hello,

this patch on top of [PATCH][SMACK] convert smack rule list to linux list V2 converts "smack_known" to a regular linux list. (rcu variant)

I'm having some trouble applying this group of patches. I assume that I'm starting at the wrong place. Could you do a single patch to help me avoid confusion?

Thank you.

Quoted 12 lines

regards,
Etienne

Signed-off-by <[email protected]>

---

security/smack/smack.h +0 -0
index 0dcb907..64164f8 100644
@@ -109,7 +109,6 @@ struct smk_netlbladdr {
  */
 
author
#2 lore raw
Quoted 17 lines · Casey Schaufler
Quoted 6 lines · etienne

hello,

this patch on top of [PATCH][SMACK] convert smack rule list to linux list V2 converts "smack_known" to a regular linux list. (rcu variant)

I'm having some trouble applying this group of patches. I assume that I'm starting at the wrong place. Could you do a single patch to help me avoid confusion?

Thank you.

Quoted 3 lines

regards,
Etienne

Quoted 12 lines

security/smack/smack.h struct smk_netlbladdr { · line 110

Quoted 9 lines
Signed-off-by <[email protected]>

---

security/smack/smack.h +0 -0
index 0dcb907..64164f8 100644
@@ -109,7 +109,6 @@ struct smk_netlbladdr {
  */
 

here you are!
(it is still on top of my 02/20 "[PATCH] SMACK netlabel fixes v2")

happy testing ;)
Etienne

Signed-off-by <[email protected]>

---

security/smack/smack.h +12 -16
index b79582e..64164f8 100644
@@ -18,6 +18,8 @@
 #include <linux/security.h>
 #include <linux/in.h>
 #include <net/netlabel.h>
+#include <linux/list.h>
+#include <linux/rculist.h>
 
 /*
  * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
@@ -59,17 +61,10 @@ struct inode_smack {
  * A label access rule.
  */
 struct smack_rule {
-	char	*smk_subject;
-	char	*smk_object;
-	int	smk_access;
-};
-
-/*
- * An entry in the table of permitted label accesses.
- */
-struct smk_list_entry {
-	struct smk_list_entry	*smk_next;
-	struct smack_rule	smk_rule;
+	struct list_head	list;
+	char			*smk_subject;
+	char			*smk_object;
+	int			smk_access;
 };
 
 /*
@@ -85,7 +80,7 @@ struct smack_cipso {
  * An entry in the table identifying hosts.
  */
 struct smk_netlbladdr {
-	struct smk_netlbladdr	*smk_next;
+	struct list_head	list;
 	struct sockaddr_in	smk_host;	/* network address */
 	struct in_addr		smk_mask;	/* network mask */
 	char			*smk_label;	/* label */
@@ -113,7 +108,7 @@ struct smk_netlbladdr {
  * the cipso direct mapping in used internally.
  */
 struct smack_known {
-	struct smack_known	*smk_next;
+	struct list_head	list;
 	char			smk_known[SMK_LABELLEN];
 	u32			smk_secid;
 	struct smack_cipso	*smk_cipso;
@@ -206,7 +201,6 @@ extern int smack_cipso_direct;
 extern char *smack_net_ambient;
 extern char *smack_onlycap;
 
-extern struct smack_known *smack_known;
 extern struct smack_known smack_known_floor;
 extern struct smack_known smack_known_hat;
 extern struct smack_known smack_known_huh;
@@ -214,8 +208,10 @@ extern struct smack_known smack_known_invalid;
 extern struct smack_known smack_known_star;
 extern struct smack_known smack_known_web;
 
-extern struct smk_list_entry *smack_list;
-extern struct smk_netlbladdr *smack_netlbladdrs;
+extern struct list_head smack_known_list;
+extern struct list_head smack_rule_list;
+extern struct list_head smk_netlbladdr_list;
+
 extern struct security_operations smack_ops;
 
 /*
security/smack/smack_access.c +38 -24

178 lines not on this page · raw message

security/smack/smack_lsm.c +17 -3
index e7ded13..e6f89d6 100644
@@ -1509,8 +1509,8 @@ static char *smack_host_label(struct sockaddr_in *sip)
 
 	if (siap->s_addr == 0)
 		return NULL;
-
-	for (snp = smack_netlbladdrs; snp != NULL; snp = snp->smk_next) {
+	rcu_read_lock();
+	list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list) {
 		/*
 		 * we break after finding the first match because
 		 * the list is sorted from longest to shortest mask
@@ -1518,10 +1518,11 @@ static char *smack_host_label(struct sockaddr_in *sip)
 		 */
 		if ((&snp->smk_host.sin_addr)->s_addr  ==
 			(siap->s_addr & (&snp->smk_mask)->s_addr)) {
+			rcu_read_unlock();
 			return snp->smk_label;
 		}
 	}
-
+	rcu_read_unlock();
 	return NULL;
 }
 
@@ -2934,6 +2935,17 @@ struct security_operations smack_ops = {
 	.release_secctx = 		smack_release_secctx,
 };
 
+
+static __init init_smack_know_list(void)
+{
+	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);
+}
+
 /**
  * smack_init - initialize the smack system
  *
@@ -2954,6 +2966,8 @@ static __init int smack_init(void)
 	cred = (struct cred *) current->cred;
 	cred->security = &smack_known_floor.smk_known;
 
+	/* initilize the smack_know_list */
+	init_smack_know_list();
 	/*
 	 * Initialize locks
 	 */
security/smack/smackfs.c +108 -89

361 lines not on this page · raw message

#3 lore raw
Quoted 10 lines · etienne
Quoted 9 lines · Casey Schaufler
Quoted 4 lines · etienne

hello,

this patch on top of [PATCH][SMACK] convert smack rule list to linux list V2 converts "smack_known" to a regular linux list. (rcu variant)

I'm having some trouble applying this group of patches. I assume that I'm starting at the wrong place. Could you do a single patch to help me avoid confusion?

...

Quoted 3 lines

here you are!
(it is still on top of my 02/20 "[PATCH] SMACK netlabel fixes v2")

If Casey wants to ACK your Smack labeled networking patch from last week I'm okay with pulling it into the lblnet-2.6_next tree (it is sorta labeled networking related) so you can use it as a base if needed. It would also get the patch into the linux-next tree which is important if you want to target 2.6.30.

Signature · 2 lines
paul moore
linux @ hp
maintainer
#4 lore raw
In reply to etienne
Quoted 9 lines · etienne

...

here you are!
(it is still on top of my 02/20 "[PATCH] SMACK netlabel fixes v2")

happy testing ;)
Etienne

OK, I had the wrong starting point. I'm starting the test process now.

Thank you.