@@ -102,9 +102,6 @@ static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
102102
103103const char * smack_cipso_option = SMACK_CIPSO_OPTION ;
104104
105-
106- #define SEQ_READ_FINISHED ((loff_t)-1)
107-
108105/*
109106 * Values for parsing cipso rules
110107 * SMK_DIGITLEN: Length of a digit field in a rule.
@@ -357,10 +354,12 @@ static ssize_t smk_write_load_list(struct file *file, const char __user *buf,
357354
358355 rc = count ;
359356 /*
357+ * If this is "load" as opposed to "load-self" and a new rule
358+ * it needs to get added for reporting.
360359 * smk_set_access returns true if there was already a rule
361360 * for the subject/object pair, and false if it was new.
362361 */
363- if (!smk_set_access (rule , rule_list , rule_lock )) {
362+ if (load && !smk_set_access (rule , rule_list , rule_lock )) {
364363 smlp = kzalloc (sizeof (* smlp ), GFP_KERNEL );
365364 if (smlp != NULL ) {
366365 smlp -> smk_rule = rule ;
@@ -377,20 +376,20 @@ static ssize_t smk_write_load_list(struct file *file, const char __user *buf,
377376 return rc ;
378377}
379378
380-
381379/*
382- * Seq_file read operations for /smack/load
380+ * Core logic for smackfs seq list operations.
383381 */
384382
385- static void * load_seq_start (struct seq_file * s , loff_t * pos )
383+ static void * smk_seq_start (struct seq_file * s , loff_t * pos ,
384+ struct list_head * head )
386385{
387386 struct list_head * list ;
388387
389388 /*
390389 * This is 0 the first time through.
391390 */
392391 if (s -> index == 0 )
393- s -> private = & smack_rule_list ;
392+ s -> private = head ;
394393
395394 if (s -> private == NULL )
396395 return NULL ;
@@ -404,18 +403,38 @@ static void *load_seq_start(struct seq_file *s, loff_t *pos)
404403 return list ;
405404}
406405
407- static void * load_seq_next (struct seq_file * s , void * v , loff_t * pos )
406+ static void * smk_seq_next (struct seq_file * s , void * v , loff_t * pos ,
407+ struct list_head * head )
408408{
409409 struct list_head * list = v ;
410410
411- if (list_is_last (list , & smack_rule_list )) {
411+ if (list_is_last (list , head )) {
412412 s -> private = NULL ;
413413 return NULL ;
414414 }
415415 s -> private = list -> next ;
416416 return list -> next ;
417417}
418418
419+ static void smk_seq_stop (struct seq_file * s , void * v )
420+ {
421+ /* No-op */
422+ }
423+
424+ /*
425+ * Seq_file read operations for /smack/load
426+ */
427+
428+ static void * load_seq_start (struct seq_file * s , loff_t * pos )
429+ {
430+ return smk_seq_start (s , pos , & smack_rule_list );
431+ }
432+
433+ static void * load_seq_next (struct seq_file * s , void * v , loff_t * pos )
434+ {
435+ return smk_seq_next (s , v , pos , & smack_rule_list );
436+ }
437+
419438static int load_seq_show (struct seq_file * s , void * v )
420439{
421440 struct list_head * list = v ;
@@ -446,16 +465,11 @@ static int load_seq_show(struct seq_file *s, void *v)
446465 return 0 ;
447466}
448467
449- static void load_seq_stop (struct seq_file * s , void * v )
450- {
451- /* No-op */
452- }
453-
454468static const struct seq_operations load_seq_ops = {
455469 .start = load_seq_start ,
456470 .next = load_seq_next ,
457471 .show = load_seq_show ,
458- .stop = load_seq_stop ,
472+ .stop = smk_seq_stop ,
459473};
460474
461475/**
@@ -574,28 +588,12 @@ static void smk_unlbl_ambient(char *oldambient)
574588
575589static void * cipso_seq_start (struct seq_file * s , loff_t * pos )
576590{
577- if (* pos == SEQ_READ_FINISHED )
578- return NULL ;
579- if (list_empty (& smack_known_list ))
580- return NULL ;
581-
582- return smack_known_list .next ;
591+ return smk_seq_start (s , pos , & smack_known_list );
583592}
584593
585594static void * cipso_seq_next (struct seq_file * s , void * v , loff_t * pos )
586595{
587- struct list_head * list = v ;
588-
589- /*
590- * labels with no associated cipso value wont be printed
591- * in cipso_seq_show
592- */
593- if (list_is_last (list , & smack_known_list )) {
594- * pos = SEQ_READ_FINISHED ;
595- return NULL ;
596- }
597-
598- return list -> next ;
596+ return smk_seq_next (s , v , pos , & smack_known_list );
599597}
600598
601599/*
@@ -634,16 +632,11 @@ static int cipso_seq_show(struct seq_file *s, void *v)
634632 return 0 ;
635633}
636634
637- static void cipso_seq_stop (struct seq_file * s , void * v )
638- {
639- /* No-op */
640- }
641-
642635static const struct seq_operations cipso_seq_ops = {
643636 .start = cipso_seq_start ,
644- .stop = cipso_seq_stop ,
645637 .next = cipso_seq_next ,
646638 .show = cipso_seq_show ,
639+ .stop = smk_seq_stop ,
647640};
648641
649642/**
@@ -788,23 +781,12 @@ static const struct file_operations smk_cipso_ops = {
788781
789782static void * netlbladdr_seq_start (struct seq_file * s , loff_t * pos )
790783{
791- if (* pos == SEQ_READ_FINISHED )
792- return NULL ;
793- if (list_empty (& smk_netlbladdr_list ))
794- return NULL ;
795- return smk_netlbladdr_list .next ;
784+ return smk_seq_start (s , pos , & smk_netlbladdr_list );
796785}
797786
798787static void * netlbladdr_seq_next (struct seq_file * s , void * v , loff_t * pos )
799788{
800- struct list_head * list = v ;
801-
802- if (list_is_last (list , & smk_netlbladdr_list )) {
803- * pos = SEQ_READ_FINISHED ;
804- return NULL ;
805- }
806-
807- return list -> next ;
789+ return smk_seq_next (s , v , pos , & smk_netlbladdr_list );
808790}
809791#define BEBITS (sizeof(__be32) * 8)
810792
@@ -828,16 +810,11 @@ static int netlbladdr_seq_show(struct seq_file *s, void *v)
828810 return 0 ;
829811}
830812
831- static void netlbladdr_seq_stop (struct seq_file * s , void * v )
832- {
833- /* No-op */
834- }
835-
836813static const struct seq_operations netlbladdr_seq_ops = {
837814 .start = netlbladdr_seq_start ,
838- .stop = netlbladdr_seq_stop ,
839815 .next = netlbladdr_seq_next ,
840816 .show = netlbladdr_seq_show ,
817+ .stop = smk_seq_stop ,
841818};
842819
843820/**
@@ -1405,23 +1382,14 @@ static void *load_self_seq_start(struct seq_file *s, loff_t *pos)
14051382{
14061383 struct task_smack * tsp = current_security ();
14071384
1408- if (* pos == SEQ_READ_FINISHED )
1409- return NULL ;
1410- if (list_empty (& tsp -> smk_rules ))
1411- return NULL ;
1412- return tsp -> smk_rules .next ;
1385+ return smk_seq_start (s , pos , & tsp -> smk_rules );
14131386}
14141387
14151388static void * load_self_seq_next (struct seq_file * s , void * v , loff_t * pos )
14161389{
14171390 struct task_smack * tsp = current_security ();
1418- struct list_head * list = v ;
14191391
1420- if (list_is_last (list , & tsp -> smk_rules )) {
1421- * pos = SEQ_READ_FINISHED ;
1422- return NULL ;
1423- }
1424- return list -> next ;
1392+ return smk_seq_next (s , v , pos , & tsp -> smk_rules );
14251393}
14261394
14271395static int load_self_seq_show (struct seq_file * s , void * v )
@@ -1453,16 +1421,11 @@ static int load_self_seq_show(struct seq_file *s, void *v)
14531421 return 0 ;
14541422}
14551423
1456- static void load_self_seq_stop (struct seq_file * s , void * v )
1457- {
1458- /* No-op */
1459- }
1460-
14611424static const struct seq_operations load_self_seq_ops = {
14621425 .start = load_self_seq_start ,
14631426 .next = load_self_seq_next ,
14641427 .show = load_self_seq_show ,
1465- .stop = load_self_seq_stop ,
1428+ .stop = smk_seq_stop ,
14661429};
14671430
14681431
0 commit comments