aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2018-03-06 18:15:24 -0500
committerKees Cook <keescook@chromium.org>2018-03-06 18:15:24 -0500
commit555974068ee533e8e0c6093ec7ca1682057aa4c1 (patch)
tree63a9acedb92849eeb0fa21f4fb9d3bb498b1b509
parent239b716199d9aff0d09444b0086e23aacd6bd445 (diff)
pstore: Avoid size casts for 842 compression
Instead of casting, make sure we don't end up with giant values and just perform regular assignments with unsigned int instead of re-cast size_t. Signed-off-by: Kees Cook <keescook@chromium.org>
-rw-r--r--fs/pstore/platform.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 19aaefeb052f..df54dd87598a 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -452,27 +452,37 @@ static const struct pstore_zbackend backend_lz4hc = {
452static int compress_842(const void *in, void *out, size_t inlen, size_t outlen) 452static int compress_842(const void *in, void *out, size_t inlen, size_t outlen)
453{ 453{
454 int ret; 454 int ret;
455 unsigned int size;
455 456
456 ret = sw842_compress(in, inlen, out, (unsigned int *)&outlen, workspace); 457 if (outlen > UINT_MAX)
458 return -EIO;
459 size = outlen;
460
461 ret = sw842_compress(in, inlen, out, &size, workspace);
457 if (ret) { 462 if (ret) {
458 pr_err("sw842_compress error; compression failed!\n"); 463 pr_err("sw842_compress error; compression failed!\n");
459 return ret; 464 return ret;
460 } 465 }
461 466
462 return outlen; 467 return size;
463} 468}
464 469
465static int decompress_842(void *in, void *out, size_t inlen, size_t outlen) 470static int decompress_842(void *in, void *out, size_t inlen, size_t outlen)
466{ 471{
467 int ret; 472 int ret;
473 unsigned int size;
468 474
469 ret = sw842_decompress(in, inlen, out, (unsigned int *)&outlen); 475 if (outlen > UINT_MAX)
476 return -EIO;
477 size = outlen;
478
479 ret = sw842_decompress(in, inlen, out, &size);
470 if (ret) { 480 if (ret) {
471 pr_err("sw842_decompress error, ret = %d!\n", ret); 481 pr_err("sw842_decompress error, ret = %d!\n", ret);
472 return ret; 482 return ret;
473 } 483 }
474 484
475 return outlen; 485 return size;
476} 486}
477 487
478static void allocate_842(void) 488static void allocate_842(void)