Commit 49a0c458 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Linus Torvalds

sysctl: Factor out sysctl_data.

There as been no easy way to wrap the default sysctl strategy routine except
for returning 0.  Which is not always what we want.  The few instances I have
seen that want different behaviour have written their own version of
sysctl_data.  While not too hard it is unnecessary code and has the potential
for extra bugs.

So to make these situations easier and make that part of sysctl more symetric
I have factord sysctl_data out of do_sysctl_strategy and exported as a
function everyone can use.

Further having sysctl_data be an explicit function makes checking for badly
formed sysctl tables much easier.
Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
Cc: Alexey Dobriyan <adobriyan@sw.ru>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d8217f07
...@@ -972,6 +972,7 @@ extern int do_sysctl_strategy (struct ctl_table *table, ...@@ -972,6 +972,7 @@ extern int do_sysctl_strategy (struct ctl_table *table,
void __user *oldval, size_t __user *oldlenp, void __user *oldval, size_t __user *oldlenp,
void __user *newval, size_t newlen); void __user *newval, size_t newlen);
extern ctl_handler sysctl_data;
extern ctl_handler sysctl_string; extern ctl_handler sysctl_string;
extern ctl_handler sysctl_intvec; extern ctl_handler sysctl_intvec;
extern ctl_handler sysctl_jiffies; extern ctl_handler sysctl_jiffies;
......
...@@ -1443,7 +1443,6 @@ int do_sysctl_strategy (struct ctl_table *table, ...@@ -1443,7 +1443,6 @@ int do_sysctl_strategy (struct ctl_table *table,
void __user *newval, size_t newlen) void __user *newval, size_t newlen)
{ {
int op = 0, rc; int op = 0, rc;
size_t len;
if (oldval) if (oldval)
op |= 004; op |= 004;
...@@ -1464,25 +1463,10 @@ int do_sysctl_strategy (struct ctl_table *table, ...@@ -1464,25 +1463,10 @@ int do_sysctl_strategy (struct ctl_table *table,
/* If there is no strategy routine, or if the strategy returns /* If there is no strategy routine, or if the strategy returns
* zero, proceed with automatic r/w */ * zero, proceed with automatic r/w */
if (table->data && table->maxlen) { if (table->data && table->maxlen) {
if (oldval && oldlenp) { rc = sysctl_data(table, name, nlen, oldval, oldlenp,
if (get_user(len, oldlenp)) newval, newlen);
return -EFAULT; if (rc < 0)
if (len) { return rc;
if (len > table->maxlen)
len = table->maxlen;
if(copy_to_user(oldval, table->data, len))
return -EFAULT;
if(put_user(len, oldlenp))
return -EFAULT;
}
}
if (newval && newlen) {
len = newlen;
if (len > table->maxlen)
len = table->maxlen;
if(copy_from_user(table->data, newval, len))
return -EFAULT;
}
} }
return 0; return 0;
} }
...@@ -2381,6 +2365,40 @@ int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, ...@@ -2381,6 +2365,40 @@ int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
* General sysctl support routines * General sysctl support routines
*/ */
/* The generic sysctl data routine (used if no strategy routine supplied) */
int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
void __user *oldval, size_t __user *oldlenp,
void __user *newval, size_t newlen)
{
size_t len;
/* Get out of I don't have a variable */
if (!table->data || !table->maxlen)
return -ENOTDIR;
if (oldval && oldlenp) {
if (get_user(len, oldlenp))
return -EFAULT;
if (len) {
if (len > table->maxlen)
len = table->maxlen;
if (copy_to_user(oldval, table->data, len))
return -EFAULT;
if (put_user(len, oldlenp))
return -EFAULT;
}
}
if (newval && newlen) {
if (newlen > table->maxlen)
newlen = table->maxlen;
if (copy_from_user(table->data, newval, newlen))
return -EFAULT;
}
return 1;
}
/* The generic string strategy routine: */ /* The generic string strategy routine: */
int sysctl_string(struct ctl_table *table, int __user *name, int nlen, int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
void __user *oldval, size_t __user *oldlenp, void __user *oldval, size_t __user *oldlenp,
...@@ -2569,6 +2587,13 @@ asmlinkage long sys_sysctl(struct __sysctl_args __user *args) ...@@ -2569,6 +2587,13 @@ asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
return -ENOSYS; return -ENOSYS;
} }
int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
void __user *oldval, size_t __user *oldlenp,
void __user *newval, size_t newlen)
{
return -ENOSYS;
}
int sysctl_string(struct ctl_table *table, int __user *name, int nlen, int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
void __user *oldval, size_t __user *oldlenp, void __user *oldval, size_t __user *oldlenp,
void __user *newval, size_t newlen) void __user *newval, size_t newlen)
...@@ -2616,4 +2641,5 @@ EXPORT_SYMBOL(sysctl_intvec); ...@@ -2616,4 +2641,5 @@ EXPORT_SYMBOL(sysctl_intvec);
EXPORT_SYMBOL(sysctl_jiffies); EXPORT_SYMBOL(sysctl_jiffies);
EXPORT_SYMBOL(sysctl_ms_jiffies); EXPORT_SYMBOL(sysctl_ms_jiffies);
EXPORT_SYMBOL(sysctl_string); EXPORT_SYMBOL(sysctl_string);
EXPORT_SYMBOL(sysctl_data);
EXPORT_SYMBOL(unregister_sysctl_table); EXPORT_SYMBOL(unregister_sysctl_table);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment