[RFC PATCH 30/35] syscalls: do not call sys_link{,at}() within the kernel

From: Dominik Brodowski
Date: Sun Mar 11 2018 - 07:04:07 EST


CC: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
CC: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Dominik Brodowski <linux@xxxxxxxxxxxxxxxxxxxx>
---
fs/internal.h | 2 ++
fs/namei.c | 12 +++++++++---
include/linux/syscalls.h | 8 ++++++++
init/initramfs.c | 2 +-
4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/fs/internal.h b/fs/internal.h
index 4f0b67054c54..91e6fc93fcb5 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -62,6 +62,8 @@ long do_rmdir(int dfd, const char __user *pathname);
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);

/*
* namespace.c
diff --git a/fs/namei.c b/fs/namei.c
index 8459a18cdd18..10148235829f 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -4250,8 +4250,8 @@ EXPORT_SYMBOL(vfs_link);
* with linux 2.0, and to avoid hard-linking to directories
* and other special files. --ADM
*/
-SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
- int, newdfd, const char __user *, newname, int, flags)
+int do_linkat(int olddfd, const char __user *oldname, int newdfd,
+ const char __user *newname, int flags)
{
struct dentry *new_dentry;
struct path old_path, new_path;
@@ -4315,9 +4315,15 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
return error;
}

+SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
+ int, newdfd, const char __user *, newname, int, flags)
+{
+ return do_linkat(olddfd, oldname, newdfd, newname, flags);
+}
+
SYSCALL_DEFINE2(link, const char __user *, oldname, const char __user *, newname)
{
- return sys_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
+ return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
}

/**
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 617f72c0aae8..27620caed7e4 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -1001,4 +1001,12 @@ 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);
+}
+
#endif
diff --git a/init/initramfs.c b/init/initramfs.c
index 2972ed0ab399..5855ab632b4e 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -306,7 +306,7 @@ static int __init maybe_link(void)
if (nlink >= 2) {
char *old = find_link(major, minor, ino, mode, collected);
if (old)
- return (sys_link(old, collected) < 0) ? -1 : 1;
+ return (ksys_link(old, collected) < 0) ? -1 : 1;
}
return 0;
}
--
2.16.2