JAGNYA DATTA TRIPATHY has uploaded this change for review. ( https://review.gerrithub.io/c/ffilz/nfs-ganesha/+/1238122?usp=email ) Change subject: NFSv4: fix OPEN_DOWNGRADE validation for BOTH after separate opens ...................................................................... NFSv4: fix OPEN_DOWNGRADE validation for BOTH after separate opens When a client opens a file twice -- first with READ-only, then with WRITE-only -- the server accumulates share_access_prev as: (1 << OPEN4_SHARE_ACCESS_READ) = bit 1 (value 2) (1 << OPEN4_SHARE_ACCESS_WRITE) = bit 2 (value 4) share_access_prev = 6 The combined share_access is now BOTH (3). A subsequent OPEN_DOWNGRADE to BOTH is a valid no-op: the client holds all rights that BOTH represents. However the existing check: share_access_prev & (1 << OPEN4_SHARE_ACCESS_BOTH) = 6 & (1 << 3) = 6 & 8 = 0 -> NFS4ERR_INVAL fails because BOTH (3) was never passed as a single mode value to any OPEN call, so its bit (bit 3 = value 8) was never stored. RFC 7530 §16.19.4 / RFC 5661 §18.18.3 state that the downgrade target must be "a subset of those used in all OPEN calls". For BOTH this means: valid if BOTH was directly opened OR if both READ and WRITE were individually opened (their union equals BOTH). Introduce share_downgrade_allowed() to implement this rule. For any target other than BOTH the function reduces to the original single-bit check, preserving all existing pynfs OPDG test behaviour: OPDG2: OPEN(BOTH) -> downgrade(READ) -- target=READ != BOTH original check: 8 & 2 = 0 -> NFS4ERR_INVAL (correct, unchanged) OPDG3: OPEN(WRITE)+OPEN(BOTH) -> downgrade(READ) -- target=READ original check: 12 & 2 = 0 -> NFS4ERR_INVAL (correct, unchanged) The BOTH special case only activates for the accumulation scenario and correctly returns NFS4_OK where the original code returned NFS4ERR_INVAL. Change-Id: I58751d89b50933db5223e3620f23d1857893ca77 Signed-off-by: Jagnya Tripathy <jagnya.tripathy@gmail.com> --- M src/Protocols/NFS/nfs4_op_open_downgrade.c 1 file changed, 30 insertions(+), 5 deletions(-) git pull ssh://review.gerrithub.io:29418/ffilz/nfs-ganesha refs/changes/22/1238122/1 -- To view, visit https://review.gerrithub.io/c/ffilz/nfs-ganesha/+/1238122?usp=email To unsubscribe, or for help writing mail filters, visit https://review.gerrithub.io/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: ffilz/nfs-ganesha Gerrit-Branch: next Gerrit-Change-Id: I58751d89b50933db5223e3620f23d1857893ca77 Gerrit-Change-Number: 1238122 Gerrit-PatchSet: 1 Gerrit-Owner: JAGNYA DATTA TRIPATHY <jagnya.tripathy@gmail.com>