mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kamal Mostafa <kamal@canonical.com>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	kernel-team@lists.ubuntu.com
Cc: "Christian König" <christian.koenig@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Kamal Mostafa" <kamal@canonical.com>
Subject: [PATCH 3.19.y-ckt 75/92] drm/radeon: make VCE handle check more strict
Date: Tue, 26 May 2015 08:41:19 -0700	[thread overview]
Message-ID: <1432654896-28478-76-git-send-email-kamal@canonical.com> (raw)
In-Reply-To: <1432654896-28478-1-git-send-email-kamal@canonical.com>

3.19.8-ckt1 -stable review patch.  If anyone has any objections, please let me know.

------------------

From: =?UTF-8?q?Christian=20K=C3=B6nig?= <christian.koenig@amd.com>

commit 29c63fe22a17c64e54016040cd882481bd45ee5a upstream.

Invalid handles can crash the hw.

Signed-off-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 drivers/gpu/drm/radeon/radeon_vce.c | 65 +++++++++++++++++++++++++++----------
 1 file changed, 48 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_vce.c b/drivers/gpu/drm/radeon/radeon_vce.c
index 976fe43..7ed5612 100644
--- a/drivers/gpu/drm/radeon/radeon_vce.c
+++ b/drivers/gpu/drm/radeon/radeon_vce.c
@@ -493,18 +493,27 @@ int radeon_vce_cs_reloc(struct radeon_cs_parser *p, int lo, int hi,
  *
  * @p: parser context
  * @handle: handle to validate
+ * @allocated: allocated a new handle?
  *
  * Validates the handle and return the found session index or -EINVAL
  * we we don't have another free session index.
  */
-int radeon_vce_validate_handle(struct radeon_cs_parser *p, uint32_t handle)
+static int radeon_vce_validate_handle(struct radeon_cs_parser *p,
+				      uint32_t handle, bool *allocated)
 {
 	unsigned i;
 
+	*allocated = false;
+
 	/* validate the handle */
 	for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i) {
-		if (atomic_read(&p->rdev->vce.handles[i]) == handle)
+		if (atomic_read(&p->rdev->vce.handles[i]) == handle) {
+			if (p->rdev->vce.filp[i] != p->filp) {
+				DRM_ERROR("VCE handle collision detected!\n");
+				return -EINVAL;
+			}
 			return i;
+		}
 	}
 
 	/* handle not found try to alloc a new one */
@@ -512,6 +521,7 @@ int radeon_vce_validate_handle(struct radeon_cs_parser *p, uint32_t handle)
 		if (!atomic_cmpxchg(&p->rdev->vce.handles[i], 0, handle)) {
 			p->rdev->vce.filp[i] = p->filp;
 			p->rdev->vce.img_size[i] = 0;
+			*allocated = true;
 			return i;
 		}
 	}
@@ -529,10 +539,10 @@ int radeon_vce_validate_handle(struct radeon_cs_parser *p, uint32_t handle)
 int radeon_vce_cs_parse(struct radeon_cs_parser *p)
 {
 	int session_idx = -1;
-	bool destroyed = false;
+	bool destroyed = false, created = false, allocated = false;
 	uint32_t tmp, handle = 0;
 	uint32_t *size = &tmp;
-	int i, r;
+	int i, r = 0;
 
 	while (p->idx < p->chunk_ib->length_dw) {
 		uint32_t len = radeon_get_ib_value(p, p->idx);
@@ -540,18 +550,21 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
 
 		if ((len < 8) || (len & 3)) {
 			DRM_ERROR("invalid VCE command length (%d)!\n", len);
-                	return -EINVAL;
+			r = -EINVAL;
+			goto out;
 		}
 
 		if (destroyed) {
 			DRM_ERROR("No other command allowed after destroy!\n");
-			return -EINVAL;
+			r = -EINVAL;
+			goto out;
 		}
 
 		switch (cmd) {
 		case 0x00000001: // session
 			handle = radeon_get_ib_value(p, p->idx + 2);
-			session_idx = radeon_vce_validate_handle(p, handle);
+			session_idx = radeon_vce_validate_handle(p, handle,
+								 &allocated);
 			if (session_idx < 0)
 				return session_idx;
 			size = &p->rdev->vce.img_size[session_idx];
@@ -561,6 +574,13 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
 			break;
 
 		case 0x01000001: // create
+			created = true;
+			if (!allocated) {
+				DRM_ERROR("Handle already in use!\n");
+				r = -EINVAL;
+				goto out;
+			}
+
 			*size = radeon_get_ib_value(p, p->idx + 8) *
 				radeon_get_ib_value(p, p->idx + 10) *
 				8 * 3 / 2;
@@ -577,12 +597,12 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
 			r = radeon_vce_cs_reloc(p, p->idx + 10, p->idx + 9,
 						*size);
 			if (r)
-				return r;
+				goto out;
 
 			r = radeon_vce_cs_reloc(p, p->idx + 12, p->idx + 11,
 						*size / 3);
 			if (r)
-				return r;
+				goto out;
 			break;
 
 		case 0x02000001: // destroy
@@ -593,7 +613,7 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
 			r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2,
 						*size * 2);
 			if (r)
-				return r;
+				goto out;
 			break;
 
 		case 0x05000004: // video bitstream buffer
@@ -601,36 +621,47 @@ int radeon_vce_cs_parse(struct radeon_cs_parser *p)
 			r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2,
 						tmp);
 			if (r)
-				return r;
+				goto out;
 			break;
 
 		case 0x05000005: // feedback buffer
 			r = radeon_vce_cs_reloc(p, p->idx + 3, p->idx + 2,
 						4096);
 			if (r)
-				return r;
+				goto out;
 			break;
 
 		default:
 			DRM_ERROR("invalid VCE command (0x%x)!\n", cmd);
-			return -EINVAL;
+			r = -EINVAL;
+			goto out;
 		}
 
 		if (session_idx == -1) {
 			DRM_ERROR("no session command at start of IB\n");
-			return -EINVAL;
+			r = -EINVAL;
+			goto out;
 		}
 
 		p->idx += len / 4;
 	}
 
-	if (destroyed) {
-		/* IB contains a destroy msg, free the handle */
+	if (allocated && !created) {
+		DRM_ERROR("New session without create command!\n");
+		r = -ENOENT;
+	}
+
+out:
+	if ((!r && destroyed) || (r && allocated)) {
+		/*
+		 * IB contains a destroy msg or we have allocated an
+		 * handle and got an error, anyway free the handle
+		 */
 		for (i = 0; i < RADEON_MAX_VCE_HANDLES; ++i)
 			atomic_cmpxchg(&p->rdev->vce.handles[i], handle, 0);
 	}
 
-	return 0;
+	return r;
 }
 
 /**
-- 
1.9.1


  parent reply	other threads:[~2015-05-26 15:51 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-26 15:40 [3.19.y-ckt stable] Linux 3.19.8-ckt1 stable review Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 01/92] ext4: allocate entire range in zero range Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 02/92] x86/microcode/intel: Guard against stack overflow in the loader Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 03/92] ASoC: tfa9879: Fix return value check in tfa9879_i2c_probe() Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 04/92] ASoC: samsung: s3c24xx-i2s: Fix return value check in s3c24xx_iis_dev_probe() Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 05/92] ASoC: dapm: Enable autodisable on SOC_DAPM_SINGLE_TLV_AUTODISABLE Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 06/92] ASoC: rt5677: add register patch for PLL Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 07/92] btrfs: unlock i_mutex after attempting to delete subvolume during send Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 08/92] ALSA: hda - Fix mute-LED fixed mode Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 09/92] ALSA: hda - Add mute-LED mode control to Thinkpad Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 10/92] arm64: dma-mapping: always clear allocated buffers Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 11/92] ALSA: emu10k1: Fix card shortname string buffer overflow Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 12/92] ALSA: emux: Fix mutex deadlock at unloading Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 13/92] drm/radeon: Use drm_calloc_ab for CS relocs Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 14/92] drm/radeon: adjust pll when audio is not enabled Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 15/92] drm/radeon: add SI DPM quirk for Sapphire R9 270 Dual-X 2G GDDR5 Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 16/92] drm/radeon: fix lockup when BOs aren't part of the VM on release Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 17/92] drm/radeon: reset BOs address after clearing it Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 18/92] drm/radeon: check new address before removing old one Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 19/92] SCSI: add 1024 max sectors black list flag Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 20/92] 3w-sas: fix command completion race Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 21/92] 3w-xxxx: " Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 22/92] 3w-9xxx: " Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 23/92] uas: Allow uas_use_uas_driver to return usb-storage flags Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 24/92] uas: Add US_FL_MAX_SECTORS_240 flag Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 25/92] uas: Set max_sectors_240 quirk for ASM1053 devices Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 26/92] usb: chipidea: otg: remove mutex unlock and lock while stop and start role Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 27/92] cdc-acm: prevent infinite loop when parsing CDC headers Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 28/92] serial: xilinx: Use platform_get_irq to get irq description structure Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 29/92] serial: of-serial: Remove device_type = "serial" registration Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 30/92] tty/serial: at91: maxburst was missing for dma transfers Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 31/92] ALSA: emux: Fix mutex deadlock in OSS emulation Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 32/92] ACPI / SBS: Enable battery manager when present Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 33/92] ALSA: emu10k1: Emu10k2 32 bit DMA mode Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 34/92] ASoC: rt5677: fixed wrong DMIC ref clock Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 35/92] rbd: end I/O the entire obj_request on error Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 36/92] ext4: fix data corruption caused by unwritten and delayed extents Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 37/92] ext4: move check under lock scope to close a race Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 38/92] powerpc/pseries: Correct cpu affinity for dlpar added cpus Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 39/92] powerpc/powernv: Restore non-volatile CRs after nap Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 40/92] efivarfs: Ensure VariableName is NUL-terminated Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 41/92] x86/efi: Store upper bits of command line buffer address in ext_cmd_line_ptr Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 42/92] blk-mq: fix race between timeout and CPU hotplug Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 43/92] blk-mq: fix CPU hotplug handling Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 44/92] writeback: use |1 instead of +1 to protect against div by zero Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 45/92] ARM: mvebu: armada-xp-openblocks-ax3-4: Disable internal RTC Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 46/92] ARM: dts: imx23-olinuxino: Fix polarity of LED GPIO Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 47/92] ARM: dts: imx23-olinuxino: Fix dr_mode of usb0 Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 48/92] ARM: dts: imx6: phyFLEX: USB VBUS control is active-high Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 49/92] ARM: dts: imx25: Add #pwm-cells to pwm4 Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 50/92] ARM: dts: imx28: Fix AUART4 TX-DMA interrupt name Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 51/92] [media] marvell-ccic: fix Y'CbCr ordering Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 52/92] gpio: sysfs: fix memory leaks and device hotplug Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 53/92] ACPI / SBS: Add 5 us delay to fix SBS hangs on MacBook Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 54/92] ACPI / PNP: add two IDs to list for PNPACPI device enumeration Kamal Mostafa
2015-05-26 15:40 ` [PATCH 3.19.y-ckt 55/92] ARM: OMAP2+: Fix omap off idle power consumption creeping up Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 56/92] ARM: dts: OMAP3-N900: Add microphone bias voltages Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 57/92] drm/radeon: disable semaphores for UVD V1 (v2) Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 58/92] x86/spinlocks: Fix regression in spinlock contention detection Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 59/92] RDMA/CMA: Canonize IPv4 on IPV6 sockets properly Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 60/92] drm/i915: Assume dual channel LVDS if pixel clock necessitates it Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 61/92] drm/i915: Add missing MacBook Pro models with dual channel LVDS Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 62/92] efi: Fix error handling in add_sysfs_runtime_map_entry() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 63/92] Revert "dm crypt: fix deadlock when async crypto algorithm returns -EBUSY" Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 64/92] xen/events: Clear cpu_evtchn_mask before resuming Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 65/92] xen/xenbus: Update xenbus event channel on resume Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 66/92] xen/console: Update console " Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 67/92] xen/events: Set irq_info->evtchn before binding the channel to CPU in __startup_pirq() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 68/92] mm/memory-failure: call shake_page() when error hits thp tail page Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 69/92] mm: soft-offline: fix num_poisoned_pages counting on concurrent events Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 70/92] nilfs2: fix sanity check of btree level in nilfs_btree_root_broken() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 71/92] ocfs2: dlm: fix race between purge and get lock resource Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 72/92] drm/i915/dp: there is no audio on port A Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 73/92] drm/amdkfd: allow unregister process with queues Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 74/92] drm/radeon: fix userptr BO unpin bug v3 Kamal Mostafa
2015-05-26 15:41 ` Kamal Mostafa [this message]
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 76/92] drm/radeon: make UVD handle checking more strict Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 77/92] drm/radeon: more strictly validate the UVD codec Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 78/92] path_openat(): fix double fput() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 79/92] mnt: Fix fs_fully_visible to verify the root directory is visible Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 80/92] drm: Zero out invalid vblank timestamp in drm_update_vblank_count Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 81/92] ARM: ux500: Move GPIO regulator for SD-card into board DTSs Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 82/92] ARM: ux500: Enable GPIO regulator for SD-card for HREF boards Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 83/92] ARM: ux500: Enable GPIO regulator for SD-card for snowball Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 84/92] xen-pciback: Add name prefix to global 'permissive' variable Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 85/92] mmc: core: add missing pm event in mmc_pm_notify to fix hib restore Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 86/92] ARM: dts: am57xx-beagle-x15: Fix IRQ type for mcp7941x Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 87/92] mmc: sh_mmcif: Fix timeout value for command request Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 88/92] mmc: card: Don't access RPMB partitions for normal read/write Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 89/92] pinctrl: Don't just pretend to protect pinctrl_maps, do it for real Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 90/92] arm64: add missing PAGE_ALIGN() to __dma_free() Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 91/92] vhost/scsi: potential memory corruption Kamal Mostafa
2015-05-26 15:41 ` [PATCH 3.19.y-ckt 92/92] md/raid0: fix restore to sector variable in raid0_make_request Kamal Mostafa

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=1432654896-28478-76-git-send-email-kamal@canonical.com \
    --to=kamal@canonical.com \
    --cc=alexander.deucher@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=kernel-team@lists.ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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

all inboxes | Powered by JetHome®