]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
ACPI: sysfs: Fix create_pnp_modalias() and create_of_modalias()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Mon, 23 Oct 2023 18:32:54 +0000 (20:32 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 09:27:33 +0000 (10:27 +0100)
commit20b9527ebe03396799fa17a6ec685eb23d173f0f
treea6e61cac7d560aee20f25d4a182d43c0e5037e19
parentb55f0a9f865be75ca1019aad331f3225f7b50ce8
ACPI: sysfs: Fix create_pnp_modalias() and create_of_modalias()

[ Upstream commit 48cf49d31994ff97b33c4044e618560ec84d35fb ]

snprintf() does not return negative values on error.

To know if the buffer was too small, the returned value needs to be
compared with the length of the passed buffer. If it is greater or
equal, the output has been truncated, so add checks for the truncation
to create_pnp_modalias() and create_of_modalias(). Also make them
return -ENOMEM in that case, as they already do that elsewhere.

Moreover, the remaining size of the buffer used by snprintf() needs to
be updated after the first write to avoid out-of-bounds access as
already done correctly in create_pnp_modalias(), but not in
create_of_modalias(), so change the latter accordingly.

Fixes: 8765c5ba1949 ("ACPI / scan: Rework modalias creation when "compatible" is present")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
[ rjw: Merge two patches into one, combine changelogs, add subject ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/acpi/device_sysfs.c