mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Rashidwi <rashidwinter@gmail.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] uimage: fix CRC32 verification on NFS
Date: Wed,  2 Oct 2024 18:07:15 +0200	[thread overview]
Message-ID: <20241002160714.2423842-1-a.fatoum@pengutronix.de> (raw)

Reading a file over NFS is prone to return short reads as the file
content is split over multiple UDP packets and reads won't return
more than the number of bytes that have gathered in the FIFO.

The uImage verification code didn't account for this and handled neither
short reads or the file prematurely ending.

Address both to fix this unexpected result:

  uimage -v /mnt/nfs/uImage
  verifying data CRC... Bad Data CRC: 0x56474aa2 != 0x6b8f0a9c

  cp /mnt/nfs/uImage .
  uimage -v uImage
  verifying data CRC... ok

Fixes: 390249968c4e ("reimplement uImage code")
Closes: https://github.com/barebox/barebox/issues/28
Reported-by: Rashidwi <rashidwinter@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/uimage.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/common/uimage.c b/common/uimage.c
index 140a08c1e426..c578edae2606 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -272,7 +272,9 @@ int uimage_verify(struct uimage_handle *handle)
 		ret = read(handle->fd, buf, now);
 		if (ret < 0)
 			goto err;
-		crc = crc32(crc, buf, now);
+		if (!ret)
+			break;
+		crc = crc32(crc, buf, ret);
 		len -= ret;
 	}
 
-- 
2.39.5




             reply	other threads:[~2024-10-02 16:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-02 16:07 Ahmad Fatoum [this message]
2024-10-14 13:10 ` Sascha Hauer
2024-10-14 13:18   ` Ahmad Fatoum
2024-10-14 14:52     ` Sascha Hauer
2024-10-14 15:00       ` Ahmad Fatoum
2024-10-15  8:17 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241002160714.2423842-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=rashidwinter@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox