[Devel] [PATCH RH8 43/61] ploop: Check top delta rw

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 14 18:58:28 MSK 2021


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