lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Fri, 19 Jan 2024 10:06:02 +0100
From: Markus Elfring <Markus.Elfring@....de>
To: Kunwu Chan <chentao@...inos.cn>, linux-amlogic@...ts.infradead.org,
 linux-arm-kernel@...ts.infradead.org, kernel-janitors@...r.kernel.org,
 Jerome Brunet <jbrunet@...libre.com>, Kevin Hilman <khilman@...libre.com>,
 Martin Blumenstingl <martin.blumenstingl@...glemail.com>,
 Neil Armstrong <neil.armstrong@...aro.org>
Cc: LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] meson-mx-socinfo: Fix possible null-pointer dereference
 issues in meson_mx_socinfo_init

> In meson_mx_socinfo_revision, kasprintf() returns a pointer
> to dynamically allocated memory which can be NULL upon failure.
>
> Similarly, the kstrdup_const in the meson_mx_socinfo_soc_id
> returns a null pointer when it fails. Ensure the allocation was successful
> by checking the pointer validity. Avoid null pointer dereference issues.

Would you like to add the tag “Fixes” for the completion of the error handling
in this function implementation?


…
> +++ b/drivers/soc/amlogic/meson-mx-socinfo.c
> @@ -160,6 +160,12 @@ static int __init meson_mx_socinfo_init(void)
>  							   metal_rev);
>  	soc_dev_attr->soc_id = meson_mx_socinfo_soc_id(major_ver, metal_rev);
>
> +	if (!soc_dev_attr->revision || !soc_dev_attr->soc_id) {

I suggest to split such a check for null pointers.


> +		kfree_const(soc_dev_attr->revision);
> +		kfree_const(soc_dev_attr->soc_id);
> +		kfree(soc_dev_attr);
> +		return -ENOMEM;
> +	}
>  	soc_dev = soc_device_register(soc_dev_attr);
>  	if (IS_ERR(soc_dev)) {
>  		kfree_const(soc_dev_attr->revision);

Please use a goto chain for better exception handling.
https://wiki.sei.cmu.edu/confluence/display/c/MEM12-C.+Consider+using+a+goto+chain+when+leaving+a+function+on+error+when+using+and+releasing+resources

Regards,
Markus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ