Skip to contentSkip to conversation

rbd: fix leak of format 2 snapshot context

PATCH In review Alex Elder 2 participants 2 messages May 7, 2013 – May 12, 2013

Subsystems (2)
lore
Share & tools
lore

Alex Elder

author
#0 lore raw

PATCH 1/1 rbd: fix leak of format 2 snapshot context

When rbd_dev_v2_refresh() is called, the rbd device already has a snapshot context associated with it. But that never gets freed, the pointer just gets overwritten.

Fix this by dropping the rbd device's reference to the snapshot context before overwriting the pointer.

Because ceph_put_snap_context() already handles for a null pointer we don't need to check for that (for the probe case, where no context has yet been assigned).

This resolves:

    http://tracker.ceph.com/issues/4912
---
 drivers/block/rbd.c |    1 +
 1 file changed, 1 insertion(+)
drivers/block/rbd.c +0 -0
index c2ca181..4263743 100644
@@ -4004,6 +4004,7 @@ static int rbd_dev_v2_snap_context(struct

rbd_device *rbd_dev)
for (i = 0; i < snap_count; i++)
snapc->snaps[i] = ceph_decode_64(&p);

+ ceph_put_snap_context(rbd_dev->header.snapc);
rbd_dev->header.snapc = snapc;

dout(" snap context seq = %llu, snap_count = %u\n",

Signature · 1 line
1.7.9.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 31 lines · Alex Elder

When rbd_dev_v2_refresh() is called, the rbd device already has a snapshot context associated with it. But that never gets freed, the pointer just gets overwritten.

Fix this by dropping the rbd device's reference to the snapshot context before overwriting the pointer.

Because ceph_put_snap_context() already handles for a null pointer we don't need to check for that (for the probe case, where no context has yet been assigned).

This resolves:

   http://tracker.ceph.com/issues/4912

---
drivers/block/rbd.c | 1 +

1 file changed, 1 insertion(+)
drivers/block/rbd.c +1 -0
index c2ca181..4263743 100644
@@ -4004,6 +4004,7 @@ static int rbd_dev_v2_snap_context(struct
 rbd_device *rbd_dev)
 	for (i = 0; i < snap_count; i++)
 		snapc->snaps[i] = ceph_decode_64(&p);
 
+	ceph_put_snap_context(rbd_dev->header.snapc);
 	rbd_dev->header.snapc = snapc;
 
Quoted 1 line

dout(" snap context seq = %llu, snap_count = %u\n",