Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7eca9cc5 authored by David S. Miller's avatar David S. Miller
Browse files

Merge tag 'rxrpc-rewrite-20170607-v2' of...

Merge tag 'rxrpc-rewrite-20170607-v2' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs



David Howells says:

====================
rxrpc: Tx length parameter

Here's a set of patches that allows someone initiating a client call with
AF_RXRPC to indicate upfront the total amount of data that will be
transmitted.  This will allow AF_RXRPC to encrypt directly from source
buffer to packet rather than having to copy into the buffer and only
encrypt when it's full (the encrypted portion of the packet starts with a
length and so we can't encrypt until we know what the length will be).

The three patches are:

 (1) Provide a means of finding out what control message types are actually
     supported.  EINVAL is reported if an unsupported cmsg type is seen, so
     we don't want to set the new cmsg unless we know it will be accepted.

 (2) Consolidate some stuff into a struct to reduce the parameter count on
     the function that parses the cmsg buffer.

 (3) Introduce the RXRPC_TX_LENGTH cmsg.  This can be provided on the first
     sendmsg() that contributes data to a client call request or a service
     call reply.  If provided, the user must provide exactly that amount of
     data or an error will be incurred.

Changes in version 2:

 (*) struct rxrpc_send_params::tx_total_len should be s64 not u64.  Thanks to
     Julia Lawall for reporting this.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 546692e1 e754eba6
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -327,6 +327,7 @@ calls, to invoke certain actions and to report certain conditions. These are:
	RXRPC_ACCEPT		s-- n/a		Accept new call
	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

	(SRT = usable in Sendmsg / delivered by Recvmsg / Terminal message)

@@ -406,6 +407,23 @@ calls, to invoke certain actions and to report certain conditions. These are:
     future communication to that server and RXRPC_UPGRADE_SERVICE should no
     longer be set.

 (*) RXRPC_TX_LENGTH

     This is used to inform the kernel of the total amount of data that is
     going to be transmitted by a call (whether in a client request or a
     service response).  If given, it allows the kernel to encrypt from the
     userspace buffer directly to the packet buffers, rather than copying into
     the buffer and then encrypting in place.  This may only be given with the
     first sendmsg() providing data for a call.  EMSGSIZE will be generated if
     the amount of data actually given is different.

     This takes a parameter of __s64 type that indicates how much will be
     transmitted.  This may not be less than zero.

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).


==============
SOCKET OPTIONS
@@ -459,6 +477,11 @@ AF_RXRPC sockets support a few socket options at the SOL_RXRPC level:
     must point to an array of two unsigned short ints.  The first is the
     service ID to upgrade from and the second the service ID to upgrade to.

 (*) RXRPC_SUPPORTED_CMSG

     This is a read-only option that writes an int into the buffer indicating
     the highest control message type supported.


========
SECURITY
@@ -568,6 +591,9 @@ A client would issue an operation by:
     MSG_MORE should be set in msghdr::msg_flags on all but the last part of
     the request.  Multiple requests may be made simultaneously.

     An RXRPC_TX_LENGTH control message can also be specified on the first
     sendmsg() call.

     If a call is intended to go to a destination other than the default
     specified through connect(), then msghdr::msg_name should be set on the
     first request message of that call.
@@ -755,6 +781,7 @@ The kernel interface functions are as follows:
				struct sockaddr_rxrpc *srx,
				struct key *key,
				unsigned long user_call_ID,
				s64 tx_total_len,
				gfp_t gfp);

     This allocates the infrastructure to make a new RxRPC call and assigns
@@ -771,6 +798,11 @@ The kernel interface functions are as follows:
     control data buffer.  It is entirely feasible to use this to point to a
     kernel data structure.

     tx_total_len is the amount of data the caller is intending to transmit
     with this call (or -1 if unknown at this point).  Setting the data size
     allows the kernel to encrypt directly to the packet buffers, thereby
     saving a copy.  The value may not be less than -1.

     If this function is successful, an opaque reference to the RxRPC call is
     returned.  The caller now holds a reference on this and it must be
     properly ended.
@@ -922,6 +954,17 @@ The kernel interface functions are as follows:

     This is used to find the remote peer address of a call.

 (*) Set the total transmit data size on a call.

	void rxrpc_kernel_set_tx_length(struct socket *sock,
					struct rxrpc_call *call,
					s64 tx_total_len);

     This sets the amount of data that the caller is intending to transmit on a
     call.  It's intended to be used for setting the reply size as the request
     size should be set when the call is begun.  tx_total_len may not be less
     than zero.


=======================
CONFIGURABLE PARAMETERS
+17 −1
Original line number Diff line number Diff line
@@ -341,6 +341,7 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp,
	struct msghdr msg;
	struct kvec iov[1];
	size_t offset;
	s64 tx_total_len;
	u32 abort_code;
	int ret;

@@ -364,9 +365,20 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp,
	srx.transport.sin.sin_port = call->port;
	memcpy(&srx.transport.sin.sin_addr, addr, 4);

	/* Work out the length we're going to transmit.  This is awkward for
	 * calls such as FS.StoreData where there's an extra injection of data
	 * after the initial fixed part.
	 */
	tx_total_len = call->request_size;
	if (call->send_pages) {
		tx_total_len += call->last_to - call->first_offset;
		tx_total_len += (call->last - call->first) * PAGE_SIZE;
	}

	/* create a call */
	rxcall = rxrpc_kernel_begin_call(afs_socket, &srx, call->key,
					 (unsigned long) call, gfp,
					 (unsigned long)call,
					 tx_total_len, gfp,
					 (async ?
					  afs_wake_up_async_call :
					  afs_wake_up_call_waiter));
@@ -738,6 +750,8 @@ void afs_send_empty_reply(struct afs_call *call)

	_enter("");

	rxrpc_kernel_set_tx_length(afs_socket, call->rxcall, 0);

	msg.msg_name		= NULL;
	msg.msg_namelen		= 0;
	iov_iter_kvec(&msg.msg_iter, WRITE | ITER_KVEC, NULL, 0, 0);
@@ -772,6 +786,8 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len)

	_enter("");

	rxrpc_kernel_set_tx_length(afs_socket, call->rxcall, len);

	iov[0].iov_base		= (void *) buf;
	iov[0].iov_len		= len;
	msg.msg_name		= NULL;
+15 −10
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ struct sockaddr_rxrpc {
#define RXRPC_EXCLUSIVE_CONNECTION	3	/* Deprecated; use RXRPC_EXCLUSIVE_CALL instead */
#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 */

/*
 * RxRPC control messages
@@ -45,16 +46,20 @@ struct sockaddr_rxrpc {
 * - terminal messages mean that a user call ID tag can be recycled
 * - s/r/- indicate whether these are applicable to sendmsg() and/or recvmsg()
 */
#define RXRPC_USER_CALL_ID	1	/* sr: user call ID specifier */
#define RXRPC_ABORT		2	/* sr: abort request / notification [terminal] */
#define RXRPC_ACK		3	/* -r: [Service] RPC op final ACK received [terminal] */
#define RXRPC_NET_ERROR		5	/* -r: network error received [terminal] */
#define RXRPC_BUSY		6	/* -r: server busy received [terminal] */
#define RXRPC_LOCAL_ERROR	7	/* -r: local error generated [terminal] */
#define RXRPC_NEW_CALL		8	/* -r: [Service] new incoming call notification */
#define RXRPC_ACCEPT		9	/* s-: [Service] accept request */
#define RXRPC_EXCLUSIVE_CALL	10	/* s-: Call should be on exclusive connection */
#define RXRPC_UPGRADE_SERVICE	11	/* s-: Request service upgrade for client call */
enum rxrpc_cmsg_type {
	RXRPC_USER_CALL_ID	= 1,	/* sr: user call ID specifier */
	RXRPC_ABORT		= 2,	/* sr: abort request / notification [terminal] */
	RXRPC_ACK		= 3,	/* -r: [Service] RPC op final ACK received [terminal] */
	RXRPC_NET_ERROR		= 5,	/* -r: network error received [terminal] */
	RXRPC_BUSY		= 6,	/* -r: server busy received [terminal] */
	RXRPC_LOCAL_ERROR	= 7,	/* -r: local error generated [terminal] */
	RXRPC_NEW_CALL		= 8,	/* -r: [Service] new incoming call notification */
	RXRPC_ACCEPT		= 9,	/* s-: [Service] accept request */
	RXRPC_EXCLUSIVE_CALL	= 10,	/* s-: Call should be on exclusive connection */
	RXRPC_UPGRADE_SERVICE	= 11,	/* s-: Request service upgrade for client call */
	RXRPC_TX_LENGTH		= 12,	/* s-: Total length of Tx data */
	RXRPC__SUPPORTED
};

/*
 * RxRPC security levels
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *,
					   struct sockaddr_rxrpc *,
					   struct key *,
					   unsigned long,
					   s64,
					   gfp_t,
					   rxrpc_notify_rx_t);
int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *,
@@ -46,5 +47,6 @@ void rxrpc_kernel_get_peer(struct socket *, struct rxrpc_call *,
			   struct sockaddr_rxrpc *);
int rxrpc_kernel_charge_accept(struct socket *, rxrpc_notify_rx_t,
			       rxrpc_user_attach_call_t, unsigned long, gfp_t);
void rxrpc_kernel_set_tx_length(struct socket *, struct rxrpc_call *, s64);

#endif /* _NET_RXRPC_H */
+33 −2
Original line number Diff line number Diff line
@@ -262,6 +262,7 @@ static int rxrpc_listen(struct socket *sock, int backlog)
 * @srx: The address of the peer to contact
 * @key: The security context to use (defaults to socket setting)
 * @user_call_ID: The ID to use
 * @tx_total_len: Total length of data to transmit during the call (or -1)
 * @gfp: The allocation constraints
 * @notify_rx: Where to send notifications instead of socket queue
 *
@@ -276,6 +277,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
					   struct sockaddr_rxrpc *srx,
					   struct key *key,
					   unsigned long user_call_ID,
					   s64 tx_total_len,
					   gfp_t gfp,
					   rxrpc_notify_rx_t notify_rx)
{
@@ -303,7 +305,8 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
	cp.security_level	= 0;
	cp.exclusive		= false;
	cp.service_id		= srx->srx_service;
	call = rxrpc_new_client_call(rx, &cp, srx, user_call_ID, gfp);
	call = rxrpc_new_client_call(rx, &cp, srx, user_call_ID, tx_total_len,
				     gfp);
	/* The socket has been unlocked. */
	if (!IS_ERR(call))
		call->notify_rx = notify_rx;
@@ -581,6 +584,34 @@ static int rxrpc_setsockopt(struct socket *sock, int level, int optname,
	return ret;
}

/*
 * Get socket options.
 */
static int rxrpc_getsockopt(struct socket *sock, int level, int optname,
			    char __user *optval, int __user *_optlen)
{
	int optlen;
	
	if (level != SOL_RXRPC)
		return -EOPNOTSUPP;

	if (get_user(optlen, _optlen))
		return -EFAULT;
	
	switch (optname) {
	case RXRPC_SUPPORTED_CMSG:
		if (optlen < sizeof(int))
			return -ETOOSMALL;
		if (put_user(RXRPC__SUPPORTED - 1, (int __user *)optval) ||
		    put_user(sizeof(int), _optlen))
			return -EFAULT;
		return 0;
		
	default:
		return -EOPNOTSUPP;
	}
}

/*
 * permit an RxRPC socket to be polled
 */
@@ -784,7 +815,7 @@ static const struct proto_ops rxrpc_rpc_ops = {
	.listen		= rxrpc_listen,
	.shutdown	= rxrpc_shutdown,
	.setsockopt	= rxrpc_setsockopt,
	.getsockopt	= sock_no_getsockopt,
	.getsockopt	= rxrpc_getsockopt,
	.sendmsg	= rxrpc_sendmsg,
	.recvmsg	= rxrpc_recvmsg,
	.mmap		= sock_no_mmap,
Loading