Merge patch series "fix integer overflows in filesystem code"
This series from Timo tp Preißl <t.preissl@proton.me> fixes some (potential) interger overflows in some filesystems by using __builtin_XXX_overflow helps to catch issues. Link: https://lore.kernel.org/r/20260109112428.262793-1-t.preissl@proton.me
This commit is contained in:
@@ -108,7 +108,13 @@ int ext4fs_get_bgdtable(void)
|
||||
{
|
||||
int status;
|
||||
struct ext_filesystem *fs = get_fs();
|
||||
int gdsize_total = ROUND(fs->no_blkgrp * fs->gdsize, fs->blksz);
|
||||
size_t alloc;
|
||||
size_t gdsize_total;
|
||||
|
||||
if (__builtin_mul_overflow(fs->no_blkgrp, fs->gdsize, &alloc))
|
||||
return -1;
|
||||
|
||||
gdsize_total = ROUND(alloc, fs->blksz);
|
||||
fs->no_blk_pergdt = gdsize_total / fs->blksz;
|
||||
|
||||
/* allocate memory for gdtable */
|
||||
|
||||
16
fs/fs.c
16
fs/fs.c
@@ -1059,15 +1059,25 @@ int do_mv(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
|
||||
*/
|
||||
if (dirs) {
|
||||
char *src_name = strrchr(src, '/');
|
||||
int dst_len;
|
||||
|
||||
if (src_name)
|
||||
src_name += 1;
|
||||
else
|
||||
src_name = src;
|
||||
|
||||
dst_len = strlen(dst);
|
||||
new_dst = calloc(1, dst_len + strlen(src_name) + 2);
|
||||
size_t dst_len = strlen(dst);
|
||||
size_t src_len = strlen(src_name);
|
||||
size_t total;
|
||||
|
||||
if (__builtin_add_overflow(dst_len, src_len, &total) ||
|
||||
__builtin_add_overflow(total, 2, &total)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
new_dst = calloc(1, total);
|
||||
if (!new_dst)
|
||||
return 0;
|
||||
|
||||
strcpy(new_dst, dst);
|
||||
|
||||
/* If there is already a trailing slash, don't add another */
|
||||
|
||||
@@ -255,10 +255,14 @@ static char *sqfs_concat_tokens(char **token_list, int token_count)
|
||||
{
|
||||
char *result;
|
||||
int i, length = 0, offset = 0;
|
||||
size_t alloc;
|
||||
|
||||
length = sqfs_get_tokens_length(token_list, token_count);
|
||||
|
||||
result = malloc(length + 1);
|
||||
if (__builtin_add_overflow(length, 1, &alloc))
|
||||
return 0;
|
||||
|
||||
result = malloc(alloc);
|
||||
if (!result)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -1617,6 +1617,7 @@ zfs_nvlist_lookup_nvlist(char *nvlist, char *name)
|
||||
char *ret;
|
||||
size_t size;
|
||||
int found;
|
||||
size_t alloc;
|
||||
|
||||
found = nvlist_find_value(nvlist, name, DATA_TYPE_NVLIST, &nvpair,
|
||||
&size, 0);
|
||||
@@ -1627,7 +1628,10 @@ zfs_nvlist_lookup_nvlist(char *nvlist, char *name)
|
||||
* nvlist to hold the encoding method, and two zero uint32's after the
|
||||
* nvlist as the NULL terminator.
|
||||
*/
|
||||
ret = calloc(1, size + 3 * sizeof(uint32_t));
|
||||
if (__builtin_add_overflow(size, 3 * sizeof(uint32_t), &alloc))
|
||||
return 0;
|
||||
|
||||
ret = calloc(1, alloc);
|
||||
if (!ret)
|
||||
return 0;
|
||||
memcpy(ret, nvlist, sizeof(uint32_t));
|
||||
|
||||
Reference in New Issue
Block a user