public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] pstore: Avoid size casts for 842 compression
@ 2018-03-06 23:18 Kees Cook
  0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2018-03-06 23:18 UTC (permalink / raw)
  To: Geliang Tang; +Cc: linux-kernel, Anton Vorontsov, Colin Cross, Tony Luck

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>
---
 fs/pstore/platform.c | 18 ++++++++++++++----
 1 file 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 = {
 static int compress_842(const void *in, void *out, size_t inlen, size_t outlen)
 {
 	int ret;
+	unsigned int size;
 
-	ret = sw842_compress(in, inlen, out, (unsigned int *)&outlen, workspace);
+	if (outlen > UINT_MAX)
+		return -EIO;
+	size = outlen;
+
+	ret = sw842_compress(in, inlen, out, &size, workspace);
 	if (ret) {
 		pr_err("sw842_compress error; compression failed!\n");
 		return ret;
 	}
 
-	return outlen;
+	return size;
 }
 
 static int decompress_842(void *in, void *out, size_t inlen, size_t outlen)
 {
 	int ret;
+	unsigned int size;
 
-	ret = sw842_decompress(in, inlen, out, (unsigned int *)&outlen);
+	if (outlen > UINT_MAX)
+		return -EIO;
+	size = outlen;
+
+	ret = sw842_decompress(in, inlen, out, &size);
 	if (ret) {
 		pr_err("sw842_decompress error, ret = %d!\n", ret);
 		return ret;
 	}
 
-	return outlen;
+	return size;
 }
 
 static void allocate_842(void)
-- 
2.7.4


-- 
Kees Cook
Pixel Security

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-03-06 23:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-06 23:18 [PATCH -next] pstore: Avoid size casts for 842 compression Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox