Skip to content

Commit 6659db4

Browse files
author
Trond Myklebust
committed
NFSv4: Ensure decode_compound_hdr() sanity checks the tag
The server is supposed to return the same tag that the client sends in the outgoing RPC call, but we should still sanity check the length just in case. Reported-by: <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 4798f80 commit 6659db4

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

fs/nfs/nfs4xdr.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,20 +3168,23 @@ static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char
31683168

31693169
static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
31703170
{
3171-
__be32 *p;
3171+
ssize_t ret;
3172+
void *ptr;
3173+
u32 tmp;
31723174

3173-
p = xdr_inline_decode(xdr, 8);
3174-
if (unlikely(!p))
3175+
if (xdr_stream_decode_u32(xdr, &tmp) < 0)
31753176
return -EIO;
3176-
hdr->status = be32_to_cpup(p++);
3177-
hdr->taglen = be32_to_cpup(p);
3177+
hdr->status = tmp;
31783178

3179-
p = xdr_inline_decode(xdr, hdr->taglen + 4);
3180-
if (unlikely(!p))
3179+
ret = xdr_stream_decode_opaque_inline(xdr, &ptr, NFS4_OPAQUE_LIMIT);
3180+
if (ret < 0)
3181+
return -EIO;
3182+
hdr->taglen = ret;
3183+
hdr->tag = ptr;
3184+
3185+
if (xdr_stream_decode_u32(xdr, &tmp) < 0)
31813186
return -EIO;
3182-
hdr->tag = (char *)p;
3183-
p += XDR_QUADLEN(hdr->taglen);
3184-
hdr->nops = be32_to_cpup(p);
3187+
hdr->nops = tmp;
31853188
if (unlikely(hdr->nops < 1))
31863189
return nfs4_stat_to_errno(hdr->status);
31873190
return 0;

0 commit comments

Comments
 (0)