summaryrefslogtreecommitdiff
blob: d09c68385caa6712d4617f206a8a87e3dab404ab (plain)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
Index: linux-2.6.17/include/linux/vserver/context.h
===================================================================
--- linux-2.6.17.orig/include/linux/vserver/context.h
+++ linux-2.6.17/include/linux/vserver/context.h
@@ -42,6 +42,7 @@
 
 #define VXF_STATE_SETUP		(1ULL<<32)
 #define VXF_STATE_INIT		(1ULL<<33)
+#define VXF_STATE_ADMIN		(1ULL<<34)
 
 #define VXF_SC_HELPER		(1ULL<<36)
 #define VXF_REBOOT_KILL		(1ULL<<37)
@@ -52,9 +53,9 @@
 
 #define VXF_IGNEG_NICE		(1ULL<<52)
 
-#define VXF_ONE_TIME		(0x0003ULL<<32)
+#define VXF_ONE_TIME		(0x0007ULL<<32)
 
-#define VXF_INIT_SET		(VXF_STATE_SETUP|VXF_STATE_INIT)
+#define VXF_INIT_SET		(VXF_STATE_SETUP|VXF_STATE_INIT|VXF_STATE_ADMIN)
 
 
 /* context migration */
Index: linux-2.6.17/include/linux/vserver/network.h
===================================================================
--- linux-2.6.17.orig/include/linux/vserver/network.h
+++ linux-2.6.17/include/linux/vserver/network.h
@@ -14,13 +14,14 @@
 /* network flags */
 
 #define NXF_STATE_SETUP		(1ULL<<32)
+#define NXF_STATE_ADMIN		(1ULL<<34)
 
 #define NXF_SC_HELPER		(1ULL<<36)
 #define NXF_PERSISTENT		(1ULL<<38)
 
-#define NXF_ONE_TIME		(0x0001ULL<<32)
+#define NXF_ONE_TIME		(0x0005ULL<<32)
 
-#define NXF_INIT_SET		(0)
+#define NXF_INIT_SET		(NXF_STATE_ADMIN)
 
 
 /* address types */
Index: linux-2.6.17/kernel/vserver/context.c
===================================================================
--- linux-2.6.17.orig/kernel/vserver/context.c
+++ linux-2.6.17/kernel/vserver/context.c
@@ -18,6 +18,7 @@
  *  V0.11  and back to locking again
  *  V0.12  referenced context store
  *  V0.13  separate per cpu data
+ *  V0.14  added lock and admin flags
  *
  */
 
@@ -693,6 +694,9 @@ int vx_set_reaper(struct vx_info *vxi, s
 	if (!vxi)
 		return -EINVAL;
 
+	if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0))
+		return -EACCES;
+
 	vxdprintk(VXD_CBIT(xid, 6),
 		"vx_set_reaper(%p[#%d],%p[#%d,%d])",
 		vxi, vxi->vx_id, p, p->xid, p->pid);
@@ -713,6 +717,9 @@ int vx_set_init(struct vx_info *vxi, str
 	if (!vxi)
 		return -EINVAL;
 
+	if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0))
+		return -EACCES;
+
 	vxdprintk(VXD_CBIT(xid, 6),
 		"vx_set_init(%p[#%d],%p[#%d,%d,%d])",
 		vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
@@ -913,6 +920,10 @@ int vc_set_cflags(uint32_t id, void __us
 	if (!vxi)
 		return -ESRCH;
 
+	ret = -EACCES;
+	if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0))
+		goto out_put;
+
 	/* special STATE flag handling */
 	mask = vx_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
 	trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
@@ -986,16 +997,22 @@ static int do_set_caps(xid_t xid, uint64
 	uint64_t ccaps, uint64_t cmask)
 {
 	struct vx_info *vxi;
+	int ret;
 
 	vxi = lookup_vx_info(xid);
 	if (!vxi)
 		return -ESRCH;
 
+	ret = -EACCES;
+	if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0))
+		goto out_put;
+
 	vxi->vx_bcaps = vx_mask_flags(vxi->vx_bcaps, bcaps, bmask);
 	vxi->vx_ccaps = vx_mask_flags(vxi->vx_ccaps, ccaps, cmask);
-
+	ret = 0;
+out_put:
 	put_vx_info(vxi);
-	return 0;
+	return ret;
 }
 
 int vc_set_ccaps_v0(uint32_t id, void __user *data)
Index: linux-2.6.17/kernel/vserver/namespace.c
===================================================================
--- linux-2.6.17.orig/kernel/vserver/namespace.c
+++ linux-2.6.17/kernel/vserver/namespace.c
@@ -7,6 +7,7 @@
  *
  *  V0.01  broken out from context.c 0.07
  *  V0.02  added task locking for namespace
+ *  V0.03  added lock and admin flags
  *
  */
 
Index: linux-2.6.17/kernel/vserver/network.c
===================================================================
--- linux-2.6.17.orig/kernel/vserver/network.c
+++ linux-2.6.17/kernel/vserver/network.c
@@ -10,6 +10,7 @@
  *  V0.03  added equiv nx commands
  *  V0.04  switch to RCU based hash
  *  V0.05  and back to locking again
+ *  V0.06  added lock and admin flags
  *
  */
 
@@ -716,6 +717,7 @@ int vc_set_nflags(uint32_t id, void __us
 	struct nx_info *nxi;
 	struct vcmd_net_flags_v0 vc_data;
 	uint64_t mask, trigger;
+	int ret;
 
 	if (copy_from_user (&vc_data, data, sizeof(vc_data)))
 		return -EFAULT;
@@ -724,6 +726,10 @@ int vc_set_nflags(uint32_t id, void __us
 	if (!nxi)
 		return -ESRCH;
 
+	ret = -EACCES;
+	if (!nx_info_flags(nxi, NXF_STATE_ADMIN, 0))
+		goto out_put;
+
 	/* special STATE flag handling */
 	mask = vx_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
 	trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
@@ -732,9 +738,10 @@ int vc_set_nflags(uint32_t id, void __us
 		vc_data.flagword, mask);
 	if (trigger & NXF_PERSISTENT)
 		nx_set_persistent(nxi);
-
+	ret = 0;
+out_put:
 	put_nx_info(nxi);
-	return 0;
+	return ret;
 }
 
 int vc_get_ncaps(uint32_t id, void __user *data)
@@ -759,6 +766,7 @@ int vc_set_ncaps(uint32_t id, void __use
 {
 	struct nx_info *nxi;
 	struct vcmd_net_caps_v0 vc_data;
+	int ret;
 
 	if (copy_from_user (&vc_data, data, sizeof(vc_data)))
 		return -EFAULT;
@@ -767,10 +775,16 @@ int vc_set_ncaps(uint32_t id, void __use
 	if (!nxi)
 		return -ESRCH;
 
+	ret = -EACCES;
+	if (!nx_info_flags(nxi, NXF_STATE_ADMIN, 0))
+		goto out_put;
+
 	nxi->nx_ncaps = vx_mask_flags(nxi->nx_ncaps,
 		vc_data.ncaps, vc_data.cmask);
+	ret = 0;
+out_put:
 	put_nx_info(nxi);
-	return 0;
+	return ret;
 }
 
 
Index: linux-2.6.17/kernel/vserver/signal.c
===================================================================
--- linux-2.6.17.orig/kernel/vserver/signal.c
+++ linux-2.6.17/kernel/vserver/signal.c
@@ -3,7 +3,7 @@
  *
  *  Virtual Server: Signal Support
  *
- *  Copyright (C) 2003-2005  Herbert P�tzl
+ *  Copyright (C) 2003-2006  Herbert P�tzl
  *
  *  V0.01  broken out from vcontext V0.05
  *
@@ -71,9 +71,9 @@ int vx_info_kill(struct vx_info *vxi, in
 
 int vc_ctx_kill(uint32_t id, void __user *data)
 {
-	int retval;
 	struct vcmd_ctx_kill_v0 vc_data;
 	struct vx_info *vxi;
+	int ret;
 
 	if (copy_from_user (&vc_data, data, sizeof(vc_data)))
 		return -EFAULT;
@@ -82,9 +82,14 @@ int vc_ctx_kill(uint32_t id, void __user
 	if (!vxi)
 		return -ESRCH;
 
-	retval = vx_info_kill(vxi, vc_data.pid, vc_data.sig);
+	ret = -EACCES;
+	if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) && (vc_data.pid != 1))
+		goto out_put;
+
+	ret = vx_info_kill(vxi, vc_data.pid, vc_data.sig);
+out_put:
 	put_vx_info(vxi);
-	return retval;
+	return ret;
 }