From 5409ed3f5aa5da495ff97fa093aa726817511195 Mon Sep 17 00:00:00 2001 From: krw Date: Fri, 8 Dec 2017 20:17:28 +0000 Subject: [PATCH] When accepting a BOOTP lease, do not leak offered values of lease time, renewal time, rebinding time. Use the ACTION_DEFAULT mechanism to set the default expiry time for any lease so gauche as to not provide one. Use the DHCP default lease times for BOOTP leases instead of, bizarrely, shorter times. --- sbin/dhclient/clparse.c | 26 +++++++++++++++++++++++--- sbin/dhclient/dhclient.c | 40 ++++------------------------------------ 2 files changed, 27 insertions(+), 39 deletions(-) diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 071dbf58fd8..ee00f748233 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.152 2017/12/07 19:03:15 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.153 2017/12/08 20:17:28 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -121,8 +121,10 @@ add_lease(struct client_lease_tq *tq, struct client_lease *lease) void read_client_conf(char *name) { - FILE *cfile; - int token; + struct option_data *option; + FILE *cfile; + int token; + uint32_t expiry; new_parse(path_dhclient_conf); @@ -137,6 +139,24 @@ read_client_conf(char *name) config->backoff_cutoff = 10; /* max secs between packet retries */ config->initial_interval = 1; /* secs before 1st retry */ + /* + * Set default lease length, which will determine default renewal + * and rebind times. + * + * XXX Thus applies to both BOOTP and DHCP leases. + * + * DHO_DHCP_LEASE_TIME (12 hours == 43200 seconds), + */ + option = &config->defaults[DHO_DHCP_LEASE_TIME]; + option->data = malloc(4); + if (option->data == NULL) + fatal("default lease length"); + + config->default_actions[DHO_DHCP_LEASE_TIME] = ACTION_DEFAULT; + option->len = 4; + expiry = htonl(43200); + memcpy(option->data, &expiry, 4); + config->requested_options [config->requested_option_count++] = DHO_SUBNET_MASK; config->requested_options diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 4de0fda2b5a..264eaebc2e0 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.538 2017/12/07 19:17:13 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.539 2017/12/08 20:17:28 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -793,8 +793,6 @@ state_init(struct interface_info *ifi) void state_selecting(struct interface_info *ifi) { - struct option_data *option; - cancel_timeout(ifi); if (ifi->offer == NULL) { @@ -802,45 +800,15 @@ state_selecting(struct interface_info *ifi) return; } + ifi->state = S_REQUESTING; + /* If it was a BOOTREPLY, we can just take the lease right now. */ if (BOOTP_LEASE(ifi->offer)) { - /* - * Set (unsigned 32 bit) options - * - * DHO_DHCP_LEASE_TIME (12000 seconds), - * DHO_RENEWAL_TIME (8000 seconds) - * DHO_REBINDING_TIME (10000 seconds) - * - * so bind_lease() can set the lease times. Note that the - * values must be big-endian. - */ - option = &ifi->offer->options[DHO_DHCP_LEASE_TIME]; - option->data = malloc(4); - if (option->data) { - option->len = 4; - memcpy(option->data, "\x00\x00\x2e\xe0", 4); - } - option = &ifi->offer->options[DHO_DHCP_RENEWAL_TIME]; - option->data = malloc(4); - if (option->data) { - option->len = 4; - memcpy(option->data, "\x00\x00\x1f\x40", 4); - } - option = &ifi->offer->options[DHO_DHCP_REBINDING_TIME]; - option->data = malloc(4); - if (option->data) { - option->len = 4; - memcpy(option->data, "\x00\x00\x27\x10", 4); - } - - ifi->state = S_REQUESTING; bind_lease(ifi); - return; } ifi->destination.s_addr = INADDR_BROADCAST; - ifi->state = S_REQUESTING; time(&ifi->first_sending); ifi->interval = 0; @@ -2553,7 +2521,7 @@ lease_expiry(struct client_lease *lease) { uint32_t expiry; - expiry = 43200; /* Default to 12 hours */ + expiry = 0; if (lease->options[DHO_DHCP_LEASE_TIME].len == sizeof(expiry)) { memcpy(&expiry, lease->options[DHO_DHCP_LEASE_TIME].data, sizeof(expiry)); -- 2.20.1