NFS: Add missing null check for failed allocation
authorColin Ian King <colin.king@canonical.com>
Mon, 6 Jan 2020 13:17:34 +0000 (13:17 +0000)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Wed, 15 Jan 2020 15:54:31 +0000 (10:54 -0500)
Currently the allocation of buf is not being null checked and
a null pointer dereference can occur when the memory allocation fails.
Fix this by adding a check and returning -ENOMEM.

Addresses-Coverity: ("Dereference null return")
Fixes: 6d972518b821 ("NFS: Add fs_context support.")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/nfs4namespace.c

index 10e9e18878416d72f633656de282dd26be15e6b6..de6875a9b39190d2b59decf900b66b507c27bd7d 100644 (file)
@@ -137,6 +137,9 @@ static int nfs4_validate_fspath(struct dentry *dentry,
        int n;
 
        buf = kmalloc(4096, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
        path = nfs4_path(dentry, buf, 4096);
        if (IS_ERR(path)) {
                kfree(buf);