Skip to contentSkip to conversation

drm/nouveau: do not allow negative sizes for now

DISCUSSION Dave Jones 1 participant 1 message Jul 30, 2013 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Dave Jones

author
#1 lore raw
Quoted 23 lines · Linux Kernel
Gitweb:     http://git.kernel.org/linus/;a=commit;h=0108bc808107b97e101b15af9705729626be6447
Commit:     0108bc808107b97e101b15af9705729626be6447
Author:     Maarten Lankhorst <[email protected]>
AuthorDate: Sun Jul 7 10:40:19 2013 +0200
Committer:  Ben Skeggs <[email protected]>
CommitDate: Wed Jul 10 10:48:07 2013 +1000

drm/nouveau: do not allow negative sizes for now

The API allows up to 64-bits allocations, but size is handled as int inside nouveau almost everywhere. Until this is fixed it's better to prevent negative sizes.

The 256 kB before INT_MAX is paranoia, because of the large page aligning below that could flip it above INT_MAX.

drivers/gpu/drm/nouveau/nouveau_bo.c +0 -0
index 459a445..4e7ee5f 100644
@@ -198,6 +198,12 @@ nouveau_bo_new(struct drm_device *dev, int size, int align,
 	size_t acc_size;
 	int ret;

drivers/gpu/drm/nouveau/nouveau_bo.c nouveau_bo_new(struct drm_device *dev, int size, int align, · line 209

Quoted 10 lines
drivers/gpu/drm/nouveau/nouveau_bo.c +6 -0
 	int type = ttm_bo_type_device;
+	int max_size = INT_MAX & ~((1 << drm->client.base.vm->vmm->lpg_shift) - 1);
+
+	if (size <= 0 || size > max_size) {
+		nv_warn(drm, "skipped size %x\n", (u32)size);
+		return -EINVAL;
+	}
 
 	if (sg)
 		type = ttm_bo_type_sg;

A few more lines down..

222 if (drm->client.base.vm) {
223 if (!(flags & TTM_PL_FLAG_TT) && size > 256 * 1024)

Which implies we may now be dereferencing NULL in some situations. Either the check needs moving higher, or removing.

Can we get here with a NULL client.base.vm ?

Dave