Skip to contentSkip to conversation

memmove_wd: copy chunk down from big address if parameter to is larger than from

PATCH In review Sonic Zhang 3 participants 3 messages Dec 10, 2014 – Jan 7, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memmove_wd: copy chunk down from big address if parameter to is larger than from

From: Sonic Zhang <[email protected]>

When watchdog is enabled, memmove_wd() always copy chunk up from small address. This damanges overlapped memory data if destination address is smaller than source address.

---

 common/image.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
common/image.c +12 -2
index b75a5ce..e691a51 100644
@@ -485,12 +485,22 @@ void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
 		return;
 
 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+	if (to > from) {
+		from += len;
+		to += len;
+	}
 	while (len > 0) {
 		size_t tail = (len > chunksz) ? chunksz : len;
 		WATCHDOG_RESET();
+		if (to > from) {
+			to -= tail;
+			from -= tail;
+		}
 		memmove(to, from, tail);
-		to += tail;
-		from += tail;
+		if (to < from) {
+			to += tail;
+			from += tail;
+		}
 		len -= tail;
 	}
 #else	/* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 memmove_wd: copy chunk down from big address if parameter to is larger than from

Quoted 11 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

When watchdog is enabled, memmove_wd() always copy chunk up from small address. This damanges overlapped memory data if destination address is smaller than source address.

---

 common/image.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
#2 lore raw
In reply to Sonic Zhang
Quoted 8 lines · Sonic Zhang

From: Sonic Zhang <[email protected]>

When watchdog is enabled, memmove_wd() always copy chunk up from small address. This damanges overlapped memory data if destination address is smaller than source address.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20150107/6bc8d713/attachment.pgp>