Unchecked kmalloc() calls
From: Oliver Henning
Date: Wed Apr 03 2019 - 08:08:19 EST
Hello
I have written a Python script to scan the kernel for unchecked kmalloc() calls. It found the following instances. I checked them manually, too. I would like to fix them myself but I do not how to do a proper failure handling. So maybe someone else can have a look.
Oliver
drivers/net/wireless/rsi/rsi_91x_mac80211.c:199
ÂÂÂÂ ÂÂÂ ÂÂÂ channels = kmalloc(sizeof(rsi_2ghz_channels), GFP_KERNEL);
ÂÂÂÂ ÂÂÂ ÂÂÂ memcpy(channels,
ÂÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂÂÂÂ rsi_2ghz_channels,
ÂÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂÂÂÂ sizeof(rsi_2ghz_channels));
---
drivers/net/wireless/rsi/rsi_91x_mac80211.c:208
ÂÂÂÂ ÂÂÂ ÂÂÂ channels = kmalloc(sizeof(rsi_5ghz_channels), GFP_KERNEL);
ÂÂÂÂ ÂÂÂ ÂÂÂ memcpy(channels,
ÂÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂÂÂÂ rsi_5ghz_channels,
ÂÂÂÂ ÂÂÂ ÂÂÂ ÂÂÂÂÂÂ sizeof(rsi_5ghz_channels));
---
arch/mips/pmcs-msp71xx/msp_prom.c:378
ÂÂÂÂÂÂÂÂÂ argv = kmalloc(len, GFP_KERNEL);
ÂÂÂÂÂÂÂÂÂ ptr = (char *) &argv[prom_argc + 1];ÂÂÂ /* strings follow array */
ÂÂÂÂ
ÂÂÂÂÂÂÂÂÂ for (argc = 0; argc < prom_argc; argc++) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ argv[argc] = ptr;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ strcpy(ptr, prom_argv[argc]);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ptr += strlen(prom_argv[argc]) + 1;
ÂÂÂÂÂÂÂÂÂ }
---
arch/mips/pmcs-msp71xx/msp_prom.c:399
ÂÂÂÂÂÂÂÂÂ envp = kmalloc(len, GFP_KERNEL);
ÂÂÂÂÂÂÂÂÂ ptr = (char *) &envp[i+1];
ÂÂÂÂ
ÂÂÂÂÂÂÂÂÂ for (argc = 0; argc < i; argc++) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ envp[argc] = ptr;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ strcpy(ptr, prom_envp[argc]);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ptr += strlen(prom_envp[argc]) + 1;
ÂÂÂÂÂÂÂÂÂ }
---
arch/powerpc/platforms/pseries/dlpar.c:389
ÂÂÂÂÂÂÂÂÂ hp_errlog_copy = kmalloc(sizeof(struct pseries_hp_errorlog),
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
ÂÂÂÂÂÂÂÂÂ memcpy(hp_errlog_copy, hp_errlog, sizeof(struct pseries_hp_errorlog));
---
drivers/media/pci/cx23885/cx23885-dvb.c:1477
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ fe0->dvb.frontend->sec_priv = kmalloc(sizeof(dib7000p_ops), GFP_KERNEL);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ memcpy(fe0->dvb.frontend->sec_priv, &dib7000p_ops, sizeof(dib7000p_ops));
---
/mnt/hgfs/Projekte/linux-master (1)/linux-master/drivers/misc/lkdtm/perms.c:135
ÂÂÂÂÂÂÂÂÂ u32 *kmalloc_area = kmalloc(EXEC_SIZE, GFP_KERNEL);
ÂÂÂÂÂÂÂÂÂ execute_location(kmalloc_area, CODE_WRITE);
ÂÂÂÂÂÂÂÂÂ kfree(kmalloc_area);
ÂÂÂÂ }
---
/mnt/hgfs/Projekte/linux-master (1)/linux-master/drivers/gpu/drm/omapdrm/dss/omapdss-boot-init.c:113
ÂÂÂÂÂÂÂÂÂ new_compat = kmalloc(new_len, GFP_KERNEL);
ÂÂÂÂ
ÂÂÂÂÂÂÂÂÂ omapdss_prefix_strcpy(new_compat, new_len, prop->value, prop->length);
ÂÂÂÂ
ÂÂÂÂÂÂÂÂÂ omapdss_update_prop(node, new_compat, new_len);
ÂÂÂÂ }
---
/mnt/hgfs/Projekte/linux-master (1)/linux-master/drivers/staging/media/davinci_vpfe/dm365_ipipe.c:1267
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ params = kmalloc(sizeof(struct ipipe_module_params),
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ to = (void *)params + module_if->param_offset;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ size = module_if->param_size;
ÂÂÂÂ
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (to && from && size) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (copy_from_user(to, (void __user *)from, size)) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ rval = -EFAULT;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ break;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ }
---
/mnt/hgfs/Projekte/linux-master (1)/linux-master/drivers/staging/media/davinci_vpfe/dm365_ipipe.c:1309
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ params = kmalloc(sizeof(struct ipipe_module_params),
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ GFP_KERNEL);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from = (void *)params + module_if->param_offset;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ size = module_if->param_size;
ÂÂÂÂ
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (to && from && size) {
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ rval = module_if->get(ipipe, from);
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (rval)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ goto error;
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (copy_to_user((void __user *)to, from, size)) {
---