From: Silvio Cesare Date: Fri, 4 May 2018 03:44:02 +0000 (+1000) Subject: UBIFS: Fix potential integer overflow in allocation X-Git-Tag: v4.9.111~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=da05be555697c3fdd3f1507b59917c1cc3b03566;p=platform%2Fkernel%2Flinux-amlogic.git UBIFS: Fix potential integer overflow in allocation commit 353748a359f1821ee934afc579cf04572406b420 upstream. There is potential for the size and len fields in ubifs_data_node to be too large causing either a negative value for the length fields or an integer overflow leading to an incorrect memory allocation. Likewise, when the len field is small, an integer underflow may occur. Signed-off-by: Silvio Cesare Fixes: 1e51764a3c2ac ("UBIFS: add new flash file system") Cc: stable@vger.kernel.org Signed-off-by: Kees Cook Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index 7d764e3..504658f 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c @@ -1265,7 +1265,7 @@ static int recomp_data_node(const struct ubifs_info *c, int err, len, compr_type, out_len; out_len = le32_to_cpu(dn->size); - buf = kmalloc(out_len * WORST_COMPR_FACTOR, GFP_NOFS); + buf = kmalloc_array(out_len, WORST_COMPR_FACTOR, GFP_NOFS); if (!buf) return -ENOMEM;