summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-06-11 20:42:39 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-07-05 16:17:12 +0200
commit2ceac684bd857826e7530fa704ed6276e87f5c62 (patch)
tree9ec36e6f631b0b8c68cb2240e01ccbab98fd098c
parent43902e57633f5dd9bc71f1a30d69d7bc0f49dc6b (diff)
downloadbarebox-2ceac684bd857826e7530fa704ed6276e87f5c62.tar.gz
barebox-2ceac684bd857826e7530fa704ed6276e87f5c62.tar.xz
digest: Drop usage of memmap
digest_file_window() first tries to memmap the file before it falls back to reading it. This is quite unnecessary, we can just always read. Moreover, memmapping a file has problems with the current code. A "md5sum foo" result in the filesize argument being MAX_LFS_FILESIZE. This is fine for files where the file is just read up to the end in this case, but for memmapped buffers this results in digesting MAX_LFS_FILESIZE bytes which is wrong. This problem is not apparent at the moment as there are only a few files which are memmappable, and on these (/dev/mem, /dev/ram0) digest commands are normally called with an explicit size argument. This changes once ramfs starts supporting memmap, so better drop memmapping in the digest code now. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--crypto/digest.c27
1 files changed, 1 insertions, 26 deletions
diff --git a/crypto/digest.c b/crypto/digest.c
index e67e8fba0d..d23245e15f 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -253,32 +253,12 @@ out_free:
return ret;
}
-static int digest_update_from_memory(struct digest *d,
- const unsigned char *buf,
- loff_t size)
-{
- while (size) {
- unsigned long now = min_t(typeof(size), PAGE_SIZE, size);
- int ret;
-
- ret = digest_update_interruptible(d, buf, now);
- if (ret)
- return ret;
-
- size -= now;
- buf += now;
- }
-
- return 0;
-}
-
int digest_file_window(struct digest *d, const char *filename,
unsigned char *hash,
const unsigned char *sig,
loff_t start, loff_t size)
{
int fd, ret;
- unsigned char *buf;
ret = digest_init(d);
if (ret)
@@ -290,12 +270,7 @@ int digest_file_window(struct digest *d, const char *filename,
return -errno;
}
- buf = memmap(fd, PROT_READ);
- if (buf == MAP_FAILED)
- ret = digest_update_from_fd(d, fd, start, size);
- else
- ret = digest_update_from_memory(d, buf + start, size);
-
+ ret = digest_update_from_fd(d, fd, start, size);
if (ret)
goto out;