diff options
| author | Casey Schaufler <casey@schaufler-ca.com> | 2015-03-21 21:26:40 -0400 |
|---|---|---|
| committer | Casey Schaufler <casey@schaufler-ca.com> | 2015-03-23 16:21:34 -0400 |
| commit | bf4b2fee99799780ea3dbb6d79d1909b3e32be13 (patch) | |
| tree | 70224834f619caa3bf5abd39a7334f5b77bf5656 /security | |
| parent | 7fc5f36e980a8f4830efdae3858f6e64eee538b7 (diff) | |
Smack: Allow an unconfined label in bringup mode
I have vehemently opposed adding a "permissive" mode to Smack
for the simple reasons that it would be subject to massive abuse
and that developers refuse to turn it off come product release.
I still believe that this is true, and still refuse to add a
general "permissive mode". So don't ask again.
Bumjin Im suggested an approach that addresses most of the concerns,
and I have implemented it here. I still believe that we'd be better
off without this sort of thing, but it looks like this minimizes the
abuse potential.
Firstly, you have to configure Smack Bringup Mode. That allows
for "release" software to be ammune from abuse. Second, only one
label gets to be "permissive" at a time. You can use it for
debugging, but that's about it.
A label written to smackfs/unconfined is treated specially.
If either the subject or object label of an access check
matches the "unconfined" label, and the access would not
have been allowed otherwise an audit record and a console
message are generated. The audit record "request" string is
marked with either "(US)" or "(UO)", to indicate that the
request was granted because of an unconfined label. The
fact that an inode was accessed by an unconfined label is
remembered, and subsequent accesses to that "impure"
object are noted in the log. The impurity is not stored in
the filesystem, so a file mislabled as a side effect of
using an unconfined label may still cause concern after
a reboot.
So, it's there, it's dangerous, but so many application
developers seem incapable of living without it I have
given in. I've tried to make it as safe as I can, but
in the end it's still a chain saw.
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Diffstat (limited to 'security')
| -rw-r--r-- | security/smack/smack.h | 8 | ||||
| -rw-r--r-- | security/smack/smack_access.c | 43 | ||||
| -rw-r--r-- | security/smack/smack_lsm.c | 52 | ||||
| -rw-r--r-- | security/smack/smackfs.c | 96 |
4 files changed, 182 insertions, 17 deletions
diff --git a/security/smack/smack.h b/security/smack/smack.h index 67ccb7b2b89b..49eada6266ec 100644 --- a/security/smack/smack.h +++ b/security/smack/smack.h | |||
| @@ -105,6 +105,7 @@ struct task_smack { | |||
| 105 | #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */ | 105 | #define SMK_INODE_INSTANT 0x01 /* inode is instantiated */ |
| 106 | #define SMK_INODE_TRANSMUTE 0x02 /* directory is transmuting */ | 106 | #define SMK_INODE_TRANSMUTE 0x02 /* directory is transmuting */ |
| 107 | #define SMK_INODE_CHANGED 0x04 /* smack was transmuted */ | 107 | #define SMK_INODE_CHANGED 0x04 /* smack was transmuted */ |
| 108 | #define SMK_INODE_IMPURE 0x08 /* involved in an impure transaction */ | ||
| 108 | 109 | ||
| 109 | /* | 110 | /* |
| 110 | * A label access rule. | 111 | * A label access rule. |
| @@ -193,6 +194,10 @@ struct smk_port_label { | |||
| 193 | #define MAY_LOCK 0x00002000 /* Locks should be writes, but ... */ | 194 | #define MAY_LOCK 0x00002000 /* Locks should be writes, but ... */ |
| 194 | #define MAY_BRINGUP 0x00004000 /* Report use of this rule */ | 195 | #define MAY_BRINGUP 0x00004000 /* Report use of this rule */ |
| 195 | 196 | ||
| 197 | #define SMACK_BRINGUP_ALLOW 1 /* Allow bringup mode */ | ||
| 198 | #define SMACK_UNCONFINED_SUBJECT 2 /* Allow unconfined label */ | ||
| 199 | #define SMACK_UNCONFINED_OBJECT 3 /* Allow unconfined label */ | ||
| 200 | |||
| 196 | /* | 201 | /* |
| 197 | * Just to make the common cases easier to deal with | 202 | * Just to make the common cases easier to deal with |
| 198 | */ | 203 | */ |
| @@ -254,6 +259,9 @@ extern int smack_cipso_mapped; | |||
| 254 | extern struct smack_known *smack_net_ambient; | 259 | extern struct smack_known *smack_net_ambient; |
| 255 | extern struct smack_known *smack_onlycap; | 260 | extern struct smack_known *smack_onlycap; |
| 256 | extern struct smack_known *smack_syslog_label; | 261 | extern struct smack_known *smack_syslog_label; |
| 262 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
| 263 | extern struct smack_known *smack_unconfined; | ||
| 264 | #endif | ||
| 257 | extern struct smack_known smack_cipso_option; | 265 | extern struct smack_known smack_cipso_option; |
| 258 | extern int smack_ptrace_rule; | 266 | extern int smack_ptrace_rule; |
| 259 | 267 | ||
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c index 1158430f5bb9..0f410fc56e33 100644 --- a/security/smack/smack_access.c +++ b/security/smack/smack_access.c | |||
| @@ -130,7 +130,8 @@ int smk_access(struct smack_known *subject, struct smack_known *object, | |||
| 130 | 130 | ||
| 131 | /* | 131 | /* |
| 132 | * Hardcoded comparisons. | 132 | * Hardcoded comparisons. |
| 133 | * | 133 | */ |
| 134 | /* | ||
| 134 | * A star subject can't access any object. | 135 | * A star subject can't access any object. |
| 135 | */ | 136 | */ |
| 136 | if (subject == &smack_known_star) { | 137 | if (subject == &smack_known_star) { |
| @@ -189,10 +190,20 @@ int smk_access(struct smack_known *subject, struct smack_known *object, | |||
| 189 | * succeed because of "b" rules. | 190 | * succeed because of "b" rules. |
| 190 | */ | 191 | */ |
| 191 | if (may & MAY_BRINGUP) | 192 | if (may & MAY_BRINGUP) |
| 192 | rc = MAY_BRINGUP; | 193 | rc = SMACK_BRINGUP_ALLOW; |
| 193 | #endif | 194 | #endif |
| 194 | 195 | ||
| 195 | out_audit: | 196 | out_audit: |
| 197 | |||
| 198 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
| 199 | if (rc < 0) { | ||
| 200 | if (object == smack_unconfined) | ||
| 201 | rc = SMACK_UNCONFINED_OBJECT; | ||
| 202 | if (subject == smack_unconfined) | ||
| 203 | rc = SMACK_UNCONFINED_SUBJECT; | ||
| 204 | } | ||
| 205 | #endif | ||
| 206 | |||
| 196 | #ifdef CONFIG_AUDIT | 207 | #ifdef CONFIG_AUDIT |
| 197 | if (a) | 208 | if (a) |
| 198 | smack_log(subject->smk_known, object->smk_known, | 209 | smack_log(subject->smk_known, object->smk_known, |
| @@ -338,19 +349,16 @@ static void smack_log_callback(struct audit_buffer *ab, void *a) | |||
| 338 | void smack_log(char *subject_label, char *object_label, int request, | 349 | void smack_log(char *subject_label, char *object_label, int request, |
| 339 | int result, struct smk_audit_info *ad) | 350 | int result, struct smk_audit_info *ad) |
| 340 | { | 351 | { |
| 352 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
| 353 | char request_buffer[SMK_NUM_ACCESS_TYPE + 5]; | ||
| 354 | #else | ||
| 341 | char request_buffer[SMK_NUM_ACCESS_TYPE + 1]; | 355 | char request_buffer[SMK_NUM_ACCESS_TYPE + 1]; |
| 356 | #endif | ||
| 342 | struct smack_audit_data *sad; | 357 | struct smack_audit_data *sad; |
| 343 | struct common_audit_data *a = &ad->a; | 358 | struct common_audit_data *a = &ad->a; |
| 344 | 359 | ||
| 345 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
| 346 | /* | ||
| 347 | * The result may be positive in bringup mode. | ||
| 348 | */ | ||
| 349 | if (result > 0) | ||
| 350 | result = 0; | ||
| 351 | #endif | ||
| 352 | /* check if we have to log the current event */ | 360 | /* check if we have to log the current event */ |
| 353 | if (result != 0 && (log_policy & SMACK_AUDIT_DENIED) == 0) | 361 | if (result < 0 && (log_policy & SMACK_AUDIT_DENIED) == 0) |
| 354 | return; | 362 | return; |
| 355 | if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0) | 363 | if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0) |
| 356 | return; | 364 | return; |
| @@ -364,6 +372,21 @@ void smack_log(char *subject_label, char *object_label, int request, | |||
| 364 | smack_str_from_perm(request_buffer, request); | 372 | smack_str_from_perm(request_buffer, request); |
| 365 | sad->subject = subject_label; | 373 | sad->subject = subject_label; |
| 366 | sad->object = object_label; | 374 | sad->object = object_label; |
| 375 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | ||
| 376 | /* | ||
| 377 | * The result may be positive in bringup mode. | ||
| 378 | * A positive result is an allow, but not for normal reasons. | ||
| 379 | * Mark it as successful, but don't filter it out even if | ||
| 380 | * the logging policy says to do so. | ||
| 381 | */ | ||
| 382 | if (result == SMACK_UNCONFINED_SUBJECT) | ||
| 383 | strcat(request_buffer, "(US)"); | ||
| 384 | else if (result == SMACK_UNCONFINED_OBJECT) | ||
| 385 | strcat(request_buffer, "(UO)"); | ||
| 386 | |||
| 387 | if (result > 0) | ||
| 388 | result = 0; | ||
| 389 | #endif | ||
| 367 | sad->request = request_buffer; | 390 | sad->request = request_buffer; |
| 368 | sad->result = result; | 391 | sad->result = result; |
| 369 | 392 | ||
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index e2d1a7b073c0..6f3c7d866d04 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c | |||
| @@ -57,6 +57,13 @@ static struct kmem_cache *smack_inode_cache; | |||
| 57 | int smack_enabled; | 57 | int smack_enabled; |
| 58 | 58 | ||
| 59 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP | 59 | #ifdef CONFIG_SECURITY_SMACK_BRINGUP |
| 60 | static char *smk_bu_mess[] = { | ||
| 61 | "Bringup Error", /* Unused */ | ||
| 62 | "Bringup", /* SMACK_BRINGUP_ALLOW */ | ||
| 63 | "Unconfined Subject", /* SMACK_UNCONFINED_SUBJECT */ | ||
| 64 | "Unconfined Object", /* SMACK_UNCONFINED_OBJECT */ | ||
| 65 | }; | ||
| 66 | |||
| 60 | static void smk_bu_mode(int mode, char *s) | 67 | static void smk_bu_mode(int mode, char *s) |
| 61 | { | 68 | { |
| 62 | int i = 0; | 69 | int i = 0; |
| @@ -87,9 +94,11 @@ static int smk_bu_note(char *note, struct smack_known *sskp, | |||
| 87 | 94 | ||
| 88 | if (rc <= 0) | 95 | if (rc <= 0) |
| 89 | return rc; | 96 | return rc; |
| 97 | if (rc > SMACK_UNCONFINED_OBJECT) | ||
| 98 | rc = 0; | ||
| 90 | 99 | ||
| 91 | smk_bu_mode(mode, acc); | 100 | smk_bu_mode(mode, acc); |
| 92 | pr_info("Smack Bringup: (%s %s %s) %s\n", | 101 | pr_info("Smack %s: (%s %s %s) %s\n", smk_bu_mess[rc], |
| 93 | sskp->smk_known, oskp->smk_known, acc, note); | 102 | sskp->smk_known, oskp->smk_known, acc, note); |
| 94 | return 0; | 103 | return 0; |
| 95 | } | 104 | } |
| @@ -106,9 +115,11 @@ static int smk_bu_current(char *note, struct smack_known *oskp, | |||
| 106 | 115 | ||
| 107 | if (rc <= 0) | 116 | if (rc <= 0) |
| 108 | return rc; | 117 | return rc; |
| 118 | if (rc > SMACK_UNCONFINED_OBJECT) | ||
| 119 | rc = 0; | ||
| 109 | 120 | ||
| 110 | smk_bu_mode(mode, acc); | 121 | smk_bu_mode(mode, acc); |
| 111 | pr_info("Smack Bringup: (%s %s %s) %s %s\n", | 122 | pr_info("Smack %s: (%s %s %s) %s %s\n", smk_bu_mess[rc], |
| 112 | tsp->smk_task->smk_known, oskp->smk_known, | 123 | tsp->smk_task->smk_known, oskp->smk_known, |
| 113 | acc, current->comm, note); | 124 | |
