Skip to content

Commit 54a5c0e

Browse files
committed
param: Move alias resolution before protected check
Instead of resolving tweaks when the function is called, this is now done in the MGT code performing the protected check. Since aliases may be used to reset a single bit of another parameter (namely vcc_feature) the default value is looked up before the alias resolution. Unfortunately, that also means resolving deprecated aliases before showing them to the user, adding a little bit of duplicated logic. Refs #4323
1 parent 7d6cfa3 commit 54a5c0e

File tree

3 files changed

+46
-17
lines changed

3 files changed

+46
-17
lines changed

bin/varnishd/mgt/mgt_param.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ mcf_addpar(struct parspec *ps)
155155
VTAILQ_INSERT_TAIL(&phead, pl, list);
156156
}
157157

158+
static const struct parspec *
159+
mcf_alias(struct parspec *alias, const struct parspec *pp)
160+
{
161+
const struct parspec *orig;
162+
163+
orig = TRUST_ME(pp->priv);
164+
AN(orig);
165+
memcpy(alias, orig, sizeof *alias);
166+
alias->priv = TRUST_ME(orig);
167+
return (alias);
168+
}
169+
158170
/*--------------------------------------------------------------------
159171
* Wrap the text nicely.
160172
* Lines are allowed to contain two TABS and we render that as a table
@@ -253,6 +265,7 @@ mcf_param_show(struct cli *cli, const char * const *av, void *priv)
253265
{
254266
struct plist *pl;
255267
const struct parspec *pp, *pa;
268+
struct parspec alias[1];
256269
int n, lfmt = 0, chg = 0;
257270
struct vsb *vsb;
258271
const char *show = NULL;
@@ -285,9 +298,13 @@ mcf_param_show(struct cli *cli, const char * const *av, void *priv)
285298
pp = pl->spec;
286299
if (lfmt && show != NULL && strcmp(pp->name, show))
287300
continue;
288-
if (pp->func == tweak_alias &&
289-
(show == NULL || strcmp(pp->name, show)))
290-
continue;
301+
if (pp->func == tweak_alias) {
302+
if (show == NULL)
303+
continue;
304+
if (strcmp(pp->name, show))
305+
continue;
306+
pp = mcf_alias(alias, pp);
307+
}
291308
n++;
292309

293310
VSB_clear(vsb);
@@ -385,6 +402,7 @@ mcf_param_show_json(struct cli *cli, const char * const *av, void *priv)
385402
int n, comma = 0, chg = 0;
386403
struct plist *pl;
387404
const struct parspec *pp, *pa;
405+
struct parspec alias[1];
388406
struct vsb *vsb, *def;
389407
const char *show = NULL, *sep;
390408

@@ -422,9 +440,13 @@ mcf_param_show_json(struct cli *cli, const char * const *av, void *priv)
422440
pp = pl->spec;
423441
if (show != NULL && strcmp(pp->name, show) != 0)
424442
continue;
425-
if (pp->func == tweak_alias &&
426-
(show == NULL || strcmp(pp->name, show)))
427-
continue;
443+
if (pp->func == tweak_alias) {
444+
if (show == NULL)
445+
continue;
446+
if (strcmp(pp->name, show))
447+
continue;
448+
pp = mcf_alias(alias, pp);
449+
}
428450
n++;
429451

430452
VSB_clear(vsb);
@@ -544,6 +566,7 @@ void
544566
MCF_ParamSet(struct cli *cli, const char *param, const char *val)
545567
{
546568
const struct parspec *pp;
569+
struct parspec alias[1];
547570

548571
pp = mcf_findpar(param);
549572
if (pp == NULL) {
@@ -559,13 +582,17 @@ MCF_ParamSet(struct cli *cli, const char *param, const char *val)
559582
);
560583
return;
561584
}
585+
if (!val)
586+
val = pp->def;
587+
if (pp->func == tweak_alias) {
588+
pp = mcf_alias(alias, pp);
589+
alias->name = param;
590+
}
562591
if (pp->flags & PROTECTED) {
563592
VCLI_SetResult(cli, CLIS_AUTH);
564593
VCLI_Out(cli, "parameter \"%s\" is protected.", param);
565594
return;
566595
}
567-
if (!val)
568-
val = pp->def;
569596
if (pp->func(cli->sb, pp, val))
570597
VCLI_SetResult(cli, CLIS_PARAM);
571598

bin/varnishd/mgt/mgt_param_tweak.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,11 @@ tweak_storage(struct vsb *vsb, const struct parspec *par, const char *arg)
614614
int v_matchproto_(tweak_t)
615615
tweak_alias(struct vsb *vsb, const struct parspec *par, const char *arg)
616616
{
617-
const struct parspec *orig;
618-
struct parspec alias[1];
619-
620-
orig = TRUST_ME(par->priv);
621-
AN(orig);
622-
memcpy(alias, orig, sizeof *orig);
623-
alias->name = par->name;
624-
alias->priv = TRUST_ME(orig);
625-
return (alias->func(vsb, alias, arg));
617+
618+
(void)vsb;
619+
(void)par;
620+
(void)arg;
621+
WRONG("param tweak never called directly");
626622
}
627623

628624
/*--------------------------------------------------------------------

bin/varnishtest/tests/r04323.vtc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
varnishtest "parameter alias bypassing protection"
2+
3+
varnish v1 -arg "-r vcc_feature"
4+
5+
varnish v1 -clierr 107 "param.set vcc_feature all"
6+
varnish v1 -clierr 107 "param.set vcc_allow_inline_c on"

0 commit comments

Comments
 (0)