base.c (05909cd9a0c8811731b38697af13075e8954314f) base.c (0d8315dddd2899f519fe1ca3d4d5cdaf44ea421e)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/proc/base.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 *
7 * proc base directory handling functions
8 *

--- 1035 unchanged lines hidden (view full) ---

1044 if (!task)
1045 return -ESRCH;
1046 if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX)
1047 oom_adj = OOM_ADJUST_MAX;
1048 else
1049 oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) /
1050 OOM_SCORE_ADJ_MAX;
1051 put_task_struct(task);
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/fs/proc/base.c
4 *
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 *
7 * proc base directory handling functions
8 *

--- 1035 unchanged lines hidden (view full) ---

1044 if (!task)
1045 return -ESRCH;
1046 if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX)
1047 oom_adj = OOM_ADJUST_MAX;
1048 else
1049 oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) /
1050 OOM_SCORE_ADJ_MAX;
1051 put_task_struct(task);
1052 if (oom_adj > OOM_ADJUST_MAX)
1053 oom_adj = OOM_ADJUST_MAX;
1052 len = snprintf(buffer, sizeof(buffer), "%d\n", oom_adj);
1053 return simple_read_from_buffer(buf, count, ppos, buffer, len);
1054}
1055
1056static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
1057{
1054 len = snprintf(buffer, sizeof(buffer), "%d\n", oom_adj);
1055 return simple_read_from_buffer(buf, count, ppos, buffer, len);
1056}
1057
1058static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)
1059{
1058 static DEFINE_MUTEX(oom_adj_mutex);
1059 struct mm_struct *mm = NULL;
1060 struct task_struct *task;
1061 int err = 0;
1062
1063 task = get_proc_task(file_inode(file));
1064 if (!task)
1065 return -ESRCH;
1066

--- 23 unchanged lines hidden (view full) ---

1090 * Make sure we will check other processes sharing the mm if this is
1091 * not vfrok which wants its own oom_score_adj.
1092 * pin the mm so it doesn't go away and get reused after task_unlock
1093 */
1094 if (!task->vfork_done) {
1095 struct task_struct *p = find_lock_task_mm(task);
1096
1097 if (p) {
1060 struct mm_struct *mm = NULL;
1061 struct task_struct *task;
1062 int err = 0;
1063
1064 task = get_proc_task(file_inode(file));
1065 if (!task)
1066 return -ESRCH;
1067

--- 23 unchanged lines hidden (view full) ---

1091 * Make sure we will check other processes sharing the mm if this is
1092 * not vfrok which wants its own oom_score_adj.
1093 * pin the mm so it doesn't go away and get reused after task_unlock
1094 */
1095 if (!task->vfork_done) {
1096 struct task_struct *p = find_lock_task_mm(task);
1097
1098 if (p) {
1098 if (atomic_read(&p->mm->mm_users) > 1) {
1099 if (test_bit(MMF_MULTIPROCESS, &p->mm->flags)) {
1099 mm = p->mm;
1100 mmgrab(mm);
1101 }
1102 task_unlock(p);
1103 }
1104 }
1105
1106 task->signal->oom_score_adj = oom_adj;

--- 157 unchanged lines hidden (view full) ---

1264static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
1265 size_t count, loff_t *ppos)
1266{
1267 struct inode * inode = file_inode(file);
1268 uid_t loginuid;
1269 kuid_t kloginuid;
1270 int rv;
1271
1100 mm = p->mm;
1101 mmgrab(mm);
1102 }
1103 task_unlock(p);
1104 }
1105 }
1106
1107 task->signal->oom_score_adj = oom_adj;

--- 157 unchanged lines hidden (view full) ---

1265static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
1266 size_t count, loff_t *ppos)
1267{
1268 struct inode * inode = file_inode(file);
1269 uid_t loginuid;
1270 kuid_t kloginuid;
1271 int rv;
1272
1273 /* Don't let kthreads write their own loginuid */
1274 if (current->flags & PF_KTHREAD)
1275 return -EPERM;
1276
1272 rcu_read_lock();
1273 if (current != pid_task(proc_pid(inode), PIDTYPE_PID)) {
1274 rcu_read_unlock();
1275 return -EPERM;
1276 }
1277 rcu_read_unlock();
1278
1279 if (*ppos != 0) {

--- 1973 unchanged lines hidden (view full) ---

3253 ONE("patch_state", S_IRUSR, proc_pid_patch_state),
3254#endif
3255#ifdef CONFIG_STACKLEAK_METRICS
3256 ONE("stack_depth", S_IRUGO, proc_stack_depth),
3257#endif
3258#ifdef CONFIG_PROC_PID_ARCH_STATUS
3259 ONE("arch_status", S_IRUGO, proc_pid_arch_status),
3260#endif
1277 rcu_read_lock();
1278 if (current != pid_task(proc_pid(inode), PIDTYPE_PID)) {
1279 rcu_read_unlock();
1280 return -EPERM;
1281 }
1282 rcu_read_unlock();
1283
1284 if (*ppos != 0) {

--- 1973 unchanged lines hidden (view full) ---

3258 ONE("patch_state", S_IRUSR, proc_pid_patch_state),
3259#endif
3260#ifdef CONFIG_STACKLEAK_METRICS
3261 ONE("stack_depth", S_IRUGO, proc_stack_depth),
3262#endif
3263#ifdef CONFIG_PROC_PID_ARCH_STATUS
3264 ONE("arch_status", S_IRUGO, proc_pid_arch_status),
3265#endif
3266#ifdef CONFIG_SECCOMP_CACHE_DEBUG
3267 ONE("seccomp_cache", S_IRUSR, proc_pid_seccomp_cache),
3268#endif
3261};
3262
3263static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)
3264{
3265 return proc_pident_readdir(file, ctx,
3266 tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff));
3267}
3268

--- 313 unchanged lines hidden (view full) ---

3582 REG("setgroups", S_IRUGO|S_IWUSR, proc_setgroups_operations),
3583#endif
3584#ifdef CONFIG_LIVEPATCH
3585 ONE("patch_state", S_IRUSR, proc_pid_patch_state),
3586#endif
3587#ifdef CONFIG_PROC_PID_ARCH_STATUS
3588 ONE("arch_status", S_IRUGO, proc_pid_arch_status),
3589#endif
3269};
3270
3271static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)
3272{
3273 return proc_pident_readdir(file, ctx,
3274 tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff));
3275}
3276

--- 313 unchanged lines hidden (view full) ---

3590 REG("setgroups", S_IRUGO|S_IWUSR, proc_setgroups_operations),
3591#endif
3592#ifdef CONFIG_LIVEPATCH
3593 ONE("patch_state", S_IRUSR, proc_pid_patch_state),
3594#endif
3595#ifdef CONFIG_PROC_PID_ARCH_STATUS
3596 ONE("arch_status", S_IRUGO, proc_pid_arch_status),
3597#endif
3598#ifdef CONFIG_SECCOMP_CACHE_DEBUG
3599 ONE("seccomp_cache", S_IRUSR, proc_pid_seccomp_cache),
3600#endif
3590};
3591
3592static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
3593{
3594 return proc_pident_readdir(file, ctx,
3595 tid_base_stuff, ARRAY_SIZE(tid_base_stuff));
3596}
3597

--- 225 unchanged lines hidden ---
3601};
3602
3603static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
3604{
3605 return proc_pident_readdir(file, ctx,
3606 tid_base_stuff, ARRAY_SIZE(tid_base_stuff));
3607}
3608

--- 225 unchanged lines hidden ---