Fix /proc/sys/fs/nfs/nsm_use_hostnames on big endian machines
Subsystems (5)
cover Fix /proc/sys/fs/nfs/nsm_use_hostnames on big endian machines
There is an endianess problem with /proc/sys/fs/nfs/nsm_use_hostnames (which can e.g. be seen on an s390x host) :
# modprobe lockd nsm_use_hostnames=1 # cat /proc/sys/fs/nfs/nsm_use_hostnames 16777216
The nsm_use_hostnames variable is declared as "bool" which is required for the correct type for the module parameter. However, this does not work correctly with the entry in the /proc filesystem since this currently requires "int".
Jia He already provided patches for this problem a couple of years ago, but apparently they felt through the cracks and never got merged. So here's a rebased version to finally fix this issue.
Jia He (2):
sysctl: introduce new proc handler proc_dobool
lockd: change the proc_handler for nsm_use_hostnames
fs/lockd/svc.c | 2 +- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-)
Signature · 1 line
2.27.0
PATCH 1/2 sysctl: introduce new proc handler proc_dobool
From: Jia He <[email protected]>
This is to let bool variable could be correctly displayed in big/little endian sysctl procfs. sizeof(bool) is arch dependent, proc_dobool should work in all arches.
--- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
include/linux/sysctl.h +2 -0
@@ -48,6 +48,8 @@ typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos);int proc_dostring (struct ctl_table *,int ,void *,size_t *,loff_t *); +int proc_dobool (struct ctl_table *table,int write,void *buffer, +size_t *lenp,loff_t *ppos);int proc_dointvec (struct ctl_table *,int ,void *,size_t *,loff_t *);int proc_douintvec (struct ctl_table *,int ,void *,size_t *,loff_t *);int proc_dointvec_minmax (struct ctl_table *,int ,void *,size_t *,loff_t *);
kernel/sysctl.c +42 -0
66 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH 1/2] sysctl: introduce new proc handler proc_dobool
Quoted 96 lines · Thomas Huth
From: Jia He <[email protected]>
This is to let bool variable could be correctly displayed in big/little endian sysctl procfs. sizeof(bool) is arch dependent,
proc_doboolshould work in all arches.Suggested-by Pan Xinhui <[email protected]>Signed-off-by Jia He <[email protected]>[thuth: rebased the patch to the current kernel version]Signed-off-by Thomas Huth <[email protected]>--- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)include/linux/sysctl.h +2
-0@@ -48,6 +48,8 @@ typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos);int proc_dostring (struct ctl_table *,int ,void *,size_t *,loff_t *); +int proc_dobool (struct ctl_table *table,int write,void *buffer, +size_t *lenp,loff_t *ppos);int proc_dointvec (struct ctl_table *,int ,void *,size_t *,loff_t *);int proc_douintvec (struct ctl_table *,int ,void *,size_t *,loff_t *);int proc_dointvec_minmax (struct ctl_table *,int ,void *,size_t *,loff_t *);kernel/sysctl.c +41
-0@@ -536,6 +536,21 @@ static void proc_put_char(void **buf, size_t *size, char c) } } +static int do_proc_dobool_conv (bool *negp,unsigned long *lvalp, +int *valp, +int write,void *data) +{ +if (write) { + *(bool *)valp = *lvalp; + }else { +int val = *(bool *)valp; + + *lvalp = (unsigned long )val; + *negp = false; + } +return 0 ; +} +static int do_proc_dointvec_conv (bool *negp,unsigned long *lvalp,int *valp,int write,void *data)@@ -798,6 +813,26 @@ static int do_proc_douintvec(struct ctl_table *table, int write, buffer, lenp, ppos, conv, data); } +/** +* proc_dobool - read/write a bool +* @table: the sysctl table +* @write: %TRUE if this is a write to the sysctl file +* @buffer: the user buffer +* @lenp: the size of the user buffer +* @ppos: file position +* +* Reads/writes up to table->maxlen/sizeof(unsigned int) integer +* values from/to the user buffer, treated as an ASCII string. +* +* Returns 0 on success. +*/ +int proc_dobool (struct ctl_table *table,int write,void *buffer, +size_t *lenp,loff_t *ppos) +{ +return do_proc_dointvec (table, write, buffer, lenp, ppos, + do_proc_dobool_conv,NULL ); +} +/** * proc_dointvec - read a vector of integers * @table: the sysctl table @@ -1630,6 +1665,12 @@ int proc_dostring(struct ctl_table *table, int write,return -ENOSYS ; } +int proc_dobool (struct ctl_table *table,int write, +void *buffer,size_t *lenp,loff_t *ppos) +{ +return -ENOSYS ; +} +int proc_dointvec (struct ctl_table *table,int write,void *buffer,size_t *lenp,loff_t *ppos) {
kernel/sysctl.c int __init sysctl_init(void) · line 3472
Quoted 7 lines
kernel/sysctl.c +1
-0@@ -3425,6 +3466,7 @@ int __init sysctl_init(void)* No sense putting this after each symbol definition, twice, * exception granted :-) */ +EXPORT_SYMBOL (proc_dobool);EXPORT_SYMBOL (proc_dointvec);EXPORT_SYMBOL (proc_douintvec);EXPORT_SYMBOL (proc_dointvec_jiffies);
Friendly ping!
Luis, Kees, Iurii, could you please have a look and provide an Ack if this looks ok to you?
Thanks,
Thomas
Re: [PATCH 1/2] sysctl: introduce new proc handler proc_dobool
Quoted 106 lines · Thomas Huth
Quoted 95 lines · Thomas Huth
From: Jia He <[email protected]>
This is to let bool variable could be correctly displayed in big/little endian sysctl procfs. sizeof(bool) is arch dependent,
proc_doboolshould work in all arches.Suggested-by Pan Xinhui <[email protected]>Signed-off-by Jia He <[email protected]>[thuth: rebased the patch to the current kernel version]Signed-off-by Thomas Huth <[email protected]>---
include/linux/sysctl.h| 2 ++
kernel/sysctl.c | 42 ++++++++++++++++++++++++++++++++++++++++++2 files changed, 44 insertions(+)include/linux/sysctl.h +2
-0@@ -48,6 +48,8 @@ typedef int proc_handler(struct ctl_table *ctl, int write, void *buffer, size_t *lenp, loff_t *ppos); int proc_dostring(struct ctl_table *, int, void *, size_t *, loff_t *); +int proc_dobool (struct ctl_table *table,int write,void *buffer, + size_t *lenp, loff_t *ppos); int proc_dointvec(struct ctl_table *, int, void *, size_t *, loff_t *); int proc_douintvec(struct ctl_table *, int, void *, size_t *, loff_t *); int proc_dointvec_minmax(struct ctl_table *, int, void *, size_t *, loff_t *);kernel/sysctl.c +41
-0@@ -536,6 +536,21 @@ static void proc_put_char(void **buf, size_t *size, char c) } } +static int do_proc_dobool_conv (bool *negp,unsigned long *lvalp, + int *valp, + int write, void *data) +{ + if (write) { + *(bool *)valp = *lvalp; + } else { + int val = *(bool *)valp; + + *lvalp = (unsigned long)val; + *negp = false; + } + return 0; +} + static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, int *valp, int write, void *data)@@ -798,6 +813,26 @@ static int do_proc_douintvec(struct ctl_table *table,int write, buffer, lenp, ppos, conv, data); } +/** +* proc_dobool - read/write a bool +* @table: the sysctl table +* @write: %TRUE if this is a write to the sysctl file +* @buffer: the user buffer +* @lenp: the size of the user buffer +* @ppos: file position +* +* Reads/writes up to table->maxlen/sizeof(unsigned int) integer +* values from/to the user buffer, treated as an ASCII string. +* +* Returns 0 on success. +*/ +int proc_dobool (struct ctl_table *table,int write,void *buffer, + size_t *lenp, loff_t *ppos) +{ + return do_proc_dointvec(table, write, buffer, lenp, ppos, + do_proc_dobool_conv, NULL); +} + /*** proc_dointvec - read a vector of integers * @table: the sysctl table @@ -1630,6 +1665,12 @@ int proc_dostring(struct ctl_table *table, int write, return -ENOSYS; } +int proc_dobool (struct ctl_table *table,int write, + void *buffer, size_t *lenp, loff_t *ppos) +{ + return -ENOSYS; +} + int proc_dointvec(struct ctl_table *table, int write, void *buffer, size_t *lenp, loff_t *ppos) {kernel/sysctl.c int __init sysctl_init(void) · line 3472
Quoted 7 lines
kernel/sysctl.c +1
-0@@ -3425,6 +3466,7 @@ int __init sysctl_init(void)* No sense putting this after each symbol definition, twice, * exception granted :-) */ +EXPORT_SYMBOL (proc_dobool); EXPORT_SYMBOL(proc_dointvec); EXPORT_SYMBOL(proc_douintvec); EXPORT_SYMBOL(proc_dointvec_jiffies);Friendly ping!
Quoted 1 line
Luis, Kees, Iurii, could you please have a look and provide an Ack if this looks ok to you?
Ping again!
Could anybody please provide an Ack?
Thanks,
Thomas
Re: [PATCH 1/2] sysctl: introduce new proc handler proc_dobool
In reply to Thomas HuthQuoted 8 lines · Thomas Huth
From: Jia He <[email protected]>
This is to let bool variable could be correctly displayed in big/little endian sysctl procfs. sizeof(bool) is arch dependent,
proc_doboolshould work in all arches.Suggested-by Pan Xinhui <[email protected]>Signed-off-by Jia He <[email protected]>
Hi! I apologize for the delay. Yes, this looks good to me; thanks!
Signature · 1 line
Kees Cook
PATCH 2/2 lockd: change the proc_handler for nsm_use_hostnames
In reply to Thomas HuthFrom: Jia He <[email protected]>
nsm_use_hostnames is a module parameter and it will be exported to sysctl procfs. This is to let user sometimes change it from userspace. But the minimal unit for sysctl procfs read/write it sizeof(int).
In big endian system, the converting from/to bool to/from int will cause error for proc items.
This patch use a new proc_handler proc_dobool to fix it.
--- fs/lockd/svc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svc.c +1 -1
@@ -584,7 +584,7 @@ static struct ctl_table nlm_sysctls[] = { .data = &nsm_use_hostnames, .maxlen = sizeof(int), .mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dobool, }, { .procname = "nsm_local_state",
Signature · 1 line
2.27.0
Re: [PATCH 2/2] lockd: change the proc_handler for nsm_use_hostnames
Quoted 23 lines · Thomas Huth
From: Jia He <[email protected]>
nsm_use_hostnamesis a module parameter and it will be exported to sysctl procfs. This is to let user sometimes change it from userspace. But the minimal unit for sysctl procfs read/write it sizeof(int).
In big endian system, the converting from/to bool to/from int will cause error for proc items.This patch use a new
proc_handlerproc_doboolto fix it.Signed-off-by Jia He <[email protected]>Reviewed-by Pan Xinhui <[email protected]>[thuth: Fix typo in commit message]Signed-off-by Thomas Huth <[email protected]>--- fs/lockd/svc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/lockd/svc.c +0
-0
fs/lockd/svc.c static struct ctl_table nlm_sysctls[] = { · line 585
Quoted 2 lines
fs/lockd/svc.c +0
-0@@ -584,7 +584,7 @@ static struct ctl_table nlm_sysctls[] = { .data = &nsm_use_hostnames, .maxlen = sizeof(int),
For robustness, maybe this should be:
.maxlen = sizeof(nsm_use_hostnames),
Quoted 9 lines
fs/lockd/svc.c +1
-1.mode = 0644, - .proc_handler = proc_dointvec, + .proc_handler = proc_dobool, }, { .procname = "nsm_local_state",Signature · 1 line
2.27.0
Also, I wonder what other BE-corrupted bools are out there?
Signature · 1 line
Kees Cook
Looks good to me. Could Chuck take it with nfsd stuff if somebody could ACK the sysctl part?
--b.
Quoted 29 lines · Thomas Huth
There is an endianess problem with
/proc/sys/fs/nfs/nsm_use_hostnames(which can e.g. be seen on an s390x host) :# modprobe lockd nsm_use_hostnames=1 # cat /proc/sys/fs/nfs/nsm_use_hostnames 16777216The
nsm_use_hostnamesvariable is declared as "bool" which is required for the correct type for the module parameter. However, this does not work correctly with the entry in the /proc filesystem since this currently requires "int".Jia He already provided patches for this problem a couple of years ago, but apparently they felt through the cracks and never got merged. So here's a rebased version to finally fix this issue.
Jia He (2):
sysctl: introduce new proc handlerproc_dobool
lockd: change theproc_handlerfornsm_use_hostnamesfs/lockd/svc.c | 2 +- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-)Signature · 1 line
2.27.0
Thanks for your review, Bruce. I'll watch for the additional Ack.
Quoted 37 lines · J. Bruce Fields
Looks good to me. Could Chuck take it with nfsd stuff if somebody could ACK the sysctl part?
--b.
Quoted 29 lines · Thomas Huth
There is an endianess problem with
/proc/sys/fs/nfs/nsm_use_hostnames(which can e.g. be seen on an s390x host) :# modprobe lockd nsm_use_hostnames=1 # cat /proc/sys/fs/nfs/nsm_use_hostnames 16777216The
nsm_use_hostnamesvariable is declared as "bool" which is required for the correct type for the module parameter. However, this does not work correctly with the entry in the /proc filesystem since this currently requires "int".Jia He already provided patches for this problem a couple of years ago, but apparently they felt through the cracks and never got merged. So here's a rebased version to finally fix this issue.
Jia He (2):
sysctl: introduce new proc handlerproc_dobool
lockd: change theproc_handlerfornsm_use_hostnamesfs/lockd/svc.c | 2 +- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-)Signature · 1 line
2.27.0
--
Chuck Lever
Quoted 16 lines · Thomas Huth
There is an endianess problem with
/proc/sys/fs/nfs/nsm_use_hostnames(which can e.g. be seen on an s390x host) :# modprobe lockd nsm_use_hostnames=1 # cat /proc/sys/fs/nfs/nsm_use_hostnames 16777216The
nsm_use_hostnamesvariable is declared as "bool" which is required for the correct type for the module parameter. However, this does not work correctly with the entry in the /proc filesystem since this currently requires "int".Jia He already provided patches for this problem a couple of years ago, but apparently they felt through the cracks and never got merged. So here's a rebased version to finally fix this issue.
Quoted 5 lines
Jia He (2):
sysctl: introduce new proc handlerproc_dobool
lockd: change theproc_handlerfornsm_use_hostnames
Thanks for picking them up ;-)
---
Cheers,
Justin (Jia He)
Quoted 22 lines · Thomas Huth
There is an endianess problem with
/proc/sys/fs/nfs/nsm_use_hostnames(which can e.g. be seen on an s390x host) :# modprobe lockd nsm_use_hostnames=1 # cat /proc/sys/fs/nfs/nsm_use_hostnames 16777216The
nsm_use_hostnamesvariable is declared as "bool" which is required for the correct type for the module parameter. However, this does not work correctly with the entry in the /proc filesystem since this currently requires "int".Jia He already provided patches for this problem a couple of years ago, but apparently they felt through the cracks and never got merged. So here's a rebased version to finally fix this issue.
Quoted 11 lines
Jia He (2):
sysctl: introduce new proc handlerproc_dobool
lockd: change theproc_handlerfornsm_use_hostnamesfs/lockd/svc.c | 2 +- include/linux/sysctl.h | 2 ++ kernel/sysctl.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-)Signature · 1 line
2.27.0
To get these patches in front of our zero-day apparatus, I've applied them to the for-next topic branch here:
https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git/log/?h=for-next
However I haven't seen an Ack for the kernel/sysctl.c change yet.
--
Chuck Lever