init: add an init_link helper

Add a simple helper to link with a kernel space file name and switch
the early init code over to it.  Remove the now unused ksys_link.

Signed-off-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Christoph Hellwig 2020-07-22 11:14:19 +02:00
parent eb9d7d390e
commit 812931d693
6 changed files with 38 additions and 14 deletions

View file

@ -122,6 +122,39 @@ int __init init_eaccess(const char *filename)
return error;
}
int __init init_link(const char *oldname, const char *newname)
{
struct dentry *new_dentry;
struct path old_path, new_path;
int error;
error = kern_path(oldname, 0, &old_path);
if (error)
return error;
new_dentry = kern_path_create(AT_FDCWD, newname, &new_path, 0);
error = PTR_ERR(new_dentry);
if (IS_ERR(new_dentry))
goto out;
error = -EXDEV;
if (old_path.mnt != new_path.mnt)
goto out_dput;
error = may_linkat(&old_path);
if (unlikely(error))
goto out_dput;
error = security_path_link(old_path.dentry, &new_path, new_dentry);
if (error)
goto out_dput;
error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry,
NULL);
out_dput:
done_path_create(&new_path, new_dentry);
out:
path_put(&old_path);
return error;
}
int __init init_unlink(const char *pathname)
{
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));

View file

@ -69,8 +69,7 @@ long do_rmdir(int dfd, struct filename *name);
long do_unlinkat(int dfd, struct filename *name);
long do_symlinkat(const char __user *oldname, int newdfd,
const char __user *newname);
int do_linkat(int olddfd, const char __user *oldname, int newdfd,
const char __user *newname, int flags);
int may_linkat(struct path *link);
/*
* namespace.c

View file

@ -1024,7 +1024,7 @@ static bool safe_hardlink_source(struct inode *inode)
*
* Returns 0 if successful, -ve on error.
*/
static int may_linkat(struct path *link)
int may_linkat(struct path *link)
{
struct inode *inode = link->dentry->d_inode;
@ -4086,7 +4086,7 @@ EXPORT_SYMBOL(vfs_link);
* with linux 2.0, and to avoid hard-linking to directories
* and other special files. --ADM
*/
int do_linkat(int olddfd, const char __user *oldname, int newdfd,
static int do_linkat(int olddfd, const char __user *oldname, int newdfd,
const char __user *newname, int flags)
{
struct dentry *new_dentry;

View file

@ -8,5 +8,6 @@ int __init init_chroot(const char *filename);
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags);
int __init init_chmod(const char *filename, umode_t mode);
int __init init_eaccess(const char *filename);
int __init init_link(const char *oldname, const char *newname);
int __init init_unlink(const char *pathname);
int __init init_rmdir(const char *pathname);

View file

@ -1295,15 +1295,6 @@ static inline long ksys_mknod(const char __user *filename, umode_t mode,
return do_mknodat(AT_FDCWD, filename, mode, dev);
}
extern int do_linkat(int olddfd, const char __user *oldname, int newdfd,
const char __user *newname, int flags);
static inline long ksys_link(const char __user *oldname,
const char __user *newname)
{
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
}
extern int do_fchownat(int dfd, const char __user *filename, uid_t user,
gid_t group, int flag);

View file

@ -312,7 +312,7 @@ static int __init maybe_link(void)
char *old = find_link(major, minor, ino, mode, collected);
if (old) {
clean_path(collected, 0);
return (ksys_link(old, collected) < 0) ? -1 : 1;
return (init_link(old, collected) < 0) ? -1 : 1;
}
}
return 0;