Skip to contentSkip to conversation

ovl: avoid setting uninitialized creds

PATCH In review Arnd Bergmann 2 participants 2 messages Sep 19, 2016 Overlay filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ovl: avoid setting uninitialized creds

If the call to ovl_copy_up() fails, we now call revert_creds on an uninitialized structure after a recent patch, as found by "gcc -Wmayby-uninitialized":

fs/overlayfs/inode.c: In function 'ovl_open_maybe_copy_up':
fs/overlayfs/inode.c:39:2: error: 'old_cred' may be used uninitialized in this function [-Werror=maybe-uninitialized] fs/overlayfs/inode.c:22:21: note: 'old_cred' was declared here

This changes the code back to not call revert_creds unless we have already called ovl_override_creds().

Fixes 54249cd03956 ("ovl: during copy up, switch to mounter's creds early")
---
 fs/overlayfs/inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/overlayfs/inode.c +3 -2
index af87c7c109b7..65375f9c5563 100644
@@ -30,13 +30,14 @@ static int ovl_copy_up_truncate(struct dentry *dentry)
 	old_cred = ovl_override_creds(dentry->d_sb);
 	err = vfs_getattr(&lowerpath, &stat);
 	if (err)
-		goto out_dput_parent;
+		goto out_revert;
 
 	stat.size = 0;
 	err = ovl_copy_up_one(parent, dentry, &lowerpath, &stat);
 
-out_dput_parent:
+out_revert:
 	revert_creds(old_cred);
+out_dput_parent:
 	dput(parent);
 	return err;
 }
Signature · 1 line
2.9.0
maintainer
#1 lore raw
Quoted 10 lines · Arnd Bergmann

If the call to ovl_copy_up() fails, we now call revert_creds on an uninitialized structure after a recent patch, as found by "gcc -Wmayby-uninitialized":

fs/overlayfs/inode.c: In function 'ovl_open_maybe_copy_up':
fs/overlayfs/inode.c:39:2: error: 'old_cred' may be used uninitialized in this function [-Werror=maybe-uninitialized] fs/overlayfs/inode.c:22:21: note: 'old_cred' was declared here

This changes the code back to not call revert_creds unless we have already called ovl_override_creds().

Thanks. Slightly reworked fix folded into original patch and pushed out.

Thanks,
Miklos