sysctl: refactor __do_proc_doulongvec_minmax()
Subsystems (2)
PATCH 1/2 sysctl: refactor __do_proc_doulongvec_minmax()
Seperate read and write into two functions.
--- kernel/sysctl.c | 151 +++++++++++++++++++++++++++++++++--------------------- 1 files changed, 92 insertions(+), 59 deletions(-)
kernel/sysctl.c +92 -59
@@ -2448,86 +2448,119 @@ int proc_dointvec_minmax(struct ctl_table *table, int write, do_proc_dointvec_minmax_conv, ¶m); } -static int __do_proc_doulongvec_minmax (void *data,struct ctl_table *table,int write, -void __user *buffer, -size_t *lenp,loff_t *ppos, +static int __doulongvec_minmax_read (void *data,void __user *buffer, +size_t *lenp,loff_t *ppos,int vleft,unsigned long convmul,unsigned long convdiv) { -unsigned long *i, *min, *max; -int vleft, first =1 , err =0 ; -unsigned long page =0 ; -size_t left; -char *kbuf; +unsigned long *i = data; +int err =0 ; +bool first = true; +size_t left = *lenp; -if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { - *lenp =0 ; -return 0 ; +for (; left && vleft--; i++, first = false) { +unsigned long val; + + val = convdiv * (*i) / convmul; +if (!first) + err =proc_put_char (&buffer, &left,'\t' ); + err =proc_put_long (&buffer, &left, val, false); +if (err) +break ; } - i = (unsigned long *) data; - min = (unsigned long *) table->extra1; - max = (unsigned long *) table->extra2; - vleft = table->maxlen /sizeof (unsigned long ); - left = *lenp; +if (!first && left && !err) + err =proc_put_char (&buffer, &left,'\n' ); -if (write) { -if (left >PAGE_SIZE -1 ) - left =PAGE_SIZE -1 ; - page =__get_free_page (GFP_TEMPORARY ); - kbuf = (char *) page; -if (!kbuf) -return -ENOMEM ; -if (copy_from_user (kbuf, buffer, left)) { - err = -EFAULT ; - goto free; - } - kbuf[left] =0 ; + *lenp -= left; + *ppos += *lenp; +return err; +} + +static int __doulongvec_minmax_write (void *data,void __user *buffer, +size_t *lenp,loff_t *ppos,int vleft, +unsigned long min,unsigned long max) +{ +char *kbuf; +size_t left = *lenp; +unsigned long page =0 ; +unsigned long *i = (unsigned long *) data; +int err =0 ; +bool first = true; + +if (left >PAGE_SIZE -1 ) + left =PAGE_SIZE -1 ; + page =__get_free_page (GFP_TEMPORARY ); + kbuf = (char *) page; +if (!kbuf) +return -ENOMEM ; +if (copy_from_user (kbuf, buffer, left)) { + err = -EFAULT ; + goto free; } + kbuf[left] =0 ; -for (; left && vleft--; i++, first =0 ) { +for (; left && vleft--; i++, first = false) {unsigned long val; +bool neg; -if (write) { -bool neg; - - left -=proc_skip_spaces (&kbuf); + left -=proc_skip_spaces (&kbuf); - err =proc_get_long (&kbuf, &left, &val, &neg, - proc_wspace_sep, -sizeof (proc_wspace_sep),NULL ); -if (err) -break ; -if (neg) -continue ; -if ((min && val < *min) || (max && val > *max)) -continue ; - *i = val; - }else { - val = convdiv * (*i) / convmul; -if (!first) - err =proc_put_char (&buffer, &left,'\t' ); - err =proc_put_long (&buffer, &left, val, false); -if (err) -break ; - } + err =proc_get_long (&kbuf, &left, &val, &neg, + proc_wspace_sep, +sizeof (proc_wspace_sep),NULL ); +if (err) +break ; +if (neg) +continue ; +if (val < min || val > max) +continue ; + *i = val; } -if (!write && !first && left && !err) - err =proc_put_char (&buffer, &left,'\n' ); -if (write && !err) +if (!err) left -=proc_skip_spaces (&kbuf); free: -if (write) { -free_page (page); -if (first) -return err ? : -EINVAL ; - } +free_page (page); +if (first) +return err ? : -EINVAL ; + *lenp -= left; *ppos += *lenp;return err; } +static int __do_proc_doulongvec_minmax (void *data,struct ctl_table *table,int write, +void __user *buffer, +size_t *lenp,loff_t *ppos, +unsigned long convmul, +unsigned long convdiv) +{ +int vleft; +if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { + *lenp =0 ; +return 0 ; + } + + vleft = table->maxlen /sizeof (unsigned long ); +if (write) { +unsigned long min, max; + +if (table->extra1) + min = *(unsigned long *) table->extra1; +else + min =0 ; +if (table->extra2) + max = *(unsigned long *) table->extra2; +else + max =ULONG_MAX ; +return __doulongvec_minmax_write (data, buffer, lenp, + ppos, vleft, min, max); + }else +return __doulongvec_minmax_read (data, buffer, lenp, + ppos, vleft, convmul, convdiv); +} + static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, void __user *buffer, size_t *lenp, loff_t *ppos,
Signature · 1 line
1.6.5.2
PATCH 2/2 sysctl: remove sysctl syscall
Remove the obsolete sysctl syscall. It was scheduled to be removed in Sept.
--- Documentation/feature-removal-schedule.txt | 35 - init/Kconfig | 17 - kernel/sysctl_binary.c | 1367 ---------------------------- 3 files changed, 0 insertions(+), 1419 deletions(-)
Documentation/feature-removal-schedule.txt +0 -35
@@ -116,41 +116,6 @@ Who: Mauro Carvalho Chehab <[email protected]> --------------------------- -What: sys_sysctl -When: September 2010 -Option: CONFIG_SYSCTL_SYSCALL -Why: The same information is available in a more convenient from - /proc/sys, and none of the sysctl variables appear to be - important performance wise. - - Binary sysctls are a long standing source of subtle kernel - bugs and security issues. - - When I looked several months ago all I could find after - searching several distributions were 5 user space programs and - glibc (which falls back to /proc/sys) using this syscall. - - The man page for sysctl(2) documents it as unusable for user - space programs. - - sysctl(2) is not generally ABI compatible to a 32bit user - space application on a 64bit and a 32bit kernel. - - For the last several months the policy has been no new binary - sysctls and no one has put forward an argument to use them. - - Binary sysctls issues seem to keep happening appearing so - properly deprecating them (with a warning to user space) and a - 2 year grace warning period will mean eventually we can kill - them and end the pain. - - In the mean time individual binary sysctls can be dealt with - in a piecewise fashion. - -Who: Eric Biederman <[email protected]> - ---------------------------- - What: /proc/<pid>/oom_adj When: August 2012 Why: /proc/<pid>/oom_adj allows userspace to influence the oom killer's
init/Kconfig +0 -17
@@ -805,23 +805,6 @@ config UID16 help This enables the legacy 16-bit UID syscall wrappers. -config SYSCTL_SYSCALL - bool "Sysctl syscall support" if EMBEDDED - depends on PROC_SYSCTL - default y - select SYSCTL - ---help--- - sys_sysctl uses binary paths that have been found challenging - to properly maintain and use. The interface in /proc/sys - using paths with ascii names is now the primary path to this - information. - - Almost nothing using the binary sysctl interface so if you are - trying to save some space it is probably safe to disable this, - making your kernel marginally smaller. - - If unsure say Y here. - config KALLSYMS bool "Load all symbols for debugging/ksymoops" if EMBEDDED default y
kernel/sysctl_binary.c +0 -1367
1,379 lines not on this page · raw message
Signature · 1 line
1.6.5.2
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 2 lines · Amerigo Wang
Remove the obsolete sysctl syscall. It was scheduled to be removed in Sept.
I thought at least older glibc was still using it? Did anyone check what happens if it sees no sysctl(2)?
I think it's ok to remove the full tables, but keeping
a wrapper just for the functionality glibc use(s/d) is still a good idea.
-Andi
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 7 lines · Andi Kleen
Quoted 2 lines · Amerigo Wang
Remove the obsolete sysctl syscall. It was scheduled to be removed in Sept.
I thought at least older glibc was still using it? Did anyone check what happens if it sees no sysctl(2)?
At the time the deprecation was written we nearly we were in the late rc's before anything that cared in practice. glibc has stopped even providing a sys_sysctl wrapper now.
Quoted 3 lines
I think it's ok to remove the full tables, but keeping
a wrapper just for the functionality glibc use(s/d) is still a good idea.
I think the only problem should be the arm glibc. I don't know if it's iopl implementation ever got weened off of this. I tried but I didn't have good test machine and submitting patches to glibc is much more of a pain than kernel patches.
To my knowledge there has never been a version of x86 glibc that had problems if sys_sysctl returns -ENOSYS, and glibc proper removed even that dependency almost as soon as sys_sysctl was deprecated.
Last time we discussed this (when I added the compatibility wrapper) I couldn't even find a version of glibc that used sysctl, and I could not find a distribution old enough that still had a version of glibc that used sysctl on x86.
We warn on every sys_sysctl value now even the glibc uses and perhaps I am blind but I haven't seen any bug reports. So we should be safe turning this off.
As far as this goes I would just change the default to off for now. Keeping the code doesn't have any impact on the core of the kernel any more, or even any binary impact. As the int -> long conversion has shown. If we can get through a release with the code disabled killing it the next release makes a lot of sense.
Eric
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 4 lines
At the time the deprecation was written we nearly we were in the late rc's before anything that cared in practice. glibc has stopped even providing a
sys_sysctlwrapper now.
What matters are old glibc installations, not new ones.
Quoted 7 lines
Quoted 3 lines
I think it's ok to remove the full tables, but keeping
a wrapper just for the functionality glibc use(s/d) is still a good idea.I think the only problem should be the arm glibc. I don't know if it's iopl implementation ever got weened off of this. I tried but I didn't have good test machine and submitting patches to glibc is much more of a pain than kernel patches.
Eric, I think you have the wrong approach here: it doesn't matter what new glibc does, but what any old glibcs do. If any old one uses it we cannot simply remove it.
Quoted 4 lines
To my knowledge there has never been a version of x86 glibc that had problems if
sys_sysctlreturns-ENOSYS, and glibc proper removed even that dependency almost as soon assys_sysctlwas deprecated.
AFAIK older glibc didn't use some functionality in the kernel if they couldn't figure out the right kernel version. And they were using sysctl for this.
Quoted 4 lines
Last time we discussed this (when I added the compatibility wrapper) I couldn't even find a version of glibc that used sysctl, and I could not find a distribution old enough that still had a version of glibc that used sysctl on x86.
When I did my really old work for sysctl_binary() I ran into this problem. All glibc binaries on my distribution back then used sysctl.
Quoted 4 lines
We warn on every
sys_sysctlvalue now even the glibc uses and perhaps I am blind but I haven't seen any bug reports. So we should be safe turning this off.
I don't so. I don't think we can that easily break compatibility, sorry. Binary compatibility is something very important for Linux.
Anyways I'm fine with removing the bulk of the tables, but not the compat table for the one glibc uses.
I think the code could be a lot simplified and just provide support for the single kernel version sysctl though (I had a patch to do that back then)
-Andi
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 5 lines · Andi Kleen
Quoted 3 lines
At the time the deprecation was written we nearly we were in the late rc's before anything that cared in practice. glibc has stopped even providing a
sys_sysctlwrapper now.What matters are old glibc installations, not new ones.
No. It matters a lot that glibc has stopped providing the wrapper, as that makes it doubly difficult for new users to start using the binary sysctl interface.
Quoted 9 lines
Quoted 7 lines
Quoted 3 lines
I think it's ok to remove the full tables, but keeping
a wrapper just for the functionality glibc use(s/d) is still a good idea.I think the only problem should be the arm glibc. I don't know if it's iopl implementation ever got weened off of this. I tried but I didn't have good test machine and submitting patches to glibc is much more of a pain than kernel patches.
Quoted 4 lines
Eric, I think you have the wrong approach here: it doesn't matter what new glibc does,
but what any old glibcs do. If any old one uses it we cannot simply remove it.
???? If there are any current users we can not remove it.
If current glibc on arm still uses this (which I expect it does) we can not possibly remove the code. With a current user it doesn't matter what historical versions of glibc do.
Quoted 8 lines
Quoted 4 lines
To my knowledge there has never been a version of x86 glibc that had problems if
sys_sysctlreturns-ENOSYS, and glibc proper removed even that dependency almost as soon assys_sysctlwas deprecated.AFAIK older glibc didn't use some functionality in the kernel if they couldn't figure out the right kernel version. And they were using sysctl for this.
Sigh. We have had the conversation a dozen times.
I have looked and reasearched until I am bored. It was the pthreads code attempting to detect if we are smp. At worst the code would not optimize for the uniprocessor case.
But again that was long ago, and last time we had this conversation it was impossible for me to find glibc binaries on x86 that were still even trying to do this.
We have been warning on even the historical glibc pthreads usage for over a year now.
Quoted 7 lines
Quoted 4 lines
Last time we discussed this (when I added the compatibility wrapper) I couldn't even find a version of glibc that used sysctl, and I could not find a distribution old enough that still had a version of glibc that used sysctl on x86.
When I did my really old work for
sysctl_binary()I ran into this problem. All glibc binaries on my distribution back then used sysctl.
Yep. Which was what 4+ years ago?
Perhaps the question should be in practice does any enterprise distro have a glibc that uses sys_sysctl. Not that I think even that case is particularly interesting.
Quoted 7 lines
Quoted 4 lines
We warn on every
sys_sysctlvalue now even the glibc uses and perhaps I am blind but I haven't seen any bug reports. So we should be safe turning this off.I don't so. I don't think we can that easily break compatibility, sorry. Binary compatibility is something very important for Linux.
Duh! Which is why we have the code.
Of course the safe course is to keep the code and disable the feature, if no one is using it.
Quoted 2 lines
Anyways I'm fine with removing the bulk of the tables, but not the compat table for the one glibc uses.
Removing the bulk of the tables is another name for breaking binary compatibility. Which you said is a no no. We have the code and it works at this point, there is no point to neutering it. Especially when distros whose glibc pthread code used this are for the most part lost in the course of history.
To the best of my knowledge the last and user of sys_sysctl is the glibc ioperm (my apologies I mispoke when I said iopl) implementation on arm. Not that people run around calling ioperm very often in any distro.
All of that said I think disabling sys_sysctl by default now is totally reasonable. If there is a percentage in removing the code we can worry about that later. Perhaps we should add a CONFIG_CRUFT and move sys_sysctl under there. Binary compatibility that nothing needs but that we actually have code for just in case.
Eric
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 3 lines · Eric W. Biederman
To the best of my knowledge the last and user of
sys_sysctlis the glibc ioperm (my apologies I mispoke when I said iopl) implementation on arm. Not that people run around calling ioperm very often in any distro.
I saw that in Changelog of glibc too, but that was back to 2000, 10 years past, I don't see any code using sysctl() in glibc now, except sys_sysctl() itself, of course.
Quoted 6 lines
All of that said I think disabling
sys_sysctlby default now is totally reasonable. If there is a percentage in removing the code we can worry about that later. Perhaps we should add aCONFIG_CRUFTand movesys_sysctlunder there. Binary compatibility that nothing needs but that we actually have code for just in case.
But you put sysctl in features-removal-schedule.txt 3 years ago. :)
I believe they should see the kernel warnings if they are still using sysctl.
Thanks.
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 9 lines · Cong Wang
Quoted 3 lines · Eric W. Biederman
To the best of my knowledge the last and user of
sys_sysctlis the glibc ioperm (my apologies I mispoke when I said iopl) implementation on arm. Not that people run around calling ioperm very often in any distro.I saw that in Changelog of glibc too, but that was back to 2000, 10 years past, I don't see any code using
sysctl()in glibc now, exceptsys_sysctl()itself, of course.
You have to look in the glibc-ports tree to see the arm code.
The arm support is not in the main glibc tree for some reason.
Hmm. Looking I thought sys_sysctl had stopped being exported from glibc but it appears I was wrong.
Quoted 7 lines
Quoted 5 lines
All of that said I think disabling
sys_sysctlby default now is totally reasonable. If there is a percentage in removing the code we can worry about that later. Perhaps we should add aCONFIG_CRUFTand movesys_sysctlunder there. Binary compatibility that nothing needs but that we actually have code for just in case.But you put sysctl in features-removal-schedule.txt 3 years ago. :)
I did and before that the first version of the sysctl man page said the binary values were not portable between kernels, so don't use the system call.
Quoted 2 lines
I believe they should see the kernel warnings if they are still using sysctl.
Unfortunately sometimes a word to the wise isn't quite enough. Sigh. I very much think having the sysctl code disabled by default is definitely safe right now, and the first responsible step in getting this code removed from the kernel.
There were two original reasons for the deprecations. Maintaining the binary sysctl logic was bug prone, and no one was using sysctl.
The rewriting of the binary interface into binary_sysctl.c takes care of most if not all of the maintenance concerns. You may think you are using the binary interface but the kernel just rewrites it into a /proc access.
What is left is an interface in the kernel that no one uses and that will eventually bit rot, for lack of care, attention, and testing, but we still have a while until that happens.
I recommend this:
---
init/Kconfig +9 -5
@@ -808,7 +808,7 @@ config UID16 config SYSCTL_SYSCALL bool "Sysctl syscall support" if EMBEDDED depends on PROC_SYSCTL - default y + default n select SYSCTL ---help--- sys_sysctl uses binary paths that have been found challenging
@@ -816,11 +816,15 @@ config SYSCTL_SYSCALL using paths with ascii names is now the primary path to this information. - Almost nothing using the binary sysctl interface so if you are - trying to save some space it is probably safe to disable this, - making your kernel marginally smaller. + This option is kept as a service to our loyal customers who + have ignored all of our warnings over the years and have a + binary somewhere that won't work without this. + + This code is not regularly used or tested and will probably have + bit-rotted before someone cares enough to do more maintenance on it + so enable at your own risk. - If unsure say Y here. + Say N here. config KALLSYMS bool "Load all symbols for debugging/ksymoops" if EMBEDDED
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 12 lines · Eric W. Biederman
Quoted 9 lines · Cong Wang
Quoted 3 lines · Eric W. Biederman
To the best of my knowledge the last and user of
sys_sysctlis the glibc ioperm (my apologies I mispoke when I said iopl) implementation on arm. Not that people run around calling ioperm very often in any distro.I saw that in Changelog of glibc too, but that was back to 2000, 10 years past, I don't see any code using
sysctl()in glibc now, exceptsys_sysctl()itself, of course.
Quoted 6 lines
You have to look in the glibc-ports tree to see the arm code.
The arm support is not in the main glibc tree for some reason.
Hmm. Looking I thought
sys_sysctlhad stopped being exported from glibc but it appears I was wrong.
Ok, got it.
Quoted 16 lines
Quoted 2 lines
I believe they should see the kernel warnings if they are still using sysctl.
Unfortunately sometimes a word to the wise isn't quite enough. Sigh. I very much think having the sysctl code disabled by default is definitely safe right now, and the first responsible step in getting this code removed from the kernel.
There were two original reasons for the deprecations. Maintaining the binary sysctl logic was bug prone, and no one was using sysctl.
The rewriting of the binary interface into
binary_sysctl.ctakes care of most if not all of the maintenance concerns. You may think you are using the binary interface but the kernel just rewrites it into a /proc access.
Quoted 5 lines
What is left is an interface in the kernel that no one uses and that will eventually bit rot, for lack of care, attention, and testing, but we still have a while until that happens.
I recommend this:
This sounds ok for me.
Do you want to me to carry this patch for you and resend?
Quoted 25 lines
---
init/Kconfig +4
-4@@ -808,7 +808,7 @@ config UID16 config SYSCTL_SYSCALL bool "Sysctl syscall support" if EMBEDDED depends on PROC_SYSCTL - default y + default n select SYSCTL ---help--- sys_sysctl uses binary paths that have been found challenging@@ -816,11 +816,15 @@ config SYSCTL_SYSCALL using paths with ascii names is now the primary path to this information. - Almost nothing using the binary sysctl interface so if you are - trying to save some space it is probably safe to disable this, - making your kernel marginally smaller. + This option is kept as a service to our loyal customers who + have ignored all of our warnings over the years and have a + binary somewhere that won't work without this.
init/Kconfig config SYSCTL_SYSCALL · line 830
Quoted 10 lines
init/Kconfig +5
-1+ + This code is not regularly used or tested and will probably have + bit-rotted before someone cares enough to do more maintenance on it + so enable at your own risk. - If unsure say Y here. + Say N here. config KALLSYMS bool "Load all symbols for debugging/ksymoops" if EMBEDDED
Thanks!
Re: [PATCH 2/2] sysctl: remove sysctl syscall
In reply to Andi KleenQuoted 7 lines · Andi Kleen
Quoted 2 lines · Amerigo Wang
Remove the obsolete sysctl syscall. It was scheduled to be removed in Sept.
I thought at least older glibc was still using it? Did anyone check what happens if it sees no sysctl(2)?
It will fall back reading from /proc/sys.
Andreas.
Signature · 3 lines
Andreas Schwab, [email protected] GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different."
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 7 lines · Andreas Schwab
Quoted 6 lines · Amerigo Wang
Quoted 2 lines
Remove the obsolete sysctl syscall. It was scheduled to be removed in Sept.
I thought at least older glibc was still using it? Did anyone check what happens if it sees no sysctl(2)?
It will fall back reading from
/proc/sys.
First that's slow (but ok), but that will fail if there is no /proc.
-Andi
Re: [PATCH 2/2] sysctl: remove sysctl syscall
Quoted 11 lines · Andi Kleen
Quoted 7 lines · Andreas Schwab
Quoted 6 lines · Amerigo Wang
Quoted 2 lines
Remove the obsolete sysctl syscall. It was scheduled to be removed in Sept.
I thought at least older glibc was still using it? Did anyone check what happens if it sees no sysctl(2)?
It will fall back reading from
/proc/sys.First that's slow (but ok), but that will fail if there is no /proc.
I strongly doubt glibc will work if there is no /proc, a quick grep shows lots of "/proc" strings in glibc code.