Skip to content

Commit 97d6931

Browse files
Tetsuo HandaJames Morris
authored andcommitted
TOMOYO: Remove unneeded parameter.
tomoyo_path_perm() tomoyo_path2_perm() and tomoyo_check_rewrite_permission() always receive tomoyo_domain(). We can move it from caller to callee. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 7ef6123 commit 97d6931

File tree

3 files changed

+27
-38
lines changed

3 files changed

+27
-38
lines changed

security/tomoyo/common.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,10 @@ int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
637637
const struct tomoyo_path_info *filename);
638638
int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
639639
struct path *path, const int flag);
640-
int tomoyo_path_perm(struct tomoyo_domain_info *domain, const u8 operation,
641-
struct path *path);
642-
int tomoyo_path2_perm(struct tomoyo_domain_info *domain, const u8 operation,
643-
struct path *path1, struct path *path2);
644-
int tomoyo_check_rewrite_permission(struct tomoyo_domain_info *domain,
645-
struct file *filp);
640+
int tomoyo_path_perm(const u8 operation, struct path *path);
641+
int tomoyo_path2_perm(const u8 operation, struct path *path1,
642+
struct path *path2);
643+
int tomoyo_check_rewrite_permission(struct file *filp);
646644
int tomoyo_find_next_domain(struct linux_binprm *bprm);
647645

648646
/* Run garbage collector. */

security/tomoyo/file.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,17 +1135,16 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
11351135
/**
11361136
* tomoyo_path_perm - Check permission for "create", "unlink", "mkdir", "rmdir", "mkfifo", "mksock", "mkblock", "mkchar", "truncate", "symlink", "ioctl", "chmod", "chown", "chgrp", "chroot", "mount" and "unmount".
11371137
*
1138-
* @domain: Pointer to "struct tomoyo_domain_info".
11391138
* @operation: Type of operation.
11401139
* @path: Pointer to "struct path".
11411140
*
11421141
* Returns 0 on success, negative value otherwise.
11431142
*/
1144-
int tomoyo_path_perm(struct tomoyo_domain_info *domain,
1145-
const u8 operation, struct path *path)
1143+
int tomoyo_path_perm(const u8 operation, struct path *path)
11461144
{
11471145
int error = -ENOMEM;
11481146
struct tomoyo_path_info *buf;
1147+
struct tomoyo_domain_info *domain = tomoyo_domain();
11491148
const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
11501149
const bool is_enforce = (mode == 3);
11511150
int idx;
@@ -1180,15 +1179,14 @@ int tomoyo_path_perm(struct tomoyo_domain_info *domain,
11801179
/**
11811180
* tomoyo_check_rewrite_permission - Check permission for "rewrite".
11821181
*
1183-
* @domain: Pointer to "struct tomoyo_domain_info".
11841182
* @filp: Pointer to "struct file".
11851183
*
11861184
* Returns 0 on success, negative value otherwise.
11871185
*/
1188-
int tomoyo_check_rewrite_permission(struct tomoyo_domain_info *domain,
1189-
struct file *filp)
1186+
int tomoyo_check_rewrite_permission(struct file *filp)
11901187
{
11911188
int error = -ENOMEM;
1189+
struct tomoyo_domain_info *domain = tomoyo_domain();
11921190
const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
11931191
const bool is_enforce = (mode == 3);
11941192
struct tomoyo_path_info *buf;
@@ -1217,19 +1215,18 @@ int tomoyo_check_rewrite_permission(struct tomoyo_domain_info *domain,
12171215
/**
12181216
* tomoyo_path2_perm - Check permission for "rename", "link" and "pivot_root".
12191217
*
1220-
* @domain: Pointer to "struct tomoyo_domain_info".
12211218
* @operation: Type of operation.
12221219
* @path1: Pointer to "struct path".
12231220
* @path2: Pointer to "struct path".
12241221
*
12251222
* Returns 0 on success, negative value otherwise.
12261223
*/
1227-
int tomoyo_path2_perm(struct tomoyo_domain_info * const domain,
1228-
const u8 operation, struct path *path1,
1224+
int tomoyo_path2_perm(const u8 operation, struct path *path1,
12291225
struct path *path2)
12301226
{
12311227
int error = -ENOMEM;
12321228
struct tomoyo_path_info *buf1, *buf2;
1229+
struct tomoyo_domain_info *domain = tomoyo_domain();
12331230
const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
12341231
const bool is_enforce = (mode == 3);
12351232
const char *msg;

security/tomoyo/tomoyo.c

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,33 +100,33 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
100100
static int tomoyo_path_truncate(struct path *path, loff_t length,
101101
unsigned int time_attrs)
102102
{
103-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_TRUNCATE, path);
103+
return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path);
104104
}
105105

106106
static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
107107
{
108108
struct path path = { parent->mnt, dentry };
109-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_UNLINK, &path);
109+
return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path);
110110
}
111111

112112
static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
113113
int mode)
114114
{
115115
struct path path = { parent->mnt, dentry };
116-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_MKDIR, &path);
116+
return tomoyo_path_perm(TOMOYO_TYPE_MKDIR, &path);
117117
}
118118

119119
static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
120120
{
121121
struct path path = { parent->mnt, dentry };
122-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_RMDIR, &path);
122+
return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path);
123123
}
124124

125125
static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
126126
const char *old_name)
127127
{
128128
struct path path = { parent->mnt, dentry };
129-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_SYMLINK, &path);
129+
return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path);
130130
}
131131

132132
static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
@@ -149,16 +149,15 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
149149
type = TOMOYO_TYPE_MKSOCK;
150150
break;
151151
}
152-
return tomoyo_path_perm(tomoyo_domain(), type, &path);
152+
return tomoyo_path_perm(type, &path);
153153
}
154154

155155
static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
156156
struct dentry *new_dentry)
157157
{
158158
struct path path1 = { new_dir->mnt, old_dentry };
159159
struct path path2 = { new_dir->mnt, new_dentry };
160-
return tomoyo_path2_perm(tomoyo_domain(), TOMOYO_TYPE_LINK, &path1,
161-
&path2);
160+
return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
162161
}
163162

164163
static int tomoyo_path_rename(struct path *old_parent,
@@ -168,15 +167,14 @@ static int tomoyo_path_rename(struct path *old_parent,
168167
{
169168
struct path path1 = { old_parent->mnt, old_dentry };
170169
struct path path2 = { new_parent->mnt, new_dentry };
171-
return tomoyo_path2_perm(tomoyo_domain(), TOMOYO_TYPE_RENAME, &path1,
172-
&path2);
170+
return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
173171
}
174172

175173
static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
176174
unsigned long arg)
177175
{
178176
if (cmd == F_SETFL && ((arg ^ file->f_flags) & O_APPEND))
179-
return tomoyo_check_rewrite_permission(tomoyo_domain(), file);
177+
return tomoyo_check_rewrite_permission(file);
180178
return 0;
181179
}
182180

@@ -196,50 +194,46 @@ static int tomoyo_dentry_open(struct file *f, const struct cred *cred)
196194
static int tomoyo_file_ioctl(struct file *file, unsigned int cmd,
197195
unsigned long arg)
198196
{
199-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_IOCTL,
200-
&file->f_path);
197+
return tomoyo_path_perm(TOMOYO_TYPE_IOCTL, &file->f_path);
201198
}
202199

203200
static int tomoyo_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
204201
mode_t mode)
205202
{
206203
struct path path = { mnt, dentry };
207-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_CHMOD, &path);
204+
return tomoyo_path_perm(TOMOYO_TYPE_CHMOD, &path);
208205
}
209206

210207
static int tomoyo_path_chown(struct path *path, uid_t uid, gid_t gid)
211208
{
212209
int error = 0;
213210
if (uid != (uid_t) -1)
214-
error = tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_CHOWN,
215-
path);
211+
error = tomoyo_path_perm(TOMOYO_TYPE_CHOWN, path);
216212
if (!error && gid != (gid_t) -1)
217-
error = tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_CHGRP,
218-
path);
213+
error = tomoyo_path_perm(TOMOYO_TYPE_CHGRP, path);
219214
return error;
220215
}
221216

222217
static int tomoyo_path_chroot(struct path *path)
223218
{
224-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_CHROOT, path);
219+
return tomoyo_path_perm(TOMOYO_TYPE_CHROOT, path);
225220
}
226221

227222
static int tomoyo_sb_mount(char *dev_name, struct path *path,
228223
char *type, unsigned long flags, void *data)
229224
{
230-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_MOUNT, path);
225+
return tomoyo_path_perm(TOMOYO_TYPE_MOUNT, path);
231226
}
232227

233228
static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
234229
{
235230
struct path path = { mnt, mnt->mnt_root };
236-
return tomoyo_path_perm(tomoyo_domain(), TOMOYO_TYPE_UMOUNT, &path);
231+
return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path);
237232
}
238233

239234
static int tomoyo_sb_pivotroot(struct path *old_path, struct path *new_path)
240235
{
241-
return tomoyo_path2_perm(tomoyo_domain(), TOMOYO_TYPE_PIVOT_ROOT,
242-
new_path, old_path);
236+
return tomoyo_path2_perm(TOMOYO_TYPE_PIVOT_ROOT, new_path, old_path);
243237
}
244238

245239
/*

0 commit comments

Comments
 (0)