Skip to contentSkip to conversation

ovl: fix creds leak in copy up error path

PATCH Applied Amir Goldstein 2 participants 2 messages May 16, 2017

Subsystems (2)
lore
Share & tools
lore

Amir Goldstein

author maintainer
#0 lore raw

PATCH 1/1 ovl: fix creds leak in copy up error path

Fixes 42f269b92540 ("ovl: rearrange code in ovl_copy_up_locked()")
Cc <[email protected]> # v4.11
---
 fs/overlayfs/copy_up.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Miklos,

Found that fall out while trying to 'simplify' this function. (see WIP at
https://github.com/amir73il/linux/commits/ovl-index-dir).

Amir.

fs/overlayfs/copy_up.c +6 -5
index 9008ab9..061a844 100644
@@ -343,12 +343,13 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
 		temp = ovl_do_tmpfile(upperdir, stat->mode);
 	else
 		temp = ovl_lookup_temp(workdir, dentry);
-	err = PTR_ERR(temp);
-	if (IS_ERR(temp))
-		goto out1;
-
 	err = 0;
-	if (!tmpfile)
+	if (IS_ERR(temp)) {
+		err = PTR_ERR(temp);
+		temp = NULL;
+	}
+
+	if (!err && !tmpfile)
 		err = ovl_create_real(wdir, temp, &cattr, NULL, true);
 
 	if (new_creds) {
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw
Quoted 3 lines · Amir Goldstein
Fixes 42f269b92540 ("ovl: rearrange code in ovl_copy_up_locked()")
Cc <[email protected]> # v4.11

Thanks, applied.

Miklos

Quoted 37 lines
---
 fs/overlayfs/copy_up.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Miklos,

Found that fall out while trying to 'simplify' this function. (see WIP at
https://github.com/amir73il/linux/commits/ovl-index-dir).

Amir.

fs/overlayfs/copy_up.c +6 -6
index 9008ab9..061a844 100644
@@ -343,12 +343,13 @@ static int ovl_copy_up_locked(struct dentry *workdir, struct dentry *upperdir,
                temp = ovl_do_tmpfile(upperdir, stat->mode);
        else
                temp = ovl_lookup_temp(workdir, dentry);
-       err = PTR_ERR(temp);
-       if (IS_ERR(temp))
-               goto out1;
-
        err = 0;
-       if (!tmpfile)
+       if (IS_ERR(temp)) {
+               err = PTR_ERR(temp);
+               temp = NULL;
+       }
+
+       if (!err && !tmpfile)
                err = ovl_create_real(wdir, temp, &cattr, NULL, true);
 
        if (new_creds) {
--

2.7.4