ovl: Add comment on upperredirect reassignment
authorStanislav Goriainov <goriainov@ispras.ru>
Wed, 31 Aug 2022 08:06:58 +0000 (11:06 +0300)
committerMiklos Szeredi <mszeredi@redhat.com>
Thu, 8 Dec 2022 09:49:46 +0000 (10:49 +0100)
If memory for uperredirect was allocated with kstrdup() in upperdir != NULL
and d.redirect != NULL path, it may seem that it can be lost when
upperredirect is reassigned later, but it's not possible.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 0a2d0d3f2f291 ("ovl: Check redirect on index as well")
Signed-off-by: Stanislav Goriainov <goriainov@ispras.ru>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/namei.c

index 0ce1f9b3a0467f2128d5fc3f3a0f48113c48ff21..46753134533a1effb110d1cab292ac0b97a3a087 100644 (file)
@@ -1086,6 +1086,11 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
                        .mnt = ovl_upper_mnt(ofs),
                };
 
+               /*
+                * It's safe to assign upperredirect here: the previous
+                * assignment of happens only if upperdentry is non-NULL, and
+                * this one only if upperdentry is NULL.
+                */
                upperredirect = ovl_get_redirect_xattr(ofs, &upperpath, 0);
                if (IS_ERR(upperredirect)) {
                        err = PTR_ERR(upperredirect);