vfs: Fix refcounting of filenames in fs_parser
authorDavid Howells <dhowells@redhat.com>
Mon, 25 Mar 2019 16:38:22 +0000 (16:38 +0000)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 25 May 2019 22:00:02 +0000 (18:00 -0400)
Fix an overput in which filename_lookup() unconditionally drops a ref to
the filename it was given, but this isn't taken account of in the caller,
fs_lookup_param().

Addresses-Coverity-ID: 1443811 ("Use after free")
Signed-off-by: David Howells <dhowells@redhat.com>
fs/fs_parser.c

index 570d71043acf982976d3098cf5e4beaee7532241..3a1697c2f72fb9b5f2e0c6100d849e2ab8409be4 100644 (file)
@@ -268,6 +268,7 @@ int fs_lookup_param(struct fs_context *fc,
                return invalf(fc, "%s: not usable as path", param->key);
        }
 
+       f->refcnt++; /* filename_lookup() drops our ref. */
        ret = filename_lookup(param->dirfd, f, flags, _path, NULL);
        if (ret < 0) {
                errorf(fc, "%s: Lookup failure for '%s'", param->key, f->name);