Bug 1687496

Summary: nfsconf: update nfs.conf inplace instead of replacing the file
Product: Red Hat Enterprise Linux 8 Reporter: Alice Mitchell <ajmitchell>
Component: nfs-utilsAssignee: Alice Mitchell <ajmitchell>
Status: CLOSED ERRATA QA Contact: Yongcheng Yang <yoyang>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.0CC: steved, xzhou, yoyang
Target Milestone: rcKeywords: FutureFeature
Target Release: 8.1   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: nfs-utils-2.3.3-22.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-11-05 22:18:26 UTC Type: Enhancement
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1653927, 1681972    
Bug Blocks:    
Attachments:
Description Flags
Modify nfs.conf in-place
none
Proposed patch to impliment file rewriting none

Description Alice Mitchell 2019-03-11 15:42:59 UTC
Description of problem:

When nfsconf tool is used to update the contents of nfs.conf it replaces the file rather than changing the contents, and in the process loses any special permissions or modes the previous version of the file held.

As can be seen in bug 1655880

Version-Release number of selected component (if applicable):
since nfs-utils-2.3.3

How reproducible:
always

Steps to Reproduce:
1. Use nfsconf or any tool that uses it e.g nfsconvert

Actual results:
#  ls -al /etc/nfs.conf
-rw-------. 1 root root 1090 Mar 11 10:25 /etc/nfs.conf

Expected results:
#  ls -al /etc/nfs.conf
-rw-r--r--. 1 root root 1090 Mar 11 10:25 /etc/nfs.conf


Additional info:
The affected functionality exists in conffile.c within the nfs-utils main code and not just within the nfsconf cli, the code should be changed to rewrite the contents of the existing file instead of replacing the old version with a newly written replacement, this does however leave a larger window of opportunity for race conditions if some method other than nfsconf attempts to alter the same file simultaneously.

Comment 1 Alice Mitchell 2019-03-20 10:27:57 UTC
Created attachment 1545998 [details]
Modify nfs.conf in-place

Proposed patch to modify the file contents and guard it with an flock

Comment 2 Alice Mitchell 2019-03-20 16:35:52 UTC
Created attachment 1546161 [details]
Proposed patch to impliment file rewriting

Comment 4 Yongcheng Yang 2019-07-11 04:19:28 UTC
Have checked the previous permissions won't be changed after "nfsconver" now:

[root@hp-dl360g9-14 ~]# rpm -q nfs-utils
nfs-utils-2.3.3-19.el8.x86_64
[root@hp-dl360g9-14 ~]# stat /etc/nfs.conf
  File: /etc/nfs.conf
  Size: 1024            Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 50366035    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:etc_t:s0
Access: 2019-07-11 00:14:13.947382375 -0400
Modify: 2019-06-12 13:40:03.000000000 -0400
Change: 2019-07-11 00:14:12.997383859 -0400
 Birth: -
[root@hp-dl360g9-14 ~]# echo 'RPCNFSDARGS="-V4"' > /etc/sysconfig/nfs
[root@hp-dl360g9-14 ~]# nfsconvert
[root@hp-dl360g9-14 ~]# ls /etc/sysconfig/nfs
ls: cannot access '/etc/sysconfig/nfs': No such file or directory
[root@hp-dl360g9-14 ~]# grep -A1 '\[nfsd\]' /etc/nfs.conf
[nfsd]
vers4 = y
[root@hp-dl360g9-14 ~]# stat /etc/nfs.conf
  File: /etc/nfs.conf
  Size: 1034            Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 50366035    Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: system_u:object_r:etc_t:s0
Access: 2019-07-11 00:15:43.425242596 -0400
Modify: 2019-07-11 00:15:09.433295699 -0400
Change: 2019-07-11 00:15:09.434295697 -0400
 Birth: -
[root@hp-dl360g9-14 ~]# 

Will update testcase to cover this later.

Comment 9 Yongcheng Yang 2019-09-05 08:55:06 UTC
Moving to VERIFIED based on test logs of Comment #7 now.

Comment 11 errata-xmlrpc 2019-11-05 22:18:26 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2019:3579