xen, cpu_hotplug: Prevent an out of bounds access
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 7 Mar 2019 05:41:22 +0000 (08:41 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jan 2020 09:24:18 +0000 (10:24 +0100)
[ Upstream commit 201676095dda7e5b31a5e1d116d10fc22985075e ]

The "cpu" variable comes from the sscanf() so Smatch marks it as
untrusted data.  We can't pass a higher value than "nr_cpu_ids" to
cpu_possible() or it results in an out of bounds access.

Fixes: d68d82afd4c8 ("xen: implement CPU hotplugging")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/xen/cpu_hotplug.c

index f4e59c445964d57e11a400eccde3c14526cc5a42..17054d695411788da16eb4fd4f5ea08d1c9d4ad2 100644 (file)
@@ -53,7 +53,7 @@ static int vcpu_online(unsigned int cpu)
 }
 static void vcpu_hotplug(unsigned int cpu)
 {
-       if (!cpu_possible(cpu))
+       if (cpu >= nr_cpu_ids || !cpu_possible(cpu))
                return;
 
        switch (vcpu_online(cpu)) {