[master] fbe7e7559 ws: Almost ban direct access to the workspace front
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Aug 31 18:41:10 UTC 2020
commit fbe7e755990de5ca362c8652cd571052330e8f3e
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed May 6 14:01:49 2020 +0200
ws: Almost ban direct access to the workspace front
Proving that this always needed for use cases dealing with workspace
reservations.
Well, almost always, for now vmod_vtc and the panic subsystem are left
alone.
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index b7c46a8a6..9e80efcb1 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -674,7 +674,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now,
more = 0;
spc = ospc;
nobj = 0;
- ocp = (void*)wrk->aws->f;
+ ocp = WS_Reservation(wrk->aws);
Lck_Lock(&oh->mtx);
assert(oh->refcnt > 0);
VTAILQ_FOREACH(oc, &oh->objcs, hsh_list) {
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index c6e8b37d7..1c608ff3a 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -403,7 +403,7 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
if (b == NULL) {
/* Found second header, start our collection */
ml = WS_ReserveAll(hp->ws);
- b = hp->ws->f;
+ b = WS_Reservation(hp->ws);
e = b + ml;
x = Tlen(hp->hd[f]);
if (b + x >= e) {
@@ -444,7 +444,7 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
hp->nhd = (uint16_t)d;
AN(e);
*b = '\0';
- hp->hd[f].b = hp->ws->f;
+ hp->hd[f].b = WS_Reservation(hp->ws);
hp->hd[f].e = b;
WS_ReleaseP(hp->ws, b + 1);
}
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 1b13badae..147934aa0 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -124,7 +124,7 @@ ses_res_attr(struct sess *sp, enum sess_attr a, void **dst, int sz)
o = WS_ReserveSize(sp->ws, sz);
if (o < sz)
return (0);
- *dst = sp->ws->f;
+ *dst = WS_Reservation(sp->ws);
o = sp->ws->f - sp->ws->s;
WS_Release(sp->ws, sz);
assert(o >= 0 && o <= 0xffff);
@@ -210,19 +210,19 @@ HTC_Status(enum htc_status_e e)
void
HTC_RxInit(struct http_conn *htc, struct ws *ws)
{
+ unsigned r;
ssize_t l;
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
htc->ws = ws;
- (void)WS_ReserveAll(htc->ws);
- htc->rxbuf_b = ws->f;
- htc->rxbuf_e = ws->f;
+ r = WS_ReserveAll(htc->ws);
+ htc->rxbuf_b = htc->rxbuf_e = WS_Reservation(ws);
if (htc->pipeline_b != NULL) {
AN(htc->pipeline_e);
// assert(WS_Inside(ws, htc->pipeline_b, htc->pipeline_e));
l = htc->pipeline_e - htc->pipeline_b;
assert(l > 0);
- assert(l <= ws->r - htc->rxbuf_b);
+ assert(l <= r);
memmove(htc->rxbuf_b, htc->pipeline_b, l);
htc->rxbuf_e += l;
htc->pipeline_b = NULL;
@@ -415,7 +415,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
CAST_OBJ_NOTNULL(sp, wp->priv1, SESS_MAGIC);
CAST_OBJ_NOTNULL(xp, (const void*)wp->priv2, TRANSPORT_MAGIC);
AN(wp->priv2);
- assert((void *)sp->ws->f == wp);
+ assert(WS_Reservation(sp->ws) == wp);
wp->magic = 0;
wp = NULL;
@@ -434,7 +434,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
/* SES_Wait() guarantees the next will not assert. */
assert(sizeof *tp <= WS_ReserveSize(sp->ws, sizeof *tp));
- tp = (void*)sp->ws->f;
+ tp = WS_Reservation(sp->ws);
tp->func = xp->unwait;
tp->priv = sp;
if (Pool_Task(pp, tp, TASK_QUEUE_REQ))
diff --git a/bin/varnishd/cache/cache_vary.c b/bin/varnishd/cache/cache_vary.c
index 3dc23e33f..82ff49ac8 100644
--- a/bin/varnishd/cache/cache_vary.c
+++ b/bin/varnishd/cache/cache_vary.c
@@ -234,10 +234,10 @@ VRY_Prep(struct req *req)
AZ(req->vary_e);
(void)WS_ReserveAll(req->ws);
} else {
- AN(req->ws->r);
+ AN(WS_Reservation(req->ws));
}
- req->vary_b = (void*)req->ws->f;
- req->vary_e = (void*)req->ws->r;
+ req->vary_b = WS_Reservation(req->ws);
+ req->vary_e = req->vary_b + WS_ReservationSize(req->ws);
if (req->vary_b + 2 < req->vary_e)
req->vary_b[2] = '\0';
}
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index bdc50c6ec..144736ae0 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -366,7 +366,7 @@ VRT_String(struct ws *ws, const char *h, const char *p, va_list ap)
va_list aq;
u = WS_ReserveAll(ws);
- e = b = ws->f;
+ e = b = WS_Reservation(ws);
e += u;
va_copy(aq, ap);
@@ -422,7 +422,7 @@ VRT_String(struct ws *ws, const char *h, const char *p, va_list ap)
return (NULL);
}
e = b;
- b = ws->f;
+ b = WS_Reservation(ws);
WS_Release(ws, e - b);
return (b);
}
@@ -710,7 +710,7 @@ VRT_IP_string(VRT_CTX, VCL_IP ip)
WS_Release(ctx->ws, 0);
return (NULL);
}
- p = ctx->ws->f;
+ p = WS_Reservation(ctx->ws);
VTCP_name(ip, p, len, NULL, 0);
WS_Release(ctx->ws, strlen(p) + 1);
return (p);
diff --git a/bin/varnishd/cache/cache_vrt_re.c b/bin/varnishd/cache/cache_vrt_re.c
index 955fb1c2b..f38515151 100644
--- a/bin/varnishd/cache/cache_vrt_re.c
+++ b/bin/varnishd/cache/cache_vrt_re.c
@@ -130,7 +130,7 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
}
u = WS_ReserveAll(ctx->ws);
- res_e = res_b = b0 = ctx->ws->f;
+ res_e = res_b = b0 = WS_Reservation(ctx->ws);
res_e += u;
do {
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 13a7cb8ac..39e4b4361 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -246,9 +246,9 @@ Pool_Task_Arg(struct worker *wrk, enum task_prio prio, task_func_t *func,
}
AZ(wrk2->task->func);
assert(arg_len <= WS_ReserveSize(wrk2->aws, arg_len));
- memcpy(wrk2->aws->f, arg, arg_len);
+ memcpy(WS_Reservation(wrk2->aws), arg, arg_len);
wrk2->task->func = func;
- wrk2->task->priv = wrk2->aws->f;
+ wrk2->task->priv = WS_Reservation(wrk2->aws);
Lck_Unlock(&pp->mtx);
// see signaling_note at the top for explanation
if (retval)
diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c
index fcb6af3ee..da35661af 100644
--- a/bin/varnishd/http1/cache_http1_line.c
+++ b/bin/varnishd/http1/cache_http1_line.c
@@ -112,7 +112,7 @@ V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl,
u = IOV_MAX;
if (niov != 0 && u > niov)
u = niov;
- v1l->iov = (void*)ws->f;
+ v1l->iov = WS_Reservation(ws);
v1l->siov = u;
v1l->ciov = u;
v1l->wfd = fd;
diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c
index e00473452..34015ac3c 100644
--- a/bin/varnishd/http2/cache_http2_hpack.c
+++ b/bin/varnishd/http2/cache_http2_hpack.c
@@ -183,7 +183,7 @@ h2h_decode_init(const struct h2_sess *h2)
* space. Require non-zero size.
*/
XXXAN(d->out_l);
- d->out = h2->new_req->http->ws->f;
+ d->out = WS_Reservation(h2->new_req->http->ws);
d->reset = d->out;
}
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 244680bfb..948a0972b 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -76,7 +76,7 @@ vmod_updown(VRT_CTX, int up, VCL_STRANDS s)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
u = WS_ReserveAll(ctx->ws);
- e = b = ctx->ws->f;
+ e = b = WS_Reservation(ctx->ws);
e += u;
for (i = 0; i < s->n && b < e; i++) {
p = s->p[i];
@@ -96,7 +96,7 @@ vmod_updown(VRT_CTX, int up, VCL_STRANDS s)
return (NULL);
} else {
e = b;
- b = ctx->ws->f;
+ b = WS_Reservation(ctx->ws);
WS_Release(ctx->ws, e - b);
return (b);
}
diff --git a/lib/libvmod_std/vmod_std_querysort.c b/lib/libvmod_std/vmod_std_querysort.c
index 8602dc6e1..8b0a2704f 100644
--- a/lib/libvmod_std/vmod_std_querysort.c
+++ b/lib/libvmod_std/vmod_std_querysort.c
@@ -81,7 +81,7 @@ vmod_querysort(VRT_CTX, VCL_STRING url)
return (url);
u = WS_ReserveLumps(ctx->ws, sizeof(const char **));
- pp = (const char**)(void*)(ctx->ws->f);
+ pp = WS_Reservation(ctx->ws);
if (u < 4) {
WS_Release(ctx->ws, 0);
WS_MarkOverflow(ctx->ws);
More information about the varnish-commit
mailing list