blob: 860390ee1fbe9548dae129d34b1904befa04ccb7 [file] [log] [blame]
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +09001/*
2 * security/tomoyo/domain.c
3 *
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +09004 * Copyright (C) 2005-2011 NTT DATA CORPORATION
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +09005 */
6
7#include "common.h"
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +09008#include <linux/binfmts.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09009#include <linux/slab.h>
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +090010
11/* Variables definitions.*/
12
13/* The initial domain. */
14struct tomoyo_domain_info tomoyo_kernel_domain;
15
Tetsuo Handa237ab452010-06-12 20:46:22 +090016/**
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +090017 * tomoyo_update_policy - Update an entry for exception policy.
18 *
19 * @new_entry: Pointer to "struct tomoyo_acl_info".
20 * @size: Size of @new_entry in bytes.
Tetsuo Handaa238cf52011-06-26 23:17:10 +090021 * @param: Pointer to "struct tomoyo_acl_param".
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +090022 * @check_duplicate: Callback function to find duplicated entry.
23 *
24 * Returns 0 on success, negative value otherwise.
25 *
26 * Caller holds tomoyo_read_lock().
27 */
28int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +090029 struct tomoyo_acl_param *param,
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +090030 bool (*check_duplicate) (const struct tomoyo_acl_head
31 *,
32 const struct tomoyo_acl_head
33 *))
34{
Tetsuo Handaa238cf52011-06-26 23:17:10 +090035 int error = param->is_delete ? -ENOENT : -ENOMEM;
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +090036 struct tomoyo_acl_head *entry;
Tetsuo Handaa238cf52011-06-26 23:17:10 +090037 struct list_head *list = param->list;
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +090038
39 if (mutex_lock_interruptible(&tomoyo_policy_lock))
40 return -ENOMEM;
41 list_for_each_entry_rcu(entry, list, list) {
42 if (!check_duplicate(entry, new_entry))
43 continue;
Tetsuo Handaa238cf52011-06-26 23:17:10 +090044 entry->is_deleted = param->is_delete;
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +090045 error = 0;
46 break;
47 }
Tetsuo Handaa238cf52011-06-26 23:17:10 +090048 if (error && !param->is_delete) {
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +090049 entry = tomoyo_commit_ok(new_entry, size);
50 if (entry) {
51 list_add_tail_rcu(&entry->list, list);
52 error = 0;
53 }
54 }
55 mutex_unlock(&tomoyo_policy_lock);
56 return error;
57}
58
59/**
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +090060 * tomoyo_same_acl_head - Check for duplicated "struct tomoyo_acl_info" entry.
61 *
62 * @a: Pointer to "struct tomoyo_acl_info".
63 * @b: Pointer to "struct tomoyo_acl_info".
64 *
65 * Returns true if @a == @b, false otherwise.
66 */
67static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *a,
68 const struct tomoyo_acl_info *b)
69{
Tetsuo Handa2066a362011-07-08 13:21:37 +090070 return a->type == b->type && a->cond == b->cond;
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +090071}
72
73/**
Tetsuo Handa237ab452010-06-12 20:46:22 +090074 * tomoyo_update_domain - Update an entry for domain policy.
75 *
76 * @new_entry: Pointer to "struct tomoyo_acl_info".
77 * @size: Size of @new_entry in bytes.
Tetsuo Handaa238cf52011-06-26 23:17:10 +090078 * @param: Pointer to "struct tomoyo_acl_param".
Tetsuo Handa237ab452010-06-12 20:46:22 +090079 * @check_duplicate: Callback function to find duplicated entry.
80 * @merge_duplicate: Callback function to merge duplicated entry.
81 *
82 * Returns 0 on success, negative value otherwise.
83 *
84 * Caller holds tomoyo_read_lock().
85 */
86int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
Tetsuo Handaa238cf52011-06-26 23:17:10 +090087 struct tomoyo_acl_param *param,
Tetsuo Handa237ab452010-06-12 20:46:22 +090088 bool (*check_duplicate) (const struct tomoyo_acl_info
89 *,
90 const struct tomoyo_acl_info
91 *),
92 bool (*merge_duplicate) (struct tomoyo_acl_info *,
93 struct tomoyo_acl_info *,
94 const bool))
95{
Tetsuo Handaa238cf52011-06-26 23:17:10 +090096 const bool is_delete = param->is_delete;
Tetsuo Handa237ab452010-06-12 20:46:22 +090097 int error = is_delete ? -ENOENT : -ENOMEM;
98 struct tomoyo_acl_info *entry;
Tetsuo Handaa238cf52011-06-26 23:17:10 +090099 struct list_head * const list = param->list;
Tetsuo Handa237ab452010-06-12 20:46:22 +0900100
Tetsuo Handa2066a362011-07-08 13:21:37 +0900101 if (param->data[0]) {
102 new_entry->cond = tomoyo_get_condition(param);
103 if (!new_entry->cond)
104 return -EINVAL;
Tetsuo Handa6bce98e2011-09-16 22:54:25 +0900105 /*
106 * Domain transition preference is allowed for only
107 * "file execute" entries.
108 */
109 if (new_entry->cond->transit &&
110 !(new_entry->type == TOMOYO_TYPE_PATH_ACL &&
111 container_of(new_entry, struct tomoyo_path_acl, head)
112 ->perm == 1 << TOMOYO_TYPE_EXECUTE))
113 goto out;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900114 }
Tetsuo Handa237ab452010-06-12 20:46:22 +0900115 if (mutex_lock_interruptible(&tomoyo_policy_lock))
Tetsuo Handa2066a362011-07-08 13:21:37 +0900116 goto out;
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900117 list_for_each_entry_rcu(entry, list, list) {
Tetsuo Handa0df7e8b2011-06-26 23:16:36 +0900118 if (!tomoyo_same_acl_head(entry, new_entry) ||
119 !check_duplicate(entry, new_entry))
Tetsuo Handa237ab452010-06-12 20:46:22 +0900120 continue;
121 if (merge_duplicate)
122 entry->is_deleted = merge_duplicate(entry, new_entry,
123 is_delete);
124 else
125 entry->is_deleted = is_delete;
126 error = 0;
127 break;
128 }
129 if (error && !is_delete) {
130 entry = tomoyo_commit_ok(new_entry, size);
131 if (entry) {
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900132 list_add_tail_rcu(&entry->list, list);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900133 error = 0;
134 }
135 }
136 mutex_unlock(&tomoyo_policy_lock);
Tetsuo Handa2066a362011-07-08 13:21:37 +0900137out:
138 tomoyo_put_condition(new_entry->cond);
Tetsuo Handa237ab452010-06-12 20:46:22 +0900139 return error;
140}
141
Tetsuo Handa32997142011-06-26 23:19:28 +0900142/**
143 * tomoyo_check_acl - Do permission check.
144 *
145 * @r: Pointer to "struct tomoyo_request_info".
146 * @check_entry: Callback function to check type specific parameters.
147 *
148 * Returns 0 on success, negative value otherwise.
149 *
150 * Caller holds tomoyo_read_lock().
151 */
Tetsuo Handa99a85252010-06-16 16:22:51 +0900152void tomoyo_check_acl(struct tomoyo_request_info *r,
Tetsuo Handa484ca792010-07-29 14:29:55 +0900153 bool (*check_entry) (struct tomoyo_request_info *,
Tetsuo Handa99a85252010-06-16 16:22:51 +0900154 const struct tomoyo_acl_info *))
155{
156 const struct tomoyo_domain_info *domain = r->domain;
157 struct tomoyo_acl_info *ptr;
Tetsuo Handa32997142011-06-26 23:19:28 +0900158 bool retried = false;
159 const struct list_head *list = &domain->acl_info_list;
Tetsuo Handa99a85252010-06-16 16:22:51 +0900160
Tetsuo Handa32997142011-06-26 23:19:28 +0900161retry:
162 list_for_each_entry_rcu(ptr, list, list) {
Tetsuo Handa99a85252010-06-16 16:22:51 +0900163 if (ptr->is_deleted || ptr->type != r->param_type)
164 continue;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900165 if (!check_entry(r, ptr))
166 continue;
167 if (!tomoyo_condition(r, ptr->cond))
168 continue;
Tetsuo Handa1f067a62011-09-10 15:24:56 +0900169 r->matched_acl = ptr;
Tetsuo Handa2066a362011-07-08 13:21:37 +0900170 r->granted = true;
171 return;
Tetsuo Handa99a85252010-06-16 16:22:51 +0900172 }
Tetsuo Handa32997142011-06-26 23:19:28 +0900173 if (!retried) {
174 retried = true;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900175 list = &domain->ns->acl_group[domain->group];
Tetsuo Handa32997142011-06-26 23:19:28 +0900176 goto retry;
177 }
Tetsuo Handa99a85252010-06-16 16:22:51 +0900178 r->granted = false;
179}
180
Tetsuo Handaa230f9e2010-06-17 16:53:24 +0900181/* The list for "struct tomoyo_domain_info". */
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900182LIST_HEAD(tomoyo_domain_list);
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900183
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900184/**
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900185 * tomoyo_last_word - Get last component of a domainname.
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900186 *
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900187 * @name: Domainname to check.
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900188 *
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900189 * Returns the last word of @domainname.
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900190 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900191static const char *tomoyo_last_word(const char *name)
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900192{
Tetsuo Handa0f2a55d2011-07-14 14:46:51 +0900193 const char *cp = strrchr(name, ' ');
194 if (cp)
195 return cp + 1;
196 return name;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900197}
198
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900199/**
200 * tomoyo_same_transition_control - Check for duplicated "struct tomoyo_transition_control" entry.
201 *
202 * @a: Pointer to "struct tomoyo_acl_head".
203 * @b: Pointer to "struct tomoyo_acl_head".
204 *
205 * Returns true if @a == @b, false otherwise.
206 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900207static bool tomoyo_same_transition_control(const struct tomoyo_acl_head *a,
208 const struct tomoyo_acl_head *b)
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900209{
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900210 const struct tomoyo_transition_control *p1 = container_of(a,
211 typeof(*p1),
212 head);
213 const struct tomoyo_transition_control *p2 = container_of(b,
214 typeof(*p2),
215 head);
216 return p1->type == p2->type && p1->is_last_name == p2->is_last_name
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900217 && p1->domainname == p2->domainname
218 && p1->program == p2->program;
219}
220
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900221/**
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900222 * tomoyo_write_transition_control - Write "struct tomoyo_transition_control" list.
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900223 *
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900224 * @param: Pointer to "struct tomoyo_acl_param".
225 * @type: Type of this entry.
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900226 *
227 * Returns 0 on success, negative value otherwise.
228 */
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900229int tomoyo_write_transition_control(struct tomoyo_acl_param *param,
230 const u8 type)
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900231{
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900232 struct tomoyo_transition_control e = { .type = type };
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900233 int error = param->is_delete ? -ENOENT : -ENOMEM;
234 char *program = param->data;
235 char *domainname = strstr(program, " from ");
236 if (domainname) {
237 *domainname = '\0';
238 domainname += 6;
239 } else if (type == TOMOYO_TRANSITION_CONTROL_NO_KEEP ||
240 type == TOMOYO_TRANSITION_CONTROL_KEEP) {
241 domainname = program;
242 program = NULL;
243 }
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900244 if (program && strcmp(program, "any")) {
Tetsuo Handa75093152010-06-16 16:23:55 +0900245 if (!tomoyo_correct_path(program))
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900246 return -EINVAL;
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900247 e.program = tomoyo_get_name(program);
248 if (!e.program)
Tetsuo Handaca0b7df2010-02-07 20:23:59 +0900249 goto out;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900250 }
Tetsuo Handa0d2171d2011-06-26 23:17:46 +0900251 if (domainname && strcmp(domainname, "any")) {
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900252 if (!tomoyo_correct_domain(domainname)) {
253 if (!tomoyo_correct_path(domainname))
254 goto out;
255 e.is_last_name = true;
256 }
257 e.domainname = tomoyo_get_name(domainname);
258 if (!e.domainname)
259 goto out;
260 }
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900261 param->list = &param->ns->policy_list[TOMOYO_ID_TRANSITION_CONTROL];
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900262 error = tomoyo_update_policy(&e.head, sizeof(e), param,
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900263 tomoyo_same_transition_control);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900264out:
Tetsuo Handa9e4b50e2010-05-06 12:40:02 +0900265 tomoyo_put_name(e.domainname);
266 tomoyo_put_name(e.program);
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900267 return error;
268}
269
270/**
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900271 * tomoyo_scan_transition - Try to find specific domain transition type.
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900272 *
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900273 * @list: Pointer to "struct list_head".
274 * @domainname: The name of current domain.
275 * @program: The name of requested program.
276 * @last_name: The last component of @domainname.
277 * @type: One of values in "enum tomoyo_transition_type".
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900278 *
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900279 * Returns true if found one, false otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900280 *
281 * Caller holds tomoyo_read_lock().
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900282 */
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900283static inline bool tomoyo_scan_transition
284(const struct list_head *list, const struct tomoyo_path_info *domainname,
285 const struct tomoyo_path_info *program, const char *last_name,
286 const enum tomoyo_transition_type type)
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900287{
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900288 const struct tomoyo_transition_control *ptr;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900289 list_for_each_entry_rcu(ptr, list, head.list) {
290 if (ptr->head.is_deleted || ptr->type != type)
291 continue;
292 if (ptr->domainname) {
293 if (!ptr->is_last_name) {
294 if (ptr->domainname != domainname)
295 continue;
296 } else {
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900297 /*
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900298 * Use direct strcmp() since this is
299 * unlikely used.
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900300 */
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900301 if (strcmp(ptr->domainname->name, last_name))
302 continue;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900303 }
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900304 }
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900305 if (ptr->program && tomoyo_pathcmp(ptr->program, program))
306 continue;
307 return true;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900308 }
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900309 return false;
310}
311
312/**
313 * tomoyo_transition_type - Get domain transition type.
314 *
315 * @ns: Pointer to "struct tomoyo_policy_namespace".
316 * @domainname: The name of current domain.
317 * @program: The name of requested program.
318 *
319 * Returns TOMOYO_TRANSITION_CONTROL_TRANSIT if executing @program causes
320 * domain transition across namespaces, TOMOYO_TRANSITION_CONTROL_INITIALIZE if
321 * executing @program reinitializes domain transition within that namespace,
322 * TOMOYO_TRANSITION_CONTROL_KEEP if executing @program stays at @domainname ,
323 * others otherwise.
324 *
325 * Caller holds tomoyo_read_lock().
326 */
327static enum tomoyo_transition_type tomoyo_transition_type
328(const struct tomoyo_policy_namespace *ns,
329 const struct tomoyo_path_info *domainname,
330 const struct tomoyo_path_info *program)
331{
332 const char *last_name = tomoyo_last_word(domainname->name);
333 enum tomoyo_transition_type type = TOMOYO_TRANSITION_CONTROL_NO_RESET;
334 while (type < TOMOYO_MAX_TRANSITION_TYPE) {
335 const struct list_head * const list =
336 &ns->policy_list[TOMOYO_ID_TRANSITION_CONTROL];
337 if (!tomoyo_scan_transition(list, domainname, program,
338 last_name, type)) {
339 type++;
340 continue;
341 }
342 if (type != TOMOYO_TRANSITION_CONTROL_NO_RESET &&
343 type != TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE)
344 break;
345 /*
346 * Do not check for reset_domain if no_reset_domain matched.
347 * Do not check for initialize_domain if no_initialize_domain
348 * matched.
349 */
350 type++;
351 type++;
352 }
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900353 return type;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900354}
355
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900356/**
357 * tomoyo_same_aggregator - Check for duplicated "struct tomoyo_aggregator" entry.
358 *
359 * @a: Pointer to "struct tomoyo_acl_head".
360 * @b: Pointer to "struct tomoyo_acl_head".
361 *
362 * Returns true if @a == @b, false otherwise.
363 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900364static bool tomoyo_same_aggregator(const struct tomoyo_acl_head *a,
365 const struct tomoyo_acl_head *b)
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900366{
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900367 const struct tomoyo_aggregator *p1 = container_of(a, typeof(*p1),
368 head);
369 const struct tomoyo_aggregator *p2 = container_of(b, typeof(*p2),
370 head);
Tetsuo Handa36f5e1f2010-06-15 09:23:26 +0900371 return p1->original_name == p2->original_name &&
372 p1->aggregated_name == p2->aggregated_name;
373}
374
Tetsuo Handa10843072010-06-03 20:38:03 +0900375/**
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900376 * tomoyo_write_aggregator - Write "struct tomoyo_aggregator" list.
Tetsuo Handa10843072010-06-03 20:38:03 +0900377 *
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900378 * @param: Pointer to "struct tomoyo_acl_param".
Tetsuo Handa10843072010-06-03 20:38:03 +0900379 *
380 * Returns 0 on success, negative value otherwise.
381 *
382 * Caller holds tomoyo_read_lock().
383 */
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900384int tomoyo_write_aggregator(struct tomoyo_acl_param *param)
Tetsuo Handa10843072010-06-03 20:38:03 +0900385{
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900386 struct tomoyo_aggregator e = { };
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900387 int error = param->is_delete ? -ENOENT : -ENOMEM;
388 const char *original_name = tomoyo_read_token(param);
389 const char *aggregated_name = tomoyo_read_token(param);
390 if (!tomoyo_correct_word(original_name) ||
Tetsuo Handa75093152010-06-16 16:23:55 +0900391 !tomoyo_correct_path(aggregated_name))
Tetsuo Handa10843072010-06-03 20:38:03 +0900392 return -EINVAL;
393 e.original_name = tomoyo_get_name(original_name);
394 e.aggregated_name = tomoyo_get_name(aggregated_name);
395 if (!e.original_name || !e.aggregated_name ||
396 e.aggregated_name->is_patterned) /* No patterns allowed. */
397 goto out;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900398 param->list = &param->ns->policy_list[TOMOYO_ID_AGGREGATOR];
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900399 error = tomoyo_update_policy(&e.head, sizeof(e), param,
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900400 tomoyo_same_aggregator);
Tetsuo Handaa238cf52011-06-26 23:17:10 +0900401out:
Tetsuo Handa10843072010-06-03 20:38:03 +0900402 tomoyo_put_name(e.original_name);
403 tomoyo_put_name(e.aggregated_name);
404 return error;
405}
406
407/**
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900408 * tomoyo_find_namespace - Find specified namespace.
409 *
410 * @name: Name of namespace to find.
411 * @len: Length of @name.
412 *
413 * Returns pointer to "struct tomoyo_policy_namespace" if found,
414 * NULL otherwise.
415 *
416 * Caller holds tomoyo_read_lock().
417 */
418static struct tomoyo_policy_namespace *tomoyo_find_namespace
419(const char *name, const unsigned int len)
420{
421 struct tomoyo_policy_namespace *ns;
422 list_for_each_entry(ns, &tomoyo_namespace_list, namespace_list) {
423 if (strncmp(name, ns->name, len) ||
424 (name[len] && name[len] != ' '))
425 continue;
426 return ns;
427 }
428 return NULL;
429}
430
431/**
432 * tomoyo_assign_namespace - Create a new namespace.
433 *
434 * @domainname: Name of namespace to create.
435 *
436 * Returns pointer to "struct tomoyo_policy_namespace" on success,
437 * NULL otherwise.
438 *
439 * Caller holds tomoyo_read_lock().
440 */
441struct tomoyo_policy_namespace *tomoyo_assign_namespace(const char *domainname)
442{
443 struct tomoyo_policy_namespace *ptr;
444 struct tomoyo_policy_namespace *entry;
445 const char *cp = domainname;
446 unsigned int len = 0;
447 while (*cp && *cp++ != ' ')
448 len++;
449 ptr = tomoyo_find_namespace(domainname, len);
450 if (ptr)
451 return ptr;
452 if (len >= TOMOYO_EXEC_TMPSIZE - 10 || !tomoyo_domain_def(domainname))
453 return NULL;
454 entry = kzalloc(sizeof(*entry) + len + 1, GFP_NOFS);
455 if (!entry)
456 return NULL;
457 if (mutex_lock_interruptible(&tomoyo_policy_lock))
458 goto out;
459 ptr = tomoyo_find_namespace(domainname, len);
460 if (!ptr && tomoyo_memory_ok(entry)) {
461 char *name = (char *) (entry + 1);
462 ptr = entry;
463 memmove(name, domainname, len);
464 name[len] = '\0';
465 entry->name = name;
466 tomoyo_init_policy_namespace(entry);
467 entry = NULL;
468 }
469 mutex_unlock(&tomoyo_policy_lock);
470out:
471 kfree(entry);
472 return ptr;
473}
474
475/**
476 * tomoyo_namespace_jump - Check for namespace jump.
477 *
478 * @domainname: Name of domain.
479 *
480 * Returns true if namespace differs, false otherwise.
481 */
482static bool tomoyo_namespace_jump(const char *domainname)
483{
484 const char *namespace = tomoyo_current_namespace()->name;
485 const int len = strlen(namespace);
486 return strncmp(domainname, namespace, len) ||
487 (domainname[len] && domainname[len] != ' ');
488}
489
490/**
491 * tomoyo_assign_domain - Create a domain or a namespace.
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900492 *
493 * @domainname: The name of domain.
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900494 * @transit: True if transit to domain found or created.
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900495 *
496 * Returns pointer to "struct tomoyo_domain_info" on success, NULL otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900497 *
498 * Caller holds tomoyo_read_lock().
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900499 */
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900500struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900501 const bool transit)
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900502{
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900503 struct tomoyo_domain_info e = { };
504 struct tomoyo_domain_info *entry = tomoyo_find_domain(domainname);
505 bool created = false;
506 if (entry) {
507 if (transit) {
508 /*
509 * Since namespace is created at runtime, profiles may
510 * not be created by the moment the process transits to
511 * that domain. Do not perform domain transition if
512 * profile for that domain is not yet created.
513 */
514 if (!entry->ns->profile_ptr[entry->profile])
515 return NULL;
516 }
517 return entry;
518 }
519 /* Requested domain does not exist. */
520 /* Don't create requested domain if domainname is invalid. */
521 if (strlen(domainname) >= TOMOYO_EXEC_TMPSIZE - 10 ||
522 !tomoyo_correct_domain(domainname))
Tetsuo Handaca0b7df2010-02-07 20:23:59 +0900523 return NULL;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900524 /*
525 * Since definition of profiles and acl_groups may differ across
526 * namespaces, do not inherit "use_profile" and "use_group" settings
527 * by automatically creating requested domain upon domain transition.
528 */
529 if (transit && tomoyo_namespace_jump(domainname))
Tetsuo Handaca0b7df2010-02-07 20:23:59 +0900530 return NULL;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900531 e.ns = tomoyo_assign_namespace(domainname);
532 if (!e.ns)
533 return NULL;
534 /*
535 * "use_profile" and "use_group" settings for automatically created
536 * domains are inherited from current domain. These are 0 for manually
537 * created domains.
538 */
539 if (transit) {
540 const struct tomoyo_domain_info *domain = tomoyo_domain();
541 e.profile = domain->profile;
542 e.group = domain->group;
543 }
544 e.domainname = tomoyo_get_name(domainname);
545 if (!e.domainname)
546 return NULL;
Tetsuo Handa29282382010-05-06 00:18:15 +0900547 if (mutex_lock_interruptible(&tomoyo_policy_lock))
548 goto out;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900549 entry = tomoyo_find_domain(domainname);
550 if (!entry) {
551 entry = tomoyo_commit_ok(&e, sizeof(e));
552 if (entry) {
553 INIT_LIST_HEAD(&entry->acl_info_list);
554 list_add_tail_rcu(&entry->list, &tomoyo_domain_list);
555 created = true;
556 }
Tetsuo Handaca0b7df2010-02-07 20:23:59 +0900557 }
Tetsuo Handaf737d952010-01-03 21:16:32 +0900558 mutex_unlock(&tomoyo_policy_lock);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900559out:
560 tomoyo_put_name(e.domainname);
561 if (entry && transit) {
562 if (created) {
563 struct tomoyo_request_info r;
564 tomoyo_init_request_info(&r, entry,
565 TOMOYO_MAC_FILE_EXECUTE);
566 r.granted = false;
567 tomoyo_write_log(&r, "use_profile %u\n",
568 entry->profile);
569 tomoyo_write_log(&r, "use_group %u\n", entry->group);
570 }
571 }
572 return entry;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900573}
574
575/**
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900576 * tomoyo_environ - Check permission for environment variable names.
577 *
578 * @ee: Pointer to "struct tomoyo_execve".
579 *
580 * Returns 0 on success, negative value otherwise.
581 */
582static int tomoyo_environ(struct tomoyo_execve *ee)
583{
584 struct tomoyo_request_info *r = &ee->r;
585 struct linux_binprm *bprm = ee->bprm;
586 /* env_page.data is allocated by tomoyo_dump_page(). */
587 struct tomoyo_page_dump env_page = { };
588 char *arg_ptr; /* Size is TOMOYO_EXEC_TMPSIZE bytes */
589 int arg_len = 0;
590 unsigned long pos = bprm->p;
591 int offset = pos % PAGE_SIZE;
592 int argv_count = bprm->argc;
593 int envp_count = bprm->envc;
594 int error = -ENOMEM;
595
596 ee->r.type = TOMOYO_MAC_ENVIRON;
597 ee->r.profile = r->domain->profile;
598 ee->r.mode = tomoyo_get_mode(r->domain->ns, ee->r.profile,
599 TOMOYO_MAC_ENVIRON);
600 if (!r->mode || !envp_count)
601 return 0;
602 arg_ptr = kzalloc(TOMOYO_EXEC_TMPSIZE, GFP_NOFS);
603 if (!arg_ptr)
604 goto out;
605 while (error == -ENOMEM) {
606 if (!tomoyo_dump_page(bprm, pos, &env_page))
607 goto out;
608 pos += PAGE_SIZE - offset;
609 /* Read. */
610 while (argv_count && offset < PAGE_SIZE) {
611 if (!env_page.data[offset++])
612 argv_count--;
613 }
614 if (argv_count) {
615 offset = 0;
616 continue;
617 }
618 while (offset < PAGE_SIZE) {
619 const unsigned char c = env_page.data[offset++];
620
621 if (c && arg_len < TOMOYO_EXEC_TMPSIZE - 10) {
622 if (c == '=') {
623 arg_ptr[arg_len++] = '\0';
624 } else if (c == '\\') {
625 arg_ptr[arg_len++] = '\\';
626 arg_ptr[arg_len++] = '\\';
627 } else if (c > ' ' && c < 127) {
628 arg_ptr[arg_len++] = c;
629 } else {
630 arg_ptr[arg_len++] = '\\';
631 arg_ptr[arg_len++] = (c >> 6) + '0';
632 arg_ptr[arg_len++]
633 = ((c >> 3) & 7) + '0';
634 arg_ptr[arg_len++] = (c & 7) + '0';
635 }
636 } else {
637 arg_ptr[arg_len] = '\0';
638 }
639 if (c)
640 continue;
641 if (tomoyo_env_perm(r, arg_ptr)) {
642 error = -EPERM;
643 break;
644 }
645 if (!--envp_count) {
646 error = 0;
647 break;
648 }
649 arg_len = 0;
650 }
651 offset = 0;
652 }
653out:
654 if (r->mode != TOMOYO_CONFIG_ENFORCING)
655 error = 0;
656 kfree(env_page.data);
657 kfree(arg_ptr);
658 return error;
659}
660
661/**
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900662 * tomoyo_find_next_domain - Find a domain.
663 *
Tetsuo Handa56f8c9bc2009-06-19 14:13:27 +0900664 * @bprm: Pointer to "struct linux_binprm".
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900665 *
666 * Returns 0 on success, negative value otherwise.
Tetsuo Handafdb8ebb2009-12-08 09:34:43 +0900667 *
668 * Caller holds tomoyo_read_lock().
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900669 */
Tetsuo Handa56f8c9bc2009-06-19 14:13:27 +0900670int tomoyo_find_next_domain(struct linux_binprm *bprm)
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900671{
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900672 struct tomoyo_domain_info *old_domain = tomoyo_domain();
673 struct tomoyo_domain_info *domain = NULL;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900674 const char *original_name = bprm->filename;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900675 int retval = -ENOMEM;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900676 bool reject_on_transition_failure = false;
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900677 const struct tomoyo_path_info *candidate;
678 struct tomoyo_path_info exename;
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900679 struct tomoyo_execve *ee = kzalloc(sizeof(*ee), GFP_NOFS);
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900680
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900681 if (!ee)
682 return -ENOMEM;
683 ee->tmp = kzalloc(TOMOYO_EXEC_TMPSIZE, GFP_NOFS);
684 if (!ee->tmp) {
685 kfree(ee);
686 return -ENOMEM;
687 }
688 /* ee->dump->data is allocated by tomoyo_dump_page(). */
689 tomoyo_init_request_info(&ee->r, NULL, TOMOYO_MAC_FILE_EXECUTE);
690 ee->r.ee = ee;
691 ee->bprm = bprm;
692 ee->r.obj = &ee->obj;
693 ee->obj.path1 = bprm->file->f_path;
Tetsuo Handa0617c7f2010-06-21 09:58:53 +0900694 /* Get symlink's pathname of program. */
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900695 retval = -ENOENT;
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900696 exename.name = tomoyo_realpath_nofollow(original_name);
697 if (!exename.name)
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900698 goto out;
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900699 tomoyo_fill_path_info(&exename);
700retry:
Tetsuo Handa10843072010-06-03 20:38:03 +0900701 /* Check 'aggregator' directive. */
702 {
Tetsuo Handae2bf6902010-06-25 11:16:00 +0900703 struct tomoyo_aggregator *ptr;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900704 struct list_head *list =
705 &old_domain->ns->policy_list[TOMOYO_ID_AGGREGATOR];
706 /* Check 'aggregator' directive. */
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900707 candidate = &exename;
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900708 list_for_each_entry_rcu(ptr, list, head.list) {
Tetsuo Handa82e0f002010-06-15 09:22:42 +0900709 if (ptr->head.is_deleted ||
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900710 !tomoyo_path_matches_pattern(&exename,
Tetsuo Handa10843072010-06-03 20:38:03 +0900711 ptr->original_name))
712 continue;
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900713 candidate = ptr->aggregated_name;
Tetsuo Handa10843072010-06-03 20:38:03 +0900714 break;
715 }
716 }
717
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900718 /* Check execute permission. */
Tetsuo Handa6bce98e2011-09-16 22:54:25 +0900719 retval = tomoyo_execute_permission(&ee->r, candidate);
Tetsuo Handa17fcfbd2010-05-17 10:11:36 +0900720 if (retval == TOMOYO_RETRY_REQUEST)
721 goto retry;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900722 if (retval < 0)
723 goto out;
Tetsuo Handa484ca792010-07-29 14:29:55 +0900724 /*
725 * To be able to specify domainnames with wildcards, use the
726 * pathname specified in the policy (which may contain
727 * wildcard) rather than the pathname passed to execve()
728 * (which never contains wildcard).
729 */
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900730 if (ee->r.param.path.matched_path)
731 candidate = ee->r.param.path.matched_path;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900732
Tetsuo Handa6bce98e2011-09-16 22:54:25 +0900733 /*
734 * Check for domain transition preference if "file execute" matched.
735 * If preference is given, make do_execve() fail if domain transition
736 * has failed, for domain transition preference should be used with
737 * destination domain defined.
738 */
739 if (ee->transition) {
740 const char *domainname = ee->transition->name;
741 reject_on_transition_failure = true;
742 if (!strcmp(domainname, "keep"))
743 goto force_keep_domain;
744 if (!strcmp(domainname, "child"))
745 goto force_child_domain;
746 if (!strcmp(domainname, "reset"))
747 goto force_reset_domain;
748 if (!strcmp(domainname, "initialize"))
749 goto force_initialize_domain;
750 if (!strcmp(domainname, "parent")) {
751 char *cp;
752 strncpy(ee->tmp, old_domain->domainname->name,
753 TOMOYO_EXEC_TMPSIZE - 1);
754 cp = strrchr(ee->tmp, ' ');
755 if (cp)
756 *cp = '\0';
757 } else if (*domainname == '<')
758 strncpy(ee->tmp, domainname, TOMOYO_EXEC_TMPSIZE - 1);
759 else
760 snprintf(ee->tmp, TOMOYO_EXEC_TMPSIZE - 1, "%s %s",
761 old_domain->domainname->name, domainname);
762 goto force_jump_domain;
763 }
764 /*
765 * No domain transition preference specified.
766 * Calculate domain to transit to.
767 */
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900768 switch (tomoyo_transition_type(old_domain->ns, old_domain->domainname,
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900769 candidate)) {
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900770 case TOMOYO_TRANSITION_CONTROL_RESET:
Tetsuo Handa6bce98e2011-09-16 22:54:25 +0900771force_reset_domain:
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900772 /* Transit to the root of specified namespace. */
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900773 snprintf(ee->tmp, TOMOYO_EXEC_TMPSIZE - 1, "<%s>",
774 candidate->name);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900775 /*
776 * Make do_execve() fail if domain transition across namespaces
777 * has failed.
778 */
779 reject_on_transition_failure = true;
780 break;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900781 case TOMOYO_TRANSITION_CONTROL_INITIALIZE:
Tetsuo Handa6bce98e2011-09-16 22:54:25 +0900782force_initialize_domain:
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900783 /* Transit to the child of current namespace's root. */
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900784 snprintf(ee->tmp, TOMOYO_EXEC_TMPSIZE - 1, "%s %s",
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900785 old_domain->ns->name, candidate->name);
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900786 break;
787 case TOMOYO_TRANSITION_CONTROL_KEEP:
Tetsuo Handa6bce98e2011-09-16 22:54:25 +0900788force_keep_domain:
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900789 /* Keep current domain. */
790 domain = old_domain;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900791 break;
792 default:
793 if (old_domain == &tomoyo_kernel_domain &&
794 !tomoyo_policy_loaded) {
795 /*
796 * Needn't to transit from kernel domain before
797 * starting /sbin/init. But transit from kernel domain
798 * if executing initializers because they might start
799 * before /sbin/init.
800 */
801 domain = old_domain;
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900802 break;
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900803 }
Tetsuo Handa6bce98e2011-09-16 22:54:25 +0900804force_child_domain:
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900805 /* Normal domain transition. */
806 snprintf(ee->tmp, TOMOYO_EXEC_TMPSIZE - 1, "%s %s",
807 old_domain->domainname->name, candidate->name);
Tetsuo Handa5448ec42010-06-21 11:14:39 +0900808 break;
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900809 }
Tetsuo Handa6bce98e2011-09-16 22:54:25 +0900810force_jump_domain:
Tetsuo Handa7c759642011-06-26 23:15:31 +0900811 if (!domain)
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900812 domain = tomoyo_assign_domain(ee->tmp, true);
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900813 if (domain)
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900814 retval = 0;
815 else if (reject_on_transition_failure) {
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900816 printk(KERN_WARNING "ERROR: Domain '%s' not ready.\n",
817 ee->tmp);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900818 retval = -ENOMEM;
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900819 } else if (ee->r.mode == TOMOYO_CONFIG_ENFORCING)
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900820 retval = -ENOMEM;
821 else {
822 retval = 0;
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900823 if (!old_domain->flags[TOMOYO_DIF_TRANSITION_FAILED]) {
824 old_domain->flags[TOMOYO_DIF_TRANSITION_FAILED] = true;
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900825 ee->r.granted = false;
826 tomoyo_write_log(&ee->r, "%s", tomoyo_dif
Tetsuo Handa2c47ab92011-06-26 23:21:19 +0900827 [TOMOYO_DIF_TRANSITION_FAILED]);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900828 printk(KERN_WARNING
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900829 "ERROR: Domain '%s' not defined.\n", ee->tmp);
Tetsuo Handabd03a3e2011-06-26 23:19:52 +0900830 }
831 }
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900832 out:
Tetsuo Handa56f8c9bc2009-06-19 14:13:27 +0900833 if (!domain)
834 domain = old_domain;
Tetsuo Handaec8e6a42010-02-11 09:43:20 +0900835 /* Update reference count on "struct tomoyo_domain_info". */
836 atomic_inc(&domain->users);
Tetsuo Handa56f8c9bc2009-06-19 14:13:27 +0900837 bprm->cred->security = domain;
Tetsuo Handaa8f76402011-09-10 15:27:12 +0900838 kfree(exename.name);
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900839 if (!retval) {
840 ee->r.domain = domain;
841 retval = tomoyo_environ(ee);
842 }
Tetsuo Handa97fb35e2011-07-08 13:25:53 +0900843 kfree(ee->tmp);
844 kfree(ee->dump.data);
845 kfree(ee);
Kentaro Takeda26a2a1c2009-02-05 17:18:15 +0900846 return retval;
847}
Tetsuo Handa5b636852011-07-08 13:24:54 +0900848
849/**
850 * tomoyo_dump_page - Dump a page to buffer.
851 *
852 * @bprm: Pointer to "struct linux_binprm".
853 * @pos: Location to dump.
854 * @dump: Poiner to "struct tomoyo_page_dump".
855 *
856 * Returns true on success, false otherwise.
857 */
858bool tomoyo_dump_page(struct linux_binprm *bprm, unsigned long pos,
859 struct tomoyo_page_dump *dump)
860{
861 struct page *page;
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900862
863 /* dump->data is released by tomoyo_find_next_domain(). */
Tetsuo Handa5b636852011-07-08 13:24:54 +0900864 if (!dump->data) {
865 dump->data = kzalloc(PAGE_SIZE, GFP_NOFS);
866 if (!dump->data)
867 return false;
868 }
869 /* Same with get_arg_page(bprm, pos, 0) in fs/exec.c */
870#ifdef CONFIG_MMU
871 if (get_user_pages(current, bprm->mm, pos, 1, 0, 1, &page, NULL) <= 0)
872 return false;
873#else
874 page = bprm->page[pos / PAGE_SIZE];
875#endif
876 if (page != dump->page) {
877 const unsigned int offset = pos % PAGE_SIZE;
878 /*
879 * Maybe kmap()/kunmap() should be used here.
880 * But remove_arg_zero() uses kmap_atomic()/kunmap_atomic().
881 * So do I.
882 */
883 char *kaddr = kmap_atomic(page, KM_USER0);
Tetsuo Handad58e0da2011-09-10 15:22:48 +0900884
Tetsuo Handa5b636852011-07-08 13:24:54 +0900885 dump->page = page;
886 memcpy(dump->data + offset, kaddr + offset,
887 PAGE_SIZE - offset);
888 kunmap_atomic(kaddr, KM_USER0);
889 }
890 /* Same with put_arg_page(page) in fs/exec.c */
891#ifdef CONFIG_MMU
892 put_page(page);
893#endif
894 return true;
895}