X86 platform drivers
 help / color / mirror / Atom feed
* [PATCH 5.15.y] platform/x86: panasonic-laptop: Fix SINF array out of bounds accesses
@ 2024-10-11 17:55 Sherry Yang
  2024-10-11 21:40 ` Harshit Mogalapalli
  0 siblings, 1 reply; 3+ messages in thread
From: Sherry Yang @ 2024-10-11 17:55 UTC (permalink / raw)
  To: stable, sashal, gregkh
  Cc: kenneth.t.chan, hdegoede, mgross, xi.wang, mjg,
	platform-driver-x86, sherry.yang

From: Hans de Goede <hdegoede@redhat.com>

commit f52e98d16e9bd7dd2b3aef8e38db5cbc9899d6a4 upstream.

The panasonic laptop code in various places uses the SINF array with index
values of 0 - SINF_CUR_BRIGHT(0x0d) without checking that the SINF array
is big enough.

Not all panasonic laptops have this many SINF array entries, for example
the Toughbook CF-18 model only has 10 SINF array entries. So it only
supports the AC+DC brightness entries and mute.

Check that the SINF array has a minimum size which covers all AC+DC
brightness entries and refuse to load if the SINF array is smaller.

For higher SINF indexes hide the sysfs attributes when the SINF array
does not contain an entry for that attribute, avoiding show()/store()
accessing the array out of bounds and add bounds checking to the probe()
and resume() code accessing these.

Fixes: e424fb8cc4e6 ("panasonic-laptop: avoid overflow in acpi_pcc_hotkey_add()")
Cc: stable@vger.kernel.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20240909113227.254470-1-hdegoede@redhat.com
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[Sherry: clean cherry-pick backport, fix CVE-2024-46859]
Signed-off-by: Sherry Yang <sherry.yang@oracle.com>
---
 drivers/platform/x86/panasonic-laptop.c | 49 ++++++++++++++++++++-----
 1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/drivers/platform/x86/panasonic-laptop.c b/drivers/platform/x86/panasonic-laptop.c
index 7ca49b3fc6c2..b06382dcecf7 100644
--- a/drivers/platform/x86/panasonic-laptop.c
+++ b/drivers/platform/x86/panasonic-laptop.c
@@ -773,6 +773,24 @@ static DEVICE_ATTR_RW(dc_brightness);
 static DEVICE_ATTR_RW(current_brightness);
 static DEVICE_ATTR_RW(cdpower);
 
+static umode_t pcc_sysfs_is_visible(struct kobject *kobj, struct attribute *attr, int idx)
+{
+	struct device *dev = kobj_to_dev(kobj);
+	struct acpi_device *acpi = to_acpi_device(dev);
+	struct pcc_acpi *pcc = acpi_driver_data(acpi);
+
+	if (attr == &dev_attr_mute.attr)
+		return (pcc->num_sifr > SINF_MUTE) ? attr->mode : 0;
+
+	if (attr == &dev_attr_eco_mode.attr)
+		return (pcc->num_sifr > SINF_ECO_MODE) ? attr->mode : 0;
+
+	if (attr == &dev_attr_current_brightness.attr)
+		return (pcc->num_sifr > SINF_CUR_BRIGHT) ? attr->mode : 0;
+
+	return attr->mode;
+}
+
 static struct attribute *pcc_sysfs_entries[] = {
 	&dev_attr_numbatt.attr,
 	&dev_attr_lcdtype.attr,
@@ -787,8 +805,9 @@ static struct attribute *pcc_sysfs_entries[] = {
 };
 
 static const struct attribute_group pcc_attr_group = {
-	.name	= NULL,		/* put in device directory */
-	.attrs	= pcc_sysfs_entries,
+	.name		= NULL,		/* put in device directory */
+	.attrs		= pcc_sysfs_entries,
+	.is_visible	= pcc_sysfs_is_visible,
 };
 
 
@@ -941,12 +960,15 @@ static int acpi_pcc_hotkey_resume(struct device *dev)
 	if (!pcc)
 		return -EINVAL;
 
-	acpi_pcc_write_sset(pcc, SINF_MUTE, pcc->mute);
-	acpi_pcc_write_sset(pcc, SINF_ECO_MODE, pcc->eco_mode);
+	if (pcc->num_sifr > SINF_MUTE)
+		acpi_pcc_write_sset(pcc, SINF_MUTE, pcc->mute);
+	if (pcc->num_sifr > SINF_ECO_MODE)
+		acpi_pcc_write_sset(pcc, SINF_ECO_MODE, pcc->eco_mode);
 	acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, pcc->sticky_key);
 	acpi_pcc_write_sset(pcc, SINF_AC_CUR_BRIGHT, pcc->ac_brightness);
 	acpi_pcc_write_sset(pcc, SINF_DC_CUR_BRIGHT, pcc->dc_brightness);
-	acpi_pcc_write_sset(pcc, SINF_CUR_BRIGHT, pcc->current_brightness);
+	if (pcc->num_sifr > SINF_CUR_BRIGHT)
+		acpi_pcc_write_sset(pcc, SINF_CUR_BRIGHT, pcc->current_brightness);
 
 	return 0;
 }
@@ -963,8 +985,12 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
 
 	num_sifr = acpi_pcc_get_sqty(device);
 
-	if (num_sifr < 0 || num_sifr > 255) {
-		pr_err("num_sifr out of range");
+	/*
+	 * pcc->sinf is expected to at least have the AC+DC brightness entries.
+	 * Accesses to higher SINF entries are checked against num_sifr.
+	 */
+	if (num_sifr <= SINF_DC_CUR_BRIGHT || num_sifr > 255) {
+		pr_err("num_sifr %d out of range %d - 255\n", num_sifr, SINF_DC_CUR_BRIGHT + 1);
 		return -ENODEV;
 	}
 
@@ -1016,11 +1042,14 @@ static int acpi_pcc_hotkey_add(struct acpi_device *device)
 	acpi_pcc_write_sset(pcc, SINF_STICKY_KEY, 0);
 	pcc->sticky_key = 0;
 
-	pcc->eco_mode = pcc->sinf[SINF_ECO_MODE];
-	pcc->mute = pcc->sinf[SINF_MUTE];
 	pcc->ac_brightness = pcc->sinf[SINF_AC_CUR_BRIGHT];
 	pcc->dc_brightness = pcc->sinf[SINF_DC_CUR_BRIGHT];
-	pcc->current_brightness = pcc->sinf[SINF_CUR_BRIGHT];
+	if (pcc->num_sifr > SINF_MUTE)
+		pcc->mute = pcc->sinf[SINF_MUTE];
+	if (pcc->num_sifr > SINF_ECO_MODE)
+		pcc->eco_mode = pcc->sinf[SINF_ECO_MODE];
+	if (pcc->num_sifr > SINF_CUR_BRIGHT)
+		pcc->current_brightness = pcc->sinf[SINF_CUR_BRIGHT];
 
 	/* add sysfs attributes */
 	result = sysfs_create_group(&device->dev.kobj, &pcc_attr_group);
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 5.15.y] platform/x86: panasonic-laptop: Fix SINF array out of bounds accesses
  2024-10-11 17:55 [PATCH 5.15.y] platform/x86: panasonic-laptop: Fix SINF array out of bounds accesses Sherry Yang
@ 2024-10-11 21:40 ` Harshit Mogalapalli
  2024-10-11 22:28   ` Sherry Yang
  0 siblings, 1 reply; 3+ messages in thread
From: Harshit Mogalapalli @ 2024-10-11 21:40 UTC (permalink / raw)
  To: Sherry Yang, stable, sashal, gregkh
  Cc: kenneth.t.chan, hdegoede, mgross, xi.wang, mjg,
	platform-driver-x86, Vegard Nossum

Hi Sherry,

On 11/10/24 23:25, Sherry Yang wrote:
> From: Hans de Goede <hdegoede@redhat.com>
> 
> commit f52e98d16e9bd7dd2b3aef8e38db5cbc9899d6a4 upstream.
...

> 
> Fixes: e424fb8cc4e6 ("panasonic-laptop: avoid overflow in acpi_pcc_hotkey_add()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> Link: https://lore.kernel.org/r/20240909113227.254470-1-hdegoede@redhat.com
> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> [Sherry: clean cherry-pick backport, fix CVE-2024-46859]

If this is a clean cherry-pick and has a CC:stable, I think it would be 
queued by stable maintainers.

I just checked the queue and it is already there:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree/queue-5.15

Patch in the stable-queue: 
https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree/queue-5.15/platform-x86-panasonic-laptop-fix-sinf-array-out-of-bounds-accesses.patch

I generally check the stable-queue if it is a clean cherry-pick and has 
a Cc:stable tag in it.(Also absence of "FAILED patch" for 5.15.y on lore)


Thanks,
Harshit
> Signed-off-by: Sherry Yang <sherry.yang@oracle.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 5.15.y] platform/x86: panasonic-laptop: Fix SINF array out of bounds accesses
  2024-10-11 21:40 ` Harshit Mogalapalli
@ 2024-10-11 22:28   ` Sherry Yang
  0 siblings, 0 replies; 3+ messages in thread
From: Sherry Yang @ 2024-10-11 22:28 UTC (permalink / raw)
  To: Harshit Mogalapalli
  Cc: linux-stable, sashal@kernel.org, Greg KH,
	kenneth.t.chan@gmail.com, hdegoede@redhat.com,
	mgross@linux.intel.com, xi.wang@gmail.com, mjg@redhat.com,
	platform-driver-x86@vger.kernel.org, Vegard Nossum

Hi Harshit,

> On Oct 11, 2024, at 2:40 PM, Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com> wrote:
> 
> Hi Sherry,
> 
> On 11/10/24 23:25, Sherry Yang wrote:
>> From: Hans de Goede <hdegoede@redhat.com>
>> commit f52e98d16e9bd7dd2b3aef8e38db5cbc9899d6a4 upstream.
> ...
> 
>> Fixes: e424fb8cc4e6 ("panasonic-laptop: avoid overflow in acpi_pcc_hotkey_add()")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> Link: https://lore.kernel.org/r/20240909113227.254470-1-hdegoede@redhat.com
>> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> [Sherry: clean cherry-pick backport, fix CVE-2024-46859]
> 
> If this is a clean cherry-pick and has a CC:stable, I think it would be queued by stable maintainers.
> 
> I just checked the queue and it is already there:
> https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree/queue-5.15
> 
> Patch in the stable-queue: https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree/queue-5.15/platform-x86-panasonic-laptop-fix-sinf-array-out-of-bounds-accesses.patch
> 
> I generally check the stable-queue if it is a clean cherry-pick and has a Cc:stable tag in it.(Also absence of "FAILED patch" for 5.15.y on lore)

Very detail instruction, good to know it. Will check there next time.

Thanks,
Sherry

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-11 22:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-11 17:55 [PATCH 5.15.y] platform/x86: panasonic-laptop: Fix SINF array out of bounds accesses Sherry Yang
2024-10-11 21:40 ` Harshit Mogalapalli
2024-10-11 22:28   ` Sherry Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox