SUNRPC: complete verified GSS replies after context expiry
Subsystems (3)
cover SUNRPC: complete verified GSS replies after context expiry
Hi,
I'd like to request feedback on a client-side RPCSEC_GSS change that allows an outstanding RPC to complete using its original reply after the Kerberos security context has expired.
I encountered this problem with NFSv4.0 over Kerberos. A server can execute a non-idempotent operation successfully, but its reply may be delayed until after the client's GSS context expires. The client then rejects the reply verifier, renews its credentials, and retransmits the request with a new XID. For operations such as RENAME, REMOVE, and MKDIR, the second execution can return ENOENT or EEXIST even though the original operation succeeded. NFSv4.1 and later are largely protected by the session reply cache, but they still renew credentials and retransmit.
The original issue is documented here:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2173036
The proposed change allows an already-issued RPCSEC_GSS DATA request to complete using its original reply when the reply passes the required verification checks and the request satisfies a bounded context-expiry exception. The main changes are:
* Bind reply verification to the GSS sequence number of the corresponding transmitted request, including integrity- and privacy-protected reply bodies.
* Record when the complete TCP request record was queued, and require that this happened before the Kerberos context expired. Other transports do not record this, so the exception does not apply to them.
* Introduce reply-specific GSS verification callbacks so that Kerberos can explicitly distinguish successful cryptographic verification from context lifetime expiry. The existing strict interfaces keep their behavior.
* Bound the exception using the actual Kerberos end time, REALTIME and BOOTTIME deadlines, and clock-change checks.
* Accept an expired-context reply provisionally at the verifier stage, with final acceptance only after all verification required by the selected security service has completed.
The grace period defaults to 30 seconds, is capped at 120 seconds, and can be disabled with auth_rpcgss.expired_reply_grace=0.
When the original reply satisfies these conditions, the client passes it to the existing RPC result decoder. This preserves the actual NFS result, including NFS errors, without retransmitting the operation. Otherwise, the client keeps its existing credential renewal and retransmission behavior, subject to the normal retry budget. The change does not let new requests use expired contexts, and it does not provide exactly-once semantics when the original reply cannot be accepted. No server-side changes are required.
The patch is based on v7.4-rc3 and also applies cleanly to v7.4-rc4.
Testing
-------
Clients were QEMU/KVM guests running the patched v7.4-rc3 kernel, and servers were guests running an unmodified v7.4-rc3 kernel. The final campaign used 86 client/server VM pairs on 13 hosts and covered NFSv4.0, v4.1, and v4.2 with sec=krb5, krb5i, and krb5p, using RENAME, MKDIR, REMOVE, READ, and WRITE.
A TCP proxy in front of nfsd held the target reply until after context expiry and, in some scenarios, modified it. The scenarios included delayed replies, replies beyond the grace period or with the exception disabled, GSS sequence-number re-encoding, invalid reply bodies, missing, unknown, or error accept statuses, expiry boundaries, clock steps, and original NFS error replies. A test-only kprobe delay was used for the case where the deadline passes between header and body verification.
All 8,670 valid trials matched their expected outcomes:
* 3,600 delayed original replies were accepted without credential renewal or a new XID, including 900 trials in which the request had been re-encoded once or twice with a new GSS sequence number. nfsd executed the operation exactly once in each of these trials.
* 270 original NFS error replies were returned to the application without retransmission.
* 4,800 trials in which the exception was unavailable or the reply could not be accepted followed the existing credential renewal and retransmission behavior.
No unexpected EIO or incorrect acceptance was observed. In 16 trials of the initial campaign, and in one rerun, nfsd closed the connection before the held reply could be delivered, so the injected condition did not occur. These trials were excluded and replaced with valid reruns.
As expected, when the original reply cannot be accepted, NFSv4.0 can still re-execute non-idempotent operations. The patch avoids retransmission only when the original reply can still be verified; it does not change the NFSv4.0 recovery guarantees.
The testing did not cover NFSv3, non-TCP transports, nfsd callbacks, requests queued after context expiry, exhaustion of the credential retry budget, or NFS error replies to READ and WRITE. The refactored Kerberos verify and unwrap helpers are also used by nfsd, but the servers in these tests ran unmodified kernels.
Review feedback
---------------
I would particularly appreciate feedback on:
* Whether a bounded exception for completing an already-issued RPC with a verified reply is appropriate for RPCSEC_GSS.
* Whether reply-specific verification callbacks are a suitable way to keep cryptographic verification separate from context lifetime enforcement.
* Whether keeping the existing credential renewal and retransmission behavior when the original reply cannot be accepted is the right compatibility policy.
Thanks for your time and review.
Junyoung Im
Junyoung Im (1):
SUNRPC: complete verified GSS replies after context expiry
include/linux/sunrpc/auth_gss.h | 10 ++ include/linux/sunrpc/gss_api.h | 38 +++++ include/linux/sunrpc/xprt.h | 44 +++++ net/sunrpc/auth_gss/auth_gss.c | 205 +++++++++++++++++++++--- net/sunrpc/auth_gss/gss_krb5_internal.h | 10 ++ net/sunrpc/auth_gss/gss_krb5_mech.c | 24 +++ net/sunrpc/auth_gss/gss_krb5_unseal.c | 52 ++++-- net/sunrpc/auth_gss/gss_krb5_wrap.c | 53 +++++- net/sunrpc/auth_gss/gss_mech_switch.c | 39 +++++ net/sunrpc/clnt.c | 57 ++++++- net/sunrpc/xprt.c | 58 +++++++ net/sunrpc/xprtsock.c | 1 + 12 files changed, 551 insertions(+), 40 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
Signature · 1 line
2.34.1
RFC PATCH 1/1 SUNRPC: complete verified GSS replies after context expiry
An RPCSEC_GSS context can expire while an outstanding request is waiting for its reply. Even if the server has already executed the operation, the client rejects the reply verifier, renews its credentials, and resends the RPC with a new XID.
On NFSv4.0, re-executing non-idempotent operations such as RENAME, REMOVE, or MKDIR can return ENOENT or EEXIST even though the original operation succeeded.
Allow an RPCSEC_GSS DATA request to complete using its original reply after context expiry when the reply passes the required verification checks and the corresponding request was fully queued to the TCP socket before the Kerberos context expired.
Match the reply verifier against the request's recorded GSS sequence numbers, and use the matched sequence number when validating the integrity- or privacy-protected reply body. Introduce reply-specific GSS verification callbacks so that Kerberos explicitly distinguishes cryptographic verification from context lifetime expiry, without changing the existing strict GSS interfaces.
Record the complete TCP queueing time for each GSS sequence number and retain the mechanism's actual end time. Limit the exception using both REALTIME and a fixed BOOTTIME deadline, rejecting it when the clock evidence is inconsistent. The grace period defaults to 30 seconds, is capped at 120 seconds, and can be disabled.
Accept an expired-context reply provisionally at the verifier stage, but make the final decision only after all checks required by the selected security service have completed. A verified original reply is passed to the RPC result decoder, preserving the actual NFS result, including NFS errors, without retransmission.
If the original reply cannot be accepted, preserve the existing credential renewal and retransmission behavior, subject to the task's retry budget. Ordinary reply verification failures that do not involve the expiry exception retain their existing handling.
The exception does not permit new requests to use expired contexts, bypass cryptographic verification, or provide exactly-once semantics when the original reply cannot be recovered.
--- include/linux/sunrpc/auth_gss.h | 10 ++ include/linux/sunrpc/gss_api.h | 38 +++++ include/linux/sunrpc/xprt.h | 44 +++++ net/sunrpc/auth_gss/auth_gss.c | 205 +++++++++++++++++++++--- net/sunrpc/auth_gss/gss_krb5_internal.h | 10 ++ net/sunrpc/auth_gss/gss_krb5_mech.c | 24 +++ net/sunrpc/auth_gss/gss_krb5_unseal.c | 52 ++++-- net/sunrpc/auth_gss/gss_krb5_wrap.c | 53 +++++- net/sunrpc/auth_gss/gss_mech_switch.c | 39 +++++ net/sunrpc/clnt.c | 57 ++++++- net/sunrpc/xprt.c | 58 +++++++ net/sunrpc/xprtsock.c | 1 + 12 files changed, 551 insertions(+), 40 deletions(-)
include/linux/sunrpc/auth_gss.h +10 -0
@@ -76,6 +76,16 @@ struct gss_cl_ctx {struct xdr_netobj gc_acceptor;u32 gc_win;unsigned long gc_expiry; +/* Expired-reply exception, fixed when the context is imported. +* gc_exc_end_* is the mechanism's end time on REALTIME and on +* BOOTTIME, gc_exc_deadline_* that plus the grace period, all in +* ns; gc_exc_clock_set_seq is the clock-was-set generation they +* were computed in. gc_exc_end_boot == 0: no exception. */ +s64 gc_exc_end_real; +s64 gc_exc_deadline_real; +u64 gc_exc_end_boot; +u64 gc_exc_deadline_boot; +u32 gc_exc_clock_set_seq;struct rcu_head gc_rcu; };
include/linux/sunrpc/gss_api.h +38 -0
@@ -69,6 +69,34 @@ u32 gss_unwrap(int offset, int len, struct xdr_buf *inbuf); + +/* +* Outcome of checking a received reply token. GSS_RX_VERIFIED_EXPIRED +* means the mechanism completed every cryptographic check (and, for +* unwrap, left the buffer ready to decode), and only the context +* lifetime had passed. It is reported only by mechanisms that say so +* explicitly; it does not by itself make a reply acceptable. +*/ +enum gss_rx_verdict { +GSS_RX_INVALID , +GSS_RX_VERIFIED , +GSS_RX_VERIFIED_EXPIRED , +}; + +struct gss_rx_result { +u32 major_status; +enum gss_rx_verdict verdict; +}; + +struct gss_rx_result gss_verify_mic_reply ( +struct gss_ctx *ctx_id, +struct xdr_buf *message, +struct xdr_netobj *mic_token); +struct gss_rx_result gss_unwrap_reply ( +struct gss_ctx *ctx_id, +int offset, +int len, +struct xdr_buf *inbuf);u32 gss_delete_sec_context (struct gss_ctx **ctx_id);
@@ -133,6 +161,16 @@ struct gss_api_ops { struct xdr_buf *buf);void (*gss_delete_sec_context)(void *internal_ctx_id); +/* Optional: report verification and expiry separately. */ +struct gss_rx_result (*gss_verify_mic_reply)( +struct gss_ctx *ctx_id, +struct xdr_buf *message, +struct xdr_netobj *mic_token); +struct gss_rx_result (*gss_unwrap_reply)( +struct gss_ctx *ctx_id, +int offset, +int len, +struct xdr_buf *buf); };int gss_mech_register (struct gss_api_mech *);
include/linux/sunrpc/xprt.h +44 -0
66 lines not on this page · raw message
net/sunrpc/auth_gss/auth_gss.c +187 -18
345 lines not on this page · raw message
net/sunrpc/auth_gss/gss_krb5_internal.h +10 -0
@@ -48,6 +48,16 @@ u32 gss_krb5_unwrap_v2(struct krb5_ctx *kctx, int offset, int len, struct xdr_buf *buf, unsigned int *slack, unsigned int *align); +struct gss_rx_result +gss_krb5_verify_mic_v2_reply (struct krb5_ctx *ctx, +struct xdr_buf *message_buffer, +struct xdr_netobj *read_token); + +struct gss_rx_result +gss_krb5_unwrap_v2_reply (struct krb5_ctx *kctx,int offset,int len, +struct xdr_buf *buf,unsigned int *slack, +unsigned int *align); +/* * Implementation internal functions */
net/sunrpc/auth_gss/gss_krb5_mech.c +24 -0
@@ -330,6 +330,28 @@ static u32 gss_krb5_unwrap(struct gss_ctx *gctx, int offset, &gctx->slack, &gctx->align); } +/* +* Reply variants: as gss_krb5_verify_mic and gss_krb5_unwrap, but a token +* that passed every cryptographic check on an expired context is +* reported as GSS_RX_VERIFIED_EXPIRED (unwrap: with @buf fully unwrapped). +*/ +static struct gss_rx_result +gss_krb5_verify_mic_reply (struct gss_ctx *gctx, +struct xdr_buf *message_buffer, +struct xdr_netobj *read_token) +{ +return gss_krb5_verify_mic_v2_reply (gctx->internal_ctx_id, + message_buffer, read_token); +} + +static struct gss_rx_result +gss_krb5_unwrap_reply (struct gss_ctx *gctx,int offset,int len, +struct xdr_buf *buf) +{ +return gss_krb5_unwrap_v2_reply (gctx->internal_ctx_id, offset, len, + buf, &gctx->slack, &gctx->align); +} +static const struct gss_api_ops gss_kerberos_ops = { .gss_import_sec_context = gss_krb5_import_sec_context, .gss_get_mic = gss_krb5_get_mic,
@@ -337,6 +359,8 @@ static const struct gss_api_ops gss_kerberos_ops = { .gss_wrap = gss_krb5_wrap, .gss_unwrap = gss_krb5_unwrap, .gss_delete_sec_context = gss_krb5_delete_sec_context, + .gss_verify_mic_reply = gss_krb5_verify_mic_reply, + .gss_unwrap_reply = gss_krb5_unwrap_reply, };static struct pf_desc gss_kerberos_pfs[] = {
net/sunrpc/auth_gss/gss_krb5_unseal.c +43 -9
73 lines not on this page · raw message
net/sunrpc/auth_gss/gss_krb5_wrap.c +48 -5
76 lines not on this page · raw message
net/sunrpc/auth_gss/gss_mech_switch.c +39 -0
@@ -423,6 +423,45 @@ gss_unwrap(struct gss_ctx *ctx_id, ->gss_unwrap(ctx_id, offset, len, buf); } +/* +* gss_verify_mic_reply / gss_unwrap_reply: as gss_verify_mic / gss_unwrap, +* but also say whether the token was cryptographically verified. A +* mechanism without the reply callbacks is only ever VERIFIED on +* GSS_S_COMPLETE; GSS_S_CONTEXT_EXPIRED from it stays INVALID. +*/ +struct gss_rx_result +gss_verify_mic_reply (struct gss_ctx *ctx_id, +struct xdr_buf *message, +struct xdr_netobj *mic_token) +{ +const struct gss_api_ops *ops = ctx_id->mech_type->gm_ops; +struct gss_rx_result res = { .verdict =GSS_RX_INVALID }; + +if (ops->gss_verify_mic_reply) +return ops->gss_verify_mic_reply (ctx_id, message, mic_token); + res.major_status = ops->gss_verify_mic (ctx_id, message, mic_token); +if (res.major_status ==GSS_S_COMPLETE ) + res.verdict =GSS_RX_VERIFIED ; +return res; +} + +struct gss_rx_result +gss_unwrap_reply (struct gss_ctx *ctx_id, +int offset, +int len, +struct xdr_buf *buf) +{ +const struct gss_api_ops *ops = ctx_id->mech_type->gm_ops; +struct gss_rx_result res = { .verdict =GSS_RX_INVALID }; + +if (ops->gss_unwrap_reply) +return ops->gss_unwrap_reply (ctx_id, offset, len, buf); + res.major_status = ops->gss_unwrap (ctx_id, offset, len, buf); +if (res.major_status ==GSS_S_COMPLETE ) + res.verdict =GSS_RX_VERIFIED ; +return res; +} +/* gss_delete_sec_context: free all resources associated with context_handle. * Note this differs from the RFC 2744-specified prototype in that we don't
net/sunrpc/clnt.c +49 -8
95 lines not on this page · raw message
net/sunrpc/xprt.c +58 -0
70 lines not on this page · raw message
net/sunrpc/xprtsock.c +1 -0
@@ -1158,6 +1158,7 @@ static int xs_tcp_send_request(struct rpc_rqst *req)if (likely (req->rq_bytes_sent >= msglen)) { req->rq_xmit_bytes_sent += transport->xmit.offset; transport->xmit.offset =0 ; +xprt_rqst_note_record_queued (req);if (atomic_long_read (&xprt->xmit_queuelen) ==1 )tcp_sock_set_cork (transport->inet, false);return 0 ;
Signature · 1 line
2.34.1