Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/dhcpcd/dist Import dhcpcd-5.1.12 with the follo...



details:   https://anonhg.NetBSD.org/src/rev/6dd42018e0f8
branches:  trunk
changeset: 763895:6dd42018e0f8
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Apr 06 09:06:41 2011 +0000

description:
Import dhcpcd-5.1.12 with the following changes:
* 20-resolv.conf now uses the correct variable for $IF_METRIC
* Exclude interface values when dumping the lease
* Parse static value subnet_mask when it exists instead of deriving from
  ip address
* logger calls now resemble dhcpcd calls to syslog(3)
* Reject offered IP address if INADDR_BROADCAST or INADDR_ANY
* Change the route if source address has changed
* Note the address we are requesting in the broadcast log entry
* When operating on one interface, respect the timeout for in dhcpcd.conf
* Escape | and & characters before passing the value to the shell
  Ensure we set a valid hostname, DNS domain and NIS domain.
  Document the need for input validation in dhcpcd-run-hooks(8).
  Fixes CVE-2011-996
  Based on a patch to dhcpcd-3 by Marius Tomaschewski <mt%suse.de@localhost>

diffstat:

 external/bsd/dhcpcd/dist/arp.c                       |   4 +-
 external/bsd/dhcpcd/dist/bpf.c                       |   7 ++-
 external/bsd/dhcpcd/dist/configure.c                 |  19 +++++++-
 external/bsd/dhcpcd/dist/defs.h                      |   2 +-
 external/bsd/dhcpcd/dist/dhcp.c                      |   4 +-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf |  14 +++++-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname    |  13 +++++-
 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind      |   6 ++-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in       |  12 ++++-
 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in         |  42 +++++++++++++++++++-
 external/bsd/dhcpcd/dist/dhcpcd.c                    |  33 +++++++++++---
 external/bsd/dhcpcd/dist/eloop.c                     |   2 +-
 external/bsd/dhcpcd/dist/eloop.h                     |   2 +-
 external/bsd/dhcpcd/dist/if-options.c                |   7 ++-
 external/bsd/dhcpcd/dist/ipv4ll.c                    |   2 +-
 external/bsd/dhcpcd/dist/net.c                       |  34 +++++++++-------
 external/bsd/dhcpcd/dist/net.h                       |   7 +-
 17 files changed, 162 insertions(+), 48 deletions(-)

diffs (truncated from 529 to 300 lines):

diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/arp.c
--- a/external/bsd/dhcpcd/dist/arp.c    Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/arp.c    Wed Apr 06 09:06:41 2011 +0000
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy%marples.name@localhost>
+ * Copyright (c) 2006-2011 Roy Marples <roy%marples.name@localhost>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -119,7 +119,7 @@
        state->fail.s_addr = 0;
        for(;;) {
                bytes = get_raw_packet(iface, ETHERTYPE_ARP,
-                   arp_buffer, sizeof(arp_buffer));
+                   arp_buffer, sizeof(arp_buffer), NULL);
                if (bytes == 0 || bytes == -1)
                        return;
                /* We must have a full ARP header */
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/bpf.c
--- a/external/bsd/dhcpcd/dist/bpf.c    Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/bpf.c    Wed Apr 06 09:06:41 2011 +0000
@@ -1,6 +1,6 @@
 /*
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2008 Roy Marples <roy%marples.name@localhost>
+ * Copyright (c) 2006-2011 Roy Marples <roy%marples.name@localhost>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -160,7 +160,7 @@
  * So we pass the buffer in the API so we can loop on >1 packet. */
 ssize_t
 get_raw_packet(struct interface *iface, int protocol,
-    void *data, ssize_t len)
+    void *data, ssize_t len, int *partialcsum)
 {
        int fd = -1;
        struct bpf_hdr packet;
@@ -172,6 +172,9 @@
        else
                fd = iface->raw_fd;
 
+       if (partialcsum != NULL)
+               *partialcsum = 0; /* Not supported on BSD */
+
        for (;;) {
                if (iface->buffer_len == 0) {
                        bytes = read(fd, iface->buffer, iface->buffer_size);
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/configure.c
--- a/external/bsd/dhcpcd/dist/configure.c      Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/configure.c      Wed Apr 06 09:06:41 2011 +0000
@@ -1,6 +1,6 @@
 /* 
  * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2010 Roy Marples <roy%marples.name@localhost>
+ * Copyright (c) 2006-2011 Roy Marples <roy%marples.name@localhost>
  * All rights reserved
 
  * Redistribution and use in source and binary forms, with or without
@@ -170,8 +170,14 @@
        const struct if_options *ifo = iface->state->options;
        const struct interface *ifp;
 
+       /* When dumping the lease, we only want to report interface and
+          reason - the other interface variables are meaningless */
+       if (options & DHCPCD_DUMPLEASE)
+               elen = 2;
+       else
+               elen = 8;
+
        /* Make our env */
-       elen = 8;
        env = xmalloc(sizeof(char *) * (elen + 1));
        e = strlen("interface") + strlen(iface->name) + 2;
        env[0] = xmalloc(e);
@@ -179,7 +185,10 @@
        e = strlen("reason") + strlen(iface->state->reason) + 2;
        env[1] = xmalloc(e);
        snprintf(env[1], e, "reason=%s", iface->state->reason);
-       e = 20;
+       if (options & DHCPCD_DUMPLEASE)
+               goto dumplease;
+
+       e = 20;
        env[2] = xmalloc(e);
        snprintf(env[2], e, "pid=%d", getpid());
        env[3] = xmalloc(e);
@@ -237,6 +246,8 @@
                append_config(&env, &elen, "old",
                    (const char *const *)ifo->config);
        }
+
+dumplease:
        if (iface->state->new) {
                e = configure_env(NULL, NULL, iface->state->new, ifo);
                if (e > 0) {
@@ -653,9 +664,11 @@
                        /* Is this route already in our table? */
                        if ((find_route(nrs, rt, NULL, NULL)) != NULL)
                                continue;
+                       rt->src.s_addr = ifp->addr.s_addr;
                        /* Do we already manage it? */
                        if ((or = find_route(routes, rt, &rtl, NULL))) {
                                if (or->iface != ifp ||
+                                   or->src.s_addr != ifp->addr.s_addr ||
                                    rt->gate.s_addr != or->gate.s_addr)
                                {
                                        if (c_route(or, rt, ifp) != 0)
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/defs.h
--- a/external/bsd/dhcpcd/dist/defs.h   Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/defs.h   Wed Apr 06 09:06:41 2011 +0000
@@ -28,7 +28,7 @@
 #define CONFIG_H
 
 #define PACKAGE                        "dhcpcd"
-#define VERSION                        "5.2.11"
+#define VERSION                        "5.2.12"
 
 #ifndef CONFIG
 # define CONFIG                        SYSCONFDIR "/" PACKAGE ".conf"
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/dhcp.c
--- a/external/bsd/dhcpcd/dist/dhcp.c   Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/dhcp.c   Wed Apr 06 09:06:41 2011 +0000
@@ -1143,7 +1143,9 @@
                case '\'': /* FALLTHROUGH */
                case '$':  /* FALLTHROUGH */
                case '`':  /* FALLTHROUGH */
-               case '\\':
+               case '\\': /* FALLTHROUGH */
+               case '|':  /* FALLTHROUGH */
+               case '&':
                        if (s) {
                                if (len < 3) {
                                        errno = ENOBUFS;
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf
--- a/external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf      Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/20-resolv.conf      Wed Apr 06 09:06:41 2011 +0000
@@ -81,20 +81,28 @@
        if [ -n "$new_domain_name" ]; then
                set -- $new_domain_name
                new_domain_name="$1"
-               conf="${conf}domain $new_domain_name\n"
+               if valid_domainname "$new_domain_name"; then
+                       conf="${conf}domain $new_domain_name\n"
+               else
+                       syslog err "Invalid domain name: $new_domain_name"
+               fi
                # Support RFC violating search in domain
                if [ -z "$new_domain_search" -a -n "$2" ]; then
                        new_domain_search="$@"
                fi
        fi
        if [ -n "$new_domain_search" ]; then
-               conf="${conf}search $new_domain_search\n"
+               if valid_domainname_list; then
+                       conf="${conf}search $new_domain_search\n"
+               else
+                       syslog err "Invalid domain name in list: $new_domain_search"
+               fi
        fi
        for x in ${new_domain_name_servers}; do
                conf="${conf}nameserver $x\n"
        done
        if type resolvconf >/dev/null 2>&1; then
-               [ -n "$metric" ] && export IF_METRIC="$metric"
+               [ -n "$ifmetric" ] && export IF_METRIC="$ifmetric"
                printf "$conf" | resolvconf -a "$interface"
                return $?
        fi
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname
--- a/external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/30-hostname Wed Apr 06 09:06:41 2011 +0000
@@ -18,13 +18,22 @@
        esac
 }
 
+try_hostname()
+{
+       if valid_domainname "$1"; then
+               hostname "$1"
+       else
+               syslog err "Invalid hostname: $1"
+       fi
+}
+
 set_hostname()
 {
        if need_hostname; then
                if [ -n "$new_host_name" ]; then
-                       hostname "$new_host_name"
+                       try_hostname "$new_host_name"
                elif [ -n "$new_fqdn_name" ]; then
-                       hostname "$new_fqdn_name"
+                       try_hostname "$new_fqdn_name"
                fi
        fi
 }
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind
--- a/external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind   Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-hooks/50-ypbind   Wed Apr 06 09:06:41 2011 +0000
@@ -67,7 +67,11 @@
        rm -f "$ypbind_dir/$interface"
 elif $if_up || $if_down; then
        if [ -n "$new_nis_domain" ]; then
-               make_yp_binding
+               if valid_domainname "$new_nis_domain"; then
+                       make_yp_binding
+               else
+                       syslog err "Invalid NIS domain name: $new_nis_domain"
+               fi
        elif [ -n "$old_nis_domain" ]; then
                restore_yp_binding
        fi
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in
--- a/external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in    Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-run-hooks.8.in    Wed Apr 06 09:06:41 2011 +0000
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2006-2010 Roy Marples
+.\" Copyright (c) 2006-2011 Roy Marples
 .\" All rights reserved
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd August 24, 2010
+.Dd March 23, 2011
 .Dt DHCPCD-RUN-HOOKS 8 SMM
 .Os
 .Sh NAME
@@ -135,3 +135,11 @@
 .An Roy Marples Aq roy%marples.name@localhost
 .Sh BUGS
 Please report them to http://roy.marples.name/projects/dhcpcd
+.Sh SECURITY CONSIDERATIONS
+Little validation of DHCP options is done in dhcpcd itself.
+Instead, it is up to the hooks to handle any validation needed.
+To this end, some helper functions are provided, such as valid_domainname as
+used by the
+.Pa 20-resolv.conf
+hook to ensure that the hostname is not set to an invalid value.
+valid_path is also provided, but is currently unused by a stock hook script.
diff -r 1682b35d4b4d -r 6dd42018e0f8 external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in
--- a/external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in      Wed Apr 06 08:47:55 2011 +0000
+++ b/external/bsd/dhcpcd/dist/dhcpcd-run-hooks.in      Wed Apr 06 09:06:41 2011 +0000
@@ -142,11 +142,51 @@
        [ -n "$lvl" ] && shift
        if [ -n "$*" ]; then
                if type logger >/dev/null 2>&1; then
-                       logger -t dhcpcd -p daemon."$lvl" -s "$*"
+                       logger -t dhcpcd -p daemon."$lvl" -is "$interface: $*"
                fi
        fi
 }
 
+# Check for a valid domain name as per RFC1123 with the exception of
+# allowing - and _ as they seem to be widely used.
+valid_domainname()
+{
+       local name="$1" label
+
+       [ -z "$name" -o ${#name} -gt 255 ] && return 1
+       
+       while [ -n "$name" ]; do
+               label="${name%%.*}"
+               [ -z "$label" -o ${#label} -gt 63 ] && return 1
+               case "$label" in
+               -*|_*|*-|*_)            return 1;;
+               *[![:alnum:]-_]*)       return 1;;
+               esac
+               [ "$name" = "${name#*.}" ] && break
+               name="${name#*.}"
+       done
+       return 0        
+}
+
+valid_domainname_list()
+{
+       local name
+
+       for name in $@; do
+               valid_domainname "$name" || return $?
+       done
+       return 0
+}
+
+# Check for a valid path
+valid_path()
+{
+       case "$@" in
+       *[![:alnum:]#%+-_:\.,@~\\/\[\]=\ ]*) return 1;;
+       esac
+       return 0
+}
+
 # Check a system service exists 
 service_exists()



Home | Main Index | Thread Index | Old Index