nfsd4: avoid NULL deference on strange COPY compounds
authorJ. Bruce Fields <bfields@redhat.com>
Fri, 6 Dec 2019 21:07:32 +0000 (16:07 -0500)
committerJ. Bruce Fields <bfields@redhat.com>
Mon, 9 Dec 2019 16:44:07 +0000 (11:44 -0500)
commitd781e3df710745fbbaee4eb07fd5b64331a1b175
treeb9b95fce122ce1041e0aa379944d3c2eb6912f9b
parent2e577f0faca4640348c398cb85d60a1eedac4b1e
nfsd4: avoid NULL deference on strange COPY compounds

With cross-server COPY we've introduced the possibility that the current
or saved filehandle might not have fh_dentry/fh_export filled in, but we
missed a place that assumed it was.  I think this could be triggered by
a compound like:

PUTFH(foreign filehandle)
GETATTR
SAVEFH
COPY

First, check_if_stalefh_allowed sets no_verify on the first (PUTFH) op.
Then op_func = nfsd4_putfh runs and leaves current_fh->fh_export NULL.
need_wrongsec_check returns true, since this PUTFH has OP_IS_PUTFH_LIKE
set and GETATTR does not have OP_HANDLES_WRONGSEC set.

We should probably also consider tightening the checks in
check_if_stalefh_allowed and double-checking that we don't assume the
filehandle is verified elsewhere in the compound.  But I think this
fixes the immediate issue.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: 4e48f1cccab3 "NFSD: allow inter server COPY to have... "
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfs4proc.c