diff options
author | James Morris <jmorris@namei.org> | 2009-12-09 03:01:03 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2009-12-09 03:01:03 -0500 |
commit | 1ad1f10cd915744bbe52b19423653b38287d827d (patch) | |
tree | ae072aace36b45a55d80b8cbf1b6d92523a88ea0 /security/tomoyo | |
parent | 08e3daff217059c84c360cc71212686e0a7995af (diff) | |
parent | 2b876f95d03e226394b5d360c86127cbefaf614b (diff) |
Merge branch 'master' into next
Diffstat (limited to 'security/tomoyo')
-rw-r--r-- | security/tomoyo/file.c | 21 | ||||
-rw-r--r-- | security/tomoyo/realpath.c | 9 | ||||
-rw-r--r-- | security/tomoyo/tomoyo.c | 80 | ||||
-rw-r--r-- | security/tomoyo/tomoyo.h | 2 |
4 files changed, 9 insertions, 103 deletions
diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c index 2d10f98fc551..482f0e7ed997 100644 --- a/security/tomoyo/file.c +++ b/security/tomoyo/file.c | |||
@@ -1118,27 +1118,6 @@ static int tomoyo_check_single_path_permission2(struct tomoyo_domain_info * | |||
1118 | } | 1118 | } |
1119 | 1119 | ||
1120 | /** | 1120 | /** |
1121 | * tomoyo_check_file_perm - Check permission for sysctl()'s "read" and "write". | ||
1122 | * | ||
1123 | * @domain: Pointer to "struct tomoyo_domain_info". | ||
1124 | * @filename: Filename to check. | ||
1125 | * @perm: Mode ("read" or "write" or "read/write"). | ||
1126 | * Returns 0 on success, negative value otherwise. | ||
1127 | */ | ||
1128 | int tomoyo_check_file_perm(struct tomoyo_domain_info *domain, | ||
1129 | const char *filename, const u8 perm) | ||
1130 | { | ||
1131 | struct tomoyo_path_info name; | ||
1132 | const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE); | ||
1133 | |||
1134 | if (!mode) | ||
1135 | return 0; | ||
1136 | name.name = filename; | ||
1137 | tomoyo_fill_path_info(&name); | ||
1138 | return tomoyo_check_file_perm2(domain, &name, perm, "sysctl", mode); | ||
1139 | } | ||
1140 | |||
1141 | /** | ||
1142 | * tomoyo_check_exec_perm - Check permission for "execute". | 1121 | * tomoyo_check_exec_perm - Check permission for "execute". |
1143 | * | 1122 | * |
1144 | * @domain: Pointer to "struct tomoyo_domain_info". | 1123 | * @domain: Pointer to "struct tomoyo_domain_info". |
diff --git a/security/tomoyo/realpath.c b/security/tomoyo/realpath.c index 917f564cdab1..18369d497eb8 100644 --- a/security/tomoyo/realpath.c +++ b/security/tomoyo/realpath.c | |||
@@ -110,6 +110,15 @@ int tomoyo_realpath_from_path2(struct path *path, char *newname, | |||
110 | spin_unlock(&dcache_lock); | 110 | spin_unlock(&dcache_lock); |
111 | path_put(&root); | 111 | path_put(&root); |
112 | path_put(&ns_root); | 112 | path_put(&ns_root); |
113 | /* Prepend "/proc" prefix if using internal proc vfs mount. */ | ||
114 | if (!IS_ERR(sp) && (path->mnt->mnt_parent == path->mnt) && | ||
115 | (strcmp(path->mnt->mnt_sb->s_type->name, "proc") == 0)) { | ||
116 | sp -= 5; | ||
117 | if (sp >= newname) | ||
118 | memcpy(sp, "/proc", 5); | ||
119 | else | ||
120 | sp = ERR_PTR(-ENOMEM); | ||
121 | } | ||
113 | } | 122 | } |
114 | if (IS_ERR(sp)) | 123 | if (IS_ERR(sp)) |
115 | error = PTR_ERR(sp); | 124 | error = PTR_ERR(sp); |
diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c index 3fb5f6ea4fc9..ad9555fc3765 100644 --- a/security/tomoyo/tomoyo.c +++ b/security/tomoyo/tomoyo.c | |||
@@ -85,83 +85,6 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm) | |||
85 | return tomoyo_check_open_permission(domain, &bprm->file->f_path, 1); | 85 | return tomoyo_check_open_permission(domain, &bprm->file->f_path, 1); |
86 | } | 86 | } |
87 | 87 | ||
88 | #ifdef CONFIG_SYSCTL | ||
89 | |||
90 | static int tomoyo_prepend(char **buffer, int *buflen, const char *str) | ||
91 | { | ||
92 | int namelen = strlen(str); | ||
93 | |||
94 | if (*buflen < namelen) | ||
95 | return -ENOMEM; | ||
96 | *buflen -= namelen; | ||
97 | *buffer -= namelen; | ||
98 | memcpy(*buffer, str, namelen); | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | /** | ||
103 | * tomoyo_sysctl_path - return the realpath of a ctl_table. | ||
104 | * @table: pointer to "struct ctl_table". | ||
105 | * | ||
106 | * Returns realpath(3) of the @table on success. | ||
107 | * Returns NULL on failure. | ||
108 | * | ||
109 | * This function uses tomoyo_alloc(), so the caller must call tomoyo_free() | ||
110 | * if this function didn't return NULL. | ||
111 | */ | ||
112 | static char *tomoyo_sysctl_path(struct ctl_table *table) | ||
113 | { | ||
114 | int buflen = TOMOYO_MAX_PATHNAME_LEN; | ||
115 | char *buf = tomoyo_alloc(buflen); | ||
116 | char *end = buf + buflen; | ||
117 | int error = -ENOMEM; | ||
118 | |||
119 | if (!buf) | ||
120 | return NULL; | ||
121 | |||
122 | *--end = '\0'; | ||
123 | buflen--; | ||
124 | while (table) { | ||
125 | char num[32]; | ||
126 | const char *sp = table->procname; | ||
127 | |||
128 | if (!sp) { | ||
129 | memset(num, 0, sizeof(num)); | ||
130 | snprintf(num, sizeof(num) - 1, "=%d=", table->ctl_name); | ||
131 | sp = num; | ||
132 | } | ||
133 | if (tomoyo_prepend(&end, &buflen, sp) || | ||
134 | tomoyo_prepend(&end, &buflen, "/")) | ||
135 | goto out; | ||
136 | table = table->parent; | ||
137 | } | ||
138 | if (tomoyo_prepend(&end, &buflen, "/proc/sys")) | ||
139 | goto out; | ||
140 | error = tomoyo_encode(buf, end - buf, end); | ||
141 | out: | ||
142 | if (!error) | ||
143 | return buf; | ||
144 | tomoyo_free(buf); | ||
145 | return NULL; | ||
146 | } | ||
147 | |||
148 | static int tomoyo_sysctl(struct ctl_table *table, int op) | ||
149 | { | ||
150 | int error; | ||
151 | char *name; | ||
152 | |||
153 | op &= MAY_READ | MAY_WRITE; | ||
154 | if (!op) | ||
155 | return 0; | ||
156 | name = tomoyo_sysctl_path(table); | ||
157 | if (!name) | ||
158 | return -ENOMEM; | ||
159 | error = tomoyo_check_file_perm(tomoyo_domain(), name, op); | ||
160 | tomoyo_free(name); | ||
161 | return error; | ||
162 | } | ||
163 | #endif | ||
164 | |||
165 | static int tomoyo_path_truncate(struct path *path, loff_t length, | 88 | static int tomoyo_path_truncate(struct path *path, loff_t length, |
166 | unsigned int time_attrs) | 89 | unsigned int time_attrs) |
167 | { | 90 | { |
@@ -336,9 +259,6 @@ static struct security_operations tomoyo_security_ops = { | |||
336 | .cred_transfer = tomoyo_cred_transfer, | 259 | .cred_transfer = tomoyo_cred_transfer, |
337 | .bprm_set_creds = tomoyo_bprm_set_creds, | 260 | .bprm_set_creds = tomoyo_bprm_set_creds, |
338 | .bprm_check_security = tomoyo_bprm_check_security, | 261 | .bprm_check_security = tomoyo_bprm_check_security, |
339 | #ifdef CONFIG_SYSCTL | ||
340 | .sysctl = tomoyo_sysctl, | ||
341 | #endif | ||
342 | .file_fcntl = tomoyo_file_fcntl, | 262 | .file_fcntl = tomoyo_file_fcntl, |
343 | .dentry_open = tomoyo_dentry_open, | 263 | .dentry_open = tomoyo_dentry_open, |
344 | .path_truncate = tomoyo_path_truncate, | 264 | .path_truncate = tomoyo_path_truncate, |
diff --git a/security/tomoyo/tomoyo.h b/security/tomoyo/tomoyo.h index fac02655ea4b..bf3986addc1a 100644 --- a/security/tomoyo/tomoyo.h +++ b/security/tomoyo/tomoyo.h | |||
@@ -18,8 +18,6 @@ struct inode; | |||
18 | struct linux_binprm; | 18 | struct linux_binprm; |
19 | struct pt_regs; | 19 | struct pt_regs; |
20 | 20 | ||
21 | int tomoyo_check_file_perm(struct tomoyo_domain_info *domain, | ||
22 | const char *filename, const u8 perm); | ||
23 | int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain, | 21 | int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain, |
24 | const struct tomoyo_path_info *filename); | 22 | const struct tomoyo_path_info *filename); |
25 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, | 23 | int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, |