mtd_check_oob_ops() adds the starting offset to the data length before comparing the result with the device size. On 64-bit systems, a request with offs == 1 and ops->len == SIZE_MAX wraps that sum to zero and passes the range check. The public read and write wrappers can then pass an out-of-range request to the driver. Validate the starting offset first, then compare the data length with the remaining capacity. Preserve NULL-buffer length normalization and empty requests at the end of the device. Fixes: 5cdd929da53d ("mtd: Add sanity checks in mtd_write/read_oob()") Cc: stable@vger.kernel.org Signed-off-by: James Hilliard --- drivers/mtd/mtdcore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 491a27d0315f..dda976ef52c9 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -1670,7 +1670,7 @@ static int mtd_check_oob_ops(struct mtd_info *mtd, loff_t offs, if (!ops->oobbuf) ops->ooblen = 0; - if (offs < 0 || offs + ops->len > mtd->size) + if (offs < 0 || offs > mtd->size || ops->len > mtd->size - offs) return -EINVAL; if (ops->ooblen) { --- base-commit: 1c1a342aceec79528b3ba51f376eca2be5928fe7 change-id: 20261104-submit-mtd-oob-bounds-v1-2c5cf82f2767 Best regards, -- James Hilliard