diff options
| author | Rick Macklem <rmacklem@FreeBSD.org> | 2026-11-30 19:08:02 +0000 |
|---|---|---|
| committer | Rick Macklem <rmacklem@FreeBSD.org> | 2026-11-30 19:08:02 +0000 |
| commit | 4bc351e3635bd5cd734cf76b397a0520888aceb0 (patch) | |
| tree | e379bf4c90d806dd999e8b51fee2a8737d3dc7e8 | |
| parent | 3b0b9eba0422c9606c0c6fee7116daca037c7873 (diff) | |
nlm_prot_impl.c: Fix a crash caused by a bogus file handle
This patch adds sanity checking to the file handle, so that
a bogus one will not cause a crash.
Reported by: Laam Alif at Ibteda Digital Library, J. David
Discussed with: secteam
| -rw-r--r-- | sys/nlm/nlm_prot_impl.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/sys/nlm/nlm_prot_impl.c b/sys/nlm/nlm_prot_impl.c index 02b7383cd640..6ae496b276f5 100644 --- a/sys/nlm/nlm_prot_impl.c +++ b/sys/nlm/nlm_prot_impl.c @@ -1740,10 +1740,13 @@ nlm_sm_notify(struct nlm_sm_status *argp) } } -static void +static int nlm_convert_to_fhandle_t(fhandle_t *fhp, struct netobj *p) { + if (p->n_len != sizeof(fhandle_t) || p->n_bytes == NULL) + return (EINVAL); memcpy(fhp, p->n_bytes, sizeof(fhandle_t)); + return (0); } struct vfs_state { @@ -1878,8 +1881,12 @@ nlm_do_test(nlm4_testargs *argp, nlm4_testres *result, struct svc_req *rqstp, nlm_check_expired_locks(host); sysid = host->nh_sysid; - nlm_convert_to_fhandle_t(&fh, &argp->alock.fh); + error = nlm_convert_to_fhandle_t(&fh, &argp->alock.fh); nlm_copy_netobj(&result->cookie, &argp->cookie, M_RPC); + if (error != 0) { + result->stat.stat = nlm_convert_error(error); + goto out; + } if (time_uptime < nlm_grace_threshold) { result->stat.stat = nlm4_denied_grace_period; @@ -1985,8 +1992,12 @@ nlm_do_lock(nlm4_lockargs *argp, nlm4_res *result, struct svc_req *rqstp, nlm_check_expired_locks(host); sysid = host->nh_sysid; - nlm_convert_to_fhandle_t(&fh, &argp->alock.fh); + error = nlm_convert_to_fhandle_t(&fh, &argp->alock.fh); nlm_copy_netobj(&result->cookie, &argp->cookie, M_RPC); + if (error != 0) { + result->stat.stat = nlm_convert_error(error); + goto out; + } if (time_uptime < nlm_grace_threshold && !argp->reclaim) { result->stat.stat = nlm4_denied_grace_period; @@ -2165,8 +2176,12 @@ nlm_do_cancel(nlm4_cancargs *argp, nlm4_res *result, struct svc_req *rqstp, nlm_check_expired_locks(host); sysid = host->nh_sysid; - nlm_convert_to_fhandle_t(&fh, &argp->alock.fh); + error = nlm_convert_to_fhandle_t(&fh, &argp->alock.fh); nlm_copy_netobj(&result->cookie, &argp->cookie, M_RPC); + if (error != 0) { + result->stat.stat = nlm_convert_error(error); + goto out; + } if (time_uptime < nlm_grace_threshold) { result->stat.stat = nlm4_denied_grace_period; @@ -2254,8 +2269,12 @@ nlm_do_unlock(nlm4_unlockargs *argp, nlm4_res *result, struct svc_req *rqstp, nlm_check_expired_locks(host); sysid = host->nh_sysid; - nlm_convert_to_fhandle_t(&fh, &argp->alock.fh); + error = nlm_convert_to_fhandle_t(&fh, &argp->alock.fh); nlm_copy_netobj(&result->cookie, &argp->cookie, M_RPC); + if (error != 0) { + result->stat.stat = nlm_convert_error(error); + goto out; + } if (time_uptime < nlm_grace_threshold) { result->stat.stat = nlm4_denied_grace_period; |
