Skip to content

Commit 833da12

Browse files
andraprsgregkh
authored andcommitted
af_vsock: Assign the vsock transport considering the vsock address flags
[ Upstream commit 7f816984f439dfe24da25032254cb10512900346 ] The vsock flags field can be set in the connect path (user space app) and the (listen) receive path (kernel space logic). When the vsock transport is assigned, the remote CID is used to distinguish between types of connection. Use the vsock flags value (in addition to the CID) from the remote address to decide which vsock transport to assign. For the sibling VMs use case, all the vsock packets need to be forwarded to the host, so always assign the guest->host transport if the VMADDR_FLAG_TO_HOST flag is set. For the other use cases, the vsock transport assignment logic is not changed. Changelog v3 -> v4 * Update the "remote_flags" local variable type to reflect the change of the "svm_flags" field to be 1 byte in size. v2 -> v3 * Update bitwise check logic to not compare result to the flag value. v1 -> v2 * Use bitwise operator to check the vsock flag. * Use the updated "VMADDR_FLAG_TO_HOST" flag naming. * Merge the checks for the g2h transport assignment in one "if" block. Signed-off-by: Andra Paraschiv <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Stable-dep-of: 687aa0c5581b ("vsock: Fix transport_* TOCTOU") Signed-off-by: Sasha Levin <[email protected]>
1 parent 0e7a8ad commit 833da12

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

net/vmw_vsock/af_vsock.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,16 @@ static void vsock_deassign_transport(struct vsock_sock *vsk)
431431
* The vsk->remote_addr is used to decide which transport to use:
432432
* - remote CID == VMADDR_CID_LOCAL or g2h->local_cid or VMADDR_CID_HOST if
433433
* g2h is not loaded, will use local transport;
434-
* - remote CID <= VMADDR_CID_HOST will use guest->host transport;
434+
* - remote CID <= VMADDR_CID_HOST or h2g is not loaded or remote flags field
435+
* includes VMADDR_FLAG_TO_HOST flag value, will use guest->host transport;
435436
* - remote CID > VMADDR_CID_HOST will use host->guest transport;
436437
*/
437438
int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
438439
{
439440
const struct vsock_transport *new_transport;
440441
struct sock *sk = sk_vsock(vsk);
441442
unsigned int remote_cid = vsk->remote_addr.svm_cid;
443+
__u8 remote_flags;
442444
int ret;
443445

444446
/* If the packet is coming with the source and destination CIDs higher
@@ -453,14 +455,17 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
453455
vsk->remote_addr.svm_cid > VMADDR_CID_HOST)
454456
vsk->remote_addr.svm_flags |= VMADDR_FLAG_TO_HOST;
455457

458+
remote_flags = vsk->remote_addr.svm_flags;
459+
456460
switch (sk->sk_type) {
457461
case SOCK_DGRAM:
458462
new_transport = transport_dgram;
459463
break;
460464
case SOCK_STREAM:
461465
if (vsock_use_local_transport(remote_cid))
462466
new_transport = transport_local;
463-
else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g)
467+
else if (remote_cid <= VMADDR_CID_HOST || !transport_h2g ||
468+
(remote_flags & VMADDR_FLAG_TO_HOST))
464469
new_transport = transport_g2h;
465470
else
466471
new_transport = transport_h2g;

0 commit comments

Comments
 (0)