]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ovl: fix missing revert_creds() on error path
authorDan Carpenter <dan.carpenter@oracle.com>
Tue, 23 Mar 2021 13:19:35 +0000 (16:19 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 14 May 2021 08:49:33 +0000 (10:49 +0200)
commit 7b279bbfd2b230c7a210ff8f405799c7e46bbf48 upstream.

Smatch complains about missing that the ovl_override_creds() doesn't
have a matching revert_creds() if the dentry is disconnected.  Fix this
by moving the ovl_override_creds() until after the disconnected check.

Fixes: aa3ff3c152ff ("ovl: copy up of disconnected dentries")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/overlayfs/copy_up.c

index 0fed532efa68d127adc8cbcc5755056495c45caf..e2ae8f4e99c23a169e6d99149bfc527b57fcc7dc 100644 (file)
@@ -932,7 +932,7 @@ static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
 static int ovl_copy_up_flags(struct dentry *dentry, int flags)
 {
        int err = 0;
-       const struct cred *old_cred = ovl_override_creds(dentry->d_sb);
+       const struct cred *old_cred;
        bool disconnected = (dentry->d_flags & DCACHE_DISCONNECTED);
 
        /*
@@ -943,6 +943,7 @@ static int ovl_copy_up_flags(struct dentry *dentry, int flags)
        if (WARN_ON(disconnected && d_is_dir(dentry)))
                return -EIO;
 
+       old_cred = ovl_override_creds(dentry->d_sb);
        while (!err) {
                struct dentry *next;
                struct dentry *parent = NULL;