MCDE McdeSys: the root update takes only a directory, file:/// or https:// as its source (t0078)
sysupgrade-1.5 fetches with ftp and unpacks with tar as root and checks nothing; pkg_add -uu trusts the packages it is given (docs/reference/update-verification.txt). mcde_sys_update_source_ok (common.c, fail closed: the scheme in lower case, only [A-Za-z0-9._~:/@%+,=-]) is asked by mcde_sys_update_check, which then does not even contact a refused source, and by mcde_sys_update_apply, which refuses before any root action. http://, ftp://, ssh:// and shell or query characters are out. Measured: make mcde-linux MCDE_DIRS='check lib/McdeSys' exit=0, PASS 3 of 3 (test_updatesource has 28 cases, build/logs/mcde-linux-2026-11-14-t0078.log); netbsd.c does not build on this host, its update section compiled alone with -Wall -Wextra gives no warning. This does not verify any signature: that needs a key and Konrad's decision (t0078 steps 2 and 3). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
46606008b5
commit
86ff325ecb
5 files changed
+135
-2
No files matched your search
@@ -17,11 +17,14 @@ endif
|
||||
libMcdeSys_la_LDFLAGS = -version-info 1:0:0
|
||||
|
||||
# what the system tells about itself, for a look by hand: make check runs it
|
||||
check_PROGRAMS = test_sysinfo test_netmount
|
||||
check_PROGRAMS = test_sysinfo test_netmount test_updatesource
|
||||
test_sysinfo_SOURCES = test_sysinfo.c
|
||||
test_sysinfo_CPPFLAGS = -I$(top_srcdir)/include
|
||||
test_sysinfo_LDADD = libMcdeSys.la
|
||||
test_netmount_SOURCES = test_netmount.c
|
||||
test_netmount_CPPFLAGS = -I$(top_srcdir)/include
|
||||
test_netmount_LDADD = libMcdeSys.la
|
||||
TESTS = test_sysinfo test_netmount
|
||||
test_updatesource_SOURCES = test_updatesource.c
|
||||
test_updatesource_CPPFLAGS = -I$(top_srcdir)/include
|
||||
test_updatesource_LDADD = libMcdeSys.la
|
||||
TESTS = test_sysinfo test_netmount test_updatesource
|
||||
@@ -300,6 +300,41 @@ mcde_sys_file_value(const char *file, const char *key, char *buf, size_t len)
|
||||
return found;
|
||||
}
|
||||
|
||||
/* An update source the root update may use (tasksd t0078, docs/reference/
|
||||
* update-verification.txt): a directory, "file:///DIR" or "https://HOST/DIR".
|
||||
* sysupgrade(8) unpacks the sets as root and checks nothing, pkg_add trusts
|
||||
* the packages it is given; with http:// anyone on the path could replace
|
||||
* them. Fail closed: the scheme in lower case exactly as written here (what
|
||||
* sysupgrade's case patterns and ftp(1) see), and only characters that cannot
|
||||
* mean anything to a shell, a URL query or an option -- a release directory
|
||||
* needs no more. Returns 1 if the source may be used. */
|
||||
int
|
||||
mcde_sys_update_source_ok(const char *url)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if (url == NULL)
|
||||
return 0;
|
||||
if (strncmp(url, "https://", 8) == 0)
|
||||
p = url + 8;
|
||||
else if (strncmp(url, "file:///", 8) == 0)
|
||||
p = url + 7; /* keeps the first "/" of the path */
|
||||
else if (url[0] == '/')
|
||||
p = url;
|
||||
else
|
||||
return 0;
|
||||
if (url[0] == 'h' && !((p[0] >= 'a' && p[0] <= 'z') ||
|
||||
(p[0] >= 'A' && p[0] <= 'Z') || (p[0] >= '0' && p[0] <= '9')))
|
||||
return 0; /* no host after https:// */
|
||||
for (; *p != '\0'; p++) {
|
||||
if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z') ||
|
||||
(*p >= '0' && *p <= '9') || strchr("._~-:/@%+,=", *p) != NULL)
|
||||
continue;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
mcde_sys_hostname_get(char *name, size_t len)
|
||||
{
|
||||
|
||||
@@ -1189,6 +1189,13 @@ mcde_sys_update_check(McdeSysUpdate *u)
|
||||
"(%s).", updateConf);
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
if (!mcde_sys_update_source_ok(u->source)) {
|
||||
/* not even asked: http:// could be answered by anyone */
|
||||
snprintf(u->note, sizeof u->note, "The update source is not "
|
||||
"allowed: it must be a directory, file:/// or https:// "
|
||||
"(%s).", updateConf);
|
||||
return MCDE_SYS_OK;
|
||||
}
|
||||
snprintf(url, sizeof url, "%s/RELEASE", u->source);
|
||||
if (mcde_sys_capture(argv, out, sizeof out) != MCDE_SYS_OK)
|
||||
return mcde_sys_fail(MCDE_SYS_EFAIL, "The update source does "
|
||||
@@ -1227,6 +1234,13 @@ mcde_sys_update_apply(void)
|
||||
if (!UpdateSource(url, sizeof url))
|
||||
return mcde_sys_fail(MCDE_SYS_ENOENT, "No update source is set "
|
||||
"(%s).", updateConf);
|
||||
/* sysupgrade unpacks the sets as root and checks nothing, pkg_add
|
||||
* -uu trusts the packages it is given: only a source nobody on the
|
||||
* way can change (t0078, docs/reference/update-verification.txt) */
|
||||
if (!mcde_sys_update_source_ok(url))
|
||||
return mcde_sys_fail(MCDE_SYS_EINVAL, "The update source is "
|
||||
"not allowed: it must be a directory, file:/// or https:// "
|
||||
"(%s).", updateConf);
|
||||
if ((r = mcde_sys_run(sysupgrade)) != MCDE_SYS_OK)
|
||||
return r;
|
||||
/* the installed packages, by name ("vim-9.2.1202 comment" -> vim),
|
||||
|
||||
@@ -29,6 +29,10 @@ int mcde_sys_run_input(char *const argv[], const char *input);
|
||||
int mcde_sys_file_value(const char *file, const char *key, char *buf,
|
||||
size_t len);
|
||||
|
||||
/* an update source the root update may use: a directory, file:/// or https://
|
||||
* (not http://); 1 if so (common.c, tasksd t0078) */
|
||||
int mcde_sys_update_source_ok(const char *url);
|
||||
|
||||
/* the backend: the fields of INFO that only the system can tell (common.c
|
||||
* has filled in what POSIX gives, the backend may replace it) */
|
||||
void mcde_sys_info_backend(McdeSysInfo *info);
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* test_updatesource.c -- McdeSys: which update sources root may use (make check)
|
||||
*
|
||||
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
||||
*
|
||||
* The root update runs sysupgrade(8), which unpacks the sets and checks
|
||||
* nothing, and pkg_add -uu on the packages it is given. With an http://
|
||||
* source anyone on the way could replace them, so only a directory, file:///
|
||||
* and https:// are accepted (tasksd t0078, docs/reference/
|
||||
* update-verification.txt). The other characters keep a source from meaning
|
||||
* more than a place to a shell, an option or a URL query.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Mcde/McdeSys.h>
|
||||
|
||||
#include "private.h" /* mcde_sys_update_source_ok: the library's, not the API */
|
||||
|
||||
static const struct {
|
||||
const char *url;
|
||||
int ok;
|
||||
} cases[] = {
|
||||
{ "/mnt/release", 1 }, /* a directory */
|
||||
{ "/home/user/makronix-0.99.10", 1 },
|
||||
{ "file:///mnt/release", 1 },
|
||||
{ "https://updates.example.org/makronix/0.99", 1 },
|
||||
{ "https://updates.example.org:8443/m", 1 },
|
||||
{ "https://10.0.0.5/m", 1 },
|
||||
/* refused: the way can be read and changed */
|
||||
{ "http://updates.example.org/makronix", 0 },
|
||||
{ "HTTP://updates.example.org/makronix", 0 },
|
||||
{ "ftp://updates.example.org/makronix", 0 },
|
||||
{ "ssh://root@host/makronix", 0 },
|
||||
{ "HTTPS://updates.example.org/m", 0 }, /* only the form sysupgrade knows */
|
||||
{ "https://", 0 }, /* no host */
|
||||
{ "https:///m", 0 },
|
||||
{ "file://host/m", 0 }, /* a remote "file" */
|
||||
{ "file:/mnt/release", 0 },
|
||||
{ "relative/dir", 0 },
|
||||
{ "-oProxyCommand=id", 0 }, /* an option, not a place */
|
||||
{ "", 0 },
|
||||
/* refused: characters that mean something */
|
||||
{ "/mnt/release; reboot", 0 },
|
||||
{ "/mnt/rel ease", 0 },
|
||||
{ "/mnt/$(id)", 0 },
|
||||
{ "/mnt/`id`", 0 },
|
||||
{ "https://host/m?x=1&y=2", 0 },
|
||||
{ "https://host/m#frag", 0 },
|
||||
{ "/mnt/it's", 0 },
|
||||
{ "/mnt/a\nb", 0 },
|
||||
{ "/mnt/a\\b", 0 },
|
||||
};
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
size_t i;
|
||||
int failures = 0, ok;
|
||||
|
||||
if (mcde_sys_update_source_ok(NULL) != 0) {
|
||||
printf("FAIL NULL: accepted\n");
|
||||
failures++;
|
||||
}
|
||||
for (i = 0; i < sizeof cases / sizeof cases[0]; i++) {
|
||||
ok = mcde_sys_update_source_ok(cases[i].url) != 0;
|
||||
if (ok != cases[i].ok) {
|
||||
printf("FAIL \"%s\": %s\n", cases[i].url,
|
||||
ok ? "accepted" : "refused");
|
||||
failures++;
|
||||
}
|
||||
}
|
||||
printf("test_updatesource: %d cases, %d failures\n",
|
||||
(int) (sizeof cases / sizeof cases[0]) + 1, failures);
|
||||
return failures != 0;
|
||||
}
|
||||
Reference in new issue
Block a user