Skip to content

Commit 6e9544f

Browse files
numo68gregkh
authored andcommitted
nvmem: mxs-ocotp: fix buffer overflow in read
commit d1306eb675ad7a9a760b6b8e8e189824b8db89e7 upstream. This patch fixes the issue where the mxs_ocotp_read is reading the ocotp in reg_size steps but decrements the remaining size by 1. The number of iterations is thus four times higher, overwriting the area behind the output buffer. Fixes: c01e9a1 ("nvmem: add driver for ocotp in i.MX23 and i.MX28") Tested-by: Stefan Wahren <stefan.wahren@i2se.com> Signed-off-by: Stanislav Meduna <stano@meduna.org> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e5dd50f commit 6e9544f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/nvmem/mxs-ocotp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int mxs_ocotp_read(void *context, const void *reg, size_t reg_size,
9494
if (ret)
9595
goto close_banks;
9696

97-
while (val_size) {
97+
while (val_size >= reg_size) {
9898
if ((offset < OCOTP_DATA_OFFSET) || (offset % 16)) {
9999
/* fill up non-data register */
100100
*buf = 0;
@@ -103,7 +103,7 @@ static int mxs_ocotp_read(void *context, const void *reg, size_t reg_size,
103103
}
104104

105105
buf++;
106-
val_size--;
106+
val_size -= reg_size;
107107
offset += reg_size;
108108
}
109109

0 commit comments

Comments
 (0)