Print this page
14025 ipnet sniffing leaks promisc mode

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/inet/ipnet/ipnet.c
          +++ new/usr/src/uts/common/inet/ipnet/ipnet.c
↓ open down ↓ 18 lines elided ↑ open up ↑
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24   24   * Use is subject to license terms.
  25   25   * Copyright (c) 2016 by Delphix. All rights reserved.
  26   26   */
  27   27  
  28   28  /*
  29      - * Copyright (c) 2016, Joyent, Inc. All rights reserved.
       29 + * Copyright 2021 Joyent, Inc.
  30   30   */
  31   31  
  32   32  /*
  33   33   * The ipnet device defined here provides access to packets at the IP layer. To
  34   34   * provide access to packets at this layer it registers a callback function in
  35   35   * the ip module and when there are open instances of the device ip will pass
  36   36   * packets into the device. Packets from ip are passed on the input, output and
  37   37   * loopback paths. Internally the module returns to ip as soon as possible by
  38   38   * deferring processing using a taskq.
  39   39   *
↓ open down ↓ 2198 lines elided ↑ open up ↑
2238 2238  
2239 2239          *mhandle = (uintptr_t)ipnet;
2240 2240          netstack_rele(ns);
2241 2241  
2242 2242          return (0);
2243 2243  
2244 2244  regfail:
2245 2245          cmn_err(CE_WARN, "net_hook_register failed: %d", error);
2246 2246          strfree(ipnet->ipnet_hook->h_name);
2247 2247          hook_free(ipnet->ipnet_hook);
     2248 +        ipnet_leave_allmulti(ifp, ns->netstack_ipnet);
2248 2249          netstack_rele(ns);
2249 2250          return (error);
2250 2251  }
2251 2252  
2252 2253  void
2253 2254  ipnet_promisc_remove(void *data)
2254 2255  {
2255 2256          ip_stack_t      *ipst;
2256 2257          ipnet_t         *ipnet;
2257 2258          hook_t          *hook;
↓ open down ↓ 5 lines elided ↑ open up ↑
2263 2264          VERIFY(net_hook_unregister(ipst->ips_ip4_observe_pr, NH_OBSERVE,
2264 2265              hook) == 0);
2265 2266  
2266 2267          VERIFY(net_hook_unregister(ipst->ips_ip6_observe_pr, NH_OBSERVE,
2267 2268              hook) == 0);
2268 2269  
2269 2270          strfree(hook->h_name);
2270 2271  
2271 2272          hook_free(hook);
2272 2273  
     2274 +        ipnet_leave_allmulti(ipnet->ipnet_if, ipnet->ipnet_ns->netstack_ipnet);
     2275 +
2273 2276          kmem_free(ipnet, sizeof (*ipnet));
2274 2277  }
2275 2278  
2276 2279  /*
2277 2280   * arg here comes from the ipnet_t allocated in ipnet_promisc_add.
2278 2281   * An important field from that structure is "ipnet_data" that
2279 2282   * contains the "data" pointer passed into ipnet_promisc_add: it needs
2280 2283   * to be passed back to bpf when we call into ipnet_itap.
2281 2284   *
2282 2285   * ipnet_itap is set by ipnet_set_bpfattach, which in turn is called
↓ open down ↓ 116 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX