2020-07-21 09:12:08 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Routines that mimic syscalls, but don't use the user address space or file
|
|
|
|
* descriptors. Only for init/ and related early init code.
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/fs.h>
|
2020-07-22 09:25:21 +00:00
|
|
|
#include <linux/fs_struct.h>
|
2020-07-21 09:12:08 +00:00
|
|
|
#include <linux/init_syscalls.h>
|
2020-07-22 09:26:13 +00:00
|
|
|
#include <linux/security.h>
|
2020-07-21 09:12:08 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
int __init init_mount(const char *dev_name, const char *dir_name,
|
|
|
|
const char *type_page, unsigned long flags, void *data_page)
|
|
|
|
{
|
|
|
|
struct path path;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = kern_path(dir_name, LOOKUP_FOLLOW, &path);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = path_mount(dev_name, &path, type_page, flags, data_page);
|
|
|
|
path_put(&path);
|
|
|
|
return ret;
|
|
|
|
}
|
2020-07-23 06:23:08 +00:00
|
|
|
|
|
|
|
int __init init_umount(const char *name, int flags)
|
|
|
|
{
|
|
|
|
int lookup_flags = LOOKUP_MOUNTPOINT;
|
|
|
|
struct path path;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(flags & UMOUNT_NOFOLLOW))
|
|
|
|
lookup_flags |= LOOKUP_FOLLOW;
|
|
|
|
ret = kern_path(name, lookup_flags, &path);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
return path_umount(&path, flags);
|
|
|
|
}
|
2020-07-23 06:23:40 +00:00
|
|
|
|
2020-07-22 09:25:21 +00:00
|
|
|
int __init init_chdir(const char *filename)
|
|
|
|
{
|
|
|
|
struct path path;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
|
|
|
|
if (!error)
|
|
|
|
set_fs_pwd(current->fs, &path);
|
|
|
|
path_put(&path);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2020-07-22 09:26:13 +00:00
|
|
|
int __init init_chroot(const char *filename)
|
|
|
|
{
|
|
|
|
struct path path;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = kern_path(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
|
|
|
|
if (error)
|
|
|
|
goto dput_and_out;
|
|
|
|
error = -EPERM;
|
|
|
|
if (!ns_capable(current_user_ns(), CAP_SYS_CHROOT))
|
|
|
|
goto dput_and_out;
|
|
|
|
error = security_path_chroot(&path);
|
|
|
|
if (error)
|
|
|
|
goto dput_and_out;
|
|
|
|
set_fs_root(current->fs, &path);
|
|
|
|
dput_and_out:
|
|
|
|
path_put(&path);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2020-07-22 09:13:26 +00:00
|
|
|
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags)
|
|
|
|
{
|
|
|
|
int lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
|
|
|
|
struct path path;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = kern_path(filename, lookup_flags, &path);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
error = mnt_want_write(path.mnt);
|
|
|
|
if (!error) {
|
|
|
|
error = chown_common(&path, user, group);
|
|
|
|
mnt_drop_write(path.mnt);
|
|
|
|
}
|
|
|
|
path_put(&path);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2020-07-23 06:23:40 +00:00
|
|
|
int __init init_unlink(const char *pathname)
|
|
|
|
{
|
|
|
|
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));
|
|
|
|
}
|
2020-07-22 09:11:45 +00:00
|
|
|
|
|
|
|
int __init init_rmdir(const char *pathname)
|
|
|
|
{
|
|
|
|
return do_rmdir(AT_FDCWD, getname_kernel(pathname));
|
|
|
|
}
|