~ubuntu-branches/ubuntu/karmic/linux-mvl-dove/karmic-proposed

« back to all changes in this revision

Viewing changes to ubuntu/apparmor/include/context.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader
  • Date: 2010-03-10 22:24:12 UTC
  • mto: (15.1.2 karmic-security)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20100310222412-k86m3r53jw0je7x1
Tags: upstream-2.6.31
ImportĀ upstreamĀ versionĀ 2.6.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * AppArmor security module
3
 
 *
4
 
 * This file contains AppArmor contexts used to associate "labels" to objects.
5
 
 *
6
 
 * Copyright (C) 1998-2008 Novell/SUSE
7
 
 * Copyright 2009 Canonical Ltd.
8
 
 *
9
 
 * This program is free software; you can redistribute it and/or
10
 
 * modify it under the terms of the GNU General Public License as
11
 
 * published by the Free Software Foundation, version 2 of the
12
 
 * License.
13
 
 */
14
 
 
15
 
#ifndef __AA_CONTEXT_H
16
 
#define __AA_CONTEXT_H
17
 
 
18
 
#include <linux/cred.h>
19
 
#include <linux/slab.h>
20
 
#include <linux/sched.h>
21
 
 
22
 
#include "policy.h"
23
 
 
24
 
 
25
 
/* struct aa_file_cxt - the AppArmor context the file was opened in
26
 
 * @profile: the profile the file was opened under
27
 
 * @perms: the permission the file was opened with
28
 
 */
29
 
struct aa_file_cxt {
30
 
        struct aa_profile *profile;
31
 
        u16 allowed;
32
 
};
33
 
 
34
 
static inline struct aa_file_cxt *aa_alloc_file_context(gfp_t gfp)
35
 
{
36
 
        return kzalloc(sizeof(struct aa_file_cxt), gfp);
37
 
}
38
 
 
39
 
static inline void aa_free_file_context(struct aa_file_cxt *cxt)
40
 
{
41
 
        aa_put_profile(cxt->profile);
42
 
        memset(cxt, 0, sizeof(struct aa_file_cxt));
43
 
        kfree(cxt);
44
 
}
45
 
 
46
 
 
47
 
 
48
 
 
49
 
 
50
 
/* struct aa_task_cxt_group - a grouping label data for confined tasks
51
 
 * @profile: the current profile
52
 
 * @exec: profile to transition to on next exec
53
 
 * @previous: profile the task may return to
54
 
 * @token: magic value the task must know for returning to @previous_profile
55
 
 *
56
 
 * Contains the task's current profile (which could change due to
57
 
 * change_hat).  Plus the hat_magic needed during change_hat.
58
 
 */
59
 
struct aa_task_cxt_group {
60
 
        struct aa_profile *profile;
61
 
        struct aa_profile *onexec;
62
 
        struct aa_profile *previous;
63
 
        u64 token;
64
 
};
65
 
 
66
 
/**
67
 
 * struct aa_task_context - primary label for confined tasks
68
 
 * @sys: the system labeling for the task
69
 
 *
70
 
 * A task is confined by the intersection of its system and user profiles
71
 
 */
72
 
struct aa_task_context {
73
 
        struct aa_task_cxt_group sys;
74
 
};
75
 
 
76
 
struct aa_task_context *aa_alloc_task_context(gfp_t flags);
77
 
void aa_free_task_context(struct aa_task_context *cxt);
78
 
struct aa_task_context *aa_dup_task_context(struct aa_task_context *old_cxt,
79
 
                                            gfp_t gfp);
80
 
void aa_cred_policy(const struct cred *cred, struct aa_profile **sys);
81
 
struct cred *aa_get_task_policy(const struct task_struct *task,
82
 
                                struct aa_profile **sys);
83
 
int aa_replace_current_profiles(struct aa_profile *sys);
84
 
void aa_put_task_policy(struct cred *cred);
85
 
int aa_set_current_onexec(struct aa_profile *sys);
86
 
int aa_set_current_hat(struct aa_profile *profile, u64 token);
87
 
int aa_restore_previous_profile(u64 cookie);
88
 
 
89
 
 
90
 
static inline struct aa_task_context *__aa_task_cxt(struct task_struct *task)
91
 
{
92
 
        return __task_cred(task)->security;
93
 
}
94
 
 
95
 
/**
96
 
 * __aa_task_is_confined - determine if @task has any confinement
97
 
 * @task: task to check confinement of
98
 
 *
99
 
 * If @task != current needs to be in RCU safe critical section
100
 
 */
101
 
static inline int __aa_task_is_confined(struct task_struct *task)
102
 
{
103
 
        struct aa_task_context *cxt;
104
 
        int rc = 1;
105
 
 
106
 
        cxt = __aa_task_cxt(task);
107
 
        if (!cxt || (cxt->sys.profile->flags & PFLAG_UNCONFINED))
108
 
                rc = 0;
109
 
 
110
 
        return rc;
111
 
}
112
 
 
113
 
static inline const struct cred *aa_current_policy(struct aa_profile **sys)
114
 
{
115
 
        const struct cred *cred = current_cred();
116
 
        struct aa_task_context *cxt = cred->security;
117
 
        BUG_ON(!cxt);
118
 
        *sys = aa_filtered_profile(aa_profile_newest(cxt->sys.profile));
119
 
 
120
 
        return cred;
121
 
}
122
 
 
123
 
static inline const struct cred *aa_current_policy_wupd(struct aa_profile **sys)
124
 
{
125
 
        const struct cred *cred = current_cred();
126
 
        struct aa_task_context *cxt = cred->security;
127
 
        BUG_ON(!cxt);
128
 
 
129
 
        *sys = aa_profile_newest(cxt->sys.profile);
130
 
        if (unlikely((cxt->sys.profile != *sys)))
131
 
                aa_replace_current_profiles(*sys);
132
 
        *sys = aa_filtered_profile(*sys);
133
 
 
134
 
        return cred;
135
 
}
136
 
 
137
 
static inline struct aa_profile *aa_current_profile(void)
138
 
{
139
 
        const struct cred *cred = current_cred();
140
 
        struct aa_task_context *cxt = cred->security;
141
 
        BUG_ON(!cxt);
142
 
        return aa_filtered_profile(aa_profile_newest(cxt->sys.profile));
143
 
}
144
 
 
145
 
static inline struct aa_profile *aa_current_profile_wupd(void)
146
 
{
147
 
        struct aa_profile *p;
148
 
        aa_current_policy_wupd(&p);
149
 
        return p;
150
 
}
151
 
 
152
 
 
153
 
#endif  /* __AA_CONTEXT_H */