This is a note to let you know that I've just added the patch titled ata: sata_mv: Fix incorrect string length computation in mv_dump_mem() to the 6.5-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: ata-sata_mv-fix-incorrect-string-length-computation-.patch and it can be found in the queue-6.5 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 31e5b24e78c2c454b0a84991cdc6d11d3a4a3a52 Author: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx> Date: Mon Sep 4 21:54:36 2023 +0200 ata: sata_mv: Fix incorrect string length computation in mv_dump_mem() [ Upstream commit e97eb65dd464e7f118a16a26337322d07eb653e2 ] snprintf() returns the "number of characters which *would* be generated for the given input", not the size *really* generated. In order to avoid too large values for 'o' (and potential negative values for "sizeof(linebuf) o") use scnprintf() instead of snprintf(). Note that given the "w < 4" in the for loop, the buffer can NOT overflow, but using the *right* function is always better. Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx> Signed-off-by: Damien Le Moal <dlemoal@xxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c index d404e631d1527..68e660e4cc410 100644 --- a/drivers/ata/sata_mv.c +++ b/drivers/ata/sata_mv.c @@ -1255,8 +1255,8 @@ static void mv_dump_mem(struct device *dev, void __iomem *start, unsigned bytes) for (b = 0; b < bytes; ) { for (w = 0, o = 0; b < bytes && w < 4; w++) { - o += snprintf(linebuf + o, sizeof(linebuf) - o, - "%08x ", readl(start + b)); + o += scnprintf(linebuf + o, sizeof(linebuf) - o, + "%08x ", readl(start + b)); b += sizeof(u32); } dev_dbg(dev, "%s: %p: %s\n",