2 * security/tomoyo/domain.c
4 * Copyright (C) 2005-2011 NTT DATA CORPORATION
8 #include <linux/binfmts.h>
9 #include <linux/slab.h>
11 /* Variables definitions.*/
13 /* The initial domain. */
14 struct tomoyo_domain_info tomoyo_kernel_domain
;
17 * tomoyo_update_policy - Update an entry for exception policy.
19 * @new_entry: Pointer to "struct tomoyo_acl_info".
20 * @size: Size of @new_entry in bytes.
21 * @param: Pointer to "struct tomoyo_acl_param".
22 * @check_duplicate: Callback function to find duplicated entry.
24 * Returns 0 on success, negative value otherwise.
26 * Caller holds tomoyo_read_lock().
28 int tomoyo_update_policy(struct tomoyo_acl_head
*new_entry
, const int size
,
29 struct tomoyo_acl_param
*param
,
30 bool (*check_duplicate
) (const struct tomoyo_acl_head
32 const struct tomoyo_acl_head
35 int error
= param
->is_delete
? -ENOENT
: -ENOMEM
;
36 struct tomoyo_acl_head
*entry
;
37 struct list_head
*list
= param
->list
;
39 if (mutex_lock_interruptible(&tomoyo_policy_lock
))
41 list_for_each_entry_rcu(entry
, list
, list
) {
42 if (!check_duplicate(entry
, new_entry
))
44 entry
->is_deleted
= param
->is_delete
;
48 if (error
&& !param
->is_delete
) {
49 entry
= tomoyo_commit_ok(new_entry
, size
);
51 list_add_tail_rcu(&entry
->list
, list
);
55 mutex_unlock(&tomoyo_policy_lock
);
60 * tomoyo_same_acl_head - Check for duplicated "struct tomoyo_acl_info" entry.
62 * @a: Pointer to "struct tomoyo_acl_info".
63 * @b: Pointer to "struct tomoyo_acl_info".
65 * Returns true if @a == @b, false otherwise.
67 static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info
*a
,
68 const struct tomoyo_acl_info
*b
)
70 return a
->type
== b
->type
&& a
->cond
== b
->cond
;
74 * tomoyo_update_domain - Update an entry for domain policy.
76 * @new_entry: Pointer to "struct tomoyo_acl_info".
77 * @size: Size of @new_entry in bytes.
78 * @param: Pointer to "struct tomoyo_acl_param".
79 * @check_duplicate: Callback function to find duplicated entry.
80 * @merge_duplicate: Callback function to merge duplicated entry.
82 * Returns 0 on success, negative value otherwise.
84 * Caller holds tomoyo_read_lock().
86 int tomoyo_update_domain(struct tomoyo_acl_info
*new_entry
, const int size
,
87 struct tomoyo_acl_param
*param
,
88 bool (*check_duplicate
) (const struct tomoyo_acl_info
90 const struct tomoyo_acl_info
92 bool (*merge_duplicate
) (struct tomoyo_acl_info
*,
93 struct tomoyo_acl_info
*,
96 const bool is_delete
= param
->is_delete
;
97 int error
= is_delete
? -ENOENT
: -ENOMEM
;
98 struct tomoyo_acl_info
*entry
;
99 struct list_head
* const list
= param
->list
;
101 if (param
->data
[0]) {
102 new_entry
->cond
= tomoyo_get_condition(param
);
103 if (!new_entry
->cond
)
106 if (mutex_lock_interruptible(&tomoyo_policy_lock
))
108 list_for_each_entry_rcu(entry
, list
, list
) {
109 if (!tomoyo_same_acl_head(entry
, new_entry
) ||
110 !check_duplicate(entry
, new_entry
))
113 entry
->is_deleted
= merge_duplicate(entry
, new_entry
,
116 entry
->is_deleted
= is_delete
;
120 if (error
&& !is_delete
) {
121 entry
= tomoyo_commit_ok(new_entry
, size
);
123 list_add_tail_rcu(&entry
->list
, list
);
127 mutex_unlock(&tomoyo_policy_lock
);
129 tomoyo_put_condition(new_entry
->cond
);
134 * tomoyo_check_acl - Do permission check.
136 * @r: Pointer to "struct tomoyo_request_info".
137 * @check_entry: Callback function to check type specific parameters.
139 * Returns 0 on success, negative value otherwise.
141 * Caller holds tomoyo_read_lock().
143 void tomoyo_check_acl(struct tomoyo_request_info
*r
,
144 bool (*check_entry
) (struct tomoyo_request_info
*,
145 const struct tomoyo_acl_info
*))
147 const struct tomoyo_domain_info
*domain
= r
->domain
;
148 struct tomoyo_acl_info
*ptr
;
149 bool retried
= false;
150 const struct list_head
*list
= &domain
->acl_info_list
;
153 list_for_each_entry_rcu(ptr
, list
, list
) {
154 if (ptr
->is_deleted
|| ptr
->type
!= r
->param_type
)
156 if (!check_entry(r
, ptr
))
158 if (!tomoyo_condition(r
, ptr
->cond
))
165 list
= &domain
->ns
->acl_group
[domain
->group
];
171 /* The list for "struct tomoyo_domain_info". */
172 LIST_HEAD(tomoyo_domain_list
);
175 * tomoyo_last_word - Get last component of a domainname.
177 * @name: Domainname to check.
179 * Returns the last word of @domainname.
181 static const char *tomoyo_last_word(const char *name
)
183 const char *cp
= strrchr(name
, ' ');
190 * tomoyo_same_transition_control - Check for duplicated "struct tomoyo_transition_control" entry.
192 * @a: Pointer to "struct tomoyo_acl_head".
193 * @b: Pointer to "struct tomoyo_acl_head".
195 * Returns true if @a == @b, false otherwise.
197 static bool tomoyo_same_transition_control(const struct tomoyo_acl_head
*a
,
198 const struct tomoyo_acl_head
*b
)
200 const struct tomoyo_transition_control
*p1
= container_of(a
,
203 const struct tomoyo_transition_control
*p2
= container_of(b
,
206 return p1
->type
== p2
->type
&& p1
->is_last_name
== p2
->is_last_name
207 && p1
->domainname
== p2
->domainname
208 && p1
->program
== p2
->program
;
212 * tomoyo_write_transition_control - Write "struct tomoyo_transition_control" list.
214 * @param: Pointer to "struct tomoyo_acl_param".
215 * @type: Type of this entry.
217 * Returns 0 on success, negative value otherwise.
219 int tomoyo_write_transition_control(struct tomoyo_acl_param
*param
,
222 struct tomoyo_transition_control e
= { .type
= type
};
223 int error
= param
->is_delete
? -ENOENT
: -ENOMEM
;
224 char *program
= param
->data
;
225 char *domainname
= strstr(program
, " from ");
229 } else if (type
== TOMOYO_TRANSITION_CONTROL_NO_KEEP
||
230 type
== TOMOYO_TRANSITION_CONTROL_KEEP
) {
231 domainname
= program
;
234 if (program
&& strcmp(program
, "any")) {
235 if (!tomoyo_correct_path(program
))
237 e
.program
= tomoyo_get_name(program
);
241 if (domainname
&& strcmp(domainname
, "any")) {
242 if (!tomoyo_correct_domain(domainname
)) {
243 if (!tomoyo_correct_path(domainname
))
245 e
.is_last_name
= true;
247 e
.domainname
= tomoyo_get_name(domainname
);
251 param
->list
= ¶m
->ns
->policy_list
[TOMOYO_ID_TRANSITION_CONTROL
];
252 error
= tomoyo_update_policy(&e
.head
, sizeof(e
), param
,
253 tomoyo_same_transition_control
);
255 tomoyo_put_name(e
.domainname
);
256 tomoyo_put_name(e
.program
);
261 * tomoyo_scan_transition - Try to find specific domain transition type.
263 * @list: Pointer to "struct list_head".
264 * @domainname: The name of current domain.
265 * @program: The name of requested program.
266 * @last_name: The last component of @domainname.
267 * @type: One of values in "enum tomoyo_transition_type".
269 * Returns true if found one, false otherwise.
271 * Caller holds tomoyo_read_lock().
273 static inline bool tomoyo_scan_transition
274 (const struct list_head
*list
, const struct tomoyo_path_info
*domainname
,
275 const struct tomoyo_path_info
*program
, const char *last_name
,
276 const enum tomoyo_transition_type type
)
278 const struct tomoyo_transition_control
*ptr
;
279 list_for_each_entry_rcu(ptr
, list
, head
.list
) {
280 if (ptr
->head
.is_deleted
|| ptr
->type
!= type
)
282 if (ptr
->domainname
) {
283 if (!ptr
->is_last_name
) {
284 if (ptr
->domainname
!= domainname
)
288 * Use direct strcmp() since this is
291 if (strcmp(ptr
->domainname
->name
, last_name
))
295 if (ptr
->program
&& tomoyo_pathcmp(ptr
->program
, program
))
303 * tomoyo_transition_type - Get domain transition type.
305 * @ns: Pointer to "struct tomoyo_policy_namespace".
306 * @domainname: The name of current domain.
307 * @program: The name of requested program.
309 * Returns TOMOYO_TRANSITION_CONTROL_TRANSIT if executing @program causes
310 * domain transition across namespaces, TOMOYO_TRANSITION_CONTROL_INITIALIZE if
311 * executing @program reinitializes domain transition within that namespace,
312 * TOMOYO_TRANSITION_CONTROL_KEEP if executing @program stays at @domainname ,
315 * Caller holds tomoyo_read_lock().
317 static enum tomoyo_transition_type tomoyo_transition_type
318 (const struct tomoyo_policy_namespace
*ns
,
319 const struct tomoyo_path_info
*domainname
,
320 const struct tomoyo_path_info
*program
)
322 const char *last_name
= tomoyo_last_word(domainname
->name
);
323 enum tomoyo_transition_type type
= TOMOYO_TRANSITION_CONTROL_NO_RESET
;
324 while (type
< TOMOYO_MAX_TRANSITION_TYPE
) {
325 const struct list_head
* const list
=
326 &ns
->policy_list
[TOMOYO_ID_TRANSITION_CONTROL
];
327 if (!tomoyo_scan_transition(list
, domainname
, program
,
332 if (type
!= TOMOYO_TRANSITION_CONTROL_NO_RESET
&&
333 type
!= TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE
)
336 * Do not check for reset_domain if no_reset_domain matched.
337 * Do not check for initialize_domain if no_initialize_domain
347 * tomoyo_same_aggregator - Check for duplicated "struct tomoyo_aggregator" entry.
349 * @a: Pointer to "struct tomoyo_acl_head".
350 * @b: Pointer to "struct tomoyo_acl_head".
352 * Returns true if @a == @b, false otherwise.
354 static bool tomoyo_same_aggregator(const struct tomoyo_acl_head
*a
,
355 const struct tomoyo_acl_head
*b
)
357 const struct tomoyo_aggregator
*p1
= container_of(a
, typeof(*p1
),
359 const struct tomoyo_aggregator
*p2
= container_of(b
, typeof(*p2
),
361 return p1
->original_name
== p2
->original_name
&&
362 p1
->aggregated_name
== p2
->aggregated_name
;
366 * tomoyo_write_aggregator - Write "struct tomoyo_aggregator" list.
368 * @param: Pointer to "struct tomoyo_acl_param".
370 * Returns 0 on success, negative value otherwise.
372 * Caller holds tomoyo_read_lock().
374 int tomoyo_write_aggregator(struct tomoyo_acl_param
*param
)
376 struct tomoyo_aggregator e
= { };
377 int error
= param
->is_delete
? -ENOENT
: -ENOMEM
;
378 const char *original_name
= tomoyo_read_token(param
);
379 const char *aggregated_name
= tomoyo_read_token(param
);
380 if (!tomoyo_correct_word(original_name
) ||
381 !tomoyo_correct_path(aggregated_name
))
383 e
.original_name
= tomoyo_get_name(original_name
);
384 e
.aggregated_name
= tomoyo_get_name(aggregated_name
);
385 if (!e
.original_name
|| !e
.aggregated_name
||
386 e
.aggregated_name
->is_patterned
) /* No patterns allowed. */
388 param
->list
= ¶m
->ns
->policy_list
[TOMOYO_ID_AGGREGATOR
];
389 error
= tomoyo_update_policy(&e
.head
, sizeof(e
), param
,
390 tomoyo_same_aggregator
);
392 tomoyo_put_name(e
.original_name
);
393 tomoyo_put_name(e
.aggregated_name
);
398 * tomoyo_find_namespace - Find specified namespace.
400 * @name: Name of namespace to find.
401 * @len: Length of @name.
403 * Returns pointer to "struct tomoyo_policy_namespace" if found,
406 * Caller holds tomoyo_read_lock().
408 static struct tomoyo_policy_namespace
*tomoyo_find_namespace
409 (const char *name
, const unsigned int len
)
411 struct tomoyo_policy_namespace
*ns
;
412 list_for_each_entry(ns
, &tomoyo_namespace_list
, namespace_list
) {
413 if (strncmp(name
, ns
->name
, len
) ||
414 (name
[len
] && name
[len
] != ' '))
422 * tomoyo_assign_namespace - Create a new namespace.
424 * @domainname: Name of namespace to create.
426 * Returns pointer to "struct tomoyo_policy_namespace" on success,
429 * Caller holds tomoyo_read_lock().
431 struct tomoyo_policy_namespace
*tomoyo_assign_namespace(const char *domainname
)
433 struct tomoyo_policy_namespace
*ptr
;
434 struct tomoyo_policy_namespace
*entry
;
435 const char *cp
= domainname
;
436 unsigned int len
= 0;
437 while (*cp
&& *cp
++ != ' ')
439 ptr
= tomoyo_find_namespace(domainname
, len
);
442 if (len
>= TOMOYO_EXEC_TMPSIZE
- 10 || !tomoyo_domain_def(domainname
))
444 entry
= kzalloc(sizeof(*entry
) + len
+ 1, GFP_NOFS
);
447 if (mutex_lock_interruptible(&tomoyo_policy_lock
))
449 ptr
= tomoyo_find_namespace(domainname
, len
);
450 if (!ptr
&& tomoyo_memory_ok(entry
)) {
451 char *name
= (char *) (entry
+ 1);
453 memmove(name
, domainname
, len
);
456 tomoyo_init_policy_namespace(entry
);
459 mutex_unlock(&tomoyo_policy_lock
);
466 * tomoyo_namespace_jump - Check for namespace jump.
468 * @domainname: Name of domain.
470 * Returns true if namespace differs, false otherwise.
472 static bool tomoyo_namespace_jump(const char *domainname
)
474 const char *namespace = tomoyo_current_namespace()->name
;
475 const int len
= strlen(namespace);
476 return strncmp(domainname
, namespace, len
) ||
477 (domainname
[len
] && domainname
[len
] != ' ');
481 * tomoyo_assign_domain - Create a domain or a namespace.
483 * @domainname: The name of domain.
484 * @transit: True if transit to domain found or created.
486 * Returns pointer to "struct tomoyo_domain_info" on success, NULL otherwise.
488 * Caller holds tomoyo_read_lock().
490 struct tomoyo_domain_info
*tomoyo_assign_domain(const char *domainname
,
493 struct tomoyo_domain_info e
= { };
494 struct tomoyo_domain_info
*entry
= tomoyo_find_domain(domainname
);
495 bool created
= false;
499 * Since namespace is created at runtime, profiles may
500 * not be created by the moment the process transits to
501 * that domain. Do not perform domain transition if
502 * profile for that domain is not yet created.
504 if (!entry
->ns
->profile_ptr
[entry
->profile
])
509 /* Requested domain does not exist. */
510 /* Don't create requested domain if domainname is invalid. */
511 if (strlen(domainname
) >= TOMOYO_EXEC_TMPSIZE
- 10 ||
512 !tomoyo_correct_domain(domainname
))
515 * Since definition of profiles and acl_groups may differ across
516 * namespaces, do not inherit "use_profile" and "use_group" settings
517 * by automatically creating requested domain upon domain transition.
519 if (transit
&& tomoyo_namespace_jump(domainname
))
521 e
.ns
= tomoyo_assign_namespace(domainname
);
525 * "use_profile" and "use_group" settings for automatically created
526 * domains are inherited from current domain. These are 0 for manually
530 const struct tomoyo_domain_info
*domain
= tomoyo_domain();
531 e
.profile
= domain
->profile
;
532 e
.group
= domain
->group
;
534 e
.domainname
= tomoyo_get_name(domainname
);
537 if (mutex_lock_interruptible(&tomoyo_policy_lock
))
539 entry
= tomoyo_find_domain(domainname
);
541 entry
= tomoyo_commit_ok(&e
, sizeof(e
));
543 INIT_LIST_HEAD(&entry
->acl_info_list
);
544 list_add_tail_rcu(&entry
->list
, &tomoyo_domain_list
);
548 mutex_unlock(&tomoyo_policy_lock
);
550 tomoyo_put_name(e
.domainname
);
551 if (entry
&& transit
) {
553 struct tomoyo_request_info r
;
554 tomoyo_init_request_info(&r
, entry
,
555 TOMOYO_MAC_FILE_EXECUTE
);
557 tomoyo_write_log(&r
, "use_profile %u\n",
559 tomoyo_write_log(&r
, "use_group %u\n", entry
->group
);
566 * tomoyo_environ - Check permission for environment variable names.
568 * @ee: Pointer to "struct tomoyo_execve".
570 * Returns 0 on success, negative value otherwise.
572 static int tomoyo_environ(struct tomoyo_execve
*ee
)
574 struct tomoyo_request_info
*r
= &ee
->r
;
575 struct linux_binprm
*bprm
= ee
->bprm
;
576 /* env_page.data is allocated by tomoyo_dump_page(). */
577 struct tomoyo_page_dump env_page
= { };
578 char *arg_ptr
; /* Size is TOMOYO_EXEC_TMPSIZE bytes */
580 unsigned long pos
= bprm
->p
;
581 int offset
= pos
% PAGE_SIZE
;
582 int argv_count
= bprm
->argc
;
583 int envp_count
= bprm
->envc
;
586 ee
->r
.type
= TOMOYO_MAC_ENVIRON
;
587 ee
->r
.profile
= r
->domain
->profile
;
588 ee
->r
.mode
= tomoyo_get_mode(r
->domain
->ns
, ee
->r
.profile
,
590 if (!r
->mode
|| !envp_count
)
592 arg_ptr
= kzalloc(TOMOYO_EXEC_TMPSIZE
, GFP_NOFS
);
595 while (error
== -ENOMEM
) {
596 if (!tomoyo_dump_page(bprm
, pos
, &env_page
))
598 pos
+= PAGE_SIZE
- offset
;
600 while (argv_count
&& offset
< PAGE_SIZE
) {
601 if (!env_page
.data
[offset
++])
608 while (offset
< PAGE_SIZE
) {
609 const unsigned char c
= env_page
.data
[offset
++];
611 if (c
&& arg_len
< TOMOYO_EXEC_TMPSIZE
- 10) {
613 arg_ptr
[arg_len
++] = '\0';
614 } else if (c
== '\\') {
615 arg_ptr
[arg_len
++] = '\\';
616 arg_ptr
[arg_len
++] = '\\';
617 } else if (c
> ' ' && c
< 127) {
618 arg_ptr
[arg_len
++] = c
;
620 arg_ptr
[arg_len
++] = '\\';
621 arg_ptr
[arg_len
++] = (c
>> 6) + '0';
623 = ((c
>> 3) & 7) + '0';
624 arg_ptr
[arg_len
++] = (c
& 7) + '0';
627 arg_ptr
[arg_len
] = '\0';
631 if (tomoyo_env_perm(r
, arg_ptr
)) {
644 if (r
->mode
!= TOMOYO_CONFIG_ENFORCING
)
646 kfree(env_page
.data
);
652 * tomoyo_find_next_domain - Find a domain.
654 * @bprm: Pointer to "struct linux_binprm".
656 * Returns 0 on success, negative value otherwise.
658 * Caller holds tomoyo_read_lock().
660 int tomoyo_find_next_domain(struct linux_binprm
*bprm
)
662 struct tomoyo_domain_info
*old_domain
= tomoyo_domain();
663 struct tomoyo_domain_info
*domain
= NULL
;
664 const char *original_name
= bprm
->filename
;
665 int retval
= -ENOMEM
;
666 bool need_kfree
= false;
667 bool reject_on_transition_failure
= false;
668 struct tomoyo_path_info rn
= { }; /* real name */
669 struct tomoyo_execve
*ee
= kzalloc(sizeof(*ee
), GFP_NOFS
);
673 ee
->tmp
= kzalloc(TOMOYO_EXEC_TMPSIZE
, GFP_NOFS
);
678 /* ee->dump->data is allocated by tomoyo_dump_page(). */
679 tomoyo_init_request_info(&ee
->r
, NULL
, TOMOYO_MAC_FILE_EXECUTE
);
682 ee
->r
.obj
= &ee
->obj
;
683 ee
->obj
.path1
= bprm
->file
->f_path
;
689 /* Get symlink's pathname of program. */
691 rn
.name
= tomoyo_realpath_nofollow(original_name
);
694 tomoyo_fill_path_info(&rn
);
697 /* Check 'aggregator' directive. */
699 struct tomoyo_aggregator
*ptr
;
700 struct list_head
*list
=
701 &old_domain
->ns
->policy_list
[TOMOYO_ID_AGGREGATOR
];
702 /* Check 'aggregator' directive. */
703 list_for_each_entry_rcu(ptr
, list
, head
.list
) {
704 if (ptr
->head
.is_deleted
||
705 !tomoyo_path_matches_pattern(&rn
,
710 /* This is OK because it is read only. */
711 rn
= *ptr
->aggregated_name
;
716 /* Check execute permission. */
717 retval
= tomoyo_path_permission(&ee
->r
, TOMOYO_TYPE_EXECUTE
, &rn
);
718 if (retval
== TOMOYO_RETRY_REQUEST
)
723 * To be able to specify domainnames with wildcards, use the
724 * pathname specified in the policy (which may contain
725 * wildcard) rather than the pathname passed to execve()
726 * (which never contains wildcard).
728 if (ee
->r
.param
.path
.matched_path
) {
732 /* This is OK because it is read only. */
733 rn
= *ee
->r
.param
.path
.matched_path
;
736 /* Calculate domain to transit to. */
737 switch (tomoyo_transition_type(old_domain
->ns
, old_domain
->domainname
,
739 case TOMOYO_TRANSITION_CONTROL_RESET
:
740 /* Transit to the root of specified namespace. */
741 snprintf(ee
->tmp
, TOMOYO_EXEC_TMPSIZE
- 1, "<%s>", rn
.name
);
743 * Make do_execve() fail if domain transition across namespaces
746 reject_on_transition_failure
= true;
748 case TOMOYO_TRANSITION_CONTROL_INITIALIZE
:
749 /* Transit to the child of current namespace's root. */
750 snprintf(ee
->tmp
, TOMOYO_EXEC_TMPSIZE
- 1, "%s %s",
751 old_domain
->ns
->name
, rn
.name
);
753 case TOMOYO_TRANSITION_CONTROL_KEEP
:
754 /* Keep current domain. */
758 if (old_domain
== &tomoyo_kernel_domain
&&
759 !tomoyo_policy_loaded
) {
761 * Needn't to transit from kernel domain before
762 * starting /sbin/init. But transit from kernel domain
763 * if executing initializers because they might start
768 /* Normal domain transition. */
769 snprintf(ee
->tmp
, TOMOYO_EXEC_TMPSIZE
- 1, "%s %s",
770 old_domain
->domainname
->name
, rn
.name
);
775 domain
= tomoyo_assign_domain(ee
->tmp
, true);
778 else if (reject_on_transition_failure
) {
779 printk(KERN_WARNING
"ERROR: Domain '%s' not ready.\n",
782 } else if (ee
->r
.mode
== TOMOYO_CONFIG_ENFORCING
)
786 if (!old_domain
->flags
[TOMOYO_DIF_TRANSITION_FAILED
]) {
787 old_domain
->flags
[TOMOYO_DIF_TRANSITION_FAILED
] = true;
788 ee
->r
.granted
= false;
789 tomoyo_write_log(&ee
->r
, "%s", tomoyo_dif
790 [TOMOYO_DIF_TRANSITION_FAILED
]);
792 "ERROR: Domain '%s' not defined.\n", ee
->tmp
);
798 /* Update reference count on "struct tomoyo_domain_info". */
799 atomic_inc(&domain
->users
);
800 bprm
->cred
->security
= domain
;
804 ee
->r
.domain
= domain
;
805 retval
= tomoyo_environ(ee
);
808 kfree(ee
->dump
.data
);
814 * tomoyo_dump_page - Dump a page to buffer.
816 * @bprm: Pointer to "struct linux_binprm".
817 * @pos: Location to dump.
818 * @dump: Poiner to "struct tomoyo_page_dump".
820 * Returns true on success, false otherwise.
822 bool tomoyo_dump_page(struct linux_binprm
*bprm
, unsigned long pos
,
823 struct tomoyo_page_dump
*dump
)
827 /* dump->data is released by tomoyo_find_next_domain(). */
829 dump
->data
= kzalloc(PAGE_SIZE
, GFP_NOFS
);
833 /* Same with get_arg_page(bprm, pos, 0) in fs/exec.c */
835 if (get_user_pages(current
, bprm
->mm
, pos
, 1, 0, 1, &page
, NULL
) <= 0)
838 page
= bprm
->page
[pos
/ PAGE_SIZE
];
840 if (page
!= dump
->page
) {
841 const unsigned int offset
= pos
% PAGE_SIZE
;
843 * Maybe kmap()/kunmap() should be used here.
844 * But remove_arg_zero() uses kmap_atomic()/kunmap_atomic().
847 char *kaddr
= kmap_atomic(page
, KM_USER0
);
850 memcpy(dump
->data
+ offset
, kaddr
+ offset
,
852 kunmap_atomic(kaddr
, KM_USER0
);
854 /* Same with put_arg_page(page) in fs/exec.c */