linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects
@ 2021-04-02  8:23 Takashi Iwai
  2021-04-07 16:34 ` [Intel-gfx] " Ville Syrjälä
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2021-04-02  8:23 UTC (permalink / raw)
  To: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi; +Cc: intel-gfx, linux-kernel

intel_dsm_platform_mux_info() tries to parse the ACPI package data
from _DSM for the debug information, but it assumes the fixed format
without checking what values are stored in the elements actually.
When an unexpected value is returned from BIOS, it may lead to GPF or
NULL dereference, as reported recently.

Add the checks of the contents in the returned values and skip the
values for invalid cases.

v1->v2: Check the info contents before dereferencing, too

BugLink: http://bugzilla.opensuse.org/show_bug.cgi?id=1184074
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 drivers/gpu/drm/i915/display/intel_acpi.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_acpi.c b/drivers/gpu/drm/i915/display/intel_acpi.c
index e21fb14d5e07..833d0c1be4f1 100644
--- a/drivers/gpu/drm/i915/display/intel_acpi.c
+++ b/drivers/gpu/drm/i915/display/intel_acpi.c
@@ -84,13 +84,31 @@ static void intel_dsm_platform_mux_info(acpi_handle dhandle)
 		return;
 	}
 
+	if (!pkg->package.count) {
+		DRM_DEBUG_DRIVER("no connection in _DSM\n");
+		return;
+	}
+
 	connector_count = &pkg->package.elements[0];
 	DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
 		  (unsigned long long)connector_count->integer.value);
 	for (i = 1; i < pkg->package.count; i++) {
 		union acpi_object *obj = &pkg->package.elements[i];
-		union acpi_object *connector_id = &obj->package.elements[0];
-		union acpi_object *info = &obj->package.elements[1];
+		union acpi_object *connector_id;
+		union acpi_object *info;
+
+		if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) {
+			DRM_DEBUG_DRIVER("Invalid object for MUX #%d\n", i);
+			continue;
+		}
+
+		connector_id = &obj->package.elements[0];
+		info = &obj->package.elements[1];
+		if (info->type != ACPI_TYPE_BUFFER || info->buffer.length < 4) {
+			DRM_DEBUG_DRIVER("Invalid info for MUX obj #%d\n", i);
+			continue;
+		}
+
 		DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
 			  (unsigned long long)connector_id->integer.value);
 		DRM_DEBUG_DRIVER("  port id: %s\n",
-- 
2.26.2


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

* Re: [Intel-gfx] [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects
  2021-04-02  8:23 [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects Takashi Iwai
@ 2021-04-07 16:34 ` Ville Syrjälä
  2021-04-07 16:56   ` Takashi Iwai
  0 siblings, 1 reply; 8+ messages in thread
From: Ville Syrjälä @ 2021-04-07 16:34 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, intel-gfx, linux-kernel

On Fri, Apr 02, 2021 at 10:23:17AM +0200, Takashi Iwai wrote:
> intel_dsm_platform_mux_info() tries to parse the ACPI package data
> from _DSM for the debug information, but it assumes the fixed format
> without checking what values are stored in the elements actually.
> When an unexpected value is returned from BIOS, it may lead to GPF or
> NULL dereference, as reported recently.
> 
> Add the checks of the contents in the returned values and skip the
> values for invalid cases.
> 
> v1->v2: Check the info contents before dereferencing, too
> 
> BugLink: http://bugzilla.opensuse.org/show_bug.cgi?id=1184074
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  drivers/gpu/drm/i915/display/intel_acpi.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_acpi.c b/drivers/gpu/drm/i915/display/intel_acpi.c
> index e21fb14d5e07..833d0c1be4f1 100644
> --- a/drivers/gpu/drm/i915/display/intel_acpi.c
> +++ b/drivers/gpu/drm/i915/display/intel_acpi.c
> @@ -84,13 +84,31 @@ static void intel_dsm_platform_mux_info(acpi_handle dhandle)
>  		return;
>  	}
>  
> +	if (!pkg->package.count) {
> +		DRM_DEBUG_DRIVER("no connection in _DSM\n");
> +		return;
> +	}
> +
>  	connector_count = &pkg->package.elements[0];
>  	DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
>  		  (unsigned long long)connector_count->integer.value);
>  	for (i = 1; i < pkg->package.count; i++) {
>  		union acpi_object *obj = &pkg->package.elements[i];
> -		union acpi_object *connector_id = &obj->package.elements[0];
> -		union acpi_object *info = &obj->package.elements[1];
> +		union acpi_object *connector_id;
> +		union acpi_object *info;
> +
> +		if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) {
> +			DRM_DEBUG_DRIVER("Invalid object for MUX #%d\n", i);
> +			continue;
> +		}
> +
> +		connector_id = &obj->package.elements[0];

You don't want to check connector_id->type as well?

> +		info = &obj->package.elements[1];
> +		if (info->type != ACPI_TYPE_BUFFER || info->buffer.length < 4) {
> +			DRM_DEBUG_DRIVER("Invalid info for MUX obj #%d\n", i);
> +			continue;
> +		}
> +
>  		DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
>  			  (unsigned long long)connector_id->integer.value);
>  		DRM_DEBUG_DRIVER("  port id: %s\n",
> -- 
> 2.26.2
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Ville Syrjälä
Intel

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

* Re: [Intel-gfx] [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects
  2021-04-07 16:34 ` [Intel-gfx] " Ville Syrjälä
@ 2021-04-07 16:56   ` Takashi Iwai
  2021-04-07 21:28     ` Ville Syrjälä
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2021-04-07 16:56 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, intel-gfx, linux-kernel

On Wed, 07 Apr 2021 18:34:46 +0200,
Ville Syrjälä wrote:
> 
> On Fri, Apr 02, 2021 at 10:23:17AM +0200, Takashi Iwai wrote:
> > intel_dsm_platform_mux_info() tries to parse the ACPI package data
> > from _DSM for the debug information, but it assumes the fixed format
> > without checking what values are stored in the elements actually.
> > When an unexpected value is returned from BIOS, it may lead to GPF or
> > NULL dereference, as reported recently.
> > 
> > Add the checks of the contents in the returned values and skip the
> > values for invalid cases.
> > 
> > v1->v2: Check the info contents before dereferencing, too
> > 
> > BugLink: http://bugzilla.opensuse.org/show_bug.cgi?id=1184074
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >  drivers/gpu/drm/i915/display/intel_acpi.c | 22 ++++++++++++++++++++--
> >  1 file changed, 20 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/display/intel_acpi.c b/drivers/gpu/drm/i915/display/intel_acpi.c
> > index e21fb14d5e07..833d0c1be4f1 100644
> > --- a/drivers/gpu/drm/i915/display/intel_acpi.c
> > +++ b/drivers/gpu/drm/i915/display/intel_acpi.c
> > @@ -84,13 +84,31 @@ static void intel_dsm_platform_mux_info(acpi_handle dhandle)
> >  		return;
> >  	}
> >  
> > +	if (!pkg->package.count) {
> > +		DRM_DEBUG_DRIVER("no connection in _DSM\n");
> > +		return;
> > +	}
> > +
> >  	connector_count = &pkg->package.elements[0];
> >  	DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
> >  		  (unsigned long long)connector_count->integer.value);
> >  	for (i = 1; i < pkg->package.count; i++) {
> >  		union acpi_object *obj = &pkg->package.elements[i];
> > -		union acpi_object *connector_id = &obj->package.elements[0];
> > -		union acpi_object *info = &obj->package.elements[1];
> > +		union acpi_object *connector_id;
> > +		union acpi_object *info;
> > +
> > +		if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) {
> > +			DRM_DEBUG_DRIVER("Invalid object for MUX #%d\n", i);
> > +			continue;
> > +		}
> > +
> > +		connector_id = &obj->package.elements[0];
> 
> You don't want to check connector_id->type as well?

I added only the minimal checks that may lead to Oops.


Takashi

> 
> > +		info = &obj->package.elements[1];
> > +		if (info->type != ACPI_TYPE_BUFFER || info->buffer.length < 4) {
> > +			DRM_DEBUG_DRIVER("Invalid info for MUX obj #%d\n", i);
> > +			continue;
> > +		}
> > +
> >  		DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
> >  			  (unsigned long long)connector_id->integer.value);
> >  		DRM_DEBUG_DRIVER("  port id: %s\n",
> > -- 
> > 2.26.2
> > 
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
> 
> -- 
> Ville Syrjälä
> Intel
> 

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

* Re: [Intel-gfx] [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects
  2021-04-07 16:56   ` Takashi Iwai
@ 2021-04-07 21:28     ` Ville Syrjälä
  2021-04-08  7:51       ` Takashi Iwai
  0 siblings, 1 reply; 8+ messages in thread
From: Ville Syrjälä @ 2021-04-07 21:28 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, intel-gfx, linux-kernel

On Wed, Apr 07, 2021 at 06:56:15PM +0200, Takashi Iwai wrote:
> On Wed, 07 Apr 2021 18:34:46 +0200,
> Ville Syrjälä wrote:
> > 
> > On Fri, Apr 02, 2021 at 10:23:17AM +0200, Takashi Iwai wrote:
> > > intel_dsm_platform_mux_info() tries to parse the ACPI package data
> > > from _DSM for the debug information, but it assumes the fixed format
> > > without checking what values are stored in the elements actually.
> > > When an unexpected value is returned from BIOS, it may lead to GPF or
> > > NULL dereference, as reported recently.
> > > 
> > > Add the checks of the contents in the returned values and skip the
> > > values for invalid cases.
> > > 
> > > v1->v2: Check the info contents before dereferencing, too
> > > 
> > > BugLink: http://bugzilla.opensuse.org/show_bug.cgi?id=1184074
> > > Cc: <stable@vger.kernel.org>
> > > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > > ---
> > >  drivers/gpu/drm/i915/display/intel_acpi.c | 22 ++++++++++++++++++++--
> > >  1 file changed, 20 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/i915/display/intel_acpi.c b/drivers/gpu/drm/i915/display/intel_acpi.c
> > > index e21fb14d5e07..833d0c1be4f1 100644
> > > --- a/drivers/gpu/drm/i915/display/intel_acpi.c
> > > +++ b/drivers/gpu/drm/i915/display/intel_acpi.c
> > > @@ -84,13 +84,31 @@ static void intel_dsm_platform_mux_info(acpi_handle dhandle)
> > >  		return;
> > >  	}
> > >  
> > > +	if (!pkg->package.count) {
> > > +		DRM_DEBUG_DRIVER("no connection in _DSM\n");
> > > +		return;
> > > +	}
> > > +
> > >  	connector_count = &pkg->package.elements[0];
> > >  	DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
> > >  		  (unsigned long long)connector_count->integer.value);
> > >  	for (i = 1; i < pkg->package.count; i++) {
> > >  		union acpi_object *obj = &pkg->package.elements[i];
> > > -		union acpi_object *connector_id = &obj->package.elements[0];
> > > -		union acpi_object *info = &obj->package.elements[1];
> > > +		union acpi_object *connector_id;
> > > +		union acpi_object *info;
> > > +
> > > +		if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) {
> > > +			DRM_DEBUG_DRIVER("Invalid object for MUX #%d\n", i);
> > > +			continue;
> > > +		}
> > > +
> > > +		connector_id = &obj->package.elements[0];
> > 
> > You don't want to check connector_id->type as well?
> 
> I added only the minimal checks that may lead to Oops.

OK. I guess misinterpreting something else as an integer isn't
particular dangerous in this case.

Pushed to drm-intel-next. Thanks.

Oh, could you ask the bug reporter to attach an acpidump to the
bug? Might be good to have that stuff on record somewhere if/when
someone wants to actually figure out what's going on here.

That said, maybe we should just nuke this whole thing instead?
Unless I'm missing someting this code doesn't seem to actually
do anything...

-- 
Ville Syrjälä
Intel

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

* Re: [Intel-gfx] [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects
  2021-04-07 21:28     ` Ville Syrjälä
@ 2021-04-08  7:51       ` Takashi Iwai
  2021-04-08 16:34         ` Takashi Iwai
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2021-04-08  7:51 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, intel-gfx, linux-kernel

On Wed, 07 Apr 2021 23:28:48 +0200,
Ville Syrjälä wrote:
> 
> On Wed, Apr 07, 2021 at 06:56:15PM +0200, Takashi Iwai wrote:
> > On Wed, 07 Apr 2021 18:34:46 +0200,
> > Ville Syrjälä wrote:
> > > 
> > > On Fri, Apr 02, 2021 at 10:23:17AM +0200, Takashi Iwai wrote:
> > > > intel_dsm_platform_mux_info() tries to parse the ACPI package data
> > > > from _DSM for the debug information, but it assumes the fixed format
> > > > without checking what values are stored in the elements actually.
> > > > When an unexpected value is returned from BIOS, it may lead to GPF or
> > > > NULL dereference, as reported recently.
> > > > 
> > > > Add the checks of the contents in the returned values and skip the
> > > > values for invalid cases.
> > > > 
> > > > v1->v2: Check the info contents before dereferencing, too
> > > > 
> > > > BugLink: http://bugzilla.opensuse.org/show_bug.cgi?id=1184074
> > > > Cc: <stable@vger.kernel.org>
> > > > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > > > ---
> > > >  drivers/gpu/drm/i915/display/intel_acpi.c | 22 ++++++++++++++++++++--
> > > >  1 file changed, 20 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/drivers/gpu/drm/i915/display/intel_acpi.c b/drivers/gpu/drm/i915/display/intel_acpi.c
> > > > index e21fb14d5e07..833d0c1be4f1 100644
> > > > --- a/drivers/gpu/drm/i915/display/intel_acpi.c
> > > > +++ b/drivers/gpu/drm/i915/display/intel_acpi.c
> > > > @@ -84,13 +84,31 @@ static void intel_dsm_platform_mux_info(acpi_handle dhandle)
> > > >  		return;
> > > >  	}
> > > >  
> > > > +	if (!pkg->package.count) {
> > > > +		DRM_DEBUG_DRIVER("no connection in _DSM\n");
> > > > +		return;
> > > > +	}
> > > > +
> > > >  	connector_count = &pkg->package.elements[0];
> > > >  	DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
> > > >  		  (unsigned long long)connector_count->integer.value);
> > > >  	for (i = 1; i < pkg->package.count; i++) {
> > > >  		union acpi_object *obj = &pkg->package.elements[i];
> > > > -		union acpi_object *connector_id = &obj->package.elements[0];
> > > > -		union acpi_object *info = &obj->package.elements[1];
> > > > +		union acpi_object *connector_id;
> > > > +		union acpi_object *info;
> > > > +
> > > > +		if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) {
> > > > +			DRM_DEBUG_DRIVER("Invalid object for MUX #%d\n", i);
> > > > +			continue;
> > > > +		}
> > > > +
> > > > +		connector_id = &obj->package.elements[0];
> > > 
> > > You don't want to check connector_id->type as well?
> > 
> > I added only the minimal checks that may lead to Oops.
> 
> OK. I guess misinterpreting something else as an integer isn't
> particular dangerous in this case.
> 
> Pushed to drm-intel-next. Thanks.

Great, thanks!

> Oh, could you ask the bug reporter to attach an acpidump to the
> bug? Might be good to have that stuff on record somewhere if/when
> someone wants to actually figure out what's going on here.

OK, I'll ask.

> That said, maybe we should just nuke this whole thing instead?
> Unless I'm missing someting this code doesn't seem to actually
> do anything...

Yeah, that looks nothing but showing the debug information and that
can be checked via acpidump output, too...


Takashi

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

* Re: [Intel-gfx] [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects
  2021-04-08  7:51       ` Takashi Iwai
@ 2021-04-08 16:34         ` Takashi Iwai
  2021-04-08 16:56           ` Ville Syrjälä
  0 siblings, 1 reply; 8+ messages in thread
From: Takashi Iwai @ 2021-04-08 16:34 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, intel-gfx, linux-kernel

On Thu, 08 Apr 2021 09:51:18 +0200,
Takashi Iwai wrote:
> 
> On Wed, 07 Apr 2021 23:28:48 +0200,
> Ville Syrjälä wrote:
> > 
> > Oh, could you ask the bug reporter to attach an acpidump to the
> > bug? Might be good to have that stuff on record somewhere if/when
> > someone wants to actually figure out what's going on here.
> 
> OK, I'll ask.

Available at
  acpidump: https://susepaste.org/59777448
  hwinfo: https://susepaste.org/86284020


thanks,

Takashi

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

* Re: [Intel-gfx] [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects
  2021-04-08 16:34         ` Takashi Iwai
@ 2021-04-08 16:56           ` Ville Syrjälä
  2021-04-08 17:29             ` Takashi Iwai
  0 siblings, 1 reply; 8+ messages in thread
From: Ville Syrjälä @ 2021-04-08 16:56 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, intel-gfx, linux-kernel

On Thu, Apr 08, 2021 at 06:34:06PM +0200, Takashi Iwai wrote:
> On Thu, 08 Apr 2021 09:51:18 +0200,
> Takashi Iwai wrote:
> > 
> > On Wed, 07 Apr 2021 23:28:48 +0200,
> > Ville Syrjälä wrote:
> > > 
> > > Oh, could you ask the bug reporter to attach an acpidump to the
> > > bug? Might be good to have that stuff on record somewhere if/when
> > > someone wants to actually figure out what's going on here.
> > 
> > OK, I'll ask.
> 
> Available at
>   acpidump: https://susepaste.org/59777448
>   hwinfo: https://susepaste.org/86284020

Those will apparently expire real soon. I took local copies out
of morbid curiosity, but that's not going to help anyone else 
in the future. I rather wish bug reporting tools would flat out
refuse to accept any pastebin links.

-- 
Ville Syrjälä
Intel

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

* Re: [Intel-gfx] [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects
  2021-04-08 16:56           ` Ville Syrjälä
@ 2021-04-08 17:29             ` Takashi Iwai
  0 siblings, 0 replies; 8+ messages in thread
From: Takashi Iwai @ 2021-04-08 17:29 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: Jani Nikula, Joonas Lahtinen, Rodrigo Vivi, intel-gfx, linux-kernel

On Thu, 08 Apr 2021 18:56:06 +0200,
Ville Syrjälä wrote:
> 
> On Thu, Apr 08, 2021 at 06:34:06PM +0200, Takashi Iwai wrote:
> > On Thu, 08 Apr 2021 09:51:18 +0200,
> > Takashi Iwai wrote:
> > > 
> > > On Wed, 07 Apr 2021 23:28:48 +0200,
> > > Ville Syrjälä wrote:
> > > > 
> > > > Oh, could you ask the bug reporter to attach an acpidump to the
> > > > bug? Might be good to have that stuff on record somewhere if/when
> > > > someone wants to actually figure out what's going on here.
> > > 
> > > OK, I'll ask.
> > 
> > Available at
> >   acpidump: https://susepaste.org/59777448
> >   hwinfo: https://susepaste.org/86284020
> 
> Those will apparently expire real soon. I took local copies out
> of morbid curiosity, but that's not going to help anyone else 
> in the future. I rather wish bug reporting tools would flat out
> refuse to accept any pastebin links.

Yeah, don't worry, I'll upload them to Bugzilla later in anyway.


Takashi

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

end of thread, other threads:[~2021-04-08 17:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-02  8:23 [PATCH v2] drm/i915: Fix invalid access to ACPI _DSM objects Takashi Iwai
2021-04-07 16:34 ` [Intel-gfx] " Ville Syrjälä
2021-04-07 16:56   ` Takashi Iwai
2021-04-07 21:28     ` Ville Syrjälä
2021-04-08  7:51       ` Takashi Iwai
2021-04-08 16:34         ` Takashi Iwai
2021-04-08 16:56           ` Ville Syrjälä
2021-04-08 17:29             ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).