nouveau.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Zhou Qingyang <zhou1615@umn.edu>
To: zhou1615@umn.edu
Cc: David Airlie <airlied@linux.ie>,
	nouveau@lists.freedesktop.org, kjlu@umn.edu,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	Ben Skeggs <bskeggs@redhat.com>, Daniel Vetter <daniel@ffwll.ch>
Subject: [Nouveau] [PATCH] drm/nouveau/dispnv04: Fix a NULL pointer dereference in nv17_tv_get_ld_modes()
Date: Wed,  1 Dec 2021 23:45:48 +0800	[thread overview]
Message-ID: <20211201154550.186374-1-zhou1615@umn.edu> (raw)

In nv17_tv_get_ld_modes(), drm_mode_duplicate() is assigned to mode
and there is a dereference of it in nv17_tv_get_ld_modes(). which could
lead to a NULL pointer dereference on failure of
drm_mode_duplicate().

Fix this bug by adding a check of mode.

As the return value of .get_modes() can not be negative, this patch
does not directly return error code, but uses NV_INFO to report and
returns n.

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_NOUVEAU=m show no new warnings,
and our static analyzer no longer warns about this code.

Fixes: f24342375927 ("drm/nouveau: Break some long lines in the TV-out code.")
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
---
 drivers/gpu/drm/nouveau/dispnv04/tvnv17.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
index 6fe103fd60e9..598180a403ab 100644
--- a/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
+++ b/drivers/gpu/drm/nouveau/dispnv04/tvnv17.c
@@ -208,6 +208,11 @@ static int nv17_tv_get_ld_modes(struct drm_encoder *encoder,
 		struct drm_display_mode *mode;

 		mode = drm_mode_duplicate(encoder->dev, tv_mode);
+		if (!mode) {
+			NV_INFO(nouveau_drm(encoder->dev),
+				"failure in drm_mode_duplicate\n");
+			return n;
+		}

 		mode->clock = tv_norm->tv_enc_mode.vrefresh *
 			mode->htotal / 1000 *
-- 
2.25.1


                 reply	other threads:[~2021-12-03 20:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20211201154550.186374-1-zhou1615@umn.edu \
    --to=zhou1615@umn.edu \
    --cc=airlied@linux.ie \
    --cc=bskeggs@redhat.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).