OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: Den Lunev <den@virtuozzo.com>, devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 v2 2/2] dm/push_backup: free the bitmaps of an expired session on restart
Date: Wed, 25 Nov 2026 12:12:06 +0000	[thread overview]
Message-ID: <20261125-push-backup-fixes-v2-2-195a2bcd82f7@virtuozzo.com> (raw)
In-Reply-To: <20261125-push-backup-fixes-v2-0-195a2bcd82f7@virtuozzo.com>

When a backup session expires, cleanup_backup() clears pb->alive but
keeps pb->map and pb->pending_map, so that the target status can still
report the session as expired. push_backup_start() refuses to start
only while pb->alive is set, so a start after an expiry goes on to
setup_pb(), which overwrites both pointers with new bitmaps. The old
bitmaps are never freed, because push_backup_stop() and pb_destroy()
free only the current pointers.

Each bitmap takes one bit per cluster. With fail_on_process_exit the
session expires as soon as the sender exits, so this is easy to hit in
a loop:

  for i in $(seq 1000); do
    dmsetup message <pb_dev> 0 push_backup_start 60 0 fail_on_process_exit
  done

Swap the new bitmaps in under pb->lock and free the old ones in
setup_pb(). Nothing dereferences the bitmaps of an expired session
without holding pb->lock, so they can be freed once the lock is
dropped. If setting up the new session fails, the expired session
keeps its bitmaps.

https://virtuozzo.atlassian.net/browse/VSTOR-155790

Feature: dm-backup: push backup target driver
Fixes: 162123bc62c7 ("dm: Add push backup driver")
Signed-off-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
---
 drivers/md/dm-push-backup.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-push-backup.c b/drivers/md/dm-push-backup.c
index 504713a9430e..433c61b63802 100644
--- a/drivers/md/dm-push-backup.c
+++ b/drivers/md/dm-push-backup.c
@@ -434,11 +434,13 @@ static int setup_pb(struct push_backup *pb, void __user *mask, int timeout)
 	map_bits = bitmap_weight(map, clus);
 
 	spin_lock_irq(&pb->lock);
-	pb->map = map;
+	swap(pb->map, map);
 	pb->map_bits = map_bits;
-	pb->pending_map = pending_map;
+	swap(pb->pending_map, pending_map);
 	pb->alive = true;
 	spin_unlock_irq(&pb->lock);
+	kvfree(map);
+	kvfree(pending_map);
 	return 0;
 err:
 	kvfree(map);

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-11-25 12:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 12:12 [Devel] [PATCH hci-8.2 v2 0/2] dm/push_backup: fix two old bugs Vasileios Almpanis
2026-11-25 12:12 ` [Devel] [PATCH hci-8.2 v2 1/2] dm/push_backup: reject a cluster size of 0 Vasileios Almpanis
2026-12-01  0:14   ` no-reply
2026-11-25 12:12 ` Vasileios Almpanis [this message]
2026-12-01  0:15   ` [Devel] [PATCH hci-8.2 v2 2/2] dm/push_backup: free the bitmaps of an expired session on restart no-reply
2026-11-25 12:16 ` [Devel] [PATCH hci-8.2 v2 0/2] dm/push_backup: fix two old bugs Andrey Zhadchenko
2026-11-30 15:06 ` Konstantin Khorenko
2026-11-30 15:06 ` Konstantin Khorenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125-push-backup-fixes-v2-2-195a2bcd82f7@virtuozzo.com \
    --to=vasileios.almpanis@virtuozzo.com \
    --cc=den@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox