mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-16 16:54:20 +08:00
61a47c1ad3
This system call has been deprecated almost since it was introduced, and in a survey of the linux distributions I can no longer find any of them that enable CONFIG_SYSCTL_SYSCALL. The only indication that I can find that anyone might care is that a few of the defconfigs in the kernel enable CONFIG_SYSCTL_SYSCALL. However this appears in only 31 of 414 defconfigs in the kernel, so I suspect this symbols presence is simply because it is harmless to include rather than because it is necessary. As there appear to be no users of the sysctl system call, remove the code. As this removes one of the few uses of the internal kernel mount of proc I hope this allows for even more simplifications of the proc filesystem. Cc: Alex Smith <alex.smith@imgtec.com> Cc: Anders Berg <anders.berg@lsi.com> Cc: Apelete Seketeli <apelete@seketeli.net> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Chee Nouk Phoon <cnphoon@altera.com> Cc: Chris Zankel <chris@zankel.net> Cc: Christian Ruppert <christian.ruppert@abilis.com> Cc: Greg Ungerer <gerg@uclinux.org> Cc: Harvey Hunt <harvey.hunt@imgtec.com> Cc: Helge Deller <deller@gmx.de> Cc: Hongliang Tao <taohl@lemote.com> Cc: Hua Yan <yanh@lemote.com> Cc: Huacai Chen <chenhc@lemote.com> Cc: John Crispin <blogic@openwrt.org> Cc: Jonas Jensen <jonas.jensen@gmail.com> Cc: Josh Boyer <jwboyer@gmail.com> Cc: Jun Nie <jun.nie@linaro.org> Cc: Kevin Hilman <khilman@linaro.org> Cc: Kevin Wells <kevin.wells@nxp.com> Cc: Kumar Gala <galak@codeaurora.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Ley Foon Tan <lftan@altera.com> Cc: Linus Walleij <linus.walleij@linaro.org> Cc: Markos Chandras <markos.chandras@imgtec.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Noam Camus <noamc@ezchip.com> Cc: Olof Johansson <olof@lixom.net> Cc: Paul Burton <paul.burton@mips.com> Cc: Paul Mundt <lethal@linux-sh.org> Cc: Phil Edworthy <phil.edworthy@renesas.com> Cc: Pierrick Hascoet <pierrick.hascoet@abilis.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Roland Stigge <stigge@antcom.de> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com> Cc: Scott Telford <stelford@cadence.com> Cc: Stephen Boyd <sboyd@codeaurora.org> Cc: Steven J. Hill <Steven.Hill@imgtec.com> Cc: Tanmay Inamdar <tinamdar@apm.com> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Wolfram Sang <w.sang@pengutronix.de> Acked-by: Andi Kleen <ak@linux.intel.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
172 lines
3.8 KiB
C
172 lines
3.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <linux/stat.h>
|
|
#include <linux/sysctl.h>
|
|
#include "../fs/xfs/xfs_sysctl.h"
|
|
#include <linux/sunrpc/debug.h>
|
|
#include <linux/string.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/namei.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/nsproxy.h>
|
|
#include <linux/pid_namespace.h>
|
|
#include <linux/file.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/netdevice.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/uuid.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/compat.h>
|
|
|
|
static ssize_t binary_sysctl(const int *name, int nlen,
|
|
void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
|
|
{
|
|
return -ENOSYS;
|
|
}
|
|
|
|
static void deprecated_sysctl_warning(const int *name, int nlen)
|
|
{
|
|
int i;
|
|
|
|
/*
|
|
* CTL_KERN/KERN_VERSION is used by older glibc and cannot
|
|
* ever go away.
|
|
*/
|
|
if (nlen >= 2 && name[0] == CTL_KERN && name[1] == KERN_VERSION)
|
|
return;
|
|
|
|
if (printk_ratelimit()) {
|
|
printk(KERN_INFO
|
|
"warning: process `%s' used the deprecated sysctl "
|
|
"system call with ", current->comm);
|
|
for (i = 0; i < nlen; i++)
|
|
printk(KERN_CONT "%d.", name[i]);
|
|
printk(KERN_CONT "\n");
|
|
}
|
|
return;
|
|
}
|
|
|
|
#define WARN_ONCE_HASH_BITS 8
|
|
#define WARN_ONCE_HASH_SIZE (1<<WARN_ONCE_HASH_BITS)
|
|
|
|
static DECLARE_BITMAP(warn_once_bitmap, WARN_ONCE_HASH_SIZE);
|
|
|
|
#define FNV32_OFFSET 2166136261U
|
|
#define FNV32_PRIME 0x01000193
|
|
|
|
/*
|
|
* Print each legacy sysctl (approximately) only once.
|
|
* To avoid making the tables non-const use a external
|
|
* hash-table instead.
|
|
* Worst case hash collision: 6, but very rarely.
|
|
* NOTE! We don't use the SMP-safe bit tests. We simply
|
|
* don't care enough.
|
|
*/
|
|
static void warn_on_bintable(const int *name, int nlen)
|
|
{
|
|
int i;
|
|
u32 hash = FNV32_OFFSET;
|
|
|
|
for (i = 0; i < nlen; i++)
|
|
hash = (hash ^ name[i]) * FNV32_PRIME;
|
|
hash %= WARN_ONCE_HASH_SIZE;
|
|
if (__test_and_set_bit(hash, warn_once_bitmap))
|
|
return;
|
|
deprecated_sysctl_warning(name, nlen);
|
|
}
|
|
|
|
static ssize_t do_sysctl(int __user *args_name, int nlen,
|
|
void __user *oldval, size_t oldlen, void __user *newval, size_t newlen)
|
|
{
|
|
int name[CTL_MAXNAME];
|
|
int i;
|
|
|
|
/* Check args->nlen. */
|
|
if (nlen < 0 || nlen > CTL_MAXNAME)
|
|
return -ENOTDIR;
|
|
/* Read in the sysctl name for simplicity */
|
|
for (i = 0; i < nlen; i++)
|
|
if (get_user(name[i], args_name + i))
|
|
return -EFAULT;
|
|
|
|
warn_on_bintable(name, nlen);
|
|
|
|
return binary_sysctl(name, nlen, oldval, oldlen, newval, newlen);
|
|
}
|
|
|
|
SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
|
|
{
|
|
struct __sysctl_args tmp;
|
|
size_t oldlen = 0;
|
|
ssize_t result;
|
|
|
|
if (copy_from_user(&tmp, args, sizeof(tmp)))
|
|
return -EFAULT;
|
|
|
|
if (tmp.oldval && !tmp.oldlenp)
|
|
return -EFAULT;
|
|
|
|
if (tmp.oldlenp && get_user(oldlen, tmp.oldlenp))
|
|
return -EFAULT;
|
|
|
|
result = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, oldlen,
|
|
tmp.newval, tmp.newlen);
|
|
|
|
if (result >= 0) {
|
|
oldlen = result;
|
|
result = 0;
|
|
}
|
|
|
|
if (tmp.oldlenp && put_user(oldlen, tmp.oldlenp))
|
|
return -EFAULT;
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
struct compat_sysctl_args {
|
|
compat_uptr_t name;
|
|
int nlen;
|
|
compat_uptr_t oldval;
|
|
compat_uptr_t oldlenp;
|
|
compat_uptr_t newval;
|
|
compat_size_t newlen;
|
|
compat_ulong_t __unused[4];
|
|
};
|
|
|
|
COMPAT_SYSCALL_DEFINE1(sysctl, struct compat_sysctl_args __user *, args)
|
|
{
|
|
struct compat_sysctl_args tmp;
|
|
compat_size_t __user *compat_oldlenp;
|
|
size_t oldlen = 0;
|
|
ssize_t result;
|
|
|
|
if (copy_from_user(&tmp, args, sizeof(tmp)))
|
|
return -EFAULT;
|
|
|
|
if (tmp.oldval && !tmp.oldlenp)
|
|
return -EFAULT;
|
|
|
|
compat_oldlenp = compat_ptr(tmp.oldlenp);
|
|
if (compat_oldlenp && get_user(oldlen, compat_oldlenp))
|
|
return -EFAULT;
|
|
|
|
result = do_sysctl(compat_ptr(tmp.name), tmp.nlen,
|
|
compat_ptr(tmp.oldval), oldlen,
|
|
compat_ptr(tmp.newval), tmp.newlen);
|
|
|
|
if (result >= 0) {
|
|
oldlen = result;
|
|
result = 0;
|
|
}
|
|
|
|
if (compat_oldlenp && put_user(oldlen, compat_oldlenp))
|
|
return -EFAULT;
|
|
|
|
return result;
|
|
}
|
|
|
|
#endif /* CONFIG_COMPAT */
|