* Re: drm/nouveau: do not allow negative sizes for now
[not found] <20130723230814.C82D766092E@gitolite.kernel.org>
@ 2013-07-30 0:21 ` Dave Jones
0 siblings, 0 replies; 2+ messages in thread
From: Dave Jones @ 2013-07-30 0:21 UTC (permalink / raw)
To: Linux Kernel Mailing List; +Cc: maarten.lankhorst, bskeggs
On Tue, Jul 23, 2013 at 11:08:14PM +0000, Linux Kernel wrote:
> Gitweb: http://git.kernel.org/linus/;a=commit;h=0108bc808107b97e101b15af9705729626be6447
> Commit: 0108bc808107b97e101b15af9705729626be6447
> Author: Maarten Lankhorst <maarten.lankhorst@canonical.com>
> AuthorDate: Sun Jul 7 10:40:19 2013 +0200
> Committer: Ben Skeggs <bskeggs@redhat.com>
> 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.
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
> index 459a445..4e7ee5f 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -198,6 +198,12 @@ nouveau_bo_new(struct drm_device *dev, int size, int align,
> size_t acc_size;
> int ret;
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* re: drm/nouveau: do not allow negative sizes for now
@ 2013-07-24 15:55 Dan Carpenter
0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2013-07-24 15:55 UTC (permalink / raw)
To: maarten.lankhorst; +Cc: dri-devel
Hello Maarten Lankhorst,
This is a semi-automatic email about new static checker warnings.
The patch 0108bc808107: "drm/nouveau: do not allow negative sizes for
now" from Jul 7, 2013, leads to the following Smatch complaint:
drivers/gpu/drm/nouveau/nouveau_bo.c:222 nouveau_bo_new()
warn: variable dereferenced before check 'drm->client.base.vm' (see line 201)
drivers/gpu/drm/nouveau/nouveau_bo.c
200 int type = ttm_bo_type_device;
201 int max_size = INT_MAX & ~((1 << drm->client.base.vm->vmm->lpg_shift) - 1);
^^^^^^^^^^^^^^^^^^^
New dereference.
202
203 if (size <= 0 || size > max_size) {
204 nv_warn(drm, "skipped size %x\n", (u32)size);
205 return -EINVAL;
206 }
207
208 if (sg)
209 type = ttm_bo_type_sg;
210
211 nvbo = kzalloc(sizeof(struct nouveau_bo), GFP_KERNEL);
212 if (!nvbo)
213 return -ENOMEM;
214 INIT_LIST_HEAD(&nvbo->head);
215 INIT_LIST_HEAD(&nvbo->entry);
216 INIT_LIST_HEAD(&nvbo->vma_list);
217 nvbo->tile_mode = tile_mode;
218 nvbo->tile_flags = tile_flags;
219 nvbo->bo.bdev = &drm->ttm.bdev;
220
221 nvbo->page_shift = 12;
222 if (drm->client.base.vm) {
^^^^^^^^^^^^^^^^^^^
Old check.
223 if (!(flags & TTM_PL_FLAG_TT) && size > 256 * 1024)
224 nvbo->page_shift = drm->client.base.vm->vmm->lpg_shift;
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-07-30 0:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20130723230814.C82D766092E@gitolite.kernel.org>
2013-07-30 0:21 ` drm/nouveau: do not allow negative sizes for now Dave Jones
2013-07-24 15:55 Dan Carpenter
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.