Bug 1764075

Summary: [s390x] nsm_use_hostnames=1 shows 16777216 by `sysctl` in big-endian architectures
Product: Red Hat Enterprise Linux 8 Reporter: Yongcheng Yang <yoyang>
Component: kernelAssignee: Alice Mitchell <ajmitchell>
kernel sub component: NFS QA Contact: Yongcheng Yang <yoyang>
Status: CLOSED WONTFIX Docs Contact:
Severity: low    
Priority: low CC: ajmitchell, bcodding, smayhew, steved, swhiteho, thuth, xzhou
Version: 8.0Keywords: Reopened, Reproducer, Triaged
Target Milestone: rc   
Target Release: 8.6   
Hardware: s390x   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1355652 Environment:
Last Closed: 2022-05-03 07:27:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Yongcheng Yang 2019-10-22 08:25:48 UTC
[root]# tail -1 /etc/modprobe.d/lockd.conf
options lockd nsm_use_hostnames=1
[root]# modprobe lockd
[root]# cat /sys/module/lockd/parameters/nsm_use_hostnames
Y
[root]# cat /proc/sys/fs/nfs/nsm_use_hostnames
16777216
[root@ibm-z-121 kernel]# ls -l /proc/sys/fs/nfs/nsm_use_hostnames /sys/module/lockd/parameters/nsm_use_hostnames
-rw-r--r--. 1 root root    0 Oct 22 04:12 /proc/sys/fs/nfs/nsm_use_hostnames
-rw-r--r--. 1 root root 4096 Oct 22 04:12 /sys/module/lockd/parameters/nsm_use_hostnames
[root@ibm-z-121 kernel]# uname --machine
s390x


+++ This bug was initially created as a clone of Bug #1355652 +++

Steps to Reproduce:
1. echo 'options lockd nsm_use_hostnames=1' >/etc/modprobe.d/lockd.conf
2. Re-load the module lockd or reboot system to make it effective
3. sysctl fs.nfs.nsm_use_hostnames
4. cat /sys/module/lockd/parameters/nsm_use_hostnames

Actual results:
# After enabled it
[root]# sysctl fs.nfs.nsm_use_hostnames
fs.nfs.nsm_use_hostnames = 16777216 <<<<<<<<<<<<<<<<< 
[root@]# cat /sys/module/lockd/parameters/nsm_use_hostnames 
Y
[root]# 

Expected results:
[root]# sysctl fs.nfs.nsm_use_hostnames
fs.nfs.nsm_use_hostnames = 1  <<<<<<<<<<<<<<<<<<<<<<<<<<
[root@]# cat /sys/module/lockd/parameters/nsm_use_hostnames 
Y
[root]#

Additional info:
[yoyang@yoyang-pc lockd]$ awk 'BEGIN{print log(16777216)/log(2)}'
24
[yoyang@yoyang-pc lockd]$ awk 'BEGIN{print 2**24}'
16777216
[yoyang@yoyang-pc lockd]$

Comment 1 Yongcheng Yang 2019-10-22 08:59:01 UTC
As the parameter "Y" is correct (in file "/sys/module/lockd/parameters/nsm_use_hostnames") and only the `sysctl` get the messy value. Let's see if this is the sysctl tool's issue.

(In reply to Yongcheng Yang from comment #0)
...
> [root]# sysctl fs.nfs.nsm_use_hostnames
> fs.nfs.nsm_use_hostnames = 16777216 <<<<<<<<<<<<<<<<< 
> [root@]# cat /sys/module/lockd/parameters/nsm_use_hostnames 
> Y
> [root]# 

Some more tests shows `sysctl -w fs.nfs.nsm_use_hostnames=1` won't work as expected:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# sysctl -w fs.nfs.nsm_use_hostnames=0
fs.nfs.nsm_use_hostnames = 0
# cat /sys/module/lockd/parameters/nsm_use_hostnames 
N
 
# sysctl -w fs.nfs.nsm_use_hostnames=1
fs.nfs.nsm_use_hostnames = 1            <<<<
# cat /sys/module/lockd/parameters/nsm_use_hostnames
N                                       <<<<
 
# sysctl -w fs.nfs.nsm_use_hostnames=16777216
fs.nfs.nsm_use_hostnames = 16777216
# cat /sys/module/lockd/parameters/nsm_use_hostnames
Y

Comment 2 Yongcheng Yang 2019-10-22 09:28:55 UTC
I'm changing this back to kernel NFS again, apologize.

Just find an upstream patch but it has not been accepted yet:
https://patchwork.kernel.org/patch/9475657/

However, it suggests the culprit is in fs/lockd/svc.c
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
582         {
583                 .procname       = "nsm_use_hostnames",
584                 .data           = &nsm_use_hostnames,
585                 .maxlen         = sizeof(int),
586                 .mode           = 0644,
587                 .proc_handler   = proc_dointvec, <<<<
588         },
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Comment 4 Alice Mitchell 2020-03-12 12:35:09 UTC
Not a config file issue as this is a sysctl kernel parameter, but it looks to me that the error is that nsm_use_hostnames is defined as a type bool, which afaics is never done for sysctl parameters, they are all int type. which leads to the buffer overruns as the size field is set to that of an int not a bool.

previous patch would not have been accepted as there is no proc_dobool() and no sysctl parameters are declared bool afaics.

I expect the following patch will fix the issue :-
--- fs/lockd/mon.c.orig	2020-03-12 12:32:16.614585321 +0000
+++ fs/lockd/mon.c	2020-03-12 12:32:19.968611359 +0000
@@ -58,7 +58,7 @@
  * Local NSM state
  */
 u32	__read_mostly		nsm_local_state;
-bool	__read_mostly		nsm_use_hostnames;
+int	__read_mostly		nsm_use_hostnames;
 
 static inline struct sockaddr *nsm_addr(const struct nsm_handle *nsm)
 {

Comment 7 RHEL Program Management 2021-04-22 07:31:27 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.

Comment 16 RHEL Program Management 2022-05-03 07:27:24 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.