Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

memory: gpmc: fix out of bounds read and dereference on gpmc_cs[]

Currently the array gpmc_cs is indexed by cs before it cs is range checked
and the pointer read from this out-of-index read is dereferenced. Fix this
by performing the range check on cs before the read and the following
pointer dereference.

Addresses-Coverity: ("Negative array index read")
Fixes: 9ed7a776eb50 ("ARM: OMAP2+: Fix support for multiple devices on a GPMC chip select")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Tony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20210223193821.17232-1-colin.king@canonical.com
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

authored by

Colin Ian King and committed by
Krzysztof Kozlowski
e004c3e6 a38fd874

+5 -2
+5 -2
drivers/memory/omap-gpmc.c
··· 1009 1009 1010 1010 void gpmc_cs_free(int cs) 1011 1011 { 1012 - struct gpmc_cs_data *gpmc = &gpmc_cs[cs]; 1013 - struct resource *res = &gpmc->mem; 1012 + struct gpmc_cs_data *gpmc; 1013 + struct resource *res; 1014 1014 1015 1015 spin_lock(&gpmc_mem_lock); 1016 1016 if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) { ··· 1018 1018 spin_unlock(&gpmc_mem_lock); 1019 1019 return; 1020 1020 } 1021 + gpmc = &gpmc_cs[cs]; 1022 + res = &gpmc->mem; 1023 + 1021 1024 gpmc_cs_disable_mem(cs); 1022 1025 if (res->flags) 1023 1026 release_resource(res);