main/dhcpcd: upgrade to 10.0.5

This commit is contained in:
Jake Buchholz Göktürk 2023-11-10 20:57:18 +00:00
parent 1d09b9fb6f
commit 8ac96091bf
2 changed files with 3 additions and 359 deletions

View File

@ -2,8 +2,8 @@
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=dhcpcd
pkgver=10.0.4
pkgrel=2
pkgver=10.0.5
pkgrel=0
pkgdesc="RFC2131 compliant DHCP client"
url="https://roy.marples.name/projects/dhcpcd"
arch="all"
@ -14,7 +14,6 @@ subpackages="$pkgname-doc $pkgname-openrc"
source="https://github.com/NetworkConfiguration/dhcpcd/releases/download/v$pkgver/dhcpcd-$pkgver.tar.xz
busybox-logger.patch
fix-chrony-conf-location.patch
fix-dhcpcd_fork_cb-truncated_read.patch
dhcpcd.initd
"
@ -48,9 +47,8 @@ package() {
}
sha512sums="
8af26c4a42ce63e9cae72de68774807b8739aabd19cc2a0260148f3baa25c587bf34a5a0b80239b54d8ab9b79661744e61b0e316d2c510c4da65615268d3e8cf dhcpcd-10.0.4.tar.xz
f8213eee93e83c174ce5d2487364400fe07b39bb0f052d072518e12f7189136704f65e1f4467432b477f195d64eebe6ca167aec160aed1575ea9ef551b43eb43 dhcpcd-10.0.5.tar.xz
b6bdaac9fc0d5d2d7e8c5e30d1a45db1cff2284d01f92f8821b2f03aaff4e0dbd8cbfbced96d8d9d934dc11f22b792a8345d634d8e4e3b84f43016b7e866e302 busybox-logger.patch
1c19eed0f7a008ee96ea392beb327169ff8c83fc27fed20f65f05c9125f60629ebe3474c5e6a7cf4aeeea448fde4264c9b84916efacd67d47ab908c47b1fc3a5 fix-chrony-conf-location.patch
51f7e5cbf323ca99f70e1be398087489ebb3343d7391572b66feb222dfe16b64ffe7e1d00494720d8d3da468938f7d3028a92094fd0a660f762b6f095599214b fix-dhcpcd_fork_cb-truncated_read.patch
7fb44b82a6fa25ee6249fc4835853a4c1fc7d327653efabd9fde303b1f306b3aa6956b2621b55a24fc007ec7ad878ce50e7418ebff0b17fece76e2fdd9e5190d dhcpcd.initd
"

View File

@ -1,354 +0,0 @@
diff --git a/compat/arc4random.c b/compat/arc4random.c
index fdf60527..7ff3105d 100644
--- a/compat/arc4random.c
+++ b/compat/arc4random.c
@@ -195,7 +195,16 @@ _rs_stir(void)
_rs_init(rnd, sizeof(rnd));
else
_rs_rekey(rnd, sizeof(rnd));
- memset(rnd, 0, sizeof(rnd)); /* discard source seed */
+#if defined(HAVE_EXPLICIT_BZERO)
+ explicit_bzero(rnd, sizeof(rnd)); /* discard source seed */
+#elif defined(HAVE_MEMSET_EXPLICIT)
+ (void)memset_explicit(rnd, 0, sizeof(rnd));
+#elif defined(HAVE_MEMSET_S)
+ (void)memset_s(rnd, sizeof(rnd), 0, sizeof(rnd));
+#else
+#warning potentially insecure use of memset discarding the source seed
+ (void)memset(rnd, 0, sizeof(rnd)); /* discard source seed */
+#endif
/* invalidate rs_buf */
rs->rs_have = 0;
diff --git a/configure b/configure
index 3d130a04..646ce803 100755
--- a/configure
+++ b/configure
@@ -896,6 +896,76 @@ if [ "$ARC4RANDOM_UNIFORM" = no ]; then
echo "#include \"compat/arc4random_uniform.h\"" >>$CONFIG_H
fi
+# Our arc4random compat needs memset_explicit, explicit_bzero or memset_s
+if [ -z "$MEMSET_EXPLICIT" ]; then
+ printf "Testing for memset_explicit ... "
+ cat <<EOF >_memset_explicit.c
+#include <string.h>
+int main(void) {
+ int a;
+ (void)memset_explicit(&a, 0, sizeof(a));
+ return 0;
+}
+EOF
+ if $XCC _memset_explicit.c -o _memset_explicit 2>&3; then
+ MEMSET_EXPLICIT=yes
+ else
+ MEMSET_EXPLICIT=no
+ fi
+ echo "$MEMSET_EXPLICIT"
+ rm -f _memset_explicit.c _memset_explicit
+fi
+if [ "$MEMSET_EXPLICIT" = yes ]; then
+ echo "#define HAVE_MEMSET_EXPLICIT" >>$CONFIG_H
+fi
+
+if [ -z "$EXPLICIT_BZERO" ]; then
+ printf "Testing for explicit_bzero ... "
+ cat <<EOF >_explicit_bzero.c
+#define _BSD_SOURCE // musl, will be added for Linux in config.h
+#include <string.h>
+int main(void) {
+ int a;
+ explicit_bzero(&a, sizeof(a));
+ return 0;
+}
+EOF
+ if $XCC _explicit_bzero.c -o _explicit_bzero 2>&3; then
+ EXPLICIT_BZERO=yes
+ else
+ EXPLICIT_BZERO=no
+ fi
+ echo "$EXPLICIT_BZERO"
+ rm -f _explicit_bzero.c _explicit_bzero
+fi
+if [ "$EXPLICIT_BZERO" = yes ]; then
+ echo "#define HAVE_EXPLICIT_BZERO" >>$CONFIG_H
+fi
+
+if [ -z "$MEMSET_S" ]; then
+ printf "Testing for memset_s ... "
+ cat <<EOF >_memset_s.c
+#define __STDC_WANT_LIB_EXT1__ 1
+#include <string.h>
+int main(void) {
+ int a;
+ memset_s(&a, sizeof(a), 0, sizeof(a));
+ return 0;
+}
+EOF
+ if $XCC _memset_s.c -o _memset_s 2>&3; then
+ MEMSET_S=yes
+ else
+ MEMSET_S=no
+ fi
+ echo "$MEMSET_S"
+ rm -f _memset_s.c _memset_s
+fi
+if [ "$MEMSET_S" = yes ]; then
+ echo "#define __STDC_WANT_LIB_EXT1__ 1" >>$CONFIG_H
+ echo "#define HAVE_MEMSET_S" >>$CONFIG_H
+fi
+
if [ -z "$OPEN_MEMSTREAM" ]; then
printf "Testing for open_memstream ... "
cat <<EOF >_open_memstream.c
diff --git a/src/dev.c b/src/dev.c
index eb158e4a..0abc3ee2 100644
--- a/src/dev.c
+++ b/src/dev.c
@@ -150,7 +150,7 @@ dev_start1(struct dhcpcd_ctx *ctx, const struct dev_dhcpcd *dev_dhcpcd)
dp = opendir(DEVDIR);
if (dp == NULL) {
logdebug("dev: %s", DEVDIR);
- return 0;
+ return -1;
}
r = 0;
diff --git a/src/dhcp.c b/src/dhcp.c
index e029cee3..014ce6cf 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -1895,6 +1895,20 @@ dhcp_discover(void *arg)
send_discover(ifp);
}
+static void
+dhcp_requestfailed(void *arg)
+{
+ struct interface *ifp = arg;
+ struct dhcp_state *state = D_STATE(ifp);
+
+ logwarnx("%s: failed to request the lease", ifp->name);
+ free(state->offer);
+ state->offer = NULL;
+ state->offer_len = 0;
+ state->interval = 0;
+ dhcp_discover(ifp);
+}
+
static void
dhcp_request(void *arg)
{
@@ -1902,6 +1916,9 @@ dhcp_request(void *arg)
struct dhcp_state *state = D_STATE(ifp);
state->state = DHS_REQUEST;
+ // Handle the server being silent to our request.
+ eloop_timeout_add_sec(ifp->ctx->eloop, ifp->options->reboot,
+ dhcp_requestfailed, ifp);
send_request(ifp);
}
diff --git a/src/dhcpcd.c b/src/dhcpcd.c
index 52ff1dbb..46c64b42 100644
--- a/src/dhcpcd.c
+++ b/src/dhcpcd.c
@@ -339,18 +339,14 @@ dhcpcd_daemonised(struct dhcpcd_ctx *ctx)
* Stop writing to stderr.
* On the happy path, only the manager process writes to stderr,
* so this just stops wasting fprintf calls to nowhere.
- * All other calls - ie errors in privsep processes or script output,
- * will error when printing.
- * If we *really* want to fix that, then we need to suck
- * stderr/stdout in the manager process and either discard it or pass
- * it to the launcher process and then to stderr.
*/
logopts &= ~LOGERR_ERR;
logsetopts(logopts);
/*
- * We need to do something with stdout/stderr to avoid SIGPIPE
- * We know that stdin is already mapped to /dev/null
+ * We need to do something with stdout/stderr to avoid SIGPIPE.
+ * We know that stdin is already mapped to /dev/null.
+ * TODO: Capture script output and log it to the logfile and/or syslog.
*/
dup2(STDIN_FILENO, STDOUT_FILENO);
dup2(STDIN_FILENO, STDERR_FILENO);
@@ -369,7 +365,6 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
return;
#else
int i;
- unsigned int logopts = loggetopts();
if (ctx->options & DHCPCD_DAEMONISE &&
!(ctx->options & (DHCPCD_DAEMONISED | DHCPCD_NOWAITIP)))
@@ -389,11 +384,6 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
!(ctx->options & DHCPCD_DAEMONISE))
return;
- /* Don't use loginfo because this makes no sense in a log. */
- if (!(logopts & LOGERR_QUIET) && ctx->stderr_valid)
- (void)fprintf(stderr,
- "forked to background, child pid %d\n", getpid());
-
#ifdef PRIVSEP
ps_daemonised(ctx);
#else
@@ -404,9 +394,8 @@ dhcpcd_daemonise(struct dhcpcd_ctx *ctx)
if (write(ctx->fork_fd, &i, sizeof(i)) == -1)
logerr("write");
ctx->options |= DHCPCD_DAEMONISED;
- eloop_event_delete(ctx->eloop, ctx->fork_fd);
- close(ctx->fork_fd);
- ctx->fork_fd = -1;
+ // dhcpcd_fork_cb will close the socket
+ shutdown(ctx->fork_fd, SHUT_RDWR);
#endif
}
@@ -1826,31 +1815,6 @@ dhcpcd_readdump(struct dhcpcd_ctx *ctx)
dhcpcd_readdump0, ctx);
}
-static void
-dhcpcd_fork_cb(void *arg, unsigned short events)
-{
- struct dhcpcd_ctx *ctx = arg;
- int exit_code;
- ssize_t len;
-
- if (!(events & ELE_READ))
- logerrx("%s: unexpected event 0x%04x", __func__, events);
-
- len = read(ctx->fork_fd, &exit_code, sizeof(exit_code));
- if (len == -1) {
- logerr(__func__);
- exit_code = EXIT_FAILURE;
- } else if ((size_t)len < sizeof(exit_code)) {
- logerrx("%s: truncated read %zd (expected %zu)",
- __func__, len, sizeof(exit_code));
- exit_code = EXIT_FAILURE;
- }
- if (ctx->options & DHCPCD_FORKED)
- eloop_exit(ctx->eloop, exit_code);
- else
- dhcpcd_signal_cb(exit_code, ctx);
-}
-
static void
dhcpcd_stderr_cb(void *arg, unsigned short events)
{
@@ -1875,6 +1839,51 @@ dhcpcd_stderr_cb(void *arg, unsigned short events)
fprintf(stderr, "%s", log);
}
+static void
+dhcpcd_fork_cb(void *arg, unsigned short events)
+{
+ struct dhcpcd_ctx *ctx = arg;
+ int exit_code;
+ ssize_t len;
+
+ if (!(events & ELE_READ))
+ logerrx("%s: unexpected event 0x%04x", __func__, events);
+
+ len = read(ctx->fork_fd, &exit_code, sizeof(exit_code));
+ if (len == -1) {
+ logerr(__func__);
+ eloop_exit(ctx->eloop, EXIT_FAILURE);
+ return;
+ }
+ if (len == 0) {
+ if (ctx->options & DHCPCD_FORKED) {
+ logerrx("%s: dhcpcd manager hungup", __func__);
+ eloop_exit(ctx->eloop, EXIT_FAILURE);
+ } else {
+ // Launcher exited
+ eloop_event_delete(ctx->eloop, ctx->fork_fd);
+ close(ctx->fork_fd);
+ ctx->fork_fd = -1;
+ }
+ return;
+ }
+ if ((size_t)len < sizeof(exit_code)) {
+ logerrx("%s: truncated read %zd (expected %zu)",
+ __func__, len, sizeof(exit_code));
+ eloop_exit(ctx->eloop, EXIT_FAILURE);
+ return;
+ }
+
+ if (ctx->options & DHCPCD_FORKED) {
+ if (exit_code == EXIT_SUCCESS)
+ logdebugx("forked to background");
+ else
+ logerrx("exited with code %d", exit_code);
+ eloop_exit(ctx->eloop, exit_code);
+ } else
+ dhcpcd_signal_cb(exit_code, ctx);
+}
+
static void
dhcpcd_pidfile_timeout(void *arg)
{
diff --git a/src/ipv4ll.c b/src/ipv4ll.c
index 86cc227d..89b3dce6 100644
--- a/src/ipv4ll.c
+++ b/src/ipv4ll.c
@@ -335,6 +335,10 @@ ipv4ll_start(void *arg)
}
}
+ if (state->running)
+ return;
+ state->running = true;
+
/* RFC 3927 Section 2.1 states that the random number generator
* SHOULD be seeded with a value derived from persistent information
* such as the IEEE 802 MAC address so that it usually picks
@@ -435,11 +439,14 @@ ipv4ll_drop(struct interface *ifp)
return;
state = IPV4LL_STATE(ifp);
- if (state && state->addr != NULL) {
- if (ifp->options->options & DHCPCD_CONFIGURE)
- ipv4_deladdr(state->addr, 1);
- state->addr = NULL;
- dropped = true;
+ if (state) {
+ state->running = false;
+ if (state->addr != NULL) {
+ if (ifp->options->options & DHCPCD_CONFIGURE)
+ ipv4_deladdr(state->addr, 1);
+ state->addr = NULL;
+ dropped = true;
+ }
}
/* Free any other link local addresses that might exist. */
diff --git a/src/ipv4ll.h b/src/ipv4ll.h
index f9e05982..78af32e5 100644
--- a/src/ipv4ll.h
+++ b/src/ipv4ll.h
@@ -44,6 +44,7 @@ struct ipv4ll_state {
struct in_addr pickedaddr;
struct ipv4_addr *addr;
char randomstate[128];
+ bool running;
bool seeded;
bool down;
size_t conflicts;
diff --git a/src/privsep-linux.c b/src/privsep-linux.c
index 1192eb6c..a40f2979 100644
--- a/src/privsep-linux.c
+++ b/src/privsep-linux.c
@@ -313,6 +313,9 @@ static struct sock_filter ps_seccomp_filter[] = {
#ifdef __NR_dup2
SECCOMP_ALLOW(__NR_dup2), // daemonising dups stderr to stdin(/dev/null)
#endif
+#ifdef __NR_dup3
+ SECCOMP_ALLOW(__NR_dup3),
+#endif
#ifdef __NR_epoll_ctl
SECCOMP_ALLOW(__NR_epoll_ctl),
#endif