Skip to content

Commit

Permalink
sparc64: viohs: Remove VLA usage
Browse files Browse the repository at this point in the history
In the quest to remove all stack VLA usage from the kernel[1], this
allocates a fixed size array for the maximum number of cookies and
adds a runtime sanity check.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1
[email protected]

Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
kees authored and davem330 committed Oct 8, 2018
1 parent df58f37 commit 31a43fa
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions arch/sparc/kernel/viohs.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,17 @@ static int send_dreg(struct vio_driver_state *vio)
struct vio_dring_register pkt;
char all[sizeof(struct vio_dring_register) +
(sizeof(struct ldc_trans_cookie) *
dr->ncookies)];
VIO_MAX_RING_COOKIES)];
} u;
size_t bytes = sizeof(struct vio_dring_register) +
(sizeof(struct ldc_trans_cookie) *
dr->ncookies);
int i;

memset(&u, 0, sizeof(u));
if (WARN_ON(bytes > sizeof(u)))
return -EINVAL;

memset(&u, 0, bytes);
init_tag(&u.pkt.tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO, VIO_DRING_REG);
u.pkt.dring_ident = 0;
u.pkt.num_descr = dr->num_entries;
Expand All @@ -206,7 +212,7 @@ static int send_dreg(struct vio_driver_state *vio)
(unsigned long long) u.pkt.cookies[i].cookie_size);
}

return send_ctrl(vio, &u.pkt.tag, sizeof(u));
return send_ctrl(vio, &u.pkt.tag, bytes);
}

static int send_rdx(struct vio_driver_state *vio)
Expand Down

0 comments on commit 31a43fa

Please sign in to comment.