diff options
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r-- | fs/proc/base.c | 72 |
1 files changed, 57 insertions, 15 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index a23651ce6960..5ab1849971b4 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -140,9 +140,13 @@ struct pid_entry { | |||
140 | #define REG(NAME, MODE, fops) \ | 140 | #define REG(NAME, MODE, fops) \ |
141 | NOD(NAME, (S_IFREG|(MODE)), NULL, &fops, {}) | 141 | NOD(NAME, (S_IFREG|(MODE)), NULL, &fops, {}) |
142 | #define ONE(NAME, MODE, show) \ | 142 | #define ONE(NAME, MODE, show) \ |
143 | NOD(NAME, (S_IFREG|(MODE)), \ | 143 | NOD(NAME, (S_IFREG|(MODE)), \ |
144 | NULL, &proc_single_file_operations, \ | 144 | NULL, &proc_single_file_operations, \ |
145 | { .proc_show = show } ) | 145 | { .proc_show = show } ) |
146 | #define ATTR(LSM, NAME, MODE) \ | ||
147 | NOD(NAME, (S_IFREG|(MODE)), \ | ||
148 | NULL, &proc_pid_attr_operations, \ | ||
149 | { .lsm = LSM }) | ||
146 | 150 | ||
147 | /* | 151 | /* |
148 | * Count the number of hardlinks for the pid_entry table, excluding the . | 152 | * Count the number of hardlinks for the pid_entry table, excluding the . |
@@ -456,7 +460,7 @@ static int proc_pid_schedstat(struct seq_file *m, struct pid_namespace *ns, | |||
456 | struct pid *pid, struct task_struct *task) | 460 | struct pid *pid, struct task_struct *task) |
457 | { | 461 | { |
458 | if (unlikely(!sched_info_on())) | 462 | if (unlikely(!sched_info_on())) |
459 | seq_printf(m, "0 0 0\n"); | 463 | seq_puts(m, "0 0 0\n"); |
460 | else | 464 | else |
461 | seq_printf(m, "%llu %llu %lu\n", | 465 | seq_printf(m, "%llu %llu %lu\n", |
462 | (unsigned long long)task->se.sum_exec_runtime, | 466 | (unsigned long long)task->se.sum_exec_runtime, |
@@ -1086,10 +1090,6 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) | |||
1086 | 1090 | ||
1087 | task_lock(p); | 1091 | task_lock(p); |
1088 | if (!p->vfork_done && process_shares_mm(p, mm)) { | 1092 | if (!p->vfork_done && process_shares_mm(p, mm)) { |
1089 | pr_info("updating oom_score_adj for %d (%s) from %d to %d because it shares mm with %d (%s). Report if this is unexpected.\n", | ||
1090 | task_pid_nr(p), p->comm, | ||
1091 | p->signal->oom_score_adj, oom_adj, | ||
1092 | task_pid_nr(task), task->comm); | ||
1093 | p->signal->oom_score_adj = oom_adj; | 1093 | p->signal->oom_score_adj = oom_adj; |
1094 | if (!legacy && has_capability_noaudit(current, CAP_SYS_RESOURCE)) | 1094 | if (!legacy && has_capability_noaudit(current, CAP_SYS_RESOURCE)) |
1095 | p->signal->oom_score_adj_min = (short)oom_adj; | 1095 | p->signal->oom_score_adj_min = (short)oom_adj; |
@@ -2525,7 +2525,7 @@ static ssize_t proc_pid_attr_read(struct file * file, char __user * buf, | |||
2525 | if (!task) | 2525 | if (!task) |
2526 | return -ESRCH; | 2526 | return -ESRCH; |
2527 | 2527 | ||
2528 | length = security_getprocattr(task, | 2528 | length = security_getprocattr(task, PROC_I(inode)->op.lsm, |
2529 | (char*)file->f_path.dentry->d_name.name, | 2529 | (char*)file->f_path.dentry->d_name.name, |
2530 | &p); | 2530 | &p); |
2531 | put_task_struct(task); | 2531 | put_task_struct(task); |
@@ -2574,7 +2574,9 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, | |||
2574 | if (rv < 0) | 2574 | if (rv < 0) |
2575 | goto out_free; | 2575 | goto out_free; |
2576 | 2576 | ||
2577 | rv = security_setprocattr(file->f_path.dentry->d_name.name, page, count); | 2577 | rv = security_setprocattr(PROC_I(inode)->op.lsm, |
2578 | file->f_path.dentry->d_name.name, page, | ||
2579 | count); | ||
2578 | mutex_unlock(¤t->signal->cred_guard_mutex); | 2580 | mutex_unlock(¤t->signal->cred_guard_mutex); |
2579 | out_free: | 2581 | out_free: |
2580 | kfree(page); | 2582 | kfree(page); |
@@ -2588,13 +2590,53 @@ static const struct file_operations proc_pid_attr_operations = { | |||
2588 | .llseek = generic_file_llseek, | 2590 | .llseek = generic_file_llseek, |
2589 | }; | 2591 | }; |
2590 | 2592 | ||
2593 | #define LSM_DIR_OPS(LSM) \ | ||
2594 | static int proc_##LSM##_attr_dir_iterate(struct file *filp, \ | ||
2595 | struct dir_context *ctx) \ | ||
2596 | { \ | ||
2597 | return proc_pident_readdir(filp, ctx, \ | ||
2598 | LSM##_attr_dir_stuff, \ | ||
2599 | ARRAY_SIZE(LSM##_attr_dir_stuff)); \ | ||
2600 | } \ | ||
2601 | \ | ||
2602 | static const struct file_operations proc_##LSM##_attr_dir_ops = { \ | ||
2603 | .read = generic_read_dir, \ | ||
2604 | .iterate = proc_##LSM##_attr_dir_iterate, \ | ||
2605 | .llseek = default_llseek, \ | ||
2606 | }; \ | ||
2607 | \ | ||
2608 | static struct dentry *proc_##LSM##_attr_dir_lookup(struct inode *dir, \ | ||
2609 | struct dentry *dentry, unsigned int flags) \ | ||
2610 | { \ | ||
2611 | return proc_pident_lookup(dir, dentry, \ | ||
2612 | LSM##_attr_dir_stuff, \ | ||
2613 | ARRAY_SIZE(LSM##_attr_dir_stuff)); \ | ||
2614 | } \ | ||
2615 | \ | ||
2616 | static const struct inode_operations proc_##LSM##_attr_dir_inode_ops = { \ | ||
2617 | .lookup = proc_##LSM##_attr_dir_lookup, \ | ||
2618 | .getattr = pid_getattr, \ | ||
2619 | .setattr = proc_setattr, \ | ||
2620 | } | ||
2621 | |||
2622 | #ifdef CONFIG_SECURITY_SMACK | ||
2623 | static const struct pid_entry smack_attr_dir_stuff[] = { | ||
2624 | ATTR("smack", "current", 0666), | ||
2625 | }; | ||
2626 | LSM_DIR_OPS(smack); | ||
2627 | #endif | ||
2628 | |||
2591 | static const struct pid_entry attr_dir_stuff[] = { | 2629 | static const struct pid_entry attr_dir_stuff[] = { |
2592 | REG("current", S_IRUGO|S_IWUGO, proc_pid_attr_operations), | 2630 | ATTR(NULL, "current", 0666), |
2593 | REG("prev", S_IRUGO, proc_pid_attr_operations), | 2631 | ATTR(NULL, "prev", 0444), |
2594 | REG("exec", S_IRUGO|S_IWUGO, proc_pid_attr_operations), | 2632 | ATTR(NULL, "exec", 0666), |
2595 | REG("fscreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), | 2633 | ATTR(NULL, "fscreate", 0666), |
2596 | REG("keycreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), | 2634 | ATTR(NULL, "keycreate", 0666), |
2597 | REG("sockcreate", S_IRUGO|S_IWUGO, proc_pid_attr_operations), | 2635 | ATTR(NULL, "sockcreate", 0666), |
2636 | #ifdef CONFIG_SECURITY_SMACK | ||
2637 | DIR("smack", 0555, | ||
2638 | proc_smack_attr_dir_inode_ops, proc_smack_attr_dir_ops), | ||
2639 | #endif | ||
2598 | }; | 2640 | }; |
2599 | 2641 | ||
2600 | static int proc_attr_dir_readdir(struct file *file, struct dir_context *ctx) | 2642 | static int proc_attr_dir_readdir(struct file *file, struct dir_context *ctx) |
@@ -3165,7 +3207,7 @@ static struct dentry *proc_pid_instantiate(struct dentry * dentry, | |||
3165 | return d_splice_alias(inode, dentry); | 3207 | return d_splice_alias(inode, dentry); |
3166 | } | 3208 | } |
3167 | 3209 | ||
3168 | struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsigned int flags) | 3210 | struct dentry *proc_pid_lookup(struct dentry *dentry, unsigned int flags) |
3169 | { | 3211 | { |
3170 | struct task_struct *task; | 3212 | struct task_struct *task; |
3171 | unsigned tgid; | 3213 | unsigned tgid; |