Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
VERSION = 6
PATCHLEVEL = 6
SUBLEVEL = 161
SUBLEVEL = 162
EXTRAVERSION =
NAME = Pinguïn Aangedreven

Expand Down
2 changes: 2 additions & 0 deletions drivers/block/xen-blkback/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,10 @@ struct xen_blkif {
unsigned int nr_ring_pages;
bool multi_ref;
/* All rings for this device. */
rwlock_t rings_lock;
struct xen_blkif_ring *rings;
unsigned int nr_rings;

unsigned long buffer_squeeze_end;
};

Expand Down
31 changes: 24 additions & 7 deletions drivers/block/xen-blkback/xenbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,23 @@ static void xen_update_blkif_status(struct xen_blkif *blkif)
return;
}

static int xen_blkif_alloc_rings(struct xen_blkif *blkif)
static int xen_blkif_alloc_rings(struct xen_blkif *blkif,
unsigned int nr_rings)
{
unsigned int r;
struct xen_blkif_ring *rings;

blkif->rings = kcalloc(blkif->nr_rings, sizeof(struct xen_blkif_ring),
GFP_KERNEL);
if (!blkif->rings)
rings = kcalloc(nr_rings, sizeof(struct xen_blkif_ring), GFP_KERNEL);
if (!rings)
return -ENOMEM;

write_lock(&blkif->rings_lock);

blkif->rings = rings;
blkif->nr_rings = nr_rings;

write_unlock(&blkif->rings_lock);

for (r = 0; r < blkif->nr_rings; r++) {
struct xen_blkif_ring *ring = &blkif->rings[r];

Expand Down Expand Up @@ -175,6 +183,7 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
blkif->domid = domid;
atomic_set(&blkif->refcnt, 1);
init_completion(&blkif->drain_complete);
rwlock_init(&blkif->rings_lock);

/*
* Because freeing back to the cache may be deferred, it is not
Expand Down Expand Up @@ -269,6 +278,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
struct pending_req *req, *n;
unsigned int j, r;
bool busy = false;
struct xen_blkif_ring *rings;

for (r = 0; r < blkif->nr_rings; r++) {
struct xen_blkif_ring *ring = &blkif->rings[r];
Expand Down Expand Up @@ -335,10 +345,16 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)
* blkif->rings was allocated in connect_ring, so we should free it in
* here.
*/
kfree(blkif->rings);
write_lock(&blkif->rings_lock);

rings = blkif->rings;
blkif->rings = NULL;
blkif->nr_rings = 0;

write_unlock(&blkif->rings_lock);

kfree(rings);

return 0;
}

Expand Down Expand Up @@ -386,6 +402,7 @@ void xen_blkif_interface_fini(void)
unsigned int i; \
unsigned long long result = 0; \
\
read_lock(&blkif->rings_lock); \
if (!blkif->rings) \
goto out; \
\
Expand All @@ -396,6 +413,7 @@ void xen_blkif_interface_fini(void)
} \
\
out: \
read_unlock(&blkif->rings_lock); \
return sprintf(buf, format, result); \
} \
static DEVICE_ATTR(name, 0444, show_##name, NULL)
Expand Down Expand Up @@ -1104,8 +1122,7 @@ static int connect_ring(struct backend_info *be)
requested_num_queues, xenblk_max_queues);
return -ENOSYS;
}
blkif->nr_rings = requested_num_queues;
if (xen_blkif_alloc_rings(blkif))
if (xen_blkif_alloc_rings(blkif, requested_num_queues))
return -ENOMEM;

pr_info("%s: using %d queues, protocol %d (%s) %s\n", dev->nodename,
Expand Down
2 changes: 0 additions & 2 deletions drivers/net/xen-netback/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,6 @@ void xenvif_disconnect_data(struct xenvif *vif)

xenvif_disconnect_queue(queue);
}

xenvif_mcast_addr_list_free(vif);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Failed reconnect retains multicast entries

When a guest adds multicast addresses while a queue is active and a later queue or ring fails to connect, xenvif_disconnect_data() now stops the queues without clearing fe_mcast_addr, and the connection-error path only synchronizes and deinitializes those queues. Guest-supplied multicast entries therefore survive a failed connection and are reused on a later connection, leaving stale multicast membership and potentially allowing multicast traffic to reach the guest after it unsubscribes.

Clear the multicast list on the failed-connect path after the synchronization point, or otherwise ensure it is reset before reconnecting.

Prompt for AI agents
In `drivers/net/xen-netback/interface.c` at line 813:

**Failed reconnect retains multicast entries**

When a guest adds multicast addresses while a queue is active and a later queue or ring fails to connect, `xenvif_disconnect_data()` now stops the queues without clearing `fe_mcast_addr`, and the connection-error path only synchronizes and deinitializes those queues. Guest-supplied multicast entries therefore survive a failed connection and are reused on a later connection, leaving stale multicast membership and potentially allowing multicast traffic to reach the guest after it unsubscribes.

Clear the multicast list on the failed-connect path after the synchronization point, or otherwise ensure it is reset before reconnecting.

}

void xenvif_disconnect_ctrl(struct xenvif *vif)
Expand Down
3 changes: 3 additions & 0 deletions drivers/net/xen-netback/xenbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ static void backend_disconnect(struct backend_info *be)
vif->num_queues = 0;
synchronize_net();

xenvif_mcast_addr_list_free(vif);

for (queue_index = 0; queue_index < num_queues; ++queue_index)
xenvif_deinit_queue(&vif->queues[queue_index]);

Expand Down Expand Up @@ -837,6 +839,7 @@ static void connect(struct backend_info *be)
err:
if (be->vif->num_queues > 0)
xenvif_disconnect_data(be->vif); /* Clean up existing queues */
synchronize_net();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Statistics can access freed queues

When queue setup fails after at least one queue has been initialized while a statistics read begins after the grace period, xenvif_get_stats() can start an RCU read after synchronize_net() returns, observe the still-positive vif->num_queues, and read vif->queues after the error path frees it with vfree(). The resulting use-after-free can crash the backend.

Set num_queues to zero before synchronize_net() in the error path, while preserving the count needed to deinitialize the queues.

Prompt for AI agents
In `drivers/net/xen-netback/xenbus.c` at line 842:

**Statistics can access freed queues**

When queue setup fails after at least one queue has been initialized while a statistics read begins after the grace period, `xenvif_get_stats()` can start an RCU read after `synchronize_net()` returns, observe the still-positive `vif->num_queues`, and read `vif->queues` after the error path frees it with `vfree()`. The resulting use-after-free can crash the backend.

Set `num_queues` to zero before `synchronize_net()` in the error path, while preserving the count needed to deinitialize the queues.

for (queue_index = 0; queue_index < be->vif->num_queues; ++queue_index)
xenvif_deinit_queue(&be->vif->queues[queue_index]);
vfree(be->vif->queues);
Expand Down