Skip to contentSkip to conversation

ovl: fix fd leak in ovl_flush()

PATCH In review Amir Goldstein 3 participants 3 messages Jan 27, 2021 – Jan 28, 2021 Overlay filesystem

lore
Share & tools
lore

Amir Goldstein

author maintainer
#0 lore raw

PATCH 1/1 ovl: fix fd leak in ovl_flush()

---

Miklos,

This patch is against overlayfs-next which currently fails xfstests.

Thanks,
Amir.

 fs/overlayfs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/overlayfs/file.c +6 -1
index 2ff818d5c2c9..6fa9ac682beb 100644
@@ -693,12 +693,17 @@ static int ovl_flush(struct file *file, fl_owner_t id)
 	int err;
 
 	err = ovl_real_fdget(file, &real);
-	if (!err && real.file->f_op->flush) {
+	if (err)
+		return err;
+
+	if (real.file->f_op->flush) {
 		old_cred = ovl_override_creds(file_inode(file)->i_sb);
 		err = real.file->f_op->flush(real.file, id);
 		revert_creds(old_cred);
 	}
 
+	fdput(real);
+
 	return err;
 }
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 38 lines · Amir Goldstein

---

Miklos,

This patch is against overlayfs-next which currently fails xfstests.

Thanks,
Amir.

 fs/overlayfs/file.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
fs/overlayfs/file.c +6 -2
index 2ff818d5c2c9..6fa9ac682beb 100644
@@ -693,12 +693,17 @@ static int ovl_flush(struct file *file, fl_owner_t id)
        int err;
 
        err = ovl_real_fdget(file, &real);
-       if (!err && real.file->f_op->flush) {
+       if (err)
+               return err;
+
+       if (real.file->f_op->flush) {
                old_cred = ovl_override_creds(file_inode(file)->i_sb);
                err = real.file->f_op->flush(real.file, id);
                revert_creds(old_cred);
        }
 
+       fdput(real);
+
        return err;
 }
 
--
Quoted 2 lines

2.25.1

Thanks.