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

mtd: physmap: physmap-bt1-rom: Fix unintentional stack access

Cast &data to (char *) in order to avoid unintentionally accessing
the stack.

Notice that data is of type u32, so any increment to &data
will be in the order of 4-byte chunks, and this piece of code
is actually intended to be a byte offset.

Fixes: b3e79e7682e0 ("mtd: physmap: Add Baikal-T1 physically mapped ROM support")
Addresses-Coverity-ID: 1497765 ("Out-of-bounds access")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210212104022.GA242669@embeddedor

authored by

Gustavo A. R. Silva and committed by
Miquel Raynal
68331399 a38fd874

+1 -1
+1 -1
drivers/mtd/maps/physmap-bt1-rom.c
··· 79 79 if (shift) { 80 80 chunk = min_t(ssize_t, 4 - shift, len); 81 81 data = readl_relaxed(src - shift); 82 - memcpy(to, &data + shift, chunk); 82 + memcpy(to, (char *)&data + shift, chunk); 83 83 src += chunk; 84 84 to += chunk; 85 85 len -= chunk;