mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arto Merilainen <amerilainen@nvidia.com>
To: <thierry.reding@gmail.com>, <airlied@linux.ie>,
	<linux-tegra@vger.kernel.org>, <dri-devel@lists.freedesktop.org>
Cc: <tbergstrom@nvidia.com>, <linux-kernel@vger.kernel.org>,
	Arto Merilainen <amerilainen@nvidia.com>
Subject: [PATCHv2 2/7] gpu: host1x: Check reloc table before usage
Date: Wed, 29 May 2013 13:26:03 +0300	[thread overview]
Message-ID: <1369823168-5396-3-git-send-email-amerilainen@nvidia.com> (raw)
In-Reply-To: <1369823168-5396-1-git-send-email-amerilainen@nvidia.com>

The firewall assumed that the user space always delivers a relocation
table when it is accessing address registers. If userspace did not
deliver a relocation table and tried to access the address registers,
the code performed bad memory accesses.

This patch modifies the firewall to check correctly that the firewall
table is available before accessing it. In addition, check_reloc() is
converted to use boolean return value (true when the reloc is valid,
false when invalid).

Signed-off-by: Arto Merilainen <amerilainen@nvidia.com>
---
 drivers/gpu/host1x/job.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
index 2974ac8..83804fd 100644
--- a/drivers/gpu/host1x/job.c
+++ b/drivers/gpu/host1x/job.c
@@ -268,15 +268,15 @@ static unsigned int do_relocs(struct host1x_job *job, struct host1x_bo *cmdbuf)
 	return 0;
 }
 
-static int check_reloc(struct host1x_reloc *reloc, struct host1x_bo *cmdbuf,
+static bool check_reloc(struct host1x_reloc *reloc, struct host1x_bo *cmdbuf,
 		       unsigned int offset)
 {
 	offset *= sizeof(u32);
 
 	if (reloc->cmdbuf != cmdbuf || reloc->cmdbuf_offset != offset)
-		return -EINVAL;
+		return false;
 
-	return 0;
+	return true;
 }
 
 struct host1x_firewall {
@@ -307,10 +307,10 @@ static int check_mask(struct host1x_firewall *fw)
 
 		if (mask & 1) {
 			if (fw->job->is_addr_reg(fw->dev, fw->class, reg)) {
-				bool bad_reloc = check_reloc(fw->reloc,
-							     fw->cmdbuf_id,
-							     fw->offset);
-				if (!fw->num_relocs || bad_reloc)
+				if (!fw->num_relocs)
+					return -EINVAL;
+				if (!check_reloc(fw->reloc, fw->cmdbuf_id,
+						 fw->offset))
 					return -EINVAL;
 				fw->reloc++;
 				fw->num_relocs--;
@@ -335,9 +335,9 @@ static int check_incr(struct host1x_firewall *fw)
 			return -EINVAL;
 
 		if (fw->job->is_addr_reg(fw->dev, fw->class, reg)) {
-			bool bad_reloc = check_reloc(fw->reloc, fw->cmdbuf_id,
-						     fw->offset);
-			if (!fw->num_relocs || bad_reloc)
+			if (!fw->num_relocs)
+				return -EINVAL;
+			if (!check_reloc(fw->reloc, fw->cmdbuf_id, fw->offset))
 				return -EINVAL;
 			fw->reloc++;
 			fw->num_relocs--;
@@ -361,9 +361,9 @@ static int check_nonincr(struct host1x_firewall *fw)
 			return -EINVAL;
 
 		if (is_addr_reg) {
-			bool bad_reloc = check_reloc(fw->reloc, fw->cmdbuf_id,
-						     fw->offset);
-			if (!fw->num_relocs || bad_reloc)
+			if (!fw->num_relocs)
+				return -EINVAL;
+			if (!check_reloc(fw->reloc, fw->cmdbuf_id, fw->offset))
 				return -EINVAL;
 			fw->reloc++;
 			fw->num_relocs--;
-- 
1.8.1.5


  parent reply	other threads:[~2013-05-29 10:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29 10:26 [PATCHv2 0/7] Miscellaneous fixes to host1x Arto Merilainen
2013-05-29 10:26 ` [PATCHv2 1/7] gpu: host1x: Check INCR opcode correctly Arto Merilainen
2013-05-29 10:26 ` Arto Merilainen [this message]
2013-05-29 10:26 ` [PATCHv2 3/7] gpu: host1x: Don't reset firewall between gathers Arto Merilainen
2013-05-29 11:21   ` Thierry Reding
2013-05-29 11:29     ` Arto Merilainen
2013-05-29 10:26 ` [PATCHv2 4/7] gpu: host1x: Copy gathers before verification Arto Merilainen
2013-05-29 10:26 ` [PATCHv2 5/7] gpu: host1x: Fix memory access in syncpt request Arto Merilainen
2013-05-29 10:26 ` [PATCHv2 6/7] gpu: host1x: Fix client_managed type Arto Merilainen
2013-05-29 10:26 ` [PATCHv2 7/7] gpu: host1x: Rework CPU syncpoint increment Arto Merilainen
2013-05-29 11:24 ` [PATCHv2 0/7] Miscellaneous fixes to host1x Thierry Reding
2013-05-31  7:03 ` Terje Bergström

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=1369823168-5396-3-git-send-email-amerilainen@nvidia.com \
    --to=amerilainen@nvidia.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=tbergstrom@nvidia.com \
    --cc=thierry.reding@gmail.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: 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

Powered by JetHome