[Devel] [PATCH RHEL8 COMMIT] ploop: Check top delta rw

Konstantin Khorenko khorenko at virtuozzo.com
Mon May 17 19:04:58 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.30
------>
commit 90e7b2154ebaac0b9df6a3655c8c087f7c168dc1
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Mon May 17 19:04:58 2021 +0300

    ploop: Check top delta rw
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    dm-ploop: Kill loop
    
    Intermediate patches can't be base for bisect.
    
    In scope of https://jira.sw.ru/browse/PSBM-123654
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-cmd.c    | 4 ++++
 drivers/md/dm-ploop-target.c | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index fb1d5d9af53e..594cf8a4c1bb 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -1182,6 +1182,7 @@ static int ploop_flip_upper_deltas(struct ploop *ploop)
 {
 	struct dm_target *ti = ploop->ti;
 	struct ploop_cmd cmd = { {0} };
+	struct file *file;
 
 	cmd.type = PLOOP_CMD_FLIP_UPPER_DELTAS;
 	cmd.ploop = ploop;
@@ -1194,6 +1195,9 @@ static int ploop_flip_upper_deltas(struct ploop *ploop)
 		return -ENOENT;
 	if (ploop->deltas[ploop->nr_deltas - 2].is_raw)
 		return -EBADSLT;
+	file = ploop->deltas[ploop->nr_deltas - 2].file;
+        if (!(file->f_mode & FMODE_WRITE))
+		return -EACCES;
 
 	init_completion(&cmd.comp);
 	ploop_queue_deferred_cmd(ploop, &cmd);
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 307463fab633..1913e836002d 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -184,9 +184,18 @@ static struct file * get_delta_file(int fd)
 
 static int check_top_delta(struct ploop *ploop, struct file *file)
 {
+	struct dm_target *ti = ploop->ti;
 	struct page *page = NULL;
+	fmode_t mode;
 	int ret;
 
+	mode = dm_table_get_mode(ti->table);
+	mode &= (FMODE_READ|FMODE_WRITE);
+
+	ret = -EACCES;
+        if (mode & ~(file->f_mode & (FMODE_READ|FMODE_WRITE)))
+		goto out;
+
 	/* Prealloc a page to read hdr */
 	ret = -ENOMEM;
 	page = alloc_page(GFP_KERNEL);


More information about the Devel mailing list