Skip to contentSkip to conversation

net: tftp: Fix tftp store address check in store_block()

PATCH RESEND Superseded Bin Meng 2 participants 4 messages Nov 16, 2019 – Dec 2, 2019 Networking

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH RESEND 1/1 net: tftp: Fix tftp store address check in store_block()

During testing of qemu-riscv32 with a 2GiB memory configuration, tftp always fails with a error message:

Load address: 0x84000000
Loading: #
TFTP error: trying to overwrite reserved memory...

It turns out the result of 'tftp_load_addr + tftp_load_size' just overflows (0x100000000) and the test logic in store_block() fails. Fix this by adjusting the end address to ULONG_MAX when overflow is detected.

Fixes a156c47e39ad ("tftp: prevent overwriting reserved memory")

---

 net/tftp.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/tftp.c +6 -1
index 5a69bca..1e3c18a 100644
@@ -171,8 +171,13 @@ static inline int store_block(int block, uchar *src, unsigned int len)
 		void *ptr;
 
 #ifdef CONFIG_LMB
+		ulong end_addr = tftp_load_addr + tftp_load_size;
+
+		if (!end_addr)
+			end_addr = ULONG_MAX;
+
 		if (store_addr < tftp_load_addr ||
-		    store_addr + len > tftp_load_addr + tftp_load_size) {
+		    store_addr + len > end_addr) {
 			puts("\nTFTP error: ");
 			puts("trying to overwrite reserved memory...\n");
 			return -1;
Signature · 1 line
2.7.4
#1 lore raw

PATCH RESEND 1/1 net: tftp: Fix tftp store address check in store_block()

Quoted 8 lines · Bin Meng

During testing of qemu-riscv32 with a 2GiB memory configuration, tftp always fails with a error message:

Load address: 0x84000000
Loading: #
TFTP error: trying to overwrite reserved memory...

Quoted 7 lines

It turns out the result of 'tftp_load_addr + tftp_load_size' just overflows (0x100000000) and the test logic in store_block() fails. Fix this by adjusting the end address to ULONG_MAX when overflow is detected.

Fixes a156c47e39ad ("tftp: prevent overwriting reserved memory")

Odd corner case, but sure...

author
#2 lore raw

PATCH RESEND 1/1 net: tftp: Fix tftp store address check in store_block()

Hi Joe,

Quoted 15 lines · Joe Hershberger
Quoted 13 lines · Bin Meng

During testing of qemu-riscv32 with a 2GiB memory configuration, tftp always fails with a error message:

Load address: 0x84000000
Loading: #
TFTP error: trying to overwrite reserved memory...

It turns out the result of 'tftp_load_addr + tftp_load_size' just overflows (0x100000000) and the test logic in store_block() fails. Fix this by adjusting the end address to ULONG_MAX when overflow is detected.

Quoted 6 lines
Quoted 2 lines
Fixes a156c47e39ad ("tftp: prevent overwriting reserved memory")

Odd corner case, but sure...

Could you pull this for v2020.01? thanks!

Regards,
Bin

#3 lore raw

PATCH RESEND 1/1 net: tftp: Fix tftp store address check in store_block()

Hi Bin,

Quoted 19 lines · Bin Meng

Hi Joe,

Quoted 15 lines · Joe Hershberger
Quoted 13 lines · Bin Meng

During testing of qemu-riscv32 with a 2GiB memory configuration, tftp always fails with a error message:

Load address: 0x84000000
Loading: #
TFTP error: trying to overwrite reserved memory...

It turns out the result of 'tftp_load_addr + tftp_load_size' just overflows (0x100000000) and the test logic in store_block() fails. Fix this by adjusting the end address to ULONG_MAX when overflow is detected.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Fixes a156c47e39ad ("tftp: prevent overwriting reserved memory")

Odd corner case, but sure...

Could you pull this for v2020.01? thanks!

Yep, working on it!

I'm currently looking for the patches that are causing sizes to expand beyond linking on a few targets.

Cheers,
-Joe