Skip to content

Commit 678ca9f

Browse files
committed
Merge tag 'Smack-for-6.14' of https://github.com/cschaufler/smack-next
Pull smack update from Casey Schaufler: "One minor code improvement for v6.14" * tag 'Smack-for-6.14' of https://github.com/cschaufler/smack-next: smack: deduplicate access to string conversion
2 parents 0ca0cf9 + 6f71ad0 commit 678ca9f

File tree

4 files changed

+15
-40
lines changed

4 files changed

+15
-40
lines changed

security/smack/smack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ int smk_access(struct smack_known *, struct smack_known *,
280280
int smk_tskacc(struct task_smack *, struct smack_known *,
281281
u32, struct smk_audit_info *);
282282
int smk_curacc(struct smack_known *, u32, struct smk_audit_info *);
283+
int smack_str_from_perm(char *string, int access);
283284
struct smack_known *smack_from_secid(const u32);
284285
char *smk_parse_smack(const char *string, int len);
285286
int smk_netlbl_mls(int, char *, struct netlbl_lsm_secattr *, int);

security/smack/smack_access.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,14 @@ int smk_curacc(struct smack_known *obj_known,
275275
return smk_tskacc(tsp, obj_known, mode, a);
276276
}
277277

278-
#ifdef CONFIG_AUDIT
279278
/**
280279
* smack_str_from_perm : helper to transalate an int to a
281280
* readable string
282281
* @string : the string to fill
283282
* @access : the int
284283
*
285284
*/
286-
static inline void smack_str_from_perm(char *string, int access)
285+
int smack_str_from_perm(char *string, int access)
287286
{
288287
int i = 0;
289288

@@ -299,8 +298,15 @@ static inline void smack_str_from_perm(char *string, int access)
299298
string[i++] = 't';
300299
if (access & MAY_LOCK)
301300
string[i++] = 'l';
301+
if (access & MAY_BRINGUP)
302+
string[i++] = 'b';
303+
if (i == 0)
304+
string[i++] = '-';
302305
string[i] = '\0';
306+
return i;
303307
}
308+
309+
#ifdef CONFIG_AUDIT
304310
/**
305311
* smack_log_callback - SMACK specific information
306312
* will be called by generic audit code

security/smack/smack_lsm.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,7 @@ static char *smk_bu_mess[] = {
107107

108108
static void smk_bu_mode(int mode, char *s)
109109
{
110-
int i = 0;
111-
112-
if (mode & MAY_READ)
113-
s[i++] = 'r';
114-
if (mode & MAY_WRITE)
115-
s[i++] = 'w';
116-
if (mode & MAY_EXEC)
117-
s[i++] = 'x';
118-
if (mode & MAY_APPEND)
119-
s[i++] = 'a';
120-
if (mode & MAY_TRANSMUTE)
121-
s[i++] = 't';
122-
if (mode & MAY_LOCK)
123-
s[i++] = 'l';
124-
if (i == 0)
125-
s[i++] = '-';
126-
s[i] = '\0';
110+
smack_str_from_perm(s, mode);
127111
}
128112
#endif
129113

security/smack/smackfs.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ static void smk_seq_stop(struct seq_file *s, void *v)
562562

563563
static void smk_rule_show(struct seq_file *s, struct smack_rule *srp, int max)
564564
{
565+
char acc[SMK_NUM_ACCESS_TYPE + 1];
565566
/*
566567
* Don't show any rules with label names too long for
567568
* interface file (/smack/load or /smack/load2)
@@ -575,28 +576,11 @@ static void smk_rule_show(struct seq_file *s, struct smack_rule *srp, int max)
575576
if (srp->smk_access == 0)
576577
return;
577578

578-
seq_printf(s, "%s %s",
579+
smack_str_from_perm(acc, srp->smk_access);
580+
seq_printf(s, "%s %s %s\n",
579581
srp->smk_subject->smk_known,
580-
srp->smk_object->smk_known);
581-
582-
seq_putc(s, ' ');
583-
584-
if (srp->smk_access & MAY_READ)
585-
seq_putc(s, 'r');
586-
if (srp->smk_access & MAY_WRITE)
587-
seq_putc(s, 'w');
588-
if (srp->smk_access & MAY_EXEC)
589-
seq_putc(s, 'x');
590-
if (srp->smk_access & MAY_APPEND)
591-
seq_putc(s, 'a');
592-
if (srp->smk_access & MAY_TRANSMUTE)
593-
seq_putc(s, 't');
594-
if (srp->smk_access & MAY_LOCK)
595-
seq_putc(s, 'l');
596-
if (srp->smk_access & MAY_BRINGUP)
597-
seq_putc(s, 'b');
598-
599-
seq_putc(s, '\n');
582+
srp->smk_object->smk_known,
583+
acc);
600584
}
601585

602586
/*

0 commit comments

Comments
 (0)