lockd: fix swapped arguments in nlmsvc_match_ip()
Subsystems (2)
PATCH 1/1 lockd: fix swapped arguments in nlmsvc_match_ip()
When releasing locks by server IP address via /proc/fs/nfsd/unlock_ip, nlmsvc_unlock_all_by_ip() calls nlm_traverse_files() with the server sockaddr as the opaque @data argument:
nlm_traverse_files(server_addr, nlmsvc_match_ip, NULL);
The match callback is later invoked from nlm_traverse_locks() as:
match(lockhost, host);
where the first argument is the nlm_host that owns the lock, and the second argument is the @data that was originally passed down (here the server sockaddr). This is the convention every other match callback relies on (nlmsvc_mark_host(), nlmsvc_same_host(), nlmsvc_is_client()):
arg1 is the real nlm_host, arg2 is the caller-supplied reference value.
nlmsvc_match_ip() has had these two arguments reversed ever since the unlock-by-IP feature was introduced in commit 4373ea84c84d ("lockd:
unlock lockd locks associated with a given server ip"):
return rpc_cmp_addr(nlm_srcaddr(host), datap);
Here @host is actually the server sockaddr, so nlm_srcaddr(host) dereferences a struct sockaddr as a struct nlm_host and reads garbage at the offset of h_srcaddr; meanwhile @datap is actually the lock owner's nlm_host but is compared as a sockaddr. As a result the comparison practically never matches and locks are not released for the requested IP.
Swap the arguments so the lock owner's source address is compared against the requested server address:
return rpc_cmp_addr(nlm_srcaddr(datap), (struct sockaddr *)host);
--- fs/lockd/svcsubs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svcsubs.c +1 -1
@@ -511,7 +511,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);static int nlmsvc_match_ip (void *datap,struct nlm_host *host) { -return rpc_cmp_addr (nlm_srcaddr (host), datap); +return rpc_cmp_addr (nlm_srcaddr (datap), (struct sockaddr *)host); }/**
Signature · 4 lines
2.34.1 Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.
Chuck Lever
maintainerQuoted 9 lines · Oscar Ou
When releasing locks by server IP address via
/proc/fs/nfsd/unlock_ip,nlmsvc_unlock_all_by_ip()callsnlm_traverse_files()with the server sockaddr as the opaque @data argument:nlm_traverse_files(server_addr, nlmsvc_match_ip, NULL);The match callback is later invoked from
nlm_traverse_locks()as:[...]
Applied to nfsd-testing, thanks!
[1/1] lockd: fix swapped arguments in nlmsvc_match_ip()
commit: 80e05cc8a30aec76f4457a9c163b222e9ff5a671
--
Chuck Lever