Re: [PATCH] NFSv4: fix bitmap length check in decode_bitmap()
From: Guanglei Zhu
Date: Mon Nov 30 2026 - 00:55:23 EST
On Sun, 29 Nov 2026 17:04:46 -0500, Trond Myklebust wrote:
> The wrap is real, but bitmap4 is a variable length array, and a
> well-formed bitmap with four or more words, for instance one with
> trailing zero words, is legal. The current code accepts such a bitmap
> in CB_GETATTR and CB_RECALL_ANY, and ignores the words past bitmap[2].
>
> > + if (unlikely(attrlen > 3))
> > + return htonl(NFS4ERR_BADXDR);
>
> Doesn't this make both of those callbacks fail with NFS4ERR_BADXDR for
> such a bitmap?
Yes. attrlen > 3 rejects every bitmap with four or more words, legal or
not, so both CB_GETATTR and CB_RECALL_ANY would fail with NFS4ERR_BADXDR
where the current code accepts the bitmap and ignores the words past
bitmap[2]. The bound I picked was the size of the local array, not the
length bitmap4 allows, and I did not test a long bitmap before sending.
> Could the length be bounded without rejecting long bitmaps instead?
> xdr_stream_decode_uint32_array() checks the count against
> SIZE_MAX / sizeof(__be32) before it calls xdr_inline_decode(), and
> returns
> -EMSGSIZE for an array longer than the destination. decode_bitmap4()
> in
> fs/nfs/nfs4xdr.c already treats that -EMSGSIZE as success.
It can. I rebuilt the decode_bitmap() from Anna's v2 2/3 [1] in a
user-space replica and compared it with the current code and with this
patch:
- attrlen = 0x40000000, message ending after the length word: the
current code reads past the end of the buffer, this patch returns
NFS4ERR_BADXDR, and 2/3 returns NFS4ERR_RESOURCE. The length is
computed as size_t, so there is no shift to wrap.
- attrlen = 4 with four words present: the current code and 2/3
decode the first three words and skip the rest, this patch returns
NFS4ERR_BADXDR.
So 2/3 fixes the wrap and keeps the behaviour for long bitmaps, and
nothing is left in this patch that 2/3 does not cover. I should have
checked the list before sending it.
I'm withdrawing this patch. Thanks for the review, and sorry for the
noise.
[1] https://lore.kernel.org/linux-nfs/20261020163749.262930-3-anna@xxxxxxxxxx/
--
2.43.0