Skip to content

Commit 353748a

Browse files
silviocesarekees
authored andcommitted
UBIFS: Fix potential integer overflow in allocation
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 <[email protected]> Fixes: 1e51764 ("UBIFS: add new flash file system") Cc: [email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent f3278e3 commit 353748a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/ubifs/journal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,10 +1282,11 @@ static int truncate_data_node(const struct ubifs_info *c, const struct inode *in
12821282
int *new_len)
12831283
{
12841284
void *buf;
1285-
int err, dlen, compr_type, out_len, old_dlen;
1285+
int err, compr_type;
1286+
u32 dlen, out_len, old_dlen;
12861287

12871288
out_len = le32_to_cpu(dn->size);
1288-
buf = kmalloc(out_len * WORST_COMPR_FACTOR, GFP_NOFS);
1289+
buf = kmalloc_array(out_len, WORST_COMPR_FACTOR, GFP_NOFS);
12891290
if (!buf)
12901291
return -ENOMEM;
12911292

0 commit comments

Comments
 (0)