drm/gma500/psb_intel_lvds: Fix a wild pointer dereference in psb_intel_lvds_get_modes()
Subsystems (3)
PATCH 1/1 drm/gma500/psb_intel_lvds: Fix a wild pointer dereference in psb_intel_lvds_get_modes()
In psb_intel_lvds_get_modes(), the return value of drm_mode_duplicate() is assigned to mode and used in drm_mode_probed_add(). drm_mode_probed_add() passes mode->head to list_add_tail(). list_add_tail() will further call __list_add() and there is a dereference of mode->head in __list_add(), which could lead to a wild pointer dereference on failure of drm_mode_duplicate().
Fix this bug by adding a check of mode.
This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs.
Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug.
Builds with CONFIG_DRM_GMA500=m show no new warnings, and our static analyzer no longer warns about this code.
--- drivers/gpu/drm/gma500/psb_intel_lvds.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/gma500/psb_intel_lvds.c +3 -0
@@ -505,6 +505,9 @@ static int psb_intel_lvds_get_modes(struct drm_connector *connector)if (mode_dev->panel_fixed_mode !=NULL ) {struct drm_display_mode *mode =drm_mode_duplicate (dev, mode_dev->panel_fixed_mode); +if (!mode) +return -ENOMEM ; +drm_mode_probed_add (connector, mode);return 1 ; }
Signature · 1 line
2.25.1
Patrik Jakobsson
maintainerQuoted 34 lines · Zhou Qingyang
In
psb_intel_lvds_get_modes(), the return value ofdrm_mode_duplicate()is assigned to mode and used indrm_mode_probed_add().drm_mode_probed_add()passesmode->headtolist_add_tail().list_add_tail()will further call__list_add()and there is a dereference ofmode->headin__list_add(), which could lead to a wild pointer dereference on failure ofdrm_mode_duplicate().Fix this bug by adding a check of mode.
This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs.
Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug.
Builds with
CONFIG_DRM_GMA500=mshow no new warnings, and our static analyzer no longer warns about this code.Fixes 89c78134cc54 ("gma500: Add Poulsbo support")Signed-off-by Zhou Qingyang <[email protected]>--- drivers/gpu/drm/gma500/psb_intel_lvds.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/gma500/psb_intel_lvds.c +0
-0
drivers/gpu/drm/gma500/psb_intel_lvds.c static int psb_intel_lvds_get_modes(struct drm_connector *connector) · line 510
Quoted 6 lines
drivers/gpu/drm/gma500/psb_intel_lvds.c +3
-0@@ -505,6 +505,9 @@ static int psb_intel_lvds_get_modes(struct drm_connector *connector)if (mode_dev->panel_fixed_mode !=NULL ) {struct drm_display_mode *mode =drm_mode_duplicate (dev, mode_dev->panel_fixed_mode); +if (!mode) +return -ENOMEM ; +
Hi, Zhou.
psb_intel_lvds_get_modes() implements .get_modes in struct drm_connector_helper_funcs. It should return the number of added modes and not an error code.
-Patrik
Quoted 6 lines
drivers/gpu/drm/gma500/psb_intel_lvds.c +0
-1drm_mode_probed_add (connector, mode);return 1 ; } --2.25.1
PATCH v2 1/1 drm/gma500/psb_intel_lvds: Fix a wild pointer dereference in psb_intel_lvds_get_modes()
In psb_intel_lvds_get_modes(), the return value of drm_mode_duplicate() is assigned to mode and used in drm_mode_probed_add(). drm_mode_probed_add() passes mode->head to list_add_tail(). list_add_tail() will further call __list_add() and there is a dereference of mode->head in __list_add(), which could lead to a wild pointer dereference on failure of drm_mode_duplicate().
Fix this bug by adding a check of mode.
This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs.
Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug.
Builds with CONFIG_DRM_GMA500=m show no new warnings, and our static analyzer no longer warns about this code.
---
Changes in v2:
- Use dev_err and return 0 instead of returning error code.
drivers/gpu/drm/gma500/psb_intel_lvds.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/gma500/psb_intel_lvds.c +5 -0
@@ -505,6 +505,11 @@ static int psb_intel_lvds_get_modes(struct drm_connector *connector)if (mode_dev->panel_fixed_mode !=NULL ) {struct drm_display_mode *mode =drm_mode_duplicate (dev, mode_dev->panel_fixed_mode); +if (!mode) { +dev_err (dev->dev,"drm_mode_duplicate() allocation error\n" ); +return 0 ; + } +drm_mode_probed_add (connector, mode);return 1 ; }
Signature · 1 line
2.25.1