From: Zhou Qingyang <zhou1615@umn.edu> To: zhou1615@umn.edu Cc: kjlu@umn.edu, Patrik Jakobsson <patrik.r.jakobsson@gmail.com>, David Airlie <airlied@linux.ie>, Daniel Vetter <daniel@ffwll.ch>, Dave Airlie <airlied@redhat.com>, Alan Cox <alan@linux.intel.com>, Zhao Yakui <yakui.zhao@intel.com>, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] drm/gma500/cdv: Fix a wild pointer dereference in cdv_intel_dp_get_modes() Date: Wed, 1 Dec 2021 23:29:03 +0800 [thread overview] Message-ID: <20211201152904.182293-1-zhou1615@umn.edu> (raw) In-Reply-To: <YaZP2HzTQw1QJxOK@intel.com> In cdv_intel_dp_get_modes(), the third 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. Fixes: d112a8163f83 ("gma500/cdv: Add eDP support") Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> --- Changes in V2: - Instead of returning -ENOMEM, this patch returns 0 - Use DRM_DEBUG_KMS to report the failure of drm_mode_duplicate() drivers/gpu/drm/gma500/cdv_intel_dp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/gma500/cdv_intel_dp.c b/drivers/gpu/drm/gma500/cdv_intel_dp.c index ba6ad1466374..bf47db488b7b 100644 --- a/drivers/gpu/drm/gma500/cdv_intel_dp.c +++ b/drivers/gpu/drm/gma500/cdv_intel_dp.c @@ -1773,6 +1773,11 @@ static int cdv_intel_dp_get_modes(struct drm_connector *connector) if (intel_dp->panel_fixed_mode != NULL) { struct drm_display_mode *mode; mode = drm_mode_duplicate(dev, intel_dp->panel_fixed_mode); + if (!mode) { + DRM_DEBUG_KMS("Failure in drm_mode_duplicate()\n"); + return 0; + } + drm_mode_probed_add(connector, mode); return 1; } -- 2.25.1
WARNING: multiple messages have this Message-ID (diff)
From: Zhou Qingyang <zhou1615@umn.edu> To: zhou1615@umn.edu Cc: David Airlie <airlied@linux.ie>, kjlu@umn.edu, linux-kernel@vger.kernel.org, Zhao Yakui <yakui.zhao@intel.com>, dri-devel@lists.freedesktop.org, Dave Airlie <airlied@redhat.com>, Alan Cox <alan@linux.intel.com> Subject: [PATCH v2] drm/gma500/cdv: Fix a wild pointer dereference in cdv_intel_dp_get_modes() Date: Wed, 1 Dec 2021 23:29:03 +0800 [thread overview] Message-ID: <20211201152904.182293-1-zhou1615@umn.edu> (raw) In-Reply-To: <YaZP2HzTQw1QJxOK@intel.com> In cdv_intel_dp_get_modes(), the third 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. Fixes: d112a8163f83 ("gma500/cdv: Add eDP support") Signed-off-by: Zhou Qingyang <zhou1615@umn.edu> --- Changes in V2: - Instead of returning -ENOMEM, this patch returns 0 - Use DRM_DEBUG_KMS to report the failure of drm_mode_duplicate() drivers/gpu/drm/gma500/cdv_intel_dp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/gma500/cdv_intel_dp.c b/drivers/gpu/drm/gma500/cdv_intel_dp.c index ba6ad1466374..bf47db488b7b 100644 --- a/drivers/gpu/drm/gma500/cdv_intel_dp.c +++ b/drivers/gpu/drm/gma500/cdv_intel_dp.c @@ -1773,6 +1773,11 @@ static int cdv_intel_dp_get_modes(struct drm_connector *connector) if (intel_dp->panel_fixed_mode != NULL) { struct drm_display_mode *mode; mode = drm_mode_duplicate(dev, intel_dp->panel_fixed_mode); + if (!mode) { + DRM_DEBUG_KMS("Failure in drm_mode_duplicate()\n"); + return 0; + } + drm_mode_probed_add(connector, mode); return 1; } -- 2.25.1
next prev parent reply other threads:[~2021-12-01 15:29 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-30 13:23 [PATCH] drm/gma500/cdv: Fix a wild pointer dereference in cdv_intel_dp_get_modes() Zhou Qingyang 2021-11-30 13:23 ` Zhou Qingyang 2021-11-30 16:22 ` Ville Syrjälä 2021-11-30 16:22 ` Ville Syrjälä 2021-12-01 15:29 ` Zhou Qingyang [this message] 2021-12-01 15:29 ` [PATCH v2] " Zhou Qingyang 2021-12-01 15:57 ` Patrik Jakobsson 2021-12-01 15:57 ` Patrik Jakobsson
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211201152904.182293-1-zhou1615@umn.edu \ --to=zhou1615@umn.edu \ --cc=airlied@linux.ie \ --cc=airlied@redhat.com \ --cc=alan@linux.intel.com \ --cc=daniel@ffwll.ch \ --cc=dri-devel@lists.freedesktop.org \ --cc=kjlu@umn.edu \ --cc=linux-kernel@vger.kernel.org \ --cc=patrik.r.jakobsson@gmail.com \ --cc=yakui.zhao@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.