powerpc/pseries/dlpar: Fix a missing check in dlpar_parse_cc_property()
authorGen Zhang <blackgod016574@gmail.com>
Sun, 26 May 2019 02:42:40 +0000 (10:42 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 5 Dec 2019 08:21:23 +0000 (09:21 +0100)
[ Upstream commit efa9ace68e487ddd29c2b4d6dd23242158f1f607 ]

In dlpar_parse_cc_property(), 'prop->name' is allocated by kstrdup().
kstrdup() may return NULL, so it should be checked and handle error.
And prop should be freed if 'prop->name' is NULL.

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/powerpc/platforms/pseries/dlpar.c

index e3010b1..c5ffcad 100644 (file)
@@ -63,6 +63,10 @@ static struct property *dlpar_parse_cc_property(struct cc_workarea *ccwa)
 
        name = (char *)ccwa + be32_to_cpu(ccwa->name_offset);
        prop->name = kstrdup(name, GFP_KERNEL);
+       if (!prop->name) {
+               dlpar_free_cc_property(prop);
+               return NULL;
+       }
 
        prop->length = be32_to_cpu(ccwa->prop_length);
        value = (char *)ccwa + be32_to_cpu(ccwa->prop_offset);