Skip to contentSkip to conversation

rxrpc: Fix CHALLENGE packet handling

PATCH In review David Howells 2 participants 17 messages Aug 24 – Aug 28

Subsystems (8)
lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

v8 cover rxrpc: Fix CHALLENGE packet handling

Here's a fix for AF_RXRPC's CHALLENGE packet handling, addressing an issue raised by Sashiko[1], plus some miscellaneous fixes found in the process of fixing this, plus a number of things raised by Sashiko[2-8].

Firstly, the miscellaneous patches:

(1) Fix rxrpc_sendmsg so that it doesn't return an error if it queued the last packet of a call. After that point, the error will be returned by recvmsg() and returned it twice in two different places may complicate userspace cleaning up its own structures.

(2) Fix the use of len vs msg->msg_iter.count in rxrpc_send_data().

(3) Fix error handling in rxrpc_send_data() for if ->secure_packet() returns an error.

(4) Fix the update of call->pending in rxrpc_send_data() in paths when the call lock has been dropped.

(5) Fix double IRQ enablement in __rxrpc_notify_socket() when called indirectly from rxrpc_end_rx_phase().

(6) Fix the generation of notifications from rxrpc after call completion.

And then there are the patches to fix CHALLENGE packet overqueuing and simplify RESPONSE packet generation by pre-creating the RxGK application data up front and passing it in a user key (thereby allowing userspace to partake). This is split into five patches:

(7) Expand the abort trace enum to be larger than a signed char as the number of elements will exceed 128.

(8) Add a refcount to the user key payload.

(9) Make the AFS filesystem generate per-server appdata keys.

(10) Pass the appdata from AFS (or userspace) to rxrpc.

(11) Change over to using the appdata key to supply the appdata.

(12) Remove all the OOB stuff.

[!] Note that this entails a significant change in the UAPI for AF_RXRPC, with the CMSG types and sockopt to support the OOB queuing being removed and replaced with a new single CMSG type that conveys the user key ID. I don't think it likely anyone is using this outside of my kafs-utils package.

This also involves a change to the user-defined key type, making the payload refcounted so that it can be accessed and the length read, then a buffer allocated that will hold it and other data, and then the content copied. The problem is that the user is perfectly at liberty to change the content of a user-defined key (which will RCU-replace the content of the key), so the length might change when we drop the RCU read lock in order to allocate. This could be got around by locking the key->rwsem sharedly, but that might be able to deadlock part of the rxrpc protocol engine if memory reclaim occurs.

David

The patches can be found here also:

http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=rxrpc-fixes

Changes
=======
ver #8)
- Rebased on latest net/main.
- Fixed more Sashiko-reported bugs[8]:
- Fixed the kerneldoc on rxrpc_kernel_send_data() as this returns the number of bytes buffered on success.
- Fixed rxrpc_send_data() to break out of the loop if either len or msg_iter's count becomes 0 and to limit the amount per copy to the msg_iter count also.
- Fixed the docs for rxrpc_kernel_send_data()'s return value.
- In afs_make_call(), remove duplicate error check and make sure the afs_sent_data tracepoint gets called on the error path.
- In rxrpc_send_data() remove setting of the already-NULL txb and tx_pending to NULL.
- Added a patch to fix __rxrpc_notify_socket() to save the old IRQ state when disabling it as the call chain may have it disabled.
- Removed comment on __rxrpc_notify_socket() about putting recvmsg_link on a dummy queue.
- Moved rxrpc_notify_socket()'s declaration to the right file section in ar-internal.h.
- Updated the comment on the user_key_payload struct.
- Updated the comment on put_user_key_payload().
- In afs_open_socket(), fixed a missing ref cleanup on error.
- Updated the docs for rxrpc_kernel_begin_call().
- Added docs for RXRPC_RESPONSE_APPDATA cmsg.
- Fixed rxrpc_sendmsg_cmsg() to require that the appdata key have its description prefixed by "rxrpc-appdata:" to prevent the reading out of arbitrary keys through a fake filemanager.
- Dropped the use of logon keys for appdata.
- Removed rxrpc_abort_response_sendmsg.
- Removed struct rxrpc_challenge and struct rxgk_challenge.
- Removed the RXRPC_MANAGE_RESPONSE constant and its rxrpc_setsockopt() stub.

ver #7)
- Rebased on latest net/main.
- Added a patch to change rxrpc_send_data() to use len rather than msg_iter count to be consistent about the amount to send so as to do the LAST flag determination correctly.
- Fixed more Sashiko-reported bugs[7]:
- Made the loops in afs_make_call() that call rxrpc_kernel_send_data() pass the amount left in the iterator rather than an unreducing size.
- Made the second loop in afs_make_call() check to see if rxrpc_kernel_send_data() returned an error.
- Removed yet more OOB references, two in linux/af_rxrpc.h and one in rxrpc.rst.

ver #6)
- Rebased on latest net/main.
- Fixed more Sashiko-reported bugs[6]:
- Fixed rxrpc_send_data() to redo the RXRPC_CALL_TX_ERROR and the RXRPC_CALL_TX_NO_MORE checks after having dropped the call mutex.
- Altered rxrpc_send_data(), as discussed with Paulo Abeni, to rewind as much as possible on retryable crypto error (e.g. ENOMEM) rather than rewinding just one byte.
- Fixed afs_make_call() to keep trying rxrpc_kernel_send_data() until the iterator is drained unless an error occurs.
- Fixed afs_create_yfs_rxgk_cm_appdata() to use kfree_sensitive().
- Removed remaining OOB trace constants.

ver #5)
- Rebased on latest net/main.
- Fixed more Sashiko-reported bugs[5]:
- Removed dropped_lock from rxrpc_do_sendmsg() as it's now always false.
- Fix rxrpc_send_data() to not leak a txbuf from the "maybe_error:" path

    by reattaching it to call->tx_pending.

- Increased the size of the rxrpc_abort_reason enum value by removing the __mode(byte) specifier.

ver #4)
- Rebased on latest net/main.
- Split out non-relevant AFS patches.
- Allow logon-type key as well as user-type key as they're basically the same thing internally.
- Fixed more Sashiko-reported bugs[4]:
- Fixed rxrpc_send_data() to wind the transmitted data back by 1 byte if ENOMEM is hit when encrypting the final packet so that the caller can retry.
- Fixed afs_create_yfs_rxgk_cm_appdata() to add the 4 bytes for the level into toksize.
- Changed bundle code to include the appdata key as part of the client connection bundle lookup criteria (don't share connections with different appdata keys).
- Fixed rxrpc_sendmsg_cmsg() to allow only, not disallow user-type keys for RXRPC_RESPONSE_APPDATA.
- Reversed the removal of the rejection of MSG_OOB passed to rxrpc_recvmsg().
- Fixed rxgk_construct_response() to use xdr_object_len() to calculate the space needed for the appdata and also the space needed for the token and the authenticator.
- Added a check into rxgk_respond_to_challenge() to make sure the key type is user or login before we access its payload.
- Remove ->sendmsg_respond_to_challenge() too.

ver #3)
- Rebased on latest net/main.
- Removed two obsoleted patches.

ver #2)
- Split the CHALLENGE/RESPONSE fix into smaller patches.
- Fixed more Sashiko-reported bugs[2][3]:
- Added some more patches to fix some more bugs.
- Get rid of the AFS_SERVER_FL_APPDATA flag and check the pointer to the appdata instead.
- Rename the appdata key pointer in the AFS_SERVER to reflect this one is only for the YFS-RxGK security class.
- Use barriers when reading or writing the server appdata key pointer.
- Ignore the appdata for RxNULL, RxKAD and OpenAFS's RxGK for now.
- Check that sendmsg() with RXRPC_RESPONSE_APPDATA is passed a user key.
- Check that the appdata key's payload isn't NULL, for instance if it gets revoked.
- Add some error path key_put()s in rxrpc_do_sendmsg().

[1] https://sashiko.dev/#/patchset/20260624163819.3017002-1-dhowells%40redhat.com
[2] https://sashiko.dev/#/patchset/20260702144919.172295-1-dhowells%40redhat.com
[3] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260702144919.172295-1-dhowells%40redhat.com
[4] https://sashiko.dev/#/patchset/20260713081022.2186481-1-dhowells%40redhat.com
[5] https://sashiko.dev/#/patchset/20260723100309.530157-1-dhowells%40redhat.com
[6] https://sashiko.dev/#/patchset/20260729160108.2031453-1-dhowells%40redhat.com
[7] https://sashiko.dev/#/patchset/20260804172639.2844491-1-dhowells%40redhat.com
[8] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/[email protected]

David Howells (12):
rxrpc: Fix sendmsg to not return an error if last packet queued
rxrpc: Fix sendmsg length
rxrpc: Fix packet encryption error handling
rxrpc: Fix update of call->tx_pending without holding lock
rxrpc: Fix double IRQ enablement
rxrpc: Fix generation of notifications after call completion
rxrpc: Expand abort trace enum
keys: Add refcounting to user-defined key type payload
afs: Create a server appdata key
rxrpc: Pass appdata key to rxrpc_call and thence to rxrpc_bundle
rxrpc: Fix CHALLENGE packet overqueuing and simplify RESPONSE
generation
rxrpc: Remove OOB challenge/response code

 Documentation/networking/rxrpc.rst |  27 +-
 fs/afs/cm_security.c               | 315 +++++++++++------------
 fs/afs/fs_probe.c                  |   5 +
 fs/afs/internal.h                  |  38 +--
 fs/afs/main.c                      |   1 -
 fs/afs/rxrpc.c                     |  81 +++---
 fs/afs/server.c                    |   2 +-
 include/keys/user-type.h           |  10 +-
 include/net/af_rxrpc.h             |  26 +-
 include/trace/events/afs.h         |   1 +
 include/trace/events/rxrpc.h       |  16 +-
 include/uapi/linux/rxrpc.h         |  24 +-
 net/dns_resolver/dns_key.c         |   1 +
 net/rxrpc/Makefile                 |   1 -
 net/rxrpc/af_rxrpc.c               |  51 +---
 net/rxrpc/ar-internal.h            |  29 +--
 net/rxrpc/call_object.c            |   2 +
 net/rxrpc/call_state.c             |  57 ++++-
 net/rxrpc/conn_client.c            |   4 +
 net/rxrpc/conn_event.c             |  70 +-----
 net/rxrpc/insecure.c               |   7 -
 net/rxrpc/key.c                    |  37 +++
 net/rxrpc/oob.c                    | 387 -----------------------------
 net/rxrpc/proc.c                   |   5 +-
 net/rxrpc/recvmsg.c                | 124 ++-------
 net/rxrpc/rxgk.c                   | 138 ++++------
 net/rxrpc/rxkad.c                  |  27 --
 net/rxrpc/sendmsg.c                | 177 +++++++++----
 net/rxrpc/server_key.c             |  40 ---
 security/keys/user_defined.c       |  23 +-
 30 files changed, 578 insertions(+), 1148 deletions(-)
 delete mode 100644 net/rxrpc/oob.c
author maintainer
#1 lore raw

PATCH v8 1/12 rxrpc: Fix sendmsg to not return an error if last packet queued

Fix AF_RXRPC sendmsg() so that it doesn't return an error if it has successfully queued the last packet of a call, but the call has seen to have completed after it did that. Rather, leave it to recvmsg() to report the completion (which it will do anyway).

The problem with trying to report the error twice is that the caller may try to clean up the dead call twice.

Fixes d41b3f5b9688 ("rxrpc: Wrap accesses to get call state to put the barrier in one place")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 fs/afs/rxrpc.c      |  2 +-
 net/rxrpc/sendmsg.c | 22 ++++++++++++++++------
 2 files changed, 17 insertions(+), 7 deletions(-)
fs/afs/rxrpc.c +1 -1
index d82916657a3d..e35b49a904eb 100644
@@ -873,7 +873,7 @@ void afs_send_empty_reply(struct afs_call *call)
 
 	switch (rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, 0,
 				       afs_notify_end_reply_tx)) {
-	case 0:
+	case 0: /* Shouldn't buffer more than 0 bytes. */
 		_leave(" [replied]");
 		return;
 
net/rxrpc/sendmsg.c +16 -6
index ed2c9a51005a..1d66e9808162 100644
@@ -453,9 +453,6 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 
 success:
 	ret = copied;
-	if (rxrpc_call_is_complete(call) &&
-	    call->error < 0)
-		ret = call->error;
 out:
 	call->tx_pending = txb;
 	_leave(" = %d", ret);
@@ -467,8 +464,14 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 	return call->error;
 
 maybe_error:
-	if (copied)
+	if (copied) {
+		if (rxrpc_call_is_complete(call) &&
+		    call->error < 0) {
+			ret = call->error;
+			goto out;
+		}
 		goto success;
+	}
 	goto out;
 
 efault:
@@ -800,9 +803,16 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
  * Allow a kernel service to send data on a call.  The call must be in an state
  * appropriate to sending data.  No control data should be supplied in @msg,
  * nor should an address be supplied.  MSG_MORE should be flagged if there's
- * more data to come, otherwise this data will end the transmission phase.
+ * more data to come, otherwise this data will end the transmission phase if
+ * all the data is buffered.
+ *
+ * Note that this function may return a short send, in which case it should be
+ * called again for the remainder of the data or to pick up an error that
+ * caused the short send.
  *
- * Return: %0 if successful and a negative error code otherwise.
+ * Return: The number of bytes buffered (could be %0 if @len is 0 or
+ * msg_iter holds 0 bytes) if successful and a negative error code
+ * otherwise.
  */
 int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
 			   struct msghdr *msg, size_t len,
author maintainer
#2 lore raw

PATCH v8 2/12 rxrpc: Fix sendmsg length

In reply to David Howells

rxrpc_send_data() is given two data lengths (len and msg->msg_iter.count) and is inconsistent about how it uses them. Fix this by using len in preference to msg->msg_iter.count. Also limit the amount copied to either len or msg->msg_iter.count, whichever is smaller.

Note that, currently, all the callers have len and msg->msg_iter.count the same and so the problem won't occur.

Fixes 382d7974de31 ("RxRPC: Use iov_iter_count() in rxrpc_send_data() instead of the len argument")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/sendmsg.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
net/rxrpc/sendmsg.c +9 -8
index 1d66e9808162..565799548102 100644
@@ -379,9 +379,9 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 
 	ret = -EMSGSIZE;
 	if (call->tx_total_len != -1) {
-		if (len - copied > call->tx_total_len)
+		if (len > call->tx_total_len)
 			goto maybe_error;
-		if (!more && len - copied != call->tx_total_len)
+		if (!more && len != call->tx_total_len)
 			goto maybe_error;
 	}
 
@@ -405,7 +405,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 			 * the security header is going to be in the padded
 			 * region (enc blocksize), but the trailer is not.
 			 */
-			remain = more ? INT_MAX : msg_data_left(msg);
+			remain = more ? INT_MAX : len;
 			txb = call->conn->security->alloc_txbuf(call, remain, sk->sk_allocation);
 			if (!txb) {
 				ret = -ENOMEM;
@@ -416,8 +416,8 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 		_debug("append");
 
 		/* append next segment of data to the current buffer */
-		if (msg_data_left(msg) > 0) {
-			size_t copy = umin(txb->space, msg_data_left(msg));
+		if (len > 0) {
+			size_t copy = min3(txb->space, len, msg_data_left(msg));
 
 			_debug("add %zu", copy);
 			if (!copy_from_iter_full(txb->data + txb->offset,
@@ -428,6 +428,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 			txb->len += copy;
 			txb->offset += copy;
 			copied += copy;
+			len -= copy;
 			if (call->tx_total_len != -1)
 				call->tx_total_len -= copy;
 		}
@@ -439,8 +440,8 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 
 		/* add the packet to the send queue if it's now full */
 		if (!txb->space ||
-		    (msg_data_left(msg) == 0 && !more)) {
-			if (msg_data_left(msg) == 0 && !more)
+		    (len == 0 && !more)) {
+			if (len == 0 && !more)
 				txb->flags |= RXRPC_LAST_PACKET;
 
 			ret = call->security->secure_packet(call, txb);
@@ -449,7 +450,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 			rxrpc_queue_packet(rx, call, txb, notify_end_tx);
 			txb = NULL;
 		}
-	} while (msg_data_left(msg) > 0);
+	} while (len > 0 && msg_data_left(msg) > 0);
 
 success:
 	ret = copied;
author maintainer
#3 lore raw

PATCH v8 3/12 rxrpc: Fix packet encryption error handling

In reply to David Howells

In rxrpc_send_data(), if ->secure_packet() returns an error, the code currently just jumps to out: and returns the error to the app on the assumption that any error returned by this is automatically fatal for the call, and may even have corrupted the transmission queue - but leaving it to userspace to deal with. Nothing stops the application from retrying the sendmsg(), which will try to encrypt the buffer again, and might succeed with a corrupt buffer.

Fix rxrpc_send_data() in the following ways:

(1) If -ENOMEM is returned, assume we never got as far as the encryption and that the operation is retryable. In which case, jump to maybe_error_rewind and, if we've copied data into the last packet, remove some of the bytes from it that we just added so that we don't tell the caller that we've completed the transmission phase. The iterator is also correspondingly rewound.

(2) If any other error occurs, set the TX_ERROR flag on the call and return that error directly; on all subsequent attempts to add data to the call, return -EIO. The app must then abort the call to get rid of it (this allows the app to choose the abort code to use).

afs_make_call() and afs_send_simple_reply() are also modified to repeat calls to rxrpc_kernel_send_data() if less than a full transfer was made.

Fixes 17926a79320a ("[AF_RXRPC]: Provide secure RxRPC sockets for use by userspace and kernel both")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 Documentation/networking/rxrpc.rst | 11 ++++--
 fs/afs/rxrpc.c                     | 38 ++++++++++++--------
 include/trace/events/rxrpc.h       |  1 +
 net/rxrpc/ar-internal.h            |  1 +
 net/rxrpc/sendmsg.c                | 58 ++++++++++++++++++++++++------
 5 files changed, 82 insertions(+), 27 deletions(-)
Documentation/networking/rxrpc.rst +9 -2
index 8926dab8e2e6..7df6aff7644c 100644
@@ -879,14 +879,21 @@ The kernel interface functions are as follows:
      exclusively to in-kernel virtual addresses.  msg.msg_flags may be given
      MSG_MORE if there will be subsequent data sends for this call.
 
-     The msg must not specify a destination address, control data or any flags
-     other than MSG_MORE.  len is the total amount of data to transmit.
+     msg must not specify a destination address, control data or any flags
+     other than MSG_MORE.  len is the amount of data to add to the
+     transmission.  The last-packet flag will only be set on the outgoing
+     packet if MSG_MORE is not set and len amount of bytes are buffered.
 
      notify_end_rx can be NULL or it can be used to specify a function to be
      called when the call changes state to end the Tx phase.  This function is
      called with a spinlock held to prevent the last DATA packet from being
      transmitted until the function returns.
 
+     The function returns the amount of data buffered or an error.  It will
+     return zero only if len is 0 or if msg->msg_iter is empty.  It may also
+     make a short write, buffering less than the amount of data provided or the
+     len specified, in which case it should be called again.
+
  (#) Receive data from a call::
 
 	int rxrpc_kernel_recv_data(struct socket *sock,
fs/afs/rxrpc.c +24 -14
index e35b49a904eb..bf0d231d30a6 100644
@@ -412,26 +412,32 @@ void afs_make_call(struct afs_call *call, gfp_t gfp)
 	msg.msg_controllen	= 0;
 	msg.msg_flags		= MSG_WAITALL | (call->write_iter ? MSG_MORE : 0);
 
-	ret = rxrpc_kernel_send_data(call->net->socket, rxcall,
-				     &msg, call->request_size,
-				     afs_notify_end_request_tx);
-	if (ret < 0)
-		goto error_do_abort;
+	do {
+		ret = rxrpc_kernel_send_data(call->net->socket, rxcall, &msg,
+					     msg_data_left(&msg),
+					     afs_notify_end_request_tx);
+		if (ret < 0)
+			goto error_do_abort;
+	} while (msg_data_left(&msg) > 0);
 
 	if (call->write_iter) {
 		msg.msg_iter = *call->write_iter;
 		msg.msg_flags &= ~MSG_MORE;
 		trace_afs_send_data(call, &msg);
 
-		ret = rxrpc_kernel_send_data(call->net->socket,
-					     call->rxcall, &msg,
-					     iov_iter_count(&msg.msg_iter),
-					     afs_notify_end_request_tx);
+		do {
+			ret = rxrpc_kernel_send_data(call->net->socket,
+						     call->rxcall, &msg,
+						     msg_data_left(&msg),
+						     afs_notify_end_request_tx);
+			if (ret < 0) {
+				trace_afs_sent_data(call, &msg, ret);
+				goto error_do_abort;
+			}
+		} while (msg_data_left(&msg) > 0);
 		*call->write_iter = msg.msg_iter;
 
-		trace_afs_sent_data(call, &msg, ret);
-		if (ret < 0)
-			goto error_do_abort;
+		trace_afs_sent_data(call, &msg, 0);
 	}
 
 	/* Note that at this point, we may have received the reply or an abort
@@ -912,8 +918,12 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)
 	msg.msg_controllen	= 0;
 	msg.msg_flags		= 0;
 
-	n = rxrpc_kernel_send_data(net->socket, call->rxcall, &msg, len,
-				   afs_notify_end_reply_tx);
+	do {
+		n = rxrpc_kernel_send_data(net->socket, call->rxcall,
+					   &msg, msg_data_left(&msg),
+					   afs_notify_end_reply_tx);
+	} while (n >= 0 && msg_data_left(&msg) > 0);
+
 	if (n >= 0) {
 		/* Success */
 		_leave(" [replied]");
include/trace/events/rxrpc.h +1 -0
index 704a10de6670..8f3e3967885a 100644
@@ -148,6 +148,7 @@
 	EM(rxrpc_eproto_wrong_security,		"wrong-sec")		\
 	EM(rxrpc_recvmsg_excess_data,		"recvmsg-excess")	\
 	EM(rxrpc_recvmsg_short_data,		"recvmsg-short")	\
+	EM(rxrpc_sendmsg_tx_error,		"tx-error")		\
 	E_(rxrpc_sendmsg_late_send,		"sendmsg-late")
 
 #define rxrpc_call_poke_traces \
net/rxrpc/ar-internal.h +1 -0
index 865f05fe37ab..a6f830c1621f 100644
@@ -642,6 +642,7 @@ enum rxrpc_call_flag {
 	RXRPC_CALL_TX_LAST,		/* Last packet in Tx buffer (at rxtx_top) */
 	RXRPC_CALL_TX_ALL_ACKED,	/* Last packet has been hard-acked */
 	RXRPC_CALL_TX_NO_MORE,		/* No more data to transmit (MSG_MORE deasserted) */
+	RXRPC_CALL_TX_ERROR,		/* Terminal error; call needs abort */
 	RXRPC_CALL_SEND_PING,		/* A ping will need to be sent */
 	RXRPC_CALL_RETRANS_TIMEOUT,	/* Retransmission due to timeout occurred */
 	RXRPC_CALL_BEGAN_RX_TIMER,	/* We began the expect_rx_by timer */
net/rxrpc/sendmsg.c +47 -11

84 lines not on this page · raw message

author maintainer
#4 lore raw

PATCH v8 4/12 rxrpc: Fix update of call->tx_pending without holding lock

In reply to David Howells

Currently, rxrpc_send_data() updates call->tx_pending just before it returns - but it won't be holding the call->lock when it does this if a wait was interrupted by a signal. This would allow a parallel sendmsg() to race.

Further, both the callers of rxrpc_send_data() call it with the lock held, and then it returns an indication through the parameter list to say whether it has dropped the lock or not - after which the callers both just drop the lock if it's still held.

Fix this by:

(1) Moving the release of call->lock down into rxrpc_send_data() and get rid of the indicator parameter. This makes it easier to see where the lock is held.

(2) After waiting, if the attempt to reacquire the mutex is interrupted, just return directly there rather than going to out_unlock

Note that there's a slight change in behaviour in that wait_for_space failure now doesn't check for completion because it doesn't hold the call user_mutex. The caller, however, should re-issue the send and pick up any error at a second attempt.

Fixes b0f571ecd794 ("rxrpc: Fix locking in rxrpc's sendmsg")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/sendmsg.c | 54 +++++++++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 26 deletions(-)
net/rxrpc/sendmsg.c +28 -26
index 3a36f82b84d9..271562450469 100644
@@ -320,8 +320,8 @@ static int rxrpc_alloc_txqueue(struct sock *sk, struct rxrpc_call *call)
 static int rxrpc_send_data(struct rxrpc_sock *rx,
 			   struct rxrpc_call *call,
 			   struct msghdr *msg, size_t len,
-			   rxrpc_notify_end_tx_t notify_end_tx,
-			   bool *_dropped_lock)
+			   rxrpc_notify_end_tx_t notify_end_tx)
+	__releases(&call->user_mutex)
 {
 	struct rxrpc_txbuf *txb;
 	struct sock *sk = &rx->sk;
@@ -334,12 +334,12 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 
 	ret = rxrpc_wait_to_be_connected(call, &timeo);
 	if (ret < 0)
-		return ret;
+		goto out_unlock;
 
 	if (call->conn->state == RXRPC_CONN_CLIENT_UNSECURED) {
 		ret = rxrpc_init_client_conn_security(call->conn);
 		if (ret < 0)
-			return ret;
+			goto out_unlock;
 	}
 
 	/* this should be in poll */
@@ -350,13 +350,15 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 		trace_rxrpc_abort(call->debug_id, rxrpc_sendmsg_late_send,
 				  call->cid, call->call_id, call->rx_consumed,
 				  0, -EPROTO);
-		return -EPROTO;
+		ret = -EPROTO;
+		goto out_unlock;
 	}
 	if (unlikely(test_bit(RXRPC_CALL_TX_ERROR, &call->flags))) {
 		trace_rxrpc_abort(call->debug_id, rxrpc_sendmsg_tx_error,
 				  call->cid, call->call_id, call->rx_consumed,
 				  0, -EIO);
-		return -EIO;
+		ret = -EIO;
+		goto out_unlock;
 	}
 
 	txb = call->tx_pending;
@@ -462,7 +464,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 				if (ret == -ENOMEM)
 					goto maybe_error_rewind;
 				set_bit(RXRPC_CALL_TX_ERROR, &call->flags);
-				goto out;
+				goto out_txb;
 			}
 
 			if (len == 0 && !more)
@@ -474,15 +476,18 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 
 success:
 	ret = copied;
-out:
+out_txb:
 	call->tx_pending = txb;
+out_unlock:
+	mutex_unlock(&call->user_mutex);
 	_leave(" = %d", ret);
 	return ret;
 
 call_terminated:
 	rxrpc_put_txbuf(txb, rxrpc_txbuf_put_send_aborted);
-	_leave(" = %d", call->error);
-	return call->error;
+	call->tx_pending = NULL;
+	ret = call->error;
+	goto out_unlock;
 
 maybe_error_rewind:
 	/* If we got a retryable error after copying all the supplied data into
@@ -505,36 +510,38 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 		if (rxrpc_call_is_complete(call) &&
 		    call->error < 0) {
 			ret = call->error;
-			goto out;
+			goto out_txb;
 		}
 		goto success;
 	}
-	goto out;
+	goto out_txb;
 
 efault:
 	ret = -EFAULT;
-	goto out;
+	goto out_txb;
 
 wait_for_space:
 	ret = -EAGAIN;
 	if (msg->msg_flags & MSG_DONTWAIT)
 		goto maybe_error;
 	mutex_unlock(&call->user_mutex);
-	*_dropped_lock = true;
+
 	ret = rxrpc_wait_for_tx_window(rx, call, &timeo,
 				       msg->msg_flags & MSG_WAITALL);
 	if (ret < 0)
-		goto maybe_error;
+		goto out_nolock;
 	if (call->interruptibility == RXRPC_INTERRUPTIBLE) {
 		if (mutex_lock_interruptible(&call->user_mutex) < 0) {
 			ret = sock_intr_errno(timeo);
-			goto maybe_error;
+			goto out_nolock;
 		}
 	} else {
 		mutex_lock(&call->user_mutex);
 	}
-	*_dropped_lock = false;
 	goto reload;
+out_nolock:
+	_leave(" = %d [intr]", ret);
+	return copied ?: ret;
 }
 
 /*
@@ -700,7 +707,6 @@ rxrpc_new_client_call_for_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg,
 int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
 {
 	struct rxrpc_call *call;
-	bool dropped_lock = false;
 	int ret;
 
 	struct rxrpc_send_params p = {
@@ -809,16 +815,15 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
 		ret = 0;
 		break;
 	case RXRPC_CMD_SEND_DATA:
-		ret = rxrpc_send_data(rx, call, msg, len, NULL, &dropped_lock);
-		break;
+		ret = rxrpc_send_data(rx, call, msg, len, NULL);
+		goto error_put;
 	default:
 		ret = -EINVAL;
 		break;
 	}
 
 out_put_unlock:
-	if (!dropped_lock)
-		mutex_unlock(&call->user_mutex);
+	mutex_unlock(&call->user_mutex);
 error_put:
 	rxrpc_put_call(call, rxrpc_call_put_sendmsg);
 	_leave(" = %d", ret);
@@ -855,7 +860,6 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
 			   struct msghdr *msg, size_t len,
 			   rxrpc_notify_end_tx_t notify_end_tx)
 {
-	bool dropped_lock = false;
 	int ret;
 
 	_enter("{%d},", call->debug_id);
@@ -866,12 +870,10 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
 	mutex_lock(&call->user_mutex);
 
 	ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg, len,
-			      notify_end_tx, &dropped_lock);
+			      notify_end_tx);
 	if (ret == -ESHUTDOWN)
 		ret = call->error;
 
-	if (!dropped_lock)
-		mutex_unlock(&call->user_mutex);
 	_leave(" = %d", ret);
 	return ret;
 }
author maintainer
#5 lore raw

PATCH v8 5/12 rxrpc: Fix double IRQ enablement

In reply to David Howells

__rxrpc_notify_socket() explicitly enables and disables IRQs, but one of its call chains (rxrpc_end_rx_phase() -> rxrpc_call_completed() -> rxrpc_set_call_completion()) has IRQs enabled around it.

Fix this by making __rxrpc_notify_socket() use irqsave spinlocks.

Fixes a2ea9a907260 ("rxrpc: Use irq-disabling spinlocks between app and I/O thread")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 net/rxrpc/recvmsg.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
net/rxrpc/recvmsg.c +5 -4
index efcba4b2e74f..56fa324d0962 100644
@@ -24,6 +24,7 @@ void rxrpc_notify_socket(struct rxrpc_call *call)
 {
 	struct rxrpc_sock *rx;
 	struct sock *sk;
+	unsigned long flags;
 
 	_enter("%d", call->debug_id);
 
@@ -38,16 +39,16 @@ void rxrpc_notify_socket(struct rxrpc_call *call)
 	sk = &rx->sk;
 	if (rx && sk->sk_state < RXRPC_CLOSE) {
 		if (call->notify_rx) {
-			spin_lock_irq(&call->notify_lock);
+			spin_lock_irqsave(&call->notify_lock, flags);
 			call->notify_rx(sk, call, call->user_call_ID);
-			spin_unlock_irq(&call->notify_lock);
+			spin_unlock_irqrestore(&call->notify_lock, flags);
 		} else {
-			spin_lock_irq(&rx->recvmsg_lock);
+			spin_lock_irqsave(&rx->recvmsg_lock, flags);
 			if (list_empty(&call->recvmsg_link)) {
 				rxrpc_get_call(call, rxrpc_call_get_notify_socket);
 				list_add_tail(&call->recvmsg_link, &rx->recvmsg_q);
 			}
-			spin_unlock_irq(&rx->recvmsg_lock);
+			spin_unlock_irqrestore(&rx->recvmsg_lock, flags);
 
 			if (!sock_flag(sk, SOCK_DEAD)) {
 				_debug("call %ps", sk->sk_data_ready);
author maintainer
#6 lore raw

PATCH v8 6/12 rxrpc: Fix generation of notifications after call completion

In reply to David Howells

AF_RXRPC may generate a notification to the application after a call has completed because it generates one notification when rxrpc_input_split_jumbo() queues the final packet and completes the call and then generates another when rxrpc_input_split_jumbo() does the aggregated data receive notification at the end of the function.

This might cause the AFS filesystem to malfunction because it tries to queue the afs_call for processing an extra time. Most of the time this happens quickly enough that the second queue_work skips, but sometimes this means that the call work may happen a second time with implications for afs_call lifetime management.

Fix this by:

(1) Create a lighter version of rxrpc_notify_socket() that's just used to requeue a call for rxrpc_recvmsg() without creating another notification.

(2) Move rxrpc_notify_socket() to call_state.c and rename it to

     __rxrpc_notify_socket().

(3) Create a wrapper called rxrpc_notify_socket() that skips the notification if a call is completed.

(4) Make rxrpc_set_call_completion() call __rxrpc_notify_socket() to avoid the skip-if-completed check.

Also remove the comment on __rxrpc_notify_socket() that said it added the call to a dummy queue to prevent further notification.

Fixes 2d1faf7a0ca3 ("rxrpc: Simplify skbuff accounting in receive path")
cc Marc Dionne <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
---
 include/trace/events/rxrpc.h |  1 +
 net/rxrpc/ar-internal.h      |  2 +-
 net/rxrpc/call_state.c       | 57 +++++++++++++++++++++++++++++++++++-
 net/rxrpc/recvmsg.c          | 43 +++++++++------------------
 4 files changed, 72 insertions(+), 31 deletions(-)
include/trace/events/rxrpc.h +1 -0
index 8f3e3967885a..d7c7b04d69fc 100644
@@ -343,6 +343,7 @@
 	EM(rxrpc_call_see_distribute_error,	"SEE dist-err") \
 	EM(rxrpc_call_see_input,		"SEE input   ") \
 	EM(rxrpc_call_see_notify_released,	"SEE nfy-rlsd") \
+	EM(rxrpc_call_see_notify_skipped,	"SEE nfy-skip") \
 	EM(rxrpc_call_see_recvmsg,		"SEE recvmsg ") \
 	EM(rxrpc_call_see_recvmsg_requeue,	"SEE recv-rqu") \
 	EM(rxrpc_call_see_recvmsg_requeue_first, "SEE recv-rqF") \
net/rxrpc/ar-internal.h +1 -1
index a6f830c1621f..cb36a709f540 100644
@@ -1110,6 +1110,7 @@ static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
 /*
  * call_state.c
  */
+void rxrpc_notify_socket(struct rxrpc_call *call);
 bool rxrpc_set_call_completion(struct rxrpc_call *call,
 			       enum rxrpc_call_completion compl,
 			       u32 abort_code,
@@ -1442,7 +1443,6 @@ extern const struct seq_operations rxrpc_local_seq_ops;
 /*
  * recvmsg.c
  */
-void rxrpc_notify_socket(struct rxrpc_call *);
 int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
 
 /*
net/rxrpc/call_state.c +56 -1

69 lines not on this page · raw message

net/rxrpc/recvmsg.c +14 -29

66 lines not on this page · raw message

author maintainer
#7 lore raw

PATCH v8 7/12 rxrpc: Expand abort trace enum

In reply to David Howells

The rxrpc_abort_reason enum is marked __mode(byte), but there are currently exactly 128 in the enum (0-127), but this is about to be increased and the enum is represented by a signed byte and an increase causes compilation errors.

Remove the mode marking to return it to a 32-bit int.

cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
cc Jarkko Sakkinen <[email protected]>
---
 include/trace/events/rxrpc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/trace/events/rxrpc.h +1 -1
index d7c7b04d69fc..ba2c6e3c78a6 100644
@@ -602,7 +602,7 @@
 #define EM(a, b) a,
 #define E_(a, b) a
 
-enum rxrpc_abort_reason		{ rxrpc_abort_reasons } __mode(byte);
+enum rxrpc_abort_reason		{ rxrpc_abort_reasons };
 enum rxrpc_bundle_trace		{ rxrpc_bundle_traces } __mode(byte);
 enum rxrpc_call_poke_trace	{ rxrpc_call_poke_traces } __mode(byte);
 enum rxrpc_call_trace		{ rxrpc_call_traces } __mode(byte);
author maintainer
#8 lore raw

PATCH v8 8/12 keys: Add refcounting to user-defined key type payload

In reply to David Howells

Add refcounting to user-defined key type payload so that a kernel service wanting to use such a key can hold onto the payload without the RCU read lock held in order that it can do an allocation without having to be concerned with the key getting updated.

This is the first part of the fix for the AF_RXRPC challenge response generation code.

---
 include/keys/user-type.h     | 10 +++++++---
 net/dns_resolver/dns_key.c   |  1 +
 security/keys/user_defined.c | 23 ++++++++++++++++-------
 3 files changed, 24 insertions(+), 10 deletions(-)
include/keys/user-type.h +7 -3
index 386c31432789..63846439596b 100644
@@ -13,19 +13,22 @@
 
 #ifdef CONFIG_KEYS
 
-/*****************************************************************************/
 /*
  * the payload for a key of type "user" or "logon"
  * - once filled in and attached to a key:
  *   - the payload struct is invariant may not be changed, only replaced
- *   - the payload must be read with RCU procedures or with the key semaphore
- *     held
+ *   - To access the payload, the caller must be holding the key semaphore or
+ *     the RCU read lock or must have first taken a ref on the payload.
+ *   - a ref may be taken on the payload only if the RCU read lock or key
+ *     semaphore is held.  refcount_inc_not_zero() needs to be used to get the
+ *     ref under RCU.
  *   - the payload may only be replaced with the key semaphore write-locked
  * - the key's data length is the size of the actual data, not including the
  *   payload wrapper
  */
 struct user_key_payload {
 	struct rcu_head	rcu;		/* RCU destructor */
+	refcount_t	ref;		/* Reference count */
 	unsigned short	datalen;	/* length of this data */
 	char		data[] __aligned(__alignof__(u64)); /* actual data */
 };
@@ -37,6 +40,7 @@ struct key_preparsed_payload;
 
 extern int user_preparse(struct key_preparsed_payload *prep);
 extern void user_free_preparse(struct key_preparsed_payload *prep);
+void put_user_key_payload(struct user_key_payload *payload);
 extern int user_update(struct key *key, struct key_preparsed_payload *prep);
 extern void user_revoke(struct key *key);
 extern void user_destroy(struct key *key);
net/dns_resolver/dns_key.c +1 -0
index 451247864a63..2bd3fb3c19f1 100644
@@ -208,6 +208,7 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
 		kleave(" = -ENOMEM");
 		return -ENOMEM;
 	}
+	refcount_set(&upayload->ref, 1);
 
 	upayload->datalen = result_len;
 	memcpy(upayload->data, data, result_len);
security/keys/user_defined.c +16 -7
index 6f88b507f927..55d5ed97b36e 100644
@@ -67,6 +67,7 @@ int user_preparse(struct key_preparsed_payload *prep)
 	upayload = kmalloc_flex(*upayload, data, datalen);
 	if (!upayload)
 		return -ENOMEM;
+	refcount_set(&upayload->ref, 1);
 
 	/* attach the data */
 	prep->quotalen = datalen;
@@ -88,12 +89,22 @@ EXPORT_SYMBOL_GPL(user_free_preparse);
 
 static void user_free_payload_rcu(struct rcu_head *head)
 {
-	struct user_key_payload *payload;
+	struct user_key_payload *payload =
+		container_of(head, struct user_key_payload, rcu);
 
-	payload = container_of(head, struct user_key_payload, rcu);
 	kfree_sensitive(payload);
 }
 
+/*
+ * Drop a ref to a user defined key payload, freeing it once all refs are gone.
+ */
+void put_user_key_payload(struct user_key_payload *payload)
+{
+	if (payload && refcount_dec_and_test(&payload->ref))
+		call_rcu(&payload->rcu, user_free_payload_rcu);
+}
+EXPORT_SYMBOL_GPL(put_user_key_payload);
+
 /*
  * update a user defined key
  * - the key's semaphore is write-locked
@@ -115,8 +126,7 @@ int user_update(struct key *key, struct key_preparsed_payload *prep)
 	rcu_assign_keypointer(key, prep->payload.data[0]);
 	prep->payload.data[0] = NULL;
 
-	if (zap)
-		call_rcu(&zap->rcu, user_free_payload_rcu);
+	put_user_key_payload(zap);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(user_update);
@@ -134,7 +144,7 @@ void user_revoke(struct key *key)
 
 	if (upayload) {
 		rcu_assign_keypointer(key, NULL);
-		call_rcu(&upayload->rcu, user_free_payload_rcu);
+		put_user_key_payload(upayload);
 	}
 }
 
@@ -147,9 +157,8 @@ void user_destroy(struct key *key)
 {
 	struct user_key_payload *upayload = key->payload.data[0];
 
-	kfree_sensitive(upayload);
+	put_user_key_payload(upayload);
 }
-
 EXPORT_SYMBOL_GPL(user_destroy);
 
 /*
author maintainer
#9 lore raw

PATCH v8 9/12 afs: Create a server appdata key

In reply to David Howells

Currently, when a CHALLENGE packet comes in, it's queued in an OOB queue on the AF_RXRPC socket that generated one of the calls on that connection for the application (which might be in userspace) to service. The application then picks up the CHALLENGE and requests a RESPONSE packet be generated, allowing the app to include app-specific data in it if appropriate. There is, however, no actual limit on the capacity of the CHALLENGE queue, and this could be abused remotely - and also getting the OOB mechanism right has proven tricky.

Further, by analogy with other AFS codebases, it's not actually necessary to generate the application data in response to the CHALLENGE. The reason I did this was to set the encryption on the app-data to be the same as that specified in the CHALLENGE as the server must be able to handle that. However, it's sufficient to use the encoding type set in the token that is going to be sent to the server; presumably the kerberos server knows that the fileserver can handle that type - otherwise why tell the client to use it?

This is a part of the fix. With this, the AFS filesystem creates an appdata key for each fileserver it talks to with RxGK and attaches it to the afs_server record.

Fixes 5800b1cf3fd8 ("rxrpc: Allow CHALLENGEs to the passed to the app for a RESPONSE")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
cc Jarkko Sakkinen <[email protected]>
---
 fs/afs/cm_security.c   | 232 +++++++++++++++++++++++++++++++++++++++++
 fs/afs/fs_probe.c      |   5 +
 fs/afs/internal.h      |   2 +
 fs/afs/rxrpc.c         |   1 +
 fs/afs/server.c        |   1 +
 include/net/af_rxrpc.h |   2 +
 net/rxrpc/key.c        |  37 +++++++
 7 files changed, 280 insertions(+)
fs/afs/cm_security.c +232 -0
index 103168c70dd4..8f04fec20a2a 100644
@@ -6,7 +6,9 @@
  */
 
 #include <linux/slab.h>
+#include <linux/key-type.h>
 #include <crypto/krb5.h>
+#include <keys/user-type.h>
 #include "internal.h"
 #include "afs_cm.h"
 #include "afs_fs.h"
@@ -23,6 +25,236 @@ static int afs_create_yfs_cm_token(struct sk_buff *challenge,
 				   struct afs_server *server);
 #endif
 
+#ifdef CONFIG_RXGK
+/*
+ * As the YFS RxGK appdata to be passed in the YFS.FS-service RESPONSE packet,
+ * create a GSS token to use as a ticket to the specified fileserver.
+ */
+static int afs_create_yfs_rxgk_cm_appdata(struct afs_server *server, u32 enctype)
+{
+	const struct krb5_enctype *conn_krb5, *token_krb5;
+	const struct krb5_buffer *token_key;
+	struct crypto_aead *aead;
+	struct scatterlist sg;
+	struct afs_net *net = server->cell->net;
+	const struct key *cm_key = net->fs_cm_token_key;
+	struct key *appdata_key = NULL;
+	size_t keysize, uuidsize, authsize, toksize, encsize, contsize;
+	size_t adatasize, offset;
+	__be32 caps[1] = {
+		[0] = htonl(AFS_CAP_ERROR_TRANSLATION),
+	};
+	__be32 *xdr;
+	void *appdata, *K0, *encbase;
+	int ret;
+
+	if (!cm_key)
+		return -ENOKEY;
+
+	/* Assume that the fileserver is happy to use the same encoding type as
+	 * we were told to use by the token obtained by the user.
+	 */
+	conn_krb5 = crypto_krb5_find_enctype(enctype);
+	if (!conn_krb5)
+		return -ENOPKG;
+	token_krb5 = cm_key->payload.data[0];
+	token_key = (const struct krb5_buffer *)&cm_key->payload.data[2];
+
+	/* struct rxgk_key {
+	 *	afs_uint32	enctype;
+	 *	opaque		key<>;
+	 * };
+	 */
+	keysize = 4 + xdr_len_object(conn_krb5->key_len);
+
+	/* struct RXGK_AuthName {
+	 *	afs_int32	kind;
+	 *	opaque		data<AUTHDATAMAX>;
+	 *	opaque		display<AUTHPRINTABLEMAX>;
+	 * };
+	 */
+	uuidsize = sizeof(server->uuid);
+	authsize = 4 + xdr_len_object(uuidsize) + xdr_len_object(0);
+
+	/* struct RXGK_Token {
+	 *	rxgk_key		K0;
+	 *	RXGK_Level		level;
+	 *	rxgkTime		starttime;
+	 *	afs_int32		lifetime;
+	 *	afs_int32		bytelife;
+	 *	rxgkTime		expirationtime;
+	 *	struct RXGK_AuthName	identities<>;
+	 * };
+	 */
+	toksize = keysize + 4 + 8 + 4 + 4 + 8 + xdr_len_object(authsize);
+
+	offset = 0;
+	encsize = crypto_krb5_how_much_buffer(token_krb5, KRB5_ENCRYPT_MODE, toksize, &offset);
+
+	/* struct RXGK_TokenContainer {
+	 *	afs_int32	kvno;
+	 *	afs_int32	enctype;
+	 *	opaque		encrypted_token<>;
+	 * };
+	 */
+	contsize = 4 + 4 + xdr_len_object(encsize);
+
+	/* struct YFSAppData {
+	 *	opr_uuid	initiatorUuid;
+	 *	opr_uuid	acceptorUuid;
+	 *	Capabilities	caps;
+	 *	afs_int32	enctype;
+	 *	opaque		callbackKey<>;
+	 *	opaque		callbackToken<>;
+	 * };
+	 */
+	adatasize = 16 + 16 +
+		xdr_len_object(sizeof(caps)) +
+		4 +
+		xdr_len_object(conn_krb5->key_len) +
+		xdr_len_object(contsize);
+
+	ret = -ENOMEM;
+	appdata = kzalloc(adatasize, GFP_KERNEL);
+	if (!appdata)
+		goto out;
+	xdr = appdata;
+
+	memcpy(xdr, &net->uuid, 16);		/* appdata.initiatorUuid */
+	xdr += 16 / 4;
+	memcpy(xdr, &server->uuid, 16);		/* appdata.acceptorUuid */
+	xdr += 16 / 4;
+	*xdr++ = htonl(ARRAY_SIZE(caps));	/* appdata.caps.len */
+	memcpy(xdr, &caps, sizeof(caps));	/* appdata.caps */
+	xdr += ARRAY_SIZE(caps);
+	*xdr++ = htonl(conn_krb5->etype);	/* appdata.enctype */
+
+	*xdr++ = htonl(conn_krb5->key_len);	/* appdata.callbackKey.len */
+	K0 = xdr;
+	get_random_bytes(K0, conn_krb5->key_len); /* appdata.callbackKey.data */
+	xdr += xdr_round_up(conn_krb5->key_len) / 4;
+
+	*xdr++ = htonl(contsize);		/* appdata.callbackToken.len */
+	*xdr++ = htonl(1);			/* cont.kvno */
+	*xdr++ = htonl(token_krb5->etype);	/* cont.enctype */
+	*xdr++ = htonl(encsize);		/* cont.encrypted_token.len */
+
+	encbase = xdr;
+	xdr += offset / 4;
+	*xdr++ = htonl(conn_krb5->etype);	/* token.K0.enctype */
+	*xdr++ = htonl(conn_krb5->key_len);	/* token.K0.key.len */
+	memcpy(xdr, K0, conn_krb5->key_len);	/* token.K0.key.data */
+	xdr += xdr_round_up(conn_krb5->key_len) / 4;
+
+	*xdr++ = htonl(RXRPC_SECURITY_ENCRYPT);	/* token.level */
+	*xdr++ = htonl(0);			/* token.starttime */
+	*xdr++ = htonl(0);			/* " */
+	*xdr++ = htonl(0);			/* token.lifetime */
+	*xdr++ = htonl(0);			/* token.bytelife */
+	*xdr++ = htonl(0);			/* token.expirationtime */
+	*xdr++ = htonl(0);			/* " */
+	*xdr++ = htonl(1);			/* token.identities.count */
+	*xdr++ = htonl(0);			/* token.identities[0].kind */
+	*xdr++ = htonl(uuidsize);		/* token.identities[0].data.len */
+	memcpy(xdr, &server->uuid, uuidsize);
+	xdr += xdr_round_up(uuidsize) / 4;
+	*xdr++ = htonl(0);			/* token.identities[0].display.len */
+
+	xdr = encbase + xdr_round_up(encsize);
+
+	if ((unsigned long)xdr - (unsigned long)appdata != adatasize)
+		pr_err("Appdata size incorrect %lx != %zx\n",
+		       (unsigned long)xdr - (unsigned long)appdata, adatasize);
+
+	aead = crypto_krb5_prepare_encryption(token_krb5, token_key, RXGK_SERVER_ENC_TOKEN,
+					      GFP_KERNEL);
+	if (IS_ERR(aead)) {
+		ret = PTR_ERR(aead);
+		goto out_token;
+	}
+
+	sg_init_one(&sg, encbase, encsize);
+	ret = crypto_krb5_encrypt(token_krb5, aead, &sg, 1, encsize, offset, toksize, false);
+	if (ret < 0)
+		goto out_aead;
+
+	appdata_key = key_alloc(&key_type_user, "rxrpc: afs rxgk appdata",
+				GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, current_cred(),
+				KEY_POS_VIEW | KEY_POS_SEARCH | KEY_USR_VIEW,
+				KEY_ALLOC_NOT_IN_QUOTA, NULL);
+	if (IS_ERR(appdata_key)) {
+		ret = PTR_ERR(appdata_key);
+		goto out_aead;
+	}
+
+	ret = key_instantiate_and_link(appdata_key, appdata, adatasize, NULL, NULL);
+	if (ret < 0) {
+		key_put(appdata_key);
+		goto out_aead;
+	}
+
+	/* Store the appdata before the key pointer */
+	smp_store_release(&server->yfs_rxgk_appdata, appdata_key);
+
+out_aead:
+	crypto_free_aead(aead);
+out_token:
+	kfree_sensitive(appdata);
+out:
+	return ret;
+}
+#endif /* CONFIG_RXGK */
+
+/*
+ * Create the application data to go in a RESPONSE packet a server's CHALLENGE
+ * from the parameters contained in a key.  The key specifies the security
+ * index and other appropriate parameters such as the encoding type for RxGK.
+ */
+int afs_create_server_appdata(struct afs_server *server, struct key *key)
+{
+	u32 krb5_enctype;
+	int ret;
+	u8 security_index;
+
+	if (!key)
+		return 0;
+
+	rxrpc_kernel_query_key(key, &security_index, &krb5_enctype);
+
+	_enter("%u,%u", security_index, krb5_enctype);
+
+	switch (security_index) {
+#ifdef CONFIG_RXGK
+	case RXRPC_SECURITY_YFS_RXGK:
+		/* Read the key pointer before the appdata */
+		if (smp_load_acquire(&server->yfs_rxgk_appdata))
+			return 0;
+		break;
+#endif
+	default:
+		return 0;
+	}
+
+	ret = 0;
+	mutex_lock(&server->cm_token_lock);
+
+	switch (security_index) {
+#ifdef CONFIG_RXGK
+	case RXRPC_SECURITY_YFS_RXGK:
+		/* Read the key pointer before the appdata */
+		if (smp_load_acquire(&server->yfs_rxgk_appdata))
+			break;
+		ret = afs_create_yfs_rxgk_cm_appdata(server, krb5_enctype);
+		break;
+#endif
+	default:
+		break;
+	}
+
+	mutex_unlock(&server->cm_token_lock);
+	return ret;
+}
+
 /*
  * Respond to an RxGK challenge, adding appdata.
  */
fs/afs/fs_probe.c +5 -0
index a91ad1938d07..e26f7f1e30a2 100644
@@ -241,9 +241,14 @@ int afs_fs_probe_fileserver(struct afs_net *net, struct afs_server *server,
 	struct afs_endpoint_state *estate, *old;
 	struct afs_addr_list *old_alist = NULL, *alist;
 	unsigned long unprobed;
+	int ret;
 
 	_enter("%pU", &server->uuid);
 
+	ret = afs_create_server_appdata(server, key);
+	if (ret < 0)
+		return ret;
+
 	estate = kzalloc_obj(*estate);
 	if (!estate)
 		return -ENOMEM;
fs/afs/internal.h +2 -0
index 290873bac89b..320c9535832a 100644
@@ -549,6 +549,7 @@ struct afs_server {
 	struct timer_list	timer;		/* Management timer */
 	struct mutex		cm_token_lock;	/* Lock governing creation of appdata */
 	struct krb5_buffer	cm_rxgk_appdata; /* Appdata to be included in RESPONSE packet */
+	struct key		*yfs_rxgk_appdata; /* Appdata to be included in RESPONSE packet */
 	time64_t		unuse_time;	/* Time at which last unused */
 	unsigned long		flags;
 #define AFS_SERVER_FL_RESPONDING 0		/* The server is responding */
@@ -1089,6 +1090,7 @@ extern bool afs_cm_incoming_call(struct afs_call *);
 /*
  * cm_security.c
  */
+int afs_create_server_appdata(struct afs_server *server, struct key *key);
 void afs_process_oob_queue(struct work_struct *work);
 #ifdef CONFIG_RXGK
 int afs_create_token_key(struct afs_net *net, struct socket *socket);
fs/afs/rxrpc.c +1 -0
index bf0d231d30a6..007e3f6af667 100644
@@ -115,6 +115,7 @@ int afs_open_socket(struct afs_net *net)
 
 error_2:
 	sock_release(socket);
+	key_put(net->fs_cm_token_key);
 error_1:
 	_leave(" = %d", ret);
 	return ret;
fs/afs/server.c +1 -0
index 0fe162ea2a36..b08d9080b0c5 100644
@@ -399,6 +399,7 @@ static void afs_server_rcu(struct rcu_head *rcu)
 			       afs_estate_trace_put_server);
 	afs_put_cell(server->cell, afs_cell_trace_put_server);
 	kfree(server->cm_rxgk_appdata.data);
+	key_put(server->yfs_rxgk_appdata);
 	kfree(server);
 }
 
include/net/af_rxrpc.h +2 -0
index 0fb4c41c9bbf..c4b68049c06f 100644
@@ -109,6 +109,8 @@ int rxkad_kernel_respond_to_challenge(struct sk_buff *challenge);
 u32 rxgk_kernel_query_challenge(struct sk_buff *challenge);
 int rxgk_kernel_respond_to_challenge(struct sk_buff *challenge,
 				     struct krb5_buffer *appdata);
+void rxrpc_kernel_query_key(const struct key *key, u8 *_security_index,
+			    u32 *_krb5_enctype);
 u8 rxrpc_kernel_query_call_security(struct rxrpc_call *call,
 				    u16 *_service_id, u32 *_enctype);
 
net/rxrpc/key.c +37 -0
index a0aa78d89289..16bab72e6f07 100644
@@ -893,3 +893,40 @@ static long rxrpc_read(const struct key *key,
 	_leave(" = %zu", size);
 	return size;
 }
+
+/**
+ * rxrpc_kernel_query_key - Query parameters from an rxrpc key
+ * @key: The key to query
+ * @_security_index: Where to return the security index
+ * @_krb5_enctype: Where to return the krb5 encryption type if applicable
+ *
+ * Query an rxrpc authentication key, extracting the security index from the
+ * first token therein.
+ */
+void rxrpc_kernel_query_key(const struct key *key, u8 *_security_index,
+			    u32 *_krb5_enctype)
+{
+	const struct rxrpc_key_token *token;
+
+	token = key->payload.data[0];
+	if (!token) {
+		*_security_index = 0;
+		*_krb5_enctype = 0;
+		return;
+	}
+
+	*_security_index = token->security_index;
+	switch (token->security_index) {
+	case RXRPC_SECURITY_RXKAD:
+		*_krb5_enctype = 0;
+		break;
+	case RXRPC_SECURITY_YFS_RXGK:
+		*_krb5_enctype = token->rxgk->enctype;
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		*_krb5_enctype = 0;
+		break;
+	}
+}
+EXPORT_SYMBOL(rxrpc_kernel_query_key);
author maintainer
#10 lore raw

PATCH v8 10/12 rxrpc: Pass appdata key to rxrpc_call and thence to rxrpc_bundle

In reply to David Howells

Currently, when a CHALLENGE packet comes in, it's queued in an OOB queue on the AF_RXRPC socket that generated one of the calls on that connection for the application (which might be in userspace) to service. The application then picks up the CHALLENGE and requests a RESPONSE packet be generated, allowing the app to include app-specific data in it if appropriate. There is, however, no actual limit on the capacity of the CHALLENGE queue, and this could be abused remotely - and also getting the OOB mechanism right has proven tricky.

Further, by analogy with other AFS codebases, it's not actually necessary to generate the application data in response to the CHALLENGE. The reason I did this was to set the encryption on the app-data to be the same as that specified in the CHALLENGE as the server must be able to handle that. However, it's sufficient to use the encoding type set in the token that is going to be sent to the server; presumably the kerberos server knows that the fileserver can handle that type - otherwise why tell the client to use it?

This is a part of the fix. With this, the appdata key created by the AFS filesystem or passed in via sendmsg CMSG to a user AF_RXRPC socket is added to an rxrpc_call struct and will then be added to an rxrpc_bundle struct.

Keys being supplied by userspace via the RXRPC_RESPONSE_APPDATA cmsg must be prefixed with "rxrpc-appdata:" to restrict the use of this mechanism to arbitrarily steal data held in user keys. The key must also grant Search access to the process.

Note that afs_make_op_call() has to be moved so that it can call afs_use_server(). afs_operation-based calls did not heretofore 'use' the server and server will be 'un-used' by afs_free_call().

Fixes 5800b1cf3fd8 ("rxrpc: Allow CHALLENGEs to the passed to the app for a RESPONSE")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
cc Jarkko Sakkinen <[email protected]>
---
 Documentation/networking/rxrpc.rst | 15 ++++++++++++++
 fs/afs/internal.h                  | 33 +++++++++++++++---------------
 fs/afs/rxrpc.c                     | 21 ++++++++++++++++++-
 include/net/af_rxrpc.h             |  1 +
 include/trace/events/afs.h         |  1 +
 include/uapi/linux/rxrpc.h         |  1 +
 net/rxrpc/af_rxrpc.c               |  3 +++
 net/rxrpc/ar-internal.h            |  3 +++
 net/rxrpc/call_object.c            |  2 ++
 net/rxrpc/conn_client.c            |  4 ++++
 net/rxrpc/proc.c                   |  5 +++--
 net/rxrpc/sendmsg.c                | 32 ++++++++++++++++++++++++++++-
 12 files changed, 101 insertions(+), 20 deletions(-)
Documentation/networking/rxrpc.rst +15 -0
index 7df6aff7644c..07f4487def31 100644
@@ -339,6 +339,7 @@ calls, to invoke certain actions and to report certain conditions.  These are:
 	RXRPC_EXCLUSIVE_CALL	s-- n/a		Make an exclusive client call
 	RXRPC_UPGRADE_SERVICE	s-- n/a		Client call can be upgraded
 	RXRPC_TX_LENGTH		s-- data len	Total length of Tx data
+	RXRPC_RESPONSE_APPDATA	Cs- key serial	RESPONSE app data key
 	=======================	=== ===========	===============================
 
 	(SRT = usable in Sendmsg / delivered by Recvmsg / Terminal message)
@@ -432,6 +433,15 @@ calls, to invoke certain actions and to report certain conditions.  These are:
      This takes a parameter of __s64 type that indicates how much will be
      transmitted.  This may not be less than zero.
 
+ (#) RXRPC_RESPONSE_APPDATA
+
+     This is used to pass a key containing application data to be included in a
+     RESPONSE packet.  Currently, this only applies to RxGK keys.  This may be
+     used, for instance, by the AFS filesystem client to pass a token to the
+     fileserver for the fileserver to use to set up a secure connection to the
+     cache manager.  This is only used when setting up a client call and
+     ignored any other time it is seen.
+
 The symbol RXRPC__SUPPORTED is defined as one more than the highest control
 message type supported.  At run time this can be queried by means of the
 RXRPC_SUPPORTED_CMSG socket option (see below).
@@ -800,6 +810,7 @@ The kernel interface functions are as follows:
 	rxrpc_kernel_begin_call(struct socket *sock,
 				struct sockaddr_rxrpc *srx,
 				struct key *key,
+				struct key *app_data,
 				unsigned long user_call_ID,
 				s64 tx_total_len,
 				gfp_t gfp,
@@ -818,6 +829,10 @@ The kernel interface functions are as follows:
      the key bound to the socket with the RXRPC_SECURITY_KEY sockopt.  Calls
      secured in this way will still share connections if at all possible.
 
+     If app_data is supplied, this needs to be a user-defined key and will
+     provide the contents of the application data field in a RESPONSE packet
+     generated in response to this call's connection.
+
      The user_call_ID is equivalent to that supplied to sendmsg() in the
      control data buffer.  It is entirely feasible to use this to point to a
      kernel data structure.
fs/afs/internal.h +17 -16
index 320c9535832a..ce05595b7d3c 100644
@@ -1418,22 +1418,6 @@ static inline void afs_see_call(struct afs_call *call, enum afs_call_trace why)
 		       __builtin_return_address(0));
 }
 
-static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
-				    gfp_t gfp)
-{
-	struct afs_addr_list *alist = op->estate->addresses;
-
-	op->call	= afs_get_call(call, afs_call_trace_get);
-	op->type	= call->type;
-	call->op	= op;
-	call->key	= op->key;
-	call->intr	= !(op->flags & AFS_OPERATION_UNINTR);
-	call->peer	= rxrpc_kernel_get_peer(alist->addrs[op->addr_index].peer);
-	call->service_id = op->server->service_id;
-	afs_make_call(call, gfp);
-	afs_put_call(call);
-}
-
 static inline void afs_extract_begin(struct afs_call *call, void *buf, size_t size)
 {
 	call->iov_len = size;
@@ -1765,6 +1749,23 @@ static inline struct inode *AFS_VNODE_TO_I(struct afs_vnode *vnode)
 	return &vnode->netfs.inode;
 }
 
+static inline void afs_make_op_call(struct afs_operation *op, struct afs_call *call,
+				    gfp_t gfp)
+{
+	struct afs_addr_list *alist = op->estate->addresses;
+
+	op->call	= afs_get_call(call, afs_call_trace_get);
+	op->type	= call->type;
+	call->op	= op;
+	call->server	= afs_use_server(op->server, false, afs_server_trace_use_call);
+	call->key	= op->key;
+	call->intr	= !(op->flags & AFS_OPERATION_UNINTR);
+	call->peer	= rxrpc_kernel_get_peer(alist->addrs[op->addr_index].peer);
+	call->service_id = op->server->service_id;
+	afs_make_call(call, gfp);
+	afs_put_call(call);
+}
+
 /*
  * Note that a dentry got changed.  We need to set d_fsdata to the data version
  * number derived from the result of the operation.  It doesn't matter if
fs/afs/rxrpc.c +20 -1
index 007e3f6af667..a71e924c10c3 100644
@@ -348,6 +348,7 @@ void afs_make_call(struct afs_call *call, gfp_t gfp)
 	struct rxrpc_call *rxcall;
 	struct msghdr msg;
 	struct kvec iov[1];
+	struct key *app_data = NULL;
 	size_t len;
 	s64 tx_total_len;
 	int ret;
@@ -379,8 +380,26 @@ void afs_make_call(struct afs_call *call, gfp_t gfp)
 		call->drop_ref = true;
 	}
 
+	if (call->key && call->server) {
+		u32 krb5_enctype = 0;
+		u8 security_index = 0;
+
+		rxrpc_kernel_query_key(call->key, &security_index, &krb5_enctype);
+		switch (security_index) {
+#ifdef CONFIG_RXGK
+		case RXRPC_SECURITY_YFS_RXGK:
+			/* Read the key pointer before the appdata */
+			app_data = smp_load_acquire(&call->server->yfs_rxgk_appdata);
+			break;
+#endif
+		default:
+			break;
+		}
+	}
+
 	/* create a call */
-	rxcall = rxrpc_kernel_begin_call(call->net->socket, call->peer, call->key,
+	rxcall = rxrpc_kernel_begin_call(call->net->socket, call->peer,
+					 call->key, app_data,
 					 (unsigned long)call,
 					 tx_total_len,
 					 call->max_lifespan,
include/net/af_rxrpc.h +1 -0
index c4b68049c06f..19c61a2f5af3 100644
@@ -55,6 +55,7 @@ void rxrpc_kernel_set_notifications(struct socket *sock,
 struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
 					   struct rxrpc_peer *peer,
 					   struct key *key,
+					   struct key *app_data,
 					   unsigned long user_call_ID,
 					   s64 tx_total_len,
 					   u32 hard_timeout,
include/trace/events/afs.h +1 -0
index 1b3c48b5591d..04b0bb682b81 100644
@@ -148,6 +148,7 @@ enum yfs_cm_operation {
 	EM(afs_server_trace_unuse_slist_isort,	"UNU isort") \
 	EM(afs_server_trace_update,		"UPDATE   ") \
 	EM(afs_server_trace_use_by_uuid,	"USE uuid ") \
+	EM(afs_server_trace_use_call,		"USE call ") \
 	EM(afs_server_trace_use_cm_call,	"USE cm-cl") \
 	EM(afs_server_trace_use_get_caps,	"USE gcaps") \
 	EM(afs_server_trace_use_give_up_cb,	"USE gvupc") \
include/uapi/linux/rxrpc.h +1 -0
index d9735abd4c79..bcdfdf9c67a1 100644
@@ -63,6 +63,7 @@ enum rxrpc_cmsg_type {
 	RXRPC_RESPOND		= 17,	/* Cs-: Respond to a challenge */
 	RXRPC_RESPONDED		= 18,	/* S-r: Data received in RESPONSE */
 	RXRPC_RESP_RXGK_APPDATA	= 19,	/* Cs-: RESPONSE: RxGK app data to include */
+	RXRPC_RESPONSE_APPDATA	= 20,	/* Cs-: User key holding app data for RESPONSE */
 	RXRPC__SUPPORTED
 };
 
net/rxrpc/af_rxrpc.c +3 -0
index 9ab0f22c881e..a19c0fd3c51a 100644
@@ -318,6 +318,7 @@ EXPORT_SYMBOL(rxrpc_kernel_put_peer);
  * @sock: The socket on which to make the call
  * @peer: The peer to contact
  * @key: The security context to use (defaults to socket setting)
+ * @app_data: The security response application data (or NULL)
  * @user_call_ID: The ID to use
  * @tx_total_len: Total length of data to transmit during the call (or -1)
  * @hard_timeout: The maximum lifespan of the call in sec
@@ -340,6 +341,7 @@ EXPORT_SYMBOL(rxrpc_kernel_put_peer);
 struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
 					   struct rxrpc_peer *peer,
 					   struct key *key,
+					   struct key *app_data,
 					   unsigned long user_call_ID,
 					   s64 tx_total_len,
 					   u32 hard_timeout,
@@ -368,6 +370,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
 		key = NULL; /* a no-security key */
 
 	memset(&p, 0, sizeof(p));
+	p.app_data		= app_data;
 	p.user_call_ID		= user_call_ID;
 	p.tx_total_len		= tx_total_len;
 	p.interruptibility	= interruptibility;
net/rxrpc/ar-internal.h +3 -0
index cb36a709f540..222b239884ca 100644
@@ -516,6 +516,7 @@ struct rxrpc_bundle {
 	struct rxrpc_local	*local;		/* Representation of local endpoint */
 	struct rxrpc_peer	*peer;		/* Remote endpoint */
 	struct key		*key;		/* Security details */
+	struct key		*app_data;	/* Security response app data */
 	struct list_head	proc_link;	/* Link in net->bundle_proc_list */
 	const struct rxrpc_security *security;	/* applied security module */
 	refcount_t		ref;
@@ -720,6 +721,7 @@ struct rxrpc_call {
 	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
 	struct rxrpc_net	*rxnet;		/* Network namespace to which call belongs */
 	struct key		*key;		/* Security details */
+	struct key		*app_data;	/* Security response app data */
 	const struct rxrpc_security *security;	/* applied security module */
 	struct mutex		user_mutex;	/* User access mutex */
 	struct sockaddr_rxrpc	dest_srx;	/* Destination address */
@@ -914,6 +916,7 @@ enum rxrpc_command {
 };
 
 struct rxrpc_call_params {
+	struct key		*app_data;	/* Security response app data */
 	s64			tx_total_len;	/* Total Tx data length (if send data) */
 	unsigned long		user_call_ID;	/* User's call ID */
 	struct {
net/rxrpc/call_object.c +2 -0
index 817ed9acb91e..9f6130d90c4c 100644
@@ -211,6 +211,7 @@ static struct rxrpc_call *rxrpc_alloc_client_call(struct rxrpc_sock *rx,
 	call->interruptibility	= p->interruptibility;
 	call->tx_total_len	= p->tx_total_len;
 	call->key		= key_get(cp->key);
+	call->app_data		= key_get(p->app_data);
 	call->peer		= rxrpc_get_peer(cp->peer, rxrpc_peer_get_call);
 	call->local		= rxrpc_get_local(cp->local, rxrpc_local_get_call);
 	call->security_level	= cp->security_level;
@@ -697,6 +698,7 @@ static void rxrpc_destroy_call(struct work_struct *work)
 	rxrpc_put_peer(call->peer, rxrpc_peer_put_call);
 	rxrpc_put_local(call->local, rxrpc_local_put_call);
 	key_put(call->key);
+	key_put(call->app_data);
 	call_rcu(&call->rcu, rxrpc_rcu_free_call);
 }
 
net/rxrpc/conn_client.c +4 -0
index 48519f0de185..dd79630d3066 100644
@@ -81,6 +81,7 @@ static struct rxrpc_bundle *rxrpc_alloc_bundle(struct rxrpc_call *call,
 		bundle->local		= call->local;
 		bundle->peer		= rxrpc_get_peer(call->peer, rxrpc_peer_get_bundle);
 		bundle->key		= key_get(call->key);
+		bundle->app_data	= key_get(call->app_data);
 		bundle->security	= call->security;
 		bundle->exclusive	= test_bit(RXRPC_CALL_EXCLUSIVE, &call->flags);
 		bundle->upgrade		= test_bit(RXRPC_CALL_UPGRADE, &call->flags);
@@ -118,6 +119,7 @@ static void rxrpc_free_bundle(struct rxrpc_bundle *bundle)
 	write_unlock(&bundle->local->rxnet->conn_lock);
 	rxrpc_put_peer(bundle->peer, rxrpc_peer_put_bundle);
 	key_put(bundle->key);
+	key_put(bundle->app_data);
 	kfree(bundle);
 }
 
@@ -274,6 +276,7 @@ int rxrpc_look_up_bundle(struct rxrpc_call *call, gfp_t gfp)
 #define cmp(X, Y) ((long)(X) - (long)(Y))
 		diff = (cmp(bundle->peer, call->peer) ?:
 			cmp(bundle->key, call->key) ?:
+			cmp(bundle->app_data, call->app_data) ?:
 			cmp(bundle->security_level, call->security_level) ?:
 			cmp(bundle->upgrade, upgrade));
 #undef cmp
@@ -303,6 +306,7 @@ int rxrpc_look_up_bundle(struct rxrpc_call *call, gfp_t gfp)
 #define cmp(X, Y) ((long)(X) - (long)(Y))
 		diff = (cmp(bundle->peer, call->peer) ?:
 			cmp(bundle->key, call->key) ?:
+			cmp(bundle->app_data, call->app_data) ?:
 			cmp(bundle->security_level, call->security_level) ?:
 			cmp(bundle->upgrade, upgrade));
 #undef cmp
net/rxrpc/proc.c +3 -2
index e9a27fa7b25d..f300491b06bd 100644
@@ -238,7 +238,7 @@ static int rxrpc_bundle_seq_show(struct seq_file *seq, void *v)
 		seq_puts(seq,
 			 "Proto Local                                          "
 			 " Remote                                         "
-			 " SvID Ref Act Flg Key      |"
+			 " SvID Ref Act Flg Key      AppData  |"
 			 " Bundle   Conn_0   Conn_1   Conn_2   Conn_3\n"
 			 );
 		return 0;
@@ -250,7 +250,7 @@ static int rxrpc_bundle_seq_show(struct seq_file *seq, void *v)
 	scnprintf(rbuff, sizeof(rbuff), "%pISpc", &bundle->peer->srx.transport);
 	seq_printf(seq,
 		   "UDP   %-47.47s %-47.47s %4x %3u %3d"
-		   " %c%c%c %08x | %08x %08x %08x %08x %08x\n",
+		   " %c%c%c %08x %08x | %08x %08x %08x %08x %08x\n",
 		   lbuff,
 		   rbuff,
 		   bundle->service_id,
@@ -260,6 +260,7 @@ static int rxrpc_bundle_seq_show(struct seq_file *seq, void *v)
 		   bundle->exclusive ? 'e' : '-',
 		   bundle->upgrade ? 'u' : '-',
 		   key_serial(bundle->key),
+		   key_serial(bundle->app_data),
 		   bundle->debug_id,
 		   bundle->conn_ids[0],
 		   bundle->conn_ids[1],
net/rxrpc/sendmsg.c +31 -1
index 271562450469..3043fd1975d3 100644
@@ -12,6 +12,7 @@
 #include <linux/skbuff.h>
 #include <linux/export.h>
 #include <linux/sched/signal.h>
+#include <keys/user-type.h>
 
 #include <net/sock.h>
 #include <net/af_rxrpc.h>
@@ -550,6 +551,8 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
 static int rxrpc_sendmsg_cmsg(struct msghdr *msg, struct rxrpc_send_params *p)
 {
 	struct cmsghdr *cmsg;
+	key_serial_t key_id;
+	key_ref_t key;
 	bool got_user_ID = false;
 	int len;
 
@@ -634,6 +637,29 @@ static int rxrpc_sendmsg_cmsg(struct msghdr *msg, struct rxrpc_send_params *p)
 				return -ERANGE;
 			break;
 
+		case RXRPC_RESPONSE_APPDATA:
+			if (len != sizeof(key_serial_t))
+				return -EINVAL;
+			if (p->call.app_data)
+				return -EINVAL;
+			key_id = *(key_serial_t *)CMSG_DATA(cmsg);
+			key = lookup_user_key(key_id, 0, KEY_NEED_SEARCH);
+			if (IS_ERR(key))
+				return PTR_ERR(key);
+			if (key_ref_to_ptr(key)->type != &key_type_user) {
+				key_ref_put(key);
+				return -EINVAL;
+			}
+			if (!key_ref_to_ptr(key)->description ||
+			    strncmp(key_ref_to_ptr(key)->description,
+				    "rxrpc-appdata:", 14) != 0) {
+				key_ref_put(key);
+				return -EINVAL;
+			}
+
+			p->call.app_data = key_ref_to_ptr(key);
+			break;
+
 		default:
 			return -EINVAL;
 		}
@@ -741,8 +767,10 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
 			goto error_release_sock;
 		call = rxrpc_new_client_call_for_sendmsg(rx, msg, &p);
 		/* The socket is now unlocked... */
-		if (IS_ERR(call))
+		if (IS_ERR(call)) {
+			key_put(p.call.app_data);
 			return PTR_ERR(call);
+		}
 		/* ... and we have the call lock. */
 		p.call.nr_timeouts = 0;
 		ret = 0;
@@ -826,11 +854,13 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
 	mutex_unlock(&call->user_mutex);
 error_put:
 	rxrpc_put_call(call, rxrpc_call_put_sendmsg);
+	key_put(p.call.app_data);
 	_leave(" = %d", ret);
 	return ret;
 
 error_release_sock:
 	release_sock(&rx->sk);
+	key_put(p.call.app_data);
 	return ret;
 }
 
author maintainer
#11 lore raw

PATCH v8 11/12 rxrpc: Fix CHALLENGE packet overqueuing and simplify RESPONSE generation

In reply to David Howells

Currently, when a CHALLENGE packet comes in, it's queued in an OOB queue on the AF_RXRPC socket that generated one of the calls on that connection for the application (which might be in userspace) to service. The application then picks up the CHALLENGE and requests a RESPONSE packet be generated, allowing the app to include app-specific data in it if appropriate. There is, however, no actual limit on the capacity of the CHALLENGE queue, and this could be abused remotely - and also getting the OOB mechanism right has proven tricky.

Further, by analogy with other AFS codebases, it's not actually necessary to generate the application data in response to the CHALLENGE. The reason I did this was to set the encryption on the app-data to be the same as that specified in the CHALLENGE as the server must be able to handle that. However, it's sufficient to use the encoding type set in the token that is going to be sent to the server; presumably the kerberos server knows that the fileserver can handle that type - otherwise why tell the client to use it?

This is the main part of the fix. It switches the code over from using the OOB communication mechanism to get the appdata on the fly from the application (either the AFS filesystem or userspace) to using the appdata key preemptively provided by the application.

The following changes are made:

(1) Revert to making the connection event processor work item parse the CHALLENGE and generate the RESPONSE directly.

(2) Add another (optional) parameter that is passed in when an rxrpc client call is created and ends up attached to the connection bundle and is a user-type containing the application data.

(3) RESPONSE generation looks at the bundle and if the app-data is there, it will include it (if the security class is YFS-RxGK; RxKAD ignores it).

The AFS filesystem driver creates an app-data key when it probes a fileserver and attaches it to the afs_server struct. This is picked up when a call is made to that server and thence passed to rxrpc.

Direct userspace users of AF_RXRPC can partake by creating a user-type key containing the app-data they want to use and passing its serial ID in a CMSG of type RXRPC_RESPONSE_APPDATA in the initial sendmsg() of a call. The key's description must also be prefixed with "rxrpc-appdata:" and the key must grant Search permission to the calling process.

Fixes 5800b1cf3fd8 ("rxrpc: Allow CHALLENGEs to the passed to the app for a RESPONSE")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
cc Jarkko Sakkinen <[email protected]>
---
 include/trace/events/rxrpc.h |  1 +
 net/rxrpc/af_rxrpc.c         |  5 +--
 net/rxrpc/conn_event.c       | 68 ++----------------------------------
 net/rxrpc/rxgk.c             | 67 ++++++++++++++++++++++-------------
 4 files changed, 48 insertions(+), 93 deletions(-)
include/trace/events/rxrpc.h +1 -0
index ba2c6e3c78a6..48e774034195 100644
@@ -78,6 +78,7 @@
 	EM(rxgk_abort_2_short_encdata,		"rxgk2-short-encdata")	\
 	EM(rxgk_abort_2_short_header,		"rxgk2-short-hdr")	\
 	EM(rxgk_abort_bad_key_number,		"rxgk-bad-key-num")	\
+	EM(rxgk_abort_chall_bad_app_key,	"rxgk-chall-bad-app-key")\
 	EM(rxgk_abort_chall_key_expired,	"rxgk-chall-key-exp")	\
 	EM(rxgk_abort_chall_no_key,		"rxgk-chall-nokey")	\
 	EM(rxgk_abort_chall_short,		"rxgk-chall-short")	\
net/rxrpc/af_rxrpc.c +1 -4
index a19c0fd3c51a..9eb6ca3c5ebf 100644
@@ -598,10 +598,7 @@ static int rxrpc_sendmsg(struct socket *sock, struct msghdr *m, size_t len)
 		fallthrough;
 	case RXRPC_SERVER_BOUND:
 	case RXRPC_SERVER_LISTENING:
-		if (m->msg_flags & MSG_OOB)
-			ret = rxrpc_sendmsg_oob(rx, m, len);
-		else
-			ret = rxrpc_do_sendmsg(rx, m, len);
+		ret = rxrpc_do_sendmsg(rx, m, len);
 		/* The socket has been unlocked */
 		goto out;
 	default:
net/rxrpc/conn_event.c +3 -65

86 lines not on this page · raw message

net/rxrpc/rxgk.c +43 -24

141 lines not on this page · raw message

author maintainer
#12 lore raw

PATCH v8 12/12 rxrpc: Remove OOB challenge/response code

In reply to David Howells

Remove all the OOB challenge/response code communication stuff along with the UAPI elements related to them as these are no longer used. This is the final part of the fix implemented in the preceding patches.

Fixes 5800b1cf3fd8 ("rxrpc: Allow CHALLENGEs to the passed to the app for a RESPONSE")
cc Marc Dionne <[email protected]>
cc Jeffrey Altman <[email protected]>
cc Eric Dumazet <[email protected]>
cc "David S. Miller" <[email protected]>
cc Jakub Kicinski <[email protected]>
cc Paolo Abeni <[email protected]>
cc Simon Horman <[email protected]>
cc Jarkko Sakkinen <[email protected]>
---
 Documentation/networking/rxrpc.rst |   1 -
 fs/afs/cm_security.c               | 259 -------------------
 fs/afs/internal.h                  |   3 -
 fs/afs/main.c                      |   1 -
 fs/afs/rxrpc.c                     |  19 --
 fs/afs/server.c                    |   1 -
 include/net/af_rxrpc.h             |  23 --
 include/trace/events/rxrpc.h       |  11 +-
 include/uapi/linux/rxrpc.h         |  23 +-
 net/rxrpc/Makefile                 |   1 -
 net/rxrpc/af_rxrpc.c               |  43 +---
 net/rxrpc/ar-internal.h            |  23 --
 net/rxrpc/conn_event.c             |   2 +-
 net/rxrpc/insecure.c               |   7 -
 net/rxrpc/oob.c                    | 387 -----------------------------
 net/rxrpc/recvmsg.c                |  82 +-----
 net/rxrpc/rxgk.c                   |  73 ------
 net/rxrpc/rxkad.c                  |  27 --
 net/rxrpc/server_key.c             |  40 ---
 19 files changed, 8 insertions(+), 1018 deletions(-)
 delete mode 100644 net/rxrpc/oob.c
Documentation/networking/rxrpc.rst +0 -1
index 07f4487def31..ba72566ea8fb 100644
@@ -1175,7 +1175,6 @@ API Function Reference
 .. kernel-doc:: net/rxrpc/af_rxrpc.c
 .. kernel-doc:: net/rxrpc/call_object.c
 .. kernel-doc:: net/rxrpc/key.c
-.. kernel-doc:: net/rxrpc/oob.c
 .. kernel-doc:: net/rxrpc/peer_object.c
 .. kernel-doc:: net/rxrpc/recvmsg.c
 .. kernel-doc:: net/rxrpc/rxgk.c
fs/afs/cm_security.c +0 -259

275 lines not on this page · raw message

fs/afs/internal.h +0 -3
index ce05595b7d3c..d2bcb567c31b 100644
@@ -283,7 +283,6 @@ struct afs_net {
 	struct socket		*socket;
 	struct afs_call		*spare_incoming_call;
 	struct work_struct	charge_preallocation_work;
-	struct work_struct	rx_oob_work;
 	struct mutex		socket_mutex;
 	atomic_t		nr_outstanding_calls;
 	atomic_t		nr_superblocks;
@@ -548,7 +547,6 @@ struct afs_server {
 	struct work_struct	destroyer;	/* Work item to try and destroy a server */
 	struct timer_list	timer;		/* Management timer */
 	struct mutex		cm_token_lock;	/* Lock governing creation of appdata */
-	struct krb5_buffer	cm_rxgk_appdata; /* Appdata to be included in RESPONSE packet */
 	struct key		*yfs_rxgk_appdata; /* Appdata to be included in RESPONSE packet */
 	time64_t		unuse_time;	/* Time at which last unused */
 	unsigned long		flags;
@@ -1091,7 +1089,6 @@ extern bool afs_cm_incoming_call(struct afs_call *);
  * cm_security.c
  */
 int afs_create_server_appdata(struct afs_server *server, struct key *key);
-void afs_process_oob_queue(struct work_struct *work);
 #ifdef CONFIG_RXGK
 int afs_create_token_key(struct afs_net *net, struct socket *socket);
 #else
fs/afs/main.c +0 -1
index 7a883c59976f..6353feaa5fb4 100644
@@ -73,7 +73,6 @@ static int __net_init afs_net_init(struct net *net_ns)
 	generate_random_uuid((unsigned char *)&net->uuid);
 
 	INIT_WORK(&net->charge_preallocation_work, afs_charge_preallocation);
-	INIT_WORK(&net->rx_oob_work, afs_process_oob_queue);
 	mutex_init(&net->socket_mutex);
 
 	net->cells = RB_ROOT;
fs/afs/rxrpc.c +0 -19
index a71e924c10c3..563857cbb599 100644
@@ -25,14 +25,12 @@ static void afs_process_async_call(struct work_struct *);
 static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long);
 static void afs_rx_discard_new_call(struct rxrpc_call *, unsigned long);
 static void afs_rx_attach(struct rxrpc_call *rxcall, unsigned long user_call_ID);
-static void afs_rx_notify_oob(struct sock *sk, struct sk_buff *oob);
 static int afs_deliver_cm_op_id(struct afs_call *);
 
 static const struct rxrpc_kernel_ops afs_rxrpc_callback_ops = {
 	.notify_new_call	= afs_rx_new_call,
 	.discard_new_call	= afs_rx_discard_new_call,
 	.user_attach_call	= afs_rx_attach,
-	.notify_oob		= afs_rx_notify_oob,
 };
 
 /* asynchronous incoming call initial processing */
@@ -74,10 +72,6 @@ int afs_open_socket(struct afs_net *net)
 	if (ret < 0)
 		goto error_2;
 
-	ret = rxrpc_sock_set_manage_response(socket->sk, true);
-	if (ret < 0)
-		goto error_2;
-
 	ret = afs_create_token_key(net, socket);
 	if (ret < 0)
 		pr_err("Couldn't create RxGK CM key: %d\n", ret);
@@ -129,7 +123,6 @@ void afs_close_socket(struct afs_net *net)
 	_enter("");
 
 	cancel_work_sync(&net->charge_preallocation_work);
-	cancel_work_sync(&net->rx_oob_work);
 	/* Future work items should now see ->live is false. */
 
 	kernel_listen(net->socket, 0);
@@ -150,7 +143,6 @@ void afs_close_socket(struct afs_net *net)
 
 	kernel_sock_shutdown(net->socket, SHUT_RDWR);
 	flush_workqueue(afs_async_calls);
-	cancel_work_sync(&net->rx_oob_work);
 	net->socket->sk->sk_user_data = NULL;
 	sock_release(net->socket);
 	key_put(net->fs_cm_token_key);
@@ -1013,14 +1005,3 @@ noinline int afs_protocol_error(struct afs_call *call,
 		call->unmarshalling_error = true;
 	return -EBADMSG;
 }
-
-/*
- * Wake up OOB notification processing.
- */
-static void afs_rx_notify_oob(struct sock *sk, struct sk_buff *oob)
-{
-	struct afs_net *net = sk->sk_user_data;
-
-	if (READ_ONCE(net->live))
-		queue_work(afs_wq, &net->rx_oob_work);
-}
fs/afs/server.c +0 -1
index b08d9080b0c5..4c3a7bd0f7d8 100644
@@ -398,7 +398,6 @@ static void afs_server_rcu(struct rcu_head *rcu)
 	afs_put_endpoint_state(rcu_access_pointer(server->endpoint_state),
 			       afs_estate_trace_put_server);
 	afs_put_cell(server->cell, afs_cell_trace_put_server);
-	kfree(server->cm_rxgk_appdata.data);
 	key_put(server->yfs_rxgk_appdata);
 	kfree(server);
 }
include/net/af_rxrpc.h +0 -23
index 19c61a2f5af3..809ef95b92a1 100644
@@ -25,10 +25,6 @@ enum rxrpc_interruptibility {
 	RXRPC_UNINTERRUPTIBLE,	/* Call should not be interruptible at all */
 };
 
-enum rxrpc_oob_type {
-	RXRPC_OOB_CHALLENGE,	/* Security challenge for a connection */
-};
-
 /*
  * Debug ID counter for tracing.
  */
@@ -42,7 +38,6 @@ struct rxrpc_kernel_ops {
 				unsigned long user_call_ID);
 	void (*discard_new_call)(struct rxrpc_call *call, unsigned long user_call_ID);
 	void (*user_attach_call)(struct rxrpc_call *call, unsigned long user_call_ID);
-	void (*notify_oob)(struct sock *sk, struct sk_buff *oob);
 };
 
 typedef void (*rxrpc_notify_rx_t)(struct sock *, struct rxrpc_call *,
@@ -92,24 +87,6 @@ bool rxrpc_kernel_check_life(const struct socket *, const struct rxrpc_call *);
 
 int rxrpc_sock_set_min_security_level(struct sock *sk, unsigned int val);
 int rxrpc_sock_set_security_keyring(struct sock *, struct key *);
-int rxrpc_sock_set_manage_response(struct sock *sk, bool set);
-
-enum rxrpc_oob_type rxrpc_kernel_query_oob(struct sk_buff *oob,
-					   struct rxrpc_peer **_peer,
-					   unsigned long *_peer_appdata);
-struct sk_buff *rxrpc_kernel_dequeue_oob(struct socket *sock,
-					 enum rxrpc_oob_type *_type);
-void rxrpc_kernel_free_oob(struct sk_buff *oob);
-void rxrpc_kernel_query_challenge(struct sk_buff *challenge,
-				  struct rxrpc_peer **_peer,
-				  unsigned long *_peer_appdata,
-				  u16 *_service_id, u8 *_security_index);
-int rxrpc_kernel_reject_challenge(struct sk_buff *challenge, u32 abort_code,
-				  int error, enum rxrpc_abort_reason why);
-int rxkad_kernel_respond_to_challenge(struct sk_buff *challenge);
-u32 rxgk_kernel_query_challenge(struct sk_buff *challenge);
-int rxgk_kernel_respond_to_challenge(struct sk_buff *challenge,
-				     struct krb5_buffer *appdata);
 void rxrpc_kernel_query_key(const struct key *key, u8 *_security_index,
 			    u32 *_krb5_enctype);
 u8 rxrpc_kernel_query_call_security(struct rxrpc_call *call,
include/trace/events/rxrpc.h +1 -10
index 48e774034195..f8788f2be17b 100644
@@ -113,7 +113,6 @@
 	EM(rxrpc_abort_call_timeout,		"call-timeout")		\
 	EM(rxrpc_abort_no_service_key,		"no-serv-key")		\
 	EM(rxrpc_abort_nomem,			"nomem")		\
-	EM(rxrpc_abort_response_sendmsg,	"resp-sendmsg")		\
 	EM(rxrpc_abort_service_not_offered,	"serv-not-offered")	\
 	EM(rxrpc_abort_shut_down,		"shut-down")		\
 	EM(rxrpc_abort_unsupported_security,	"unsup-sec")		\
@@ -169,7 +168,6 @@
 	EM(rxrpc_skb_get_conn_secured,		"GET conn-secd") \
 	EM(rxrpc_skb_get_conn_work,		"GET conn-work") \
 	EM(rxrpc_skb_get_local_work,		"GET locl-work") \
-	EM(rxrpc_skb_get_post_oob,		"GET post-oob ") \
 	EM(rxrpc_skb_get_reject_work,		"GET rej-work ") \
 	EM(rxrpc_skb_get_to_recvmsg,		"GET to-recv  ") \
 	EM(rxrpc_skb_get_to_recvmsg_oos,	"GET to-recv-o") \
@@ -186,18 +184,15 @@
 	EM(rxrpc_skb_put_error_report,		"PUT error-rep") \
 	EM(rxrpc_skb_put_input,			"PUT input    ") \
 	EM(rxrpc_skb_put_jumbo_subpacket,	"PUT jumbo-sub") \
-	EM(rxrpc_skb_put_oob,			"PUT oob      ") \
 	EM(rxrpc_skb_put_old_response,		"PUT old-resp ") \
 	EM(rxrpc_skb_put_purge,			"PUT purge    ") \
-	EM(rxrpc_skb_put_purge_oob,		"PUT purge-oob") \
 	EM(rxrpc_skb_put_response,		"PUT response ") \
 	EM(rxrpc_skb_put_response_copy,		"PUT resp-cpy ") \
 	EM(rxrpc_skb_put_rotate,		"PUT rotate   ") \
 	EM(rxrpc_skb_put_unknown,		"PUT unknown  ") \
 	EM(rxrpc_skb_see_conn_work,		"SEE conn-work") \
-	EM(rxrpc_skb_see_oob_challenge,		"SEE oob-chall") \
+	EM(rxrpc_skb_see_challenge,		"SEE challenge") \
 	EM(rxrpc_skb_see_recvmsg,		"SEE recvmsg  ") \
-	EM(rxrpc_skb_see_recvmsg_oob,		"SEE recvm-oob") \
 	EM(rxrpc_skb_see_reject,		"SEE reject   ") \
 	EM(rxrpc_skb_see_rotate,		"SEE rotate   ") \
 	EM(rxrpc_skb_see_unshare_nomem,		"SEE unshar-nm") \
@@ -264,7 +259,6 @@
 	EM(rxrpc_conn_free,			"FREE        ") \
 	EM(rxrpc_conn_get_activate_call,	"GET act-call") \
 	EM(rxrpc_conn_get_call_input,		"GET inp-call") \
-	EM(rxrpc_conn_get_challenge_input,	"GET inp-chal") \
 	EM(rxrpc_conn_get_conn_input,		"GET inp-conn") \
 	EM(rxrpc_conn_get_idle,			"GET idle    ") \
 	EM(rxrpc_conn_get_poke_abort,		"GET pk-abort") \
@@ -276,12 +270,10 @@
 	EM(rxrpc_conn_new_service,		"NEW service ") \
 	EM(rxrpc_conn_put_call,			"PUT call    ") \
 	EM(rxrpc_conn_put_call_input,		"PUT inp-call") \
-	EM(rxrpc_conn_put_challenge_input,	"PUT inp-chal") \
 	EM(rxrpc_conn_put_conn_input,		"PUT inp-conn") \
 	EM(rxrpc_conn_put_discard_idle,		"PUT disc-idl") \
 	EM(rxrpc_conn_put_local_dead,		"PUT loc-dead") \
 	EM(rxrpc_conn_put_noreuse,		"PUT noreuse ") \
-	EM(rxrpc_conn_put_oob,			"PUT oob     ") \
 	EM(rxrpc_conn_put_poke,			"PUT poke    ") \
 	EM(rxrpc_conn_put_service_reaped,	"PUT svc-reap") \
 	EM(rxrpc_conn_put_unbundle,		"PUT unbundle") \
@@ -391,7 +383,6 @@
 	EM(rxrpc_recvmsg_full,			"FULL") \
 	EM(rxrpc_recvmsg_hole,			"HOLE") \
 	EM(rxrpc_recvmsg_next,			"NEXT") \
-	EM(rxrpc_recvmsg_oobq,			"OOBQ") \
 	EM(rxrpc_recvmsg_requeue,		"REQU") \
 	EM(rxrpc_recvmsg_return,		"RETN") \
 	EM(rxrpc_recvmsg_terminal,		"TERM") \
include/uapi/linux/rxrpc.h +2 -21
index bcdfdf9c67a1..729b7a0c77e5 100644
@@ -36,7 +36,7 @@ struct sockaddr_rxrpc {
 #define RXRPC_MIN_SECURITY_LEVEL	4	/* minimum security level */
 #define RXRPC_UPGRADEABLE_SERVICE	5	/* Upgrade service[0] -> service[1] */
 #define RXRPC_SUPPORTED_CMSG		6	/* Get highest supported control message type */
-#define RXRPC_MANAGE_RESPONSE		7	/* [clnt] Want to manage RESPONSE packets */
+/* RXRPC_MANAGE_RESPONSE was at 7 */
 
 /*
  * RxRPC control messages
@@ -58,11 +58,7 @@ enum rxrpc_cmsg_type {
 	RXRPC_TX_LENGTH		= 12,	/* -s-: Total length of Tx data */
 	RXRPC_SET_CALL_TIMEOUT	= 13,	/* -s-: Set one or more call timeouts */
 	RXRPC_CHARGE_ACCEPT	= 14,	/* Ss-: Charge the accept pool with a user call ID */
-	RXRPC_OOB_ID		= 15,	/* -sr: OOB message ID */
-	RXRPC_CHALLENGED	= 16,	/* C-r: Info on a received CHALLENGE */
-	RXRPC_RESPOND		= 17,	/* Cs-: Respond to a challenge */
-	RXRPC_RESPONDED		= 18,	/* S-r: Data received in RESPONSE */
-	RXRPC_RESP_RXGK_APPDATA	= 19,	/* Cs-: RESPONSE: RxGK app data to include */
+	/* OOB Challenge/Response was here. */
 	RXRPC_RESPONSE_APPDATA	= 20,	/* Cs-: User key holding app data for RESPONSE */
 	RXRPC__SUPPORTED
 };
@@ -157,19 +153,4 @@ enum rxrpc_cmsg_type {
 #define RXGK_GSSERROR		1233242890	/* GSSAPI mechanism error */
 #endif
 
-/*
- * Challenge information in the RXRPC_CHALLENGED control message.
- */
-struct rxrpc_challenge {
-	__u16		service_id;	/* The service ID of the connection (may be upgraded) */
-	__u8		security_index;	/* The security index of the connection */
-	__u8		pad;		/* Round out to a multiple of 4 bytes. */
-	/* ... The security class gets to append extra information ... */
-};
-
-struct rxgk_challenge {
-	struct rxrpc_challenge	base;
-	__u32			enctype;	/* Krb5 encoding type */
-};
-
 #endif /* _UAPI_LINUX_RXRPC_H */
net/rxrpc/Makefile +0 -1
index f994f9f30a29..f7a5e0a592ee 100644
@@ -24,7 +24,6 @@ rxrpc-y := \
 	local_object.o \
 	misc.o \
 	net_ns.o \
-	oob.o \
 	output.o \
 	peer_event.o \
 	peer_object.o \
net/rxrpc/af_rxrpc.c +1 -42

79 lines not on this page · raw message

net/rxrpc/ar-internal.h +0 -23
index 222b239884ca..3e14074279e5 100644
@@ -171,9 +171,6 @@ struct rxrpc_sock {
 	const struct rxrpc_kernel_ops *app_ops;	/* Table of kernel app notification funcs */
 	struct rxrpc_local	*local;		/* local endpoint */
 	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
-	struct sk_buff_head	recvmsg_oobq;	/* OOB messages for recvmsg to pick up */
-	struct rb_root		pending_oobq;	/* OOB messages awaiting userspace to respond to */
-	u64			oob_id_counter;	/* OOB message ID counter */
 	spinlock_t		incoming_lock;	/* Incoming call vs service shutdown lock */
 	struct list_head	sock_calls;	/* List of calls owned by this socket */
 	struct list_head	to_be_accepted;	/* calls awaiting acceptance */
@@ -184,7 +181,6 @@ struct rxrpc_sock {
 	struct rb_root		calls;		/* User ID -> call mapping */
 	unsigned long		flags;
 #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
-#define RXRPC_SOCK_MANAGE_RESPONSE	1	/* User wants to manage RESPONSE packets */
 	rwlock_t		call_lock;	/* lock for calls */
 	u32			min_sec_level;	/* minimum security level */
 #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
@@ -241,7 +237,6 @@ struct rxrpc_skb_priv {
 			u8		reason;		/* Reason for ack */
 		} ack;
 		struct {
-			struct rxrpc_connection *conn;	/* Connection referred to */
 			union {
 				u32 rxkad_nonce;
 			};
@@ -310,17 +305,6 @@ struct rxrpc_security {
 	bool (*validate_challenge)(struct rxrpc_connection *conn,
 				   struct sk_buff *skb);
 
-	/* Fill out the cmsg for recvmsg() to pass on a challenge to userspace.
-	 * The security class gets to add additional information.
-	 */
-	int (*challenge_to_recvmsg)(struct rxrpc_connection *conn,
-				    struct sk_buff *challenge,
-				    struct msghdr *msg);
-
-	/* Parse sendmsg() control message and respond to challenge. */
-	int (*sendmsg_respond_to_challenge)(struct sk_buff *challenge,
-					    struct msghdr *msg);
-
 	/* respond to a challenge */
 	int (*respond_to_challenge)(struct rxrpc_connection *conn,
 				    struct sk_buff *challenge);
@@ -1382,13 +1366,6 @@ static inline struct rxrpc_net *rxrpc_net(struct net *net)
 	return net_generic(net, rxrpc_net_id);
 }
 
-/*
- * oob.c
- */
-bool rxrpc_notify_socket_oob(struct rxrpc_call *call, struct sk_buff *skb);
-void rxrpc_add_pending_oob(struct rxrpc_sock *rx, struct sk_buff *skb);
-int rxrpc_sendmsg_oob(struct rxrpc_sock *rx, struct msghdr *msg, size_t len);
-
 /*
  * output.c
  */
net/rxrpc/conn_event.c +1 -1
index 9146b9d4c2ac..267f2d0f883d 100644
@@ -442,7 +442,7 @@ bool rxrpc_input_conn_packet(struct rxrpc_connection *conn, struct sk_buff *skb)
 		return true;
 
 	case RXRPC_PACKET_TYPE_CHALLENGE:
-		rxrpc_see_skb(skb, rxrpc_skb_see_oob_challenge);
+		rxrpc_see_skb(skb, rxrpc_skb_see_challenge);
 		if (rxrpc_is_conn_aborted(conn)) {
 			if (conn->completion == RXRPC_CALL_LOCALLY_ABORTED)
 				rxrpc_send_conn_abort(conn);
net/rxrpc/insecure.c +0 -7
index 0b39046bdc61..c083c82c4e7f 100644
@@ -47,12 +47,6 @@ static bool none_validate_challenge(struct rxrpc_connection *conn,
 	return true;
 }
 
-static int none_sendmsg_respond_to_challenge(struct sk_buff *challenge,
-					     struct msghdr *msg)
-{
-	return -EINVAL;
-}
-
 static int none_verify_response(struct rxrpc_connection *conn,
 				struct sk_buff *response_skb,
 				void *response, unsigned int len)
@@ -88,7 +82,6 @@ const struct rxrpc_security rxrpc_no_security = {
 	.secure_packet			= none_secure_packet,
 	.verify_packet			= none_verify_packet,
 	.validate_challenge		= none_validate_challenge,
-	.sendmsg_respond_to_challenge	= none_sendmsg_respond_to_challenge,
 	.verify_response		= none_verify_response,
 	.clear				= none_clear,
 };
net/rxrpc/oob.c deleted +0 -387

387 lines not on this page · raw message

net/rxrpc/recvmsg.c +3 -79

129 lines not on this page · raw message

net/rxrpc/rxgk.c +0 -73

91 lines not on this page · raw message

net/rxrpc/rxkad.c +0 -27
index ca9f0e82cb9a..e55bfca10e1a 100644
@@ -748,32 +748,6 @@ static int rxkad_respond_to_challenge(struct rxrpc_connection *conn,
 	return ret;
 }
 
-/*
- * RxKAD does automatic response only as there's nothing to manage that isn't
- * already in the key.
- */
-static int rxkad_sendmsg_respond_to_challenge(struct sk_buff *challenge,
-					      struct msghdr *msg)
-{
-	return -EINVAL;
-}
-
-/**
- * rxkad_kernel_respond_to_challenge - Respond to a challenge with appdata
- * @challenge: The challenge to respond to
- *
- * Allow a kernel application to respond to a CHALLENGE.
- *
- * Return: %0 if successful and a negative error code otherwise.
- */
-int rxkad_kernel_respond_to_challenge(struct sk_buff *challenge)
-{
-	struct rxrpc_skb_priv *csp = rxrpc_skb(challenge);
-
-	return rxkad_respond_to_challenge(csp->chall.conn, challenge);
-}
-EXPORT_SYMBOL(rxkad_kernel_respond_to_challenge);
-
 /* Decrypt data in-place using DES-PCBC.  @len must be a multiple of 8. */
 VISIBLE_IF_KUNIT void des_pcbc_decrypt_inplace(const struct des_ctx *key,
 					       __le64 iv, u8 *data, size_t len)
@@ -1134,7 +1108,6 @@ const struct rxrpc_security rxkad = {
 	.free_call_crypto		= rxkad_free_call_crypto,
 	.issue_challenge		= rxkad_issue_challenge,
 	.validate_challenge		= rxkad_validate_challenge,
-	.sendmsg_respond_to_challenge	= rxkad_sendmsg_respond_to_challenge,
 	.respond_to_challenge		= rxkad_respond_to_challenge,
 	.verify_response		= rxkad_verify_response,
 	.clear				= rxkad_clear,
net/rxrpc/server_key.c +0 -40
index 3efe104b1930..fc6f478e1762 100644
@@ -173,43 +173,3 @@ int rxrpc_sock_set_security_keyring(struct sock *sk, struct key *keyring)
 	return ret;
 }
 EXPORT_SYMBOL(rxrpc_sock_set_security_keyring);
-
-/**
- * rxrpc_sock_set_manage_response - Set the manage-response flag for a kernel service
- * @sk: The socket to set the keyring on
- * @set: True to set, false to clear the flag
- *
- * Set the flag on an rxrpc socket to say that the caller wants to manage the
- * RESPONSE packet and the user-defined data it may contain.  Setting this
- * means that recvmsg() will return messages with RXRPC_CHALLENGED in the
- * control message buffer containing information about the challenge.
- *
- * The user should respond to the challenge by passing RXRPC_RESPOND or
- * RXRPC_RESPOND_ABORT control messages with sendmsg() to the same call.
- * Supplementary control messages, such as RXRPC_RESP_RXGK_APPDATA, may be
- * included to indicate the parts the user wants to supply.
- *
- * The server will be passed the response data with a RXRPC_RESPONDED control
- * message when it gets the first data from each call.
- *
- * Note that this is only honoured by security classes that need auxiliary data
- * (e.g. RxGK).  Those that don't offer the facility (e.g. RxKAD) respond
- * without consulting userspace.
- *
- * Return: The previous setting.
- */
-int rxrpc_sock_set_manage_response(struct sock *sk, bool set)
-{
-	struct rxrpc_sock *rx = rxrpc_sk(sk);
-	int ret;
-
-	lock_sock(sk);
-	ret = !!test_bit(RXRPC_SOCK_MANAGE_RESPONSE, &rx->flags);
-	if (set)
-		set_bit(RXRPC_SOCK_MANAGE_RESPONSE, &rx->flags);
-	else
-		clear_bit(RXRPC_SOCK_MANAGE_RESPONSE, &rx->flags);
-	release_sock(sk);
-	return ret;
-}
-EXPORT_SYMBOL(rxrpc_sock_set_manage_response);
maintainer
#13 lore raw
In reply to David Howells
Quoted 58 lines · David Howells

Here's a fix for AF_RXRPC's CHALLENGE packet handling, addressing an issue raised by Sashiko[1], plus some miscellaneous fixes found in the process of fixing this, plus a number of things raised by Sashiko[2-8].

Firstly, the miscellaneous patches:

(1) Fix rxrpc_sendmsg so that it doesn't return an error if it queued the last packet of a call. After that point, the error will be returned by recvmsg() and returned it twice in two different places may complicate userspace cleaning up its own structures.

(2) Fix the use of len vs msg->msg_iter.count in rxrpc_send_data().

(3) Fix error handling in rxrpc_send_data() for if ->secure_packet() returns an error.

(4) Fix the update of call->pending in rxrpc_send_data() in paths when the call lock has been dropped.

(5) Fix double IRQ enablement in __rxrpc_notify_socket() when called indirectly from rxrpc_end_rx_phase().

(6) Fix the generation of notifications from rxrpc after call completion.

And then there are the patches to fix CHALLENGE packet overqueuing and simplify RESPONSE packet generation by pre-creating the RxGK application data up front and passing it in a user key (thereby allowing userspace to partake). This is split into five patches:

(7) Expand the abort trace enum to be larger than a signed char as the number of elements will exceed 128.

(8) Add a refcount to the user key payload.

(9) Make the AFS filesystem generate per-server appdata keys.

(10) Pass the appdata from AFS (or userspace) to rxrpc.

(11) Change over to using the appdata key to supply the appdata.

(12) Remove all the OOB stuff.

[!] Note that this entails a significant change in the UAPI for AF_RXRPC, with the CMSG types and sockopt to support the OOB queuing being removed and replaced with a new single CMSG type that conveys the user key ID. I don't think it likely anyone is using this outside of my kafs-utils package.

This also involves a change to the user-defined key type, making the payload refcounted so that it can be accessed and the length read, then a buffer allocated that will hold it and other data, and then the content copied. The problem is that the user is perfectly at liberty to change the content of a user-defined key (which will RCU-replace the content of the key), so the length might change when we drop the RCU read lock in order to allocate. This could be got around by locking the key->rwsem sharedly, but that might be able to deadlock part of the rxrpc protocol engine if memory reclaim occurs.

Quoted 5 lines

David

The patches can be found here also:

http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=rxrpc-fixes

It looks like some of the comment raised by sashiko are new, especially on patch 9/12:

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260812110129.979970-1-dhowells%40redhat.com

Do you think later follow-ups (i.e. in another series) would be ok?

/P

author maintainer
#15 lore raw
In reply to Paolo Abeni

Did you mean:

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260824091645.415423-1-dhowells%40redhat.com

I've had a look through and I don't think there's anything that merits a respin. There's quite a bit of pre-existing stuff that will need looking at, both in rxrpc and afs, but I don't think I need to do it in this series. Also, the docs need updating, which again doesn't need to be done here.

David

author maintainer
#16 lore raw
In reply to Paolo Abeni

Actually, sashiko has a point. It's theoretically possible for userspace to fabricate a ticket with an encoding type that's supported by the client but not by the fileserver, in which case, yes the fileserver would be unable to use the proposed return channel if someone else tried to contact it with a valid ticket.

Note that this is an afs layer problem, not an rxrpc layer problem. Each rxrpc call is tagged with the keys to use and are grouped into virtual connections by those keys.

To solve the issue, it might be sufficient to ditch the appdata key from the server record if the fileserver returns RXGK_BADETYPE and the caller's key matches the enctype of the server's appdata - but that leaves a potental race in which two callers try to talk to the fileserver simultaneously.

Probably the afs server rotation code needs to be changed so that, when a new afs_server record is created, the caller creating it holds off other callers until at least one probe is completed successfully - and if not, it removes the key and moves on to the next fileserver.

David