Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

tty: vcc: Add check for kstrdup() in vcc_probe()

Add check for the return value of kstrdup() and return the error, if it
fails in order to avoid NULL pointer dereference.

Signed-off-by: Yi Yang <yiyang13@huawei.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20230904035220.48164-1-yiyang13@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Yi Yang and committed by
Greg Kroah-Hartman
d81ffb87 30e94586

+13 -3
+13 -3
drivers/tty/vcc.c
··· 579 579 return -ENOMEM; 580 580 581 581 name = kstrdup(dev_name(&vdev->dev), GFP_KERNEL); 582 + if (!name) { 583 + rv = -ENOMEM; 584 + goto free_port; 585 + } 582 586 583 587 rv = vio_driver_init(&port->vio, vdev, VDEV_CONSOLE_CON, vcc_versions, 584 588 ARRAY_SIZE(vcc_versions), NULL, name); 585 589 if (rv) 586 - goto free_port; 590 + goto free_name; 587 591 588 592 port->vio.debug = vcc_dbg_vio; 589 593 vcc_ldc_cfg.debug = vcc_dbg_ldc; 590 594 591 595 rv = vio_ldc_alloc(&port->vio, &vcc_ldc_cfg, port); 592 596 if (rv) 593 - goto free_port; 597 + goto free_name; 594 598 595 599 spin_lock_init(&port->lock); 596 600 ··· 628 624 goto unreg_tty; 629 625 } 630 626 port->domain = kstrdup(domain, GFP_KERNEL); 627 + if (!port->domain) { 628 + rv = -ENOMEM; 629 + goto unreg_tty; 630 + } 631 + 631 632 632 633 mdesc_release(hp); 633 634 ··· 662 653 vcc_table_remove(port->index); 663 654 free_ldc: 664 655 vio_ldc_free(&port->vio); 665 - free_port: 656 + free_name: 666 657 kfree(name); 658 + free_port: 667 659 kfree(port); 668 660 669 661 return rv;