[Devel] [PATCH RH9] push_backup: Do not take write lock on ENOTTY

Kirill Tkhai ktkhai at virtuozzo.com
Tue Sep 28 18:43:34 MSK 2021


Userspace may pass wrong command. Do not take write lock then.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-push-backup.c |   23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/drivers/md/dm-push-backup.c b/drivers/md/dm-push-backup.c
index 6d7b1859298a..1500d0681cee 100644
--- a/drivers/md/dm-push-backup.c
+++ b/drivers/md/dm-push-backup.c
@@ -329,11 +329,10 @@ static void pb_release_clone(struct request *clone,
 	blk_put_request(clone);
 }
 
-static bool msg_wants_down_read(const char *cmd)
+static bool msg_wants_down_write(const char *cmd)
 {
-	if (!strcmp(cmd, "push_backup_read") ||
-	    !strcmp(cmd, "push_backup_write") ||
-	    !strcmp(cmd, "push_backup_statistics"))
+	if (!strcmp(cmd, "push_backup_start") ||
+	    !strcmp(cmd, "push_backup_stop"))
 		return true;
 
 	return false;
@@ -567,7 +566,7 @@ static int pb_message(struct dm_target *ti, unsigned int argc, char **argv,
 	struct push_backup *pb = ti->private;
 	int ret = -EPERM;
 	u64 val, val2;
-	bool read;
+	bool write;
 
 	if (!capable(CAP_SYS_ADMIN))
 		goto out;
@@ -576,11 +575,11 @@ static int pb_message(struct dm_target *ti, unsigned int argc, char **argv,
 	if (argc < 1)
 		goto out;
 
-	read = msg_wants_down_read(argv[0]);
-	if (read)
-		ret = down_read_killable(&pb->ctl_rwsem);
-	else
+	write = msg_wants_down_write(argv[0]);
+	if (write)
 		ret = down_write_killable(&pb->ctl_rwsem);
+	else
+		ret = down_read_killable(&pb->ctl_rwsem);
 	if (unlikely(ret))
 		goto out;
 
@@ -612,10 +611,10 @@ static int pb_message(struct dm_target *ti, unsigned int argc, char **argv,
 	}
 
 unlock:
-	if (read)
-		up_read(&pb->ctl_rwsem);
-	else
+	if (write)
 		up_write(&pb->ctl_rwsem);
+	else
+		up_read(&pb->ctl_rwsem);
 out:
 	return ret;
 }




More information about the Devel mailing list