-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsys.c
More file actions
163 lines (130 loc) · 3.28 KB
/
Copy pathsys.c
File metadata and controls
163 lines (130 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* kernel/bc/sys.c
*
* Copyright (C) 2005 SWsoft
* All rights reserved.
*
* Licensing governed by "linux/COPYING.SWsoft" file.
*
*/
#include <linux/virtinfo.h>
#include <linux/compat.h>
#include <linux/syscalls.h>
#include <linux/sched.h>
#include <asm/uaccess.h>
#include <bc/beancounter.h>
/*
* The (rather boring) getluid syscall
*/
SYSCALL_DEFINE0(getluid)
{
struct user_beancounter *ub;
uid_t uid;
ub = get_exec_ub();
if (ub == NULL)
return -EINVAL;
uid = ub_legacy_id(ub);
if (uid == -1)
return -EINVAL;
return uid;
}
/*
* The setluid syscall
*/
SYSCALL_DEFINE1(setluid, uid_t, uid)
{
struct user_beancounter *ub;
int error;
/* You may not disown a setluid */
error = -EINVAL;
if (uid == (uid_t)-1)
goto out;
/* You may only set an ub as root */
error = -EPERM;
if (!capable(CAP_SETUID))
goto out;
/* Ok - set up a beancounter entry for this user */
error = -ENOBUFS;
ub = get_beancounter_byuid(uid, 1);
if (ub == NULL)
goto out;
error = ub_attach_task(ub, current);
put_beancounter(ub);
out:
return error;
}
long do_setublimit(uid_t uid, unsigned long resource,
unsigned long *new_limits)
{
int error;
unsigned long flags;
struct user_beancounter *ub;
error = -EINVAL;
if (resource >= UB_RESOURCES)
goto out;
error = -EINVAL;
if (new_limits[0] > UB_MAXVALUE || new_limits[1] > UB_MAXVALUE)
goto out;
error = -ENOENT;
ub = get_beancounter_byuid(uid, 0);
if (ub == NULL)
goto out;
ub_sync_memcg(ub);
spin_lock_irqsave(&ub->ub_lock, flags);
ub->ub_parms[resource].barrier = new_limits[0];
ub->ub_parms[resource].limit = new_limits[1];
init_beancounter_precharge(ub, resource);
spin_unlock_irqrestore(&ub->ub_lock, flags);
error = ub_update_memcg(ub);
put_beancounter(ub);
out:
return error;
}
/*
* The setbeanlimit syscall
*/
SYSCALL_DEFINE3(setublimit, uid_t, uid, unsigned long, resource,
unsigned long __user *, limits)
{
unsigned long new_limits[2];
if (!capable(CAP_SYS_RESOURCE))
return -EPERM;
if (copy_from_user(&new_limits, limits, sizeof(new_limits)))
return -EFAULT;
return do_setublimit(uid, resource, new_limits);
}
extern long do_ubstat(int func, unsigned long arg1, unsigned long arg2,
void __user *buf, long size);
SYSCALL_DEFINE5(ubstat, int, func, unsigned long, arg1, unsigned long, arg2,
void __user *, buf, long, size)
{
if (!capable(CAP_DAC_OVERRIDE) && !capable(CAP_DAC_READ_SEARCH))
return -EPERM;
return do_ubstat(func, arg1, arg2, buf, size);
}
#ifdef CONFIG_COMPAT
#define UB_MAXVALUE_COMPAT ((1UL << (sizeof(compat_long_t) * 8 - 1)) - 1)
asmlinkage long compat_sys_setublimit(uid_t uid,
compat_long_t resource,
compat_long_t __user *limits)
{
compat_long_t u_new_limits[2];
unsigned long new_limits[2];
if (!capable(CAP_SYS_RESOURCE))
return -EPERM;
if (copy_from_user(&u_new_limits, limits, sizeof(u_new_limits)))
return -EFAULT;
new_limits[0] = u_new_limits[0];
new_limits[1] = u_new_limits[1];
if (u_new_limits[0] == UB_MAXVALUE_COMPAT)
new_limits[0] = UB_MAXVALUE;
if (u_new_limits[1] == UB_MAXVALUE_COMPAT)
new_limits[1] = UB_MAXVALUE;
return do_setublimit(uid, resource, new_limits);
}
asmlinkage long compat_sys_ubstat(int func, unsigned int arg1,
unsigned int arg2, compat_uptr_t *buf, long size)
{
return sys_ubstat(func, arg1, arg2, buf, size);
}
#endif