SUNRPC: reset the svc decode stream after unwrapping a privacy request
Subsystems (3)
PATCH 1/1 SUNRPC: reset the svc decode stream after unwrapping a privacy request
For RPCSEC_GSS privacy (krb5p), gss_krb5_unwrap_v2() decrypts the request in place and then removes the GSS token header and the confounder from the head iovec: it memmoves the plaintext down to @offset and subtracts GSS_KRB5_TOK_HDR_LEN + headskip (32 bytes for the AES enctypes) from buf->head[0].iov_len.
svcauth_gss_unwrap_priv() only accounts for that in xdr->nwords. The stream's xdr->end still points at the end of the head as it was before unwrapping, 32 bytes past the data that is now there.
Decoding is unaffected while every argument lies within the head. It breaks once an argument spans the head and the page array: xdr_stream_subsegment() advances to the stale xdr->end, so it counts 32 bytes of leftover head buffer as argument data and then takes 32 bytes too few from the pages. xdr_stream_set_pos() corrects the position counter but not xdr->p, which is left 32 bytes inside the argument. The next operation of the COMPOUND is then decoded from argument data.
Do what the client already does in gss_unwrap_resp_priv() after decrypting a reply: discard the stream and build a new one over the buffer as it now is.
---
Found with xfstests generic/486 (a 1-byte to 64 KiB XATTR_REPLACE) on an NFSv4.2 mount with sec=krb5p; sec=sys and sec=krb5i pass. Tested with knfsd and the NFS client in one UML kernel over loopback, an MIT KDC in the guest and an xfs-backed export: generic/486 fails without this change and passes with it, and xfstests -g quick under krb5p shows no other difference.
net/sunrpc/auth_gss/svcauth_gss.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
net/sunrpc/auth_gss/svcauth_gss.c +5 -3
@@ -944,7 +944,6 @@ svcauth_gss_unwrap_priv(struct svc_rqst *rqstp, u32 seq, struct gss_ctx *ctx)struct xdr_stream *xdr = &rqstp->rq_arg_stream;u32 len, maj_stat, seq_num, offset;struct xdr_buf *buf = xdr->buf; -unsigned int saved_len;if (xdr_stream_decode_u32 (xdr, &len) <0 ) goto unwrap_failed;
@@ -959,11 +958,14 @@ svcauth_gss_unwrap_priv(struct svc_rqst *rqstp, u32 seq, struct gss_ctx *ctx) goto unwrap_failed; offset =xdr_stream_pos (xdr); - saved_len = buf->len; maj_stat =gss_unwrap (ctx, offset, offset + len, buf);if (maj_stat !=GSS_S_COMPLETE ) goto bad_unwrap; - xdr->nwords -=XDR_QUADLEN (saved_len - buf->len); +/* gss_unwrap redacts the opaque blob from the head iovec. +* buf has changed, thus the stream needs to be reset. +*/ +xdr_init_decode (xdr, buf, buf->head[0 ].iov_base + offset,NULL ); +xdr_set_scratch_folio (xdr, rqstp->rq_scratch_folio); out_seq:/* gss_unwrap() decrypted the sequence number. */
Signature · 1 line
2.51.0
Chuck Lever
maintainerQuoted 11 lines · Marcin Krystianc
For
RPCSEC_GSSprivacy (krb5p),gss_krb5_unwrap_v2()decrypts the request in place and then removes the GSS token header and the confounder from the head iovec: it memmoves the plaintext down to @offset and subtractsGSS_KRB5_TOK_HDR_LEN+ headskip (32 bytes for the AES enctypes) from buf->head[0].iov_len.
svcauth_gss_unwrap_priv()only accounts for that inxdr->nwords. The stream'sxdr->endstill points at the end of the head as it was before unwrapping, 32 bytes past the data that is now there.[...]
Applied to nfsd-testing, thanks!
[1/1] SUNRPC: reset the svc decode stream after unwrapping a privacy request
commit: 97bf905e837e345107c2ed3efb2e65108e081e0e
--
Chuck Lever