Skip to content

Commit 8b8efb4

Browse files
Tetsuo Handaxjamesmorris
authored andcommitted
LSM: Add security_path_chroot().
This patch allows pathname based LSM modules to check chroot() operations. This hook is used by TOMOYO. Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: James Morris <jmorris@namei.org>
1 parent 89eda06 commit 8b8efb4

4 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎fs/open.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
587587
error = -EPERM;
588588
if (!capable(CAP_SYS_CHROOT))
589589
goto dput_and_out;
590+
error = security_path_chroot(&path);
591+
if (error)
592+
goto dput_and_out;
590593

591594
set_fs_root(current->fs, &path);
592595
error = 0;

‎include/linux/security.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,10 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
459459
* @uid contains new owner's ID.
460460
* @gid contains new group's ID.
461461
* Return 0 if permission is granted.
462+
* @path_chroot:
463+
* Check for permission to change root directory.
464+
* @path contains the path structure.
465+
* Return 0 if permission is granted.
462466
* @inode_readlink:
463467
* Check the permission to read the symbolic link.
464468
* @dentry contains the dentry structure for the file link.
@@ -1503,6 +1507,7 @@ struct security_operations {
15031507
int (*path_chmod) (struct dentry *dentry, struct vfsmount *mnt,
15041508
mode_t mode);
15051509
int (*path_chown) (struct path *path, uid_t uid, gid_t gid);
1510+
int (*path_chroot) (struct path *path);
15061511
#endif
15071512

15081513
int (*inode_alloc_security) (struct inode *inode);
@@ -2970,6 +2975,7 @@ int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
29702975
int security_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
29712976
mode_t mode);
29722977
int security_path_chown(struct path *path, uid_t uid, gid_t gid);
2978+
int security_path_chroot(struct path *path);
29732979
#else /* CONFIG_SECURITY_PATH */
29742980
static inline int security_path_unlink(struct path *dir, struct dentry *dentry)
29752981
{
@@ -3031,6 +3037,11 @@ static inline int security_path_chown(struct path *path, uid_t uid, gid_t gid)
30313037
{
30323038
return 0;
30333039
}
3040+
3041+
static inline int security_path_chroot(struct path *path)
3042+
{
3043+
return 0;
3044+
}
30343045
#endif /* CONFIG_SECURITY_PATH */
30353046

30363047
#ifdef CONFIG_KEYS

‎security/capability.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ static int cap_path_chown(struct path *path, uid_t uid, gid_t gid)
319319
{
320320
return 0;
321321
}
322+
323+
static int cap_path_chroot(struct path *root)
324+
{
325+
return 0;
326+
}
322327
#endif
323328

324329
static int cap_file_permission(struct file *file, int mask)
@@ -990,6 +995,7 @@ void security_fixup_ops(struct security_operations *ops)
990995
set_to_cap_if_null(ops, path_truncate);
991996
set_to_cap_if_null(ops, path_chmod);
992997
set_to_cap_if_null(ops, path_chown);
998+
set_to_cap_if_null(ops, path_chroot);
993999
#endif
9941000
set_to_cap_if_null(ops, file_permission);
9951001
set_to_cap_if_null(ops, file_alloc_security);

‎security/security.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ int security_path_chown(struct path *path, uid_t uid, gid_t gid)
449449
return 0;
450450
return security_ops->path_chown(path, uid, gid);
451451
}
452+
453+
int security_path_chroot(struct path *path)
454+
{
455+
return security_ops->path_chroot(path);
456+
}
452457
#endif
453458

454459
int security_inode_create(struct inode *dir, struct dentry *dentry, int mode)

0 commit comments

Comments
 (0)