SUNRPC: Fix TCP-with-TLS transport class identification
Subsystems (4)
PATCH 1/1 SUNRPC: Fix TCP-with-TLS transport class identification
xs_setup_tcp_tls() assigns the ordinary TCP transport class to a TCP-with-TLS transport. When rpc_clnt_add_xprt() is called with an unspecified transport type, it inherits the class identifier and can create an unencrypted TCP transport.
Looks like a copy-paste error from the commit 3 years ago.
NFSv4 trunk discovery uses an unspecified transport type when adding server-advertised addresses. If the additional transport passes server-identity validation, it can be admitted to the client's transport switch.
An isolated loopback test reproduced plaintext application RPC transmission for TLS- and mTLS-configured clients, including an unpinned TLS-client RPC that selected the added transport.
Assign the TCP-with-TLS class instead. With the fix, the plaintext-only test peer receives TLS negotiation probes but no application payloads.
--- net/sunrpc/xprtsock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/xprtsock.c +1 -1
@@ -3499,7 +3499,7 @@ static struct rpc_xprt *xs_setup_tcp_tls(struct xprt_create *args) transport = container_of(xprt, struct sock_xprt, xprt); xprt->prot =IPPROTO_TCP ; - xprt->xprt_class = &xs_tcp_transport; + xprt->xprt_class = &xs_tcp_tls_transport; xprt->max_payload =RPC_MAX_FRAGMENT_SIZE ; xprt->bind_timeout =XS_BIND_TO ;
Signature · 1 line
2.43.0
Quoted 16 lines · Avi Weiss
xs_setup_tcp_tls()assigns the ordinary TCP transport class to a TCP-with-TLS transport. Whenrpc_clnt_add_xprt()is called with an unspecified transport type, it inherits the class identifier and can create an unencrypted TCP transport.Looks like a copy-paste error from the commit 3 years ago.
NFSv4 trunk discovery uses an unspecified transport type when adding server-advertised addresses. If the additional transport passes server-identity validation, it can be admitted to the client's transport switch.
An isolated loopback test reproduced plaintext application RPC transmission for TLS- and mTLS-configured clients, including an unpinned TLS-client RPC that selected the added transport.
Quoted 7 lines
Assign the TCP-with-TLS class instead. With the fix, the plaintext-only test peer receives TLS negotiation probes but no application payloads.
Fixes 75eb6af7acdf ("SUNRPC: Add a TCP-with-TLS RPC transport class")Signed-off-by Avi Weiss <[email protected]>
Hi Avi - does this also fix the problem where the sysfs "add_xprt" silently failed to perform STARTTLS for the new xprt? If so, this is significant fix IMO, and worth mentioning for products that might use that interface.
Thanks for this.
Ben
Quoted 4 lines · Avi Weiss
xs_setup_tcp_tls()assigns the ordinary TCP transport class to a TCP-with-TLS transport. Whenrpc_clnt_add_xprt()is called with an unspecified transport type, it inherits the class identifier and can create an unencrypted TCP transport.
Confirmed: rpc_clnt_add_xprt() copies cl_xprtsec into the create args, but when the caller leaves the ident at zero it fills the ident from xprt_class->ident of the existing transport. With the wrong class pointer that ident names plain TCP, so xprt_create_transport() dispatches to xs_setup_tcp(), which never looks at args->xprtsec. The TLS policy is dropped and no error is returned.
The effect is a silent policy downgrade on a mount that asked for xprtsec=tls or xprtsec=mtls. The primary transport still completes its handshake, but every transport added with an unspecified ident is a cleartext TCP connection that the xprt switch then uses for ordinary application RPCs. NFSv4 trunk discovery is the main caller; the xprt_switch add_xprt sysfs attribute reaches the same code and is also fixed here.
Against a server that requires TLS, the added trunks fail to connect and the mount loses the multipath it was supposed to gain. Against a server that accepts both policies, the client sends application data unencrypted on those trunks, with nothing in the logs or mount options to show it, even though TLS would have worked for that session. Nice catch!
As a potential follow-up patch, xs_setup_tcp() still accepts args with a TLS xprtsec policy and silently builds a plaintext transport. Nothing passes it that combination after this fix, but a check that returns -EACCES when args->xprtsec.policy is not RPC_XPRTSEC_NONE, mirroring the switch in xs_setup_tcp_tls(), would turn any recurrence of this class of bug into a connection failure instead of silently using cleartext.
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)