Skip to content

Commit fad0701

Browse files
committed
Merge branch 'serge-next-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux-security
Pull security layer updates from Serge Hallyn: "This is a merge of James Morris' security-next tree from 3.14 to yesterday's master, plus four patches from Paul Moore which are in linux-next, plus one patch from Mimi" * 'serge-next-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sergeh/linux-security: ima: audit log files opened with O_DIRECT flag selinux: conditionally reschedule in hashtab_insert while loading selinux policy selinux: conditionally reschedule in mls_convert_context while loading selinux policy selinux: reject setexeccon() on MNT_NOSUID applications with -EACCES selinux: Report permissive mode in avc: denied messages. Warning in scanf string typing Smack: Label cgroup files for systemd Smack: Verify read access on file open - v3 security: Convert use of typedef ctl_table to struct ctl_table Smack: bidirectional UDS connect check Smack: Correctly remove SMACK64TRANSMUTE attribute SMACK: Fix handling value==NULL in post setxattr bugfix patch for SMACK Smack: adds smackfs/ptrace interface Smack: unify all ptrace accesses in the smack Smack: fix the subject/object order in smack_ptrace_traceme() Minor improvement of 'smack_sb_kern_mount' smack: fix key permission verification KEYS: Move the flags representing required permission to linux/key.h
2 parents d53b47c + f9b2a73 commit fad0701

27 files changed

Lines changed: 407 additions & 137 deletions

File tree

‎Documentation/ABI/testing/ima_policy‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Description:
2323
[fowner]]
2424
lsm: [[subj_user=] [subj_role=] [subj_type=]
2525
[obj_user=] [obj_role=] [obj_type=]]
26-
option: [[appraise_type=]]
26+
option: [[appraise_type=]] [permit_directio]
2727

2828
base: func:= [BPRM_CHECK][MMAP_CHECK][FILE_CHECK][MODULE_CHECK]
2929
mask:= [MAY_READ] [MAY_WRITE] [MAY_APPEND] [MAY_EXEC]

‎Documentation/security/Smack.txt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ onlycap
204204
these capabilities are effective at for processes with any
205205
label. The value is set by writing the desired label to the
206206
file or cleared by writing "-" to the file.
207+
ptrace
208+
This is used to define the current ptrace policy
209+
0 - default: this is the policy that relies on smack access rules.
210+
For the PTRACE_READ a subject needs to have a read access on
211+
object. For the PTRACE_ATTACH a read-write access is required.
212+
1 - exact: this is the policy that limits PTRACE_ATTACH. Attach is
213+
only allowed when subject's and object's labels are equal.
214+
PTRACE_READ is not affected. Can be overriden with CAP_SYS_PTRACE.
215+
2 - draconian: this policy behaves like the 'exact' above with an
216+
exception that it can't be overriden with CAP_SYS_PTRACE.
207217
revoke-subject
208218
Writing a Smack label here sets the access to '-' for all access
209219
rules with that subject label.

‎include/linux/key.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,17 @@ static inline key_serial_t key_serial(const struct key *key)
309309

310310
extern void key_set_timeout(struct key *, unsigned);
311311

312+
/*
313+
* The permissions required on a key that we're looking up.
314+
*/
315+
#define KEY_NEED_VIEW 0x01 /* Require permission to view attributes */
316+
#define KEY_NEED_READ 0x02 /* Require permission to read content */
317+
#define KEY_NEED_WRITE 0x04 /* Require permission to update / modify */
318+
#define KEY_NEED_SEARCH 0x08 /* Require permission to search (keyring) or find (key) */
319+
#define KEY_NEED_LINK 0x10 /* Require permission to link */
320+
#define KEY_NEED_SETATTR 0x20 /* Require permission to change attributes */
321+
#define KEY_NEED_ALL 0x3f /* All the above permissions */
322+
312323
/**
313324
* key_is_instantiated - Determine if a key has been positively instantiated
314325
* @key: The key to check.

‎include/linux/security.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ struct security_operations {
17081708
void (*key_free) (struct key *key);
17091709
int (*key_permission) (key_ref_t key_ref,
17101710
const struct cred *cred,
1711-
key_perm_t perm);
1711+
unsigned perm);
17121712
int (*key_getsecurity)(struct key *key, char **_buffer);
17131713
#endif /* CONFIG_KEYS */
17141714

@@ -3034,7 +3034,7 @@ static inline int security_path_chroot(struct path *path)
30343034
int security_key_alloc(struct key *key, const struct cred *cred, unsigned long flags);
30353035
void security_key_free(struct key *key);
30363036
int security_key_permission(key_ref_t key_ref,
3037-
const struct cred *cred, key_perm_t perm);
3037+
const struct cred *cred, unsigned perm);
30383038
int security_key_getsecurity(struct key *key, char **_buffer);
30393039

30403040
#else
@@ -3052,7 +3052,7 @@ static inline void security_key_free(struct key *key)
30523052

30533053
static inline int security_key_permission(key_ref_t key_ref,
30543054
const struct cred *cred,
3055-
key_perm_t perm)
3055+
unsigned perm)
30563056
{
30573057
return 0;
30583058
}

‎security/capability.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ static void cap_key_free(struct key *key)
879879
}
880880

881881
static int cap_key_permission(key_ref_t key_ref, const struct cred *cred,
882-
key_perm_t perm)
882+
unsigned perm)
883883
{
884884
return 0;
885885
}

‎security/integrity/ima/ima_api.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
199199
struct evm_ima_xattr_data **xattr_value,
200200
int *xattr_len)
201201
{
202+
const char *audit_cause = "failed";
202203
struct inode *inode = file_inode(file);
203204
const char *filename = file->f_dentry->d_name.name;
204205
int result = 0;
@@ -213,6 +214,12 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
213214
if (!(iint->flags & IMA_COLLECTED)) {
214215
u64 i_version = file_inode(file)->i_version;
215216

217+
if (file->f_flags & O_DIRECT) {
218+
audit_cause = "failed(directio)";
219+
result = -EACCES;
220+
goto out;
221+
}
222+
216223
/* use default hash algorithm */
217224
hash.hdr.algo = ima_hash_algo;
218225

@@ -233,9 +240,10 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
233240
result = -ENOMEM;
234241
}
235242
}
243+
out:
236244
if (result)
237245
integrity_audit_msg(AUDIT_INTEGRITY_DATA, inode,
238-
filename, "collect_data", "failed",
246+
filename, "collect_data", audit_cause,
239247
result, 0);
240248
return result;
241249
}

‎security/integrity/ima/ima_main.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ static int process_measurement(struct file *file, const char *filename,
214214
xattr_ptr = &xattr_value;
215215

216216
rc = ima_collect_measurement(iint, file, xattr_ptr, &xattr_len);
217-
if (rc != 0)
217+
if (rc != 0) {
218+
if (file->f_flags & O_DIRECT)
219+
rc = (iint->flags & IMA_PERMIT_DIRECTIO) ? 0 : -EACCES;
218220
goto out_digsig;
221+
}
219222

220223
pathname = filename ?: ima_d_path(&file->f_path, &pathbuf);
221224

‎security/integrity/ima/ima_policy.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ enum {
353353
Opt_obj_user, Opt_obj_role, Opt_obj_type,
354354
Opt_subj_user, Opt_subj_role, Opt_subj_type,
355355
Opt_func, Opt_mask, Opt_fsmagic, Opt_uid, Opt_fowner,
356-
Opt_appraise_type, Opt_fsuuid
356+
Opt_appraise_type, Opt_fsuuid, Opt_permit_directio
357357
};
358358

359359
static match_table_t policy_tokens = {
@@ -375,6 +375,7 @@ static match_table_t policy_tokens = {
375375
{Opt_uid, "uid=%s"},
376376
{Opt_fowner, "fowner=%s"},
377377
{Opt_appraise_type, "appraise_type=%s"},
378+
{Opt_permit_directio, "permit_directio"},
378379
{Opt_err, NULL}
379380
};
380381

@@ -622,6 +623,9 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
622623
else
623624
result = -EINVAL;
624625
break;
626+
case Opt_permit_directio:
627+
entry->flags |= IMA_PERMIT_DIRECTIO;
628+
break;
625629
case Opt_err:
626630
ima_log_string(ab, "UNKNOWN", p);
627631
result = -EINVAL;

‎security/integrity/integrity.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#define IMA_ACTION_FLAGS 0xff000000
3131
#define IMA_DIGSIG 0x01000000
3232
#define IMA_DIGSIG_REQUIRED 0x02000000
33+
#define IMA_PERMIT_DIRECTIO 0x04000000
3334

3435
#define IMA_DO_MASK (IMA_MEASURE | IMA_APPRAISE | IMA_AUDIT | \
3536
IMA_APPRAISE_SUBMASK)

‎security/keys/internal.h‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,11 @@ extern int key_task_permission(const key_ref_t key_ref,
176176
/*
177177
* Check to see whether permission is granted to use a key in the desired way.
178178
*/
179-
static inline int key_permission(const key_ref_t key_ref, key_perm_t perm)
179+
static inline int key_permission(const key_ref_t key_ref, unsigned perm)
180180
{
181181
return key_task_permission(key_ref, current_cred(), perm);
182182
}
183183

184-
/* required permissions */
185-
#define KEY_VIEW 0x01 /* require permission to view attributes */
186-
#define KEY_READ 0x02 /* require permission to read content */
187-
#define KEY_WRITE 0x04 /* require permission to update / modify */
188-
#define KEY_SEARCH 0x08 /* require permission to search (keyring) or find (key) */
189-
#define KEY_LINK 0x10 /* require permission to link */
190-
#define KEY_SETATTR 0x20 /* require permission to change attributes */
191-
#define KEY_ALL 0x3f /* all the above permissions */
192-
193184
/*
194185
* Authorisation record for request_key().
195186
*/

0 commit comments

Comments
 (0)