public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Kieran Bingham <kbingham@kernel.org>
To: niklas.soderlund@ragnatech.se
Cc: linux-renesas-soc@vger.kernel.org, linux-media@vger.kernel.org,
	Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Subject: [PATCH 1/2] rcar-vin: Verify pads on linkage
Date: Mon, 24 Apr 2017 19:13:47 +0100	[thread overview]
Message-ID: <1493057627-27881-1-git-send-email-kbingham@kernel.org> (raw)

From: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>

The current code determines the pad from the identifiers in the DTB.
This is accepted without bounds in the driver.

Invalid port/reg addresses defined in the DTB will cause a kernel panic
when dereferencing non-existing pads.

Protect the linkage with a check that the pad numbers are valid.

Signed-off-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
---
 drivers/media/platform/rcar-vin/rcar-core.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c
index 893018963847..48557628e76d 100644
--- a/drivers/media/platform/rcar-vin/rcar-core.c
+++ b/drivers/media/platform/rcar-vin/rcar-core.c
@@ -613,6 +613,18 @@ static int rvin_group_add_link(struct rvin_dev *vin,
 	struct media_pad *source_pad, *sink_pad;
 	int ret = 0;
 
+	if (source_idx >= source->num_pads) {
+		vin_err(vin, "Source pad idx %d is greater than pad count %d\n",
+			source_idx, source->num_pads);
+		return -EINVAL;
+	}
+
+	if (sink_idx >= sink->num_pads) {
+		vin_err(vin, "Sink pad idx %d is greater than pad count %d\n",
+			source_idx, source->num_pads);
+		return -EINVAL;
+	}
+
 	source_pad = &source->pads[source_idx];
 	sink_pad = &sink->pads[sink_idx];
 
-- 
2.7.4

                 reply	other threads:[~2017-04-24 18:13 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=1493057627-27881-1-git-send-email-kbingham@kernel.org \
    --to=kbingham@kernel.org \
    --cc=kieran.bingham+renesas@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund@ragnatech.se \
    /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