Skip to content

Commit 201cb20

Browse files
committed
NFSD: Insulate nfsd4_encode_readlink() from page boundaries in the encode buffer
There's no guarantee that the pointer returned from xdr_reserve_space() will still point to the correct reserved space in the encode buffer after one or more intervening calls to xdr_reserve_space(). It just happens to work with the current implementation of xdr_reserve_space(). Reviewed-by: NeilBrown <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 26ea816 commit 201cb20

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,25 +4450,21 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr,
44504450
union nfsd4_op_u *u)
44514451
{
44524452
struct nfsd4_readlink *readlink = &u->readlink;
4453-
__be32 *p, *maxcount_p, zero = xdr_zero;
4453+
__be32 *p, wire_count, zero = xdr_zero;
44544454
struct xdr_stream *xdr = resp->xdr;
4455-
int length_offset = xdr->buf->len;
4455+
unsigned int length_offset;
44564456
int maxcount, status;
44574457

4458-
maxcount_p = xdr_reserve_space(xdr, XDR_UNIT);
4459-
if (!maxcount_p)
4458+
/* linktext4.count */
4459+
length_offset = xdr->buf->len;
4460+
if (unlikely(!xdr_reserve_space(xdr, XDR_UNIT)))
44604461
return nfserr_resource;
4461-
maxcount = PAGE_SIZE;
44624462

4463+
/* linktext4.data */
4464+
maxcount = PAGE_SIZE;
44634465
p = xdr_reserve_space(xdr, maxcount);
44644466
if (!p)
44654467
return nfserr_resource;
4466-
/*
4467-
* XXX: By default, vfs_readlink() will truncate symlinks if they
4468-
* would overflow the buffer. Is this kosher in NFSv4? If not, one
4469-
* easy fix is: if vfs_readlink() precisely fills the buffer, assume
4470-
* that truncation occurred, and return NFS4ERR_RESOURCE.
4471-
*/
44724468
nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp,
44734469
(char *)p, &maxcount);
44744470
if (nfserr == nfserr_isdir)
@@ -4481,7 +4477,9 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr,
44814477
nfserr = nfserrno(status);
44824478
goto out_err;
44834479
}
4484-
*maxcount_p = cpu_to_be32(maxcount);
4480+
4481+
wire_count = cpu_to_be32(maxcount);
4482+
write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, XDR_UNIT);
44854483
xdr_truncate_encode(xdr, length_offset + 4 + xdr_align_size(maxcount));
44864484
write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, &zero,
44874485
xdr_pad_size(maxcount));

0 commit comments

Comments
 (0)