]> git.itanic.dy.fi Git - linux-stable/commitdiff
ceph: fix dereference of null pointer cf
authorColin Ian King <colin.king@canonical.com>
Sun, 29 Aug 2021 18:18:24 +0000 (19:18 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 3 Sep 2021 08:55:51 +0000 (10:55 +0200)
Currently in the case where kmem_cache_alloc fails the null pointer
cf is dereferenced when assigning cf->is_capsnap = false. Fix this
by adding a null pointer check and return path.

Cc: stable@vger.kernel.org
Addresses-Coverity: ("Dereference null return")
Fixes: b2f9fa1f3bd8 ("ceph: correctly handle releasing an embedded cap flush")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
fs/ceph/caps.c

index 26c5029629a42ba2f2c114fd5531d2fd08115265..6c0e52fd0743efda7852e89c52c35201f38bfed6 100644 (file)
@@ -1736,6 +1736,9 @@ struct ceph_cap_flush *ceph_alloc_cap_flush(void)
        struct ceph_cap_flush *cf;
 
        cf = kmem_cache_alloc(ceph_cap_flush_cachep, GFP_KERNEL);
+       if (!cf)
+               return NULL;
+
        cf->is_capsnap = false;
        return cf;
 }