Skip to content

Commit 1196bdc

Browse files
committed
SUNRPC: Document validity guarantees of the pointer returned by reserve_space
A subtlety of this API is that if the @nbytes region traverses a page boundary, the next __xdr_commit_encode will shift the data item in the XDR encode buffer. This makes the returned pointer point to something else, leading to unexpected behavior. There are a few cases where the caller saves the returned pointer and then later uses it to insert a computed value into an earlier part of the stream. This can be safe only if either: - the data item is guaranteed to be in the XDR buffer's head, and thus is not ever going to be near a page boundary, or - the data item is no larger than 4 octets, since XDR alignment rules require all data items to start on 4-octet boundaries But that safety is only an artifact of the current implementation. It would be less brittle if these "safe" uses were eventually replaced. Reviewed-by: NeilBrown <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 4163ee7 commit 1196bdc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

net/sunrpc/xdr.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,12 @@ static noinline __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
10971097
* Checks that we have enough buffer space to encode 'nbytes' more
10981098
* bytes of data. If so, update the total xdr_buf length, and
10991099
* adjust the length of the current kvec.
1100+
*
1101+
* The returned pointer is valid only until the next call to
1102+
* xdr_reserve_space() or xdr_commit_encode() on @xdr. The current
1103+
* implementation of this API guarantees that space reserved for a
1104+
* four-byte data item remains valid until @xdr is destroyed, but
1105+
* that might not always be true in the future.
11001106
*/
11011107
__be32 * xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes)
11021108
{

0 commit comments

Comments
 (0)