Commit e569cd17 authored by Dan Carpenter's avatar Dan Carpenter Committed by Chen Ridong
Browse files

thermal: core: prevent potential string overflow

stable inclusion
from stable-v5.10.201
commit 3f795fb35c2d8a637efe76b4518216c9319b998c
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/I9RFK5
CVE: CVE-2023-52868

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=3f795fb35c2d8a637efe76b4518216c9319b998c



--------------------------------

[ Upstream commit c99626092efca3061b387043d4a7399bf75fbdd5 ]

The dev->id value comes from ida_alloc() so it's a number between zero
and INT_MAX.  If it's too high then these sprintf()s will overflow.

Fixes: 5c14409183e3 ("the generic thermal sysfs driver")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarChen Ridong <chenridong@huawei.com>
parent 80ab23a8
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -733,7 +733,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
	if (result)
	if (result)
		goto release_ida;
		goto release_ida;


	sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
	snprintf(dev->attr_name, sizeof(dev->attr_name), "cdev%d_trip_point",
		 dev->id);
	sysfs_attr_init(&dev->attr.attr);
	sysfs_attr_init(&dev->attr.attr);
	dev->attr.attr.name = dev->attr_name;
	dev->attr.attr.name = dev->attr_name;
	dev->attr.attr.mode = 0444;
	dev->attr.attr.mode = 0444;
@@ -742,7 +743,8 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
	if (result)
	if (result)
		goto remove_symbol_link;
		goto remove_symbol_link;


	sprintf(dev->weight_attr_name, "cdev%d_weight", dev->id);
	snprintf(dev->weight_attr_name, sizeof(dev->weight_attr_name),
		 "cdev%d_weight", dev->id);
	sysfs_attr_init(&dev->weight_attr.attr);
	sysfs_attr_init(&dev->weight_attr.attr);
	dev->weight_attr.attr.name = dev->weight_attr_name;
	dev->weight_attr.attr.name = dev->weight_attr_name;
	dev->weight_attr.attr.mode = S_IWUSR | S_IRUGO;
	dev->weight_attr.attr.mode = S_IWUSR | S_IRUGO;