drm/nouveau/secboot: remove VLA usage
Subsystems (3)
PATCH 1/1 drm/nouveau/secboot: remove VLA usage
In preparation to enabling -Wvla, remove VLA. In this particular case directly use macro NVKM_MSGQUEUE_CMDLINE_SIZE instead of local variable cmdline_size. Also, remove cmdline_size as it is not actually useful anymore.
The use of stack Variable Length Arrays needs to be avoided, as they can be a vector for stack exhaustion, which can be both a runtime bug or a security flaw. Also, in general, as code evolves it is easy to lose track of how big a VLA can get. Thus, we can end up having runtime failures that are hard to debug.
Also, fixed as part of the directive to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621
--- drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c +4 -4
@@ -80,12 +80,12 @@ acr_ls_msgqueue_post_run(struct nvkm_msgqueue *queue, struct nvkm_falcon *falcon, u32 addr_args) {struct nvkm_device *device = falcon->owner->device; -u32 cmdline_size =NVKM_MSGQUEUE_CMDLINE_SIZE ; -u8 buf[cmdline_size]; +u8 buf[NVKM_MSGQUEUE_CMDLINE_SIZE ]; -memset (buf,0 , cmdline_size); +memset (buf,0 ,NVKM_MSGQUEUE_CMDLINE_SIZE );nvkm_msgqueue_write_cmdline (queue, buf); -nvkm_falcon_load_dmem (falcon, buf, addr_args, cmdline_size,0 ); +nvkm_falcon_load_dmem (falcon, buf, addr_args, +NVKM_MSGQUEUE_CMDLINE_SIZE ,0 );/* rearm the queue so it will wait for the init message */ nvkm_msgqueue_reinit (queue);
Signature · 1 line
2.7.4
From: Gustavo A. R. Silva
Quoted 5 lines
Sent: 13 March 2018 14:48
In preparation to enabling -Wvla, remove VLA. In this particular case directly use macroNVKM_MSGQUEUE_CMDLINE_SIZEinstead of local variablecmdline_size. Also, removecmdline_sizeas it is not actually useful anymore.
...
Quoted 9 lines
drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c +0
-0@@ -80,12 +80,12 @@ acr_ls_msgqueue_post_run(struct nvkm_msgqueue *queue, struct nvkm_falcon *falcon, u32 addr_args) {struct nvkm_device *device = falcon->owner->device;
drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c acr_ls_msgqueue_post_run(struct nvkm_msgqueue *queue, · line 88
Quoted 10 lines
drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c +4
-4-u32 cmdline_size =NVKM_MSGQUEUE_CMDLINE_SIZE ; -u8 buf[cmdline_size]; +u8 buf[NVKM_MSGQUEUE_CMDLINE_SIZE ]; -memset (buf,0 , cmdline_size); +memset (buf,0 ,NVKM_MSGQUEUE_CMDLINE_SIZE );nvkm_msgqueue_write_cmdline (queue, buf); -nvkm_falcon_load_dmem (falcon, buf, addr_args, cmdline_size,0 ); +nvkm_falcon_load_dmem (falcon, buf, addr_args, +NVKM_MSGQUEUE_CMDLINE_SIZE ,0 );
I think I'd use 'sizeof (buf)' in both those lines.
David
Hi David,
Quoted 20 lines · David Laight
From: Gustavo A. R. Silva
Quoted 5 lines
Sent: 13 March 2018 14:48
In preparation to enabling -Wvla, remove VLA. In this particular case directly use macroNVKM_MSGQUEUE_CMDLINE_SIZEinstead of local variablecmdline_size. Also, removecmdline_sizeas it is not actually useful anymore....
Quoted 13 lines
drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c +1
-2@@ -80,12 +80,12 @@ acr_ls_msgqueue_post_run(struct nvkm_msgqueue *queue, struct nvkm_falcon *falcon, u32 addr_args) {struct nvkm_device *device = falcon->owner->device; -u32 cmdline_size =NVKM_MSGQUEUE_CMDLINE_SIZE ; -u8 buf[cmdline_size]; +u8 buf[NVKM_MSGQUEUE_CMDLINE_SIZE ];
Quoted 9 lines
drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c acr_ls_msgqueue_post_run(struct nvkm_msgqueue *queue, · line 88
Quoted 6 lines
drivers/gpu/drm/nouveau/nvkm/subdev/secboot/ls_ucode_msgqueue.c +3
-2-memset (buf,0 , cmdline_size); +memset (buf,0 ,NVKM_MSGQUEUE_CMDLINE_SIZE );nvkm_msgqueue_write_cmdline (queue, buf); -nvkm_falcon_load_dmem (falcon, buf, addr_args, cmdline_size,0 ); +nvkm_falcon_load_dmem (falcon, buf, addr_args, +NVKM_MSGQUEUE_CMDLINE_SIZE ,0 );I think I'd use 'sizeof (buf)' in both those lines.
Yeah. I like it.
I'll send v2 with that change shortly.
Thanks
--
Gustavo