summaryrefslogtreecommitdiffstats
path: root/sys/dev/softraid.c
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2019-07-04 18:09:17 +0000
committerbluhm <bluhm@openbsd.org>2019-07-04 18:09:17 +0000
commit2d9211fdec5a91fab85ffea3edc36d6ba6d05158 (patch)
tree9bc2c69ace58ce7aead3c9079ac0b23129d00337 /sys/dev/softraid.c
parentRemove a useless kernel lock from the TCP socket splicing path. (diff)
downloadwireguard-openbsd-2d9211fdec5a91fab85ffea3edc36d6ba6d05158.tar.xz
wireguard-openbsd-2d9211fdec5a91fab85ffea3edc36d6ba6d05158.zip
Fix a free size panic when detaching a crypto softraid on i386.
Store the size of struct sr_workunit depending on the softraid type in struct sr_discipline. testing and OK jan@
Diffstat (limited to 'sys/dev/softraid.c')
-rw-r--r--sys/dev/softraid.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/sys/dev/softraid.c b/sys/dev/softraid.c
index 4f04a5572c5..699a7642a77 100644
--- a/sys/dev/softraid.c
+++ b/sys/dev/softraid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid.c,v 1.394 2019/05/18 14:02:27 tim Exp $ */
+/* $OpenBSD: softraid.c,v 1.395 2019/07/04 18:09:17 bluhm Exp $ */
/*
* Copyright (c) 2007, 2008, 2009 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2008 Chris Kuethe <ckuethe@openbsd.org>
@@ -2089,7 +2089,7 @@ sr_ccb_done(struct sr_ccb *ccb)
}
int
-sr_wu_alloc(struct sr_discipline *sd, int wu_size)
+sr_wu_alloc(struct sr_discipline *sd)
{
struct sr_workunit *wu;
int i, no_wu;
@@ -2107,7 +2107,7 @@ sr_wu_alloc(struct sr_discipline *sd, int wu_size)
TAILQ_INIT(&sd->sd_wu_defq);
for (i = 0; i < no_wu; i++) {
- wu = malloc(wu_size, M_DEVBUF, M_WAITOK | M_ZERO);
+ wu = malloc(sd->sd_wu_size, M_DEVBUF, M_WAITOK | M_ZERO);
TAILQ_INSERT_TAIL(&sd->sd_wu, wu, swu_next);
TAILQ_INIT(&wu->swu_ccb);
wu->swu_dis = sd;
@@ -2134,7 +2134,7 @@ sr_wu_free(struct sr_discipline *sd)
while ((wu = TAILQ_FIRST(&sd->sd_wu)) != NULL) {
TAILQ_REMOVE(&sd->sd_wu, wu, swu_next);
- free(wu, M_DEVBUF, sizeof(*wu));
+ free(wu, M_DEVBUF, sd->sd_wu_size);
}
}
@@ -3980,6 +3980,7 @@ sr_discipline_init(struct sr_discipline *sd, int level)
task_set(&sd->sd_hotspare_rebuild_task, sr_hotspare_rebuild_callback,
sd);
+ sd->sd_wu_size = sizeof(struct sr_workunit);
switch (level) {
case 0:
sr_raid0_discipline_init(sd);
@@ -4301,7 +4302,7 @@ sr_raid_recreate_wu(struct sr_workunit *wu)
int
sr_alloc_resources(struct sr_discipline *sd)
{
- if (sr_wu_alloc(sd, sizeof(struct sr_workunit))) {
+ if (sr_wu_alloc(sd)) {
sr_error(sd->sd_sc, "unable to allocate work units");
return (ENOMEM);
}