NFS: -EIO from decode_bitmap if too many bitmaps
Subsystems (2)
PATCH 1/1 NFS: -EIO from decode_bitmap if too many bitmaps
decode_bitmap will only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return -EIO here instead of bailing out in a later xdr decode.
---
This is related to my "NFSv4: fix getacl ERANGE for some ACL buffer sizes" patch - I noticed that even though we'll only ever parse 3 bitmaps, we don't error out correctly if more are sent.
This condition is probably never hit, but if it ever is, it'd be nice to have the code error out where the problem actually occurred.
fs/nfs/nfs4xdr.c | 3 +++ 1 file changed, 3 insertions(+)
fs/nfs/nfs4xdr.c +3 -0
@@ -3146,6 +3146,9 @@ static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) goto out_overflow; bmlen =be32_to_cpup (p); +if (unlikely (bmlen >3 )) + goto out_overflow; + bitmap[0 ] = bitmap[1 ] = bitmap[2 ] =0 ; p =xdr_inline_decode (xdr, (bmlen <<2 ));if (unlikely (!p))
Signature · 1 line
1.8.3.1 (Apple Git-46)
Quoted 22 lines · Weston Andros Adamson
decode_bitmapwill only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return-EIOhere instead of bailing out in a later xdr decode.Signed-off-by Weston Andros Adamson <[email protected]>---
This is related to my "NFSv4: fix getacl ERANGE for some ACL buffer sizes" patch - I noticed that even though we'll only ever parse 3 bitmaps, we don't error out correctly if more are sent.
This condition is probably never hit, but if it ever is, it'd be nice to have the code error out where the problem actually occurred.
fs/nfs/nfs4xdr.c| 3 +++1 file changed, 3 insertions(+)fs/nfs/nfs4xdr.c +0
-0
fs/nfs/nfs4xdr.c static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) · line 3151
Quoted 6 lines
fs/nfs/nfs4xdr.c +3
-0@@ -3146,6 +3146,9 @@ static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) goto out_overflow; bmlen =be32_to_cpup (p); +if (unlikely (bmlen >3 )) + goto out_overflow; +
Nit: Using a naked integer should be avoid, if we can. Is there somewhere in the code that documents the "we only handle up t 3 bitmaps" constraint?
Quoted 10 lines
fs/nfs/nfs4xdr.c +0
-0bitmap[0 ] = bitmap[1 ] = bitmap[2 ] =0 ; p =xdr_inline_decode (xdr, (bmlen <<2 ));if (unlikely (!p))Signature · 6 lines
1.8.3.1 (Apple Git-46) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Quoted 4 lines · Weston Andros Adamson
decode_bitmapwill only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return-EIOhere instead of bailing out in a later xdr decode.
No. decode_bitmap will only _save_3 words in the bitmap[]argment, but it will decode arbitrary sized bitmaps:
p =xdr_inline_decode(xdr, (bmlen <<2));
Cheers
Trond
Quoted 11 lines · Trond Myklebust
Quoted 4 lines · Weston Andros Adamson
decode_bitmapwill only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return-EIOhere instead of bailing out in a later xdr decode.No.
decode_bitmapwill only _save_ 3 words in the bitmap[] argment, but it will decode arbitrary sized bitmaps:p = xdr_inline_decode(xdr, (bmlen << 2));
That said, we should probably check that the server isn't setting those bitmap words to any non-zero values. That would be a reason to return EIO.
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 10 lines · Trond
Quoted 9 lines · Trond Myklebust
Quoted 4 lines · Weston Andros Adamson
decode_bitmapwill only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return-EIOhere instead of bailing out in a later xdr decode.No.
decode_bitmapwill only _save_ 3 words in the bitmap[] argment, but it will decode arbitrary sized bitmaps:
Quoted 6 lines
Quoted 2 lines
p = xdr_inline_decode(xdr, (bmlen << 2));That said, we should probably check that the server isn't setting those bitmap words to any non-zero values. That would be a reason to return EIO.
Why wouldn't the client simply warn and ignore the extraneous data?
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Quoted 12 lines · Chuck Lever
Quoted 10 lines · Trond
Quoted 9 lines · Trond Myklebust
Quoted 4 lines · Weston Andros Adamson
decode_bitmapwill only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return-EIOhere instead of bailing out in a later xdr decode.No.
decode_bitmapwill only _save_ 3 words in the bitmap[] argment, but it will decode arbitrary sized bitmaps:
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
p = xdr_inline_decode(xdr, (bmlen << 2));That said, we should probably check that the server isn't setting those bitmap words to any non-zero values. That would be a reason to return EIO.
Why wouldn't the client simply warn and ignore the extraneous data?
...because unless the GETATTR is the very last operation, we'd end up failing to decode things correctly. Anyway, a server that returns attributes that we haven't requested must clearly be borken. It's definitely violating the spec.
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 10 lines · Trond
Quoted 9 lines · Chuck Lever
Quoted 7 lines · Trond
Quoted 6 lines · Trond Myklebust
Quoted 4 lines · Weston Andros Adamson
decode_bitmapwill only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return-EIOhere instead of bailing out in a later xdr decode.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
No.
decode_bitmapwill only _save_ 3 words in the bitmap[] argment, but it will decode arbitrary sized bitmaps:p = xdr_inline_decode(xdr, (bmlen << 2));
Oh, yeah.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
That said, we should probably check that the server isn't setting those bitmap words to any non-zero values. That would be a reason to return EIO.
Ok, I’ll rework this.
-dros
Quoted 16 lines
Quoted 3 lines
Why wouldn't the client simply warn and ignore the extraneous data?
...because unless the GETATTR is the very last operation, we'd end up failing to decode things correctly. Anyway, a server that returns attributes that we haven't requested must clearly be borken. It's definitely violating the spec.
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com
Quoted 20 lines · Trond
Quoted 19 lines · Chuck Lever
Quoted 16 lines · Trond
Quoted 11 lines · Trond Myklebust
Quoted 4 lines · Weston Andros Adamson
decode_bitmapwill only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return-EIOhere instead of bailing out in a later xdr decode.No.
decode_bitmapwill only _save_ 3 words in the bitmap[] argment, but it will decode arbitrary sized bitmaps:p = xdr_inline_decode(xdr, (bmlen << 2));That said, we should probably check that the server isn't setting those bitmap words to any non-zero values. That would be a reason to return EIO.
Quoted 5 lines
Quoted 2 lines
Why wouldn't the client simply warn and ignore the extraneous data?
...because unless the GETATTR is the very last operation, we'd end up failing to decode things correctly.
Surely that's only if the returned bitmap length doesn't match the number of bitmap words returned. The server can return a properly encoded result without overwriting the next operation in the compound, can't it?
Quoted 3 lines
Anyway, a server that returns
attributes that we haven't requested must clearly be borken. It's definitely violating the spec.
Definitely, but "be lenient in what you accept."
The reason I bring this up is that we had exactly this problem with NFSv4.2, where the third bitmap word was added.
Anyway, just an observation.
Signature · 2 lines
Chuck Lever chuck[dot]lever[at]oracle[dot]com
Quoted 22 lines · Chuck Lever
Quoted 20 lines · Trond
Quoted 19 lines · Chuck Lever
Quoted 16 lines · Trond
Quoted 11 lines · Trond Myklebust
Quoted 4 lines · Weston Andros Adamson
decode_bitmapwill only decode up to three bitmaps. If the xdr buffer has more than three bitmaps, return-EIOhere instead of bailing out in a later xdr decode.No.
decode_bitmapwill only _save_ 3 words in the bitmap[] argment, but it will decode arbitrary sized bitmaps:p = xdr_inline_decode(xdr, (bmlen << 2));That said, we should probably check that the server isn't setting those bitmap words to any non-zero values. That would be a reason to return EIO.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Why wouldn't the client simply warn and ignore the extraneous data?
...because unless the GETATTR is the very last operation, we'd end up failing to decode things correctly.
Surely that's only if the returned bitmap length doesn't match the number of bitmap words returned. The server can return a properly encoded result without overwriting the next operation in the compound, can't it?
How do we know? You're already talking about a broken server.
Quoted 7 lines
Quoted 3 lines
Anyway, a server that returns
attributes that we haven't requested must clearly be borken. It's definitely violating the spec.Definitely, but "be lenient in what you accept."
The reason I bring this up is that we had exactly this problem with NFSv4.2, where the third bitmap word was added.
We've never had servers returning attributes that are not requested AFAIK. In the current code, they are free to add in as many zero fillers in the bitmap as they want, and that's exactly what we should be accepting.
Signature · 6 lines
Trond Myklebust Linux NFS client maintainer NetApp [email protected] www.netapp.com