History log of /src/sys/net/npf/npf_inet.c |
Revision | | Date | Author | Comments |
1.58 |
| 01-Jul-2025 |
joe | kernel code for layer 2 filtering in NPF
reviewed by christos@
|
1.57 |
| 30-May-2020 |
rmind | Major NPF improvements (merge from upstream):
- Switch to the C11-style atomic primitives using atomic_loadstore(9).
- npfkern: introduce the 'state.key.interface' and 'state.key.direction' settings. Users can now choose whether the connection state should be strictly per-interface or global at the configuration level. Keep NAT logic to be always per-interface, though.
- npfkern: rewrite the G/C worker logic and make it self-tuning.
- npfkern and libnpf: multiple bug fixes; add param exporting; introduce more parameters. Remove npf_nvlist_{copyin,copyout}() functions and refactor npfctl_load_nvlist() with others; add npfctl_run_op() to have a single entry point for operations. Introduce npf_flow_t and clean up some code.
- npfctl: lots of fixes for the 'npfctl show' logic; make 'npfctl list' more informative; misc usability improvements and more user-friendly error messages.
- Amend and improve the manual pages.
|
1.56 |
| 23-May-2020 |
rmind | Backport selected NPF fixes from the upstream (to be pulled up):
- npf_conndb_lookup: protect the connection lookup with pserialize(9), instead of incorrectly assuming that the handler always runs at IPL_SOFNET. Should fix crashes reported on high load (PR/55182).
- npf_config_destroy: handle partially initialized config; fixes crashes with some invalid configurations.
- NAT policy creation / destruction: set the initial reference and do not wait for reference draining on destruction; destroy the policy on the last reference drop instead. Fixes a lockup with the dynamic NAT rules.
- npf_nat_{export,import}: fix a regression since dynamic NAT rules.
- npfctl: fix a regression and restore the default group behaviour.
- Add npf_cache_tcp() and validate the TCP data offset (from maxv@).
|
1.55 |
| 11-Aug-2019 |
rmind | Adjust some internal NPF APIs: * npfkern: use the npfk_ prefix. * NPF portmap: amend the API so it could be used elsewhere. * Make npf_connkey_t public.
|
1.54 |
| 23-Jul-2019 |
rmind | branches: 1.54.2; NPF improvements: - Add support for dynamic NETMAP algorithm (stateful net-to-net). - Add most of the support for the dynamic NAT rules; a little bit more userland work is needed to finish this up and enable. - Replace 'stateful-ends' with more permissive 'stateful-all'. - Add various tunable parameters and document them, see npf-params(7). - Reduce the memory usage of the connection state table (conndb). - Portmap rewrite: use memory more efficiently, handle addresses dynamically. - Bug fix: add splsoftnet()/splx() around the thmap writers and comment. - npftest: clean up and simplify; fix some memleaks to make ASAN happy.
|
1.53 |
| 19-Jan-2019 |
rmind | Major NPF improvements: - Convert NPF connection table to thmap. State lookup is now lock-free. - Improve connection state G/C: it is now incremental and tunable. - Add support for dynamic NAT address. Translation addresses can now be selected from a pool of addresses. There are two selection algorithms, "ip-hash" and "round-robin" (see the man page). - Translation address can be specified as e.g. ifaddrs(wm0) in npf.conf to dynamically choose an IP from the interface address(es). - Add support for the NETMAP algorithm with static NAT for net-to-net translation (it is equivalent to iptables NETMAP logic). - Convert 'ipset' tables to use thmap; the table lookup is now lock-free. - Misc improvements, bug fixes and more unit tests. - Bump NPF_VERSION (will also bump libnpf).
|
1.52 |
| 29-Sep-2018 |
rmind | NPF: Major rework -- migrate NPF to the libnv library. - This conversion significantly simplifies the code and moves NPF to a binary serialisation format (replacing the XML-like format). - Fix some memory/reference leaks and possibly use-after-free bugs. - Bump NPF_VERSION as this change makes libnpf incompatible with the previous versions. Also, different serialisation format means NPF connection/config saving and loading is not compatible with the previous versions either.
Thanks to christos@ for extra testing.
|
1.51 |
| 31-Aug-2018 |
maxv | Introduce npf_set_mss(). When the MSS is not 16bit-aligned, it sets:
0 8 16 24 32 +------+-----------+-----------+------+ | data | MSS (low) | MSS (hig) | data | +------+-----------+-----------+------+ ^ ^ old[0] old[1]
And sets new[0,1] accordingly with the new value. The MSS-clamping code then adjusts twice the checksum on a 16bit boundary:
from old[0] to new[0] from old[1] to new[1]
Fixes PR/53479, opened by myself. Tested with wireshark and kASan.
|
1.50 |
| 08-Apr-2018 |
maxv | branches: 1.50.2; Fix bug I introduced in previous commit.
|
1.49 |
| 07-Apr-2018 |
maxv | Rewrite npf_fetch_tcpopts:
* Instead of doing several nbuf_advance/nbuf_ensure_contig and playing with gotos, fetch the TCP options only once, and iterate over the (safe) area. The code is similar to tcp_dooptions.
* When handling TCPOPT_MAXSEG and TCPOPT_WINDOW, ensure the length is the one we're expecting. If it isn't, then skip the option. This wasn't done before, and not doing it allowed a packet to bypass the max-mss clamping procedure. Discussed on tech-net@.
|
1.48 |
| 06-Apr-2018 |
maxv | If we're trying to read the mss on a packet that for some reason has two MAXSEG options, we find ourselves patching the second option with the value of the first one.
Fix that by using a local variable.
|
1.47 |
| 23-Mar-2018 |
maxv | If we fail to advance inside TCP/UDP/ICMPv4/ICMPv6, stop pretending L4 is unknown, and error out right away.
This prevents bugs in machinery, if a place looks for L4 in 'npc_proto' without checking the cache too. I've seen a ~similar problem already.
|
1.46 |
| 22-Mar-2018 |
maxv | Retrieve the complete IPv4 header right away, and make sure we did retrieve the IPv6 option header we were iterating on.
|
1.45 |
| 22-Mar-2018 |
maxv | Change npf_cache_all so that it ensures the potential ICMP Query Id is in the nbuf. In such a way that we don't need to ensure that later.
Change npfa_icmp4_inspect and npfa_icmp6_inspect so that they touch neither the nbuf nor npc. Adapt their callers accordingly.
In the end, if a packet has a Query Id, we set NPC_ICMP_ID in npc and leave right away, without recaching npc (not needed since we didn't touch the nbuf).
This fixes the handling of Query Id packets (that I broke in my previous commit), and also fixes another possible use-after-free.
|
1.44 |
| 21-Mar-2018 |
maxv | Add XXX (we don't handle IPv6 Jumbograms), and whitespace.
|
1.43 |
| 21-Mar-2018 |
maxv | Don't read the L4 payload after IPPROTO_AH when handling IPv6 packets.
AH must be considered as the payload, otherwise a
block all pass in proto ah from any pass out proto ah from any
configuration will actually block everything, because NPF checks the protocol against the one found after AH, and not AH itself.
In addition it may have been a problem for stateful connections; an AH packet sent by an attacker with an incorrect authentication and a correct TCP/UDP/whatever payload from an active connection could manage to change NPF's FSM state, which would perhaps have altered the legitimate connection with the authenticated remote IPsec host.
Note that IPv4 already doesn't go beyond AH, which is the correct behavior.
|
1.42 |
| 17-Mar-2018 |
maxv | Fix the IPv6 payload computation in npf_tcpsaw. It was incorrect, and this caused the "return-rst" rules to send back an RST with the wrong ACK when the received SYN had an IPv6 option.
|
1.41 |
| 13-Mar-2018 |
maxv | Mmh, put back the RFC6946 check (about dummy fragments), otherwise NPF is not happy in npf_reassembly, because NPC_IPFRAG is again returned after the packet was reassembled.
I'm wondering whether it would not be better to just remove the fragment header in frag6_input directly.
|
1.40 |
| 13-Mar-2018 |
maxv | Fix two consecutive mistakes.
The first mistake was npf_inet.c rev1.37:
"Don't reassemble ipv6 fragments, instead treat the first fragment as a regular packet (subject to filtering rules), and pass subsequent fragments in the same group unconditionally."
Doing this was entirely wrong, because then a packet just had to push the L4 payload in a secondary fragment, and NPF wouldn't apply rules on it - meaning any IPv6 packet could bypass >=L4 filtering. This mistake was supposed to be a fix for the second mistake.
The second mistake was that ip6_reass_packet (in npf_reassembly) was getting called with npc->npc_hlen. But npc_hlen pointed to the last encountered header in the IPv6 chain, which was not necessarily the fragment header. So ip6_reass_packet was given garbage, and would fail, resulting in the packet getting kicked. So basically IPv6 was broken by NPF.
The first mistake is reverted, and the second one is fixed by doing:
- hlen = sizeof(struct ip6_frag); + hlen = 0;
Now the iteration stops on the fragment header, and the call to ip6_reass_packet is valid.
My npf_inet.c rev1.38 is partially reverted: we don't need to worry about failing properly to advance; once the packet is reassembled npf_cache_ip gets called again, and this time the whole chain should be there.
Tested with a simple UDPv6 server - send a 3000-byte-sized buffer, the packet gets correctly reassembled by NPF now.
|
1.39 |
| 08-Mar-2018 |
maxv | Switch nptr to uint8_t, and use nbuf_ensure_contig. Makes us use fewer magic values.
|
1.38 |
| 08-Mar-2018 |
maxv | Declare NPC_FMTERR, and use it to kick malformed packets. Several sanity checks are added in IPv6; after we see the first IPPROTO_FRAGMENT header, we are allowed to fail to advance, otherwise we kick the packet.
Sent on tech-net@ a few days ago, no response, but I'm committing it now anyway.
|
1.37 |
| 19-Feb-2017 |
christos | branches: 1.37.6; 1.37.12; Don't reassemble ipv6 fragments, instead treat the first fragment as a regular packet (subject to filtering rules), and pass subsequent fragments in the same group unconditionally.
|
1.36 |
| 26-Dec-2016 |
christos | branches: 1.36.2; Sync NPF with the version on github: backport standalone NPF changes, which allow us to create and run separate NPF instances. Minor fixes. (from rmind@)
|
1.35 |
| 07-Nov-2016 |
jnemeth | fixup misplaced #endif
|
1.34 |
| 18-Mar-2016 |
mrg | branches: 1.34.2; minimal changes necessary to link into an INET6-less kernel.
|
1.33 |
| 17-Dec-2015 |
mlelstv | make DDB print ipv6 addresses too
|
1.32 |
| 20-Jul-2014 |
rmind | branches: 1.32.2; 1.32.4; 1.32.6; 1.32.10; NPF: add nbuf_t * into npf_cache_t and remove unnecessary carrying by argument.
|
1.31 |
| 19-Jul-2014 |
rmind | NPF: partially rewrite the connection tracking mechanism: - Separate the tracking interface from the storage (state table) and thus prepare to use a new data structure for the storage. - Fix some race conditions in NAT association logic.
|
1.30 |
| 19-Feb-2014 |
rmind | branches: 1.30.2; NPF: fix the recent breakage of the traceroute ALG. Also, simplify and refactor a little bit.
|
1.29 |
| 13-Feb-2014 |
rmind | NPF: add support for IPv6-to-IPv6 Network Prefix Translation (NPTv6), as per RFC 6296. Add a unit test. Also, bump NPF_VERSION.
Thanks to S.P.Zeidler for the help with NPTv6 work!
|
1.28 |
| 06-Dec-2013 |
rmind | NPF: - Adjust NAT to not assume flow direction in some cases and thus support less usual setups which are possible when using 'map' with a custom filter criteria. - Introduce NPF_SRC/NPF_DST and replace npc_src/npc_dst with npc_ips[2] for more convenient handling. - ICMP ALG: restrict matching only to the outgoing traffic, but be more direction-agnostic elsewhere.
|
1.27 |
| 22-Nov-2013 |
rmind | Optimise checksum fixup routines: - npf_fixup16_cksum: 1's complement sum is endian-independent. - npf_fixup32_cksum: the first 32->16 bit reduction is not needed.
Pointed out by Valery Ushakov.
|
1.26 |
| 22-Nov-2013 |
rmind | npf_addr_mix: use xor rather than sum.
|
1.25 |
| 30-Oct-2013 |
mrg | used __diagused where appropriate.
|
1.24 |
| 25-Oct-2013 |
martin | Turn a few __unused into __diagused
|
1.23 |
| 23-Aug-2013 |
rmind | - npf_cache_ip: re-fetch IPv6 header since nbufs might have been reallocated. - npf_cache_all: clear NBUF_DATAREF_RESET since npf_cache_ip() handles it.
|
1.22 |
| 02-Jun-2013 |
rmind | branches: 1.22.2; - NPF connection tracking: rework synchronisation on tracking disable/enable points and document it. Split the worker thread into a separate module with an interface, so it could be re-used for other tasks. - Replace ALG list with arrays and thus hit fewer cache lines. - Misc bug fixes.
|
1.21 |
| 09-Feb-2013 |
rmind | NPF: - Implement dynamic NPF rules. Controlled through npf(3) library of via npfctl rule command. A rule can be removed using a unique identifier, returned on addition, or using a key which is SHA1 hash of the rule. Adjust npftest and add a regression test. - Improvements to rule inspection mechanism. - Initial BPF support as an alternative to n-code. - Minor fixes; bump the version.
|
1.20 |
| 24-Dec-2012 |
rmind | Silence gcc in npf_recache().
|
1.19 |
| 24-Dec-2012 |
rmind | - Rework NPF's nbuf interface: use advancing and ensuring as a main method. Eliminate unnecessary copy and simplify. Adapt regression tests. - Simplify ICMP ALG a little. While here, handle ICMP ECHO for traceroute. - Minor fixes, misc cleanup.
|
1.18 |
| 10-Dec-2012 |
rmind | npf_rwrcksum: handle delayed checksums in the network stack; also fix non-NPF_NAT_PORTS case and add some comments. PR/47235.
|
1.17 |
| 16-Sep-2012 |
rmind | Implement dynamic NPF extensions interface. An extension consists of dynamically loaded module (.so) supplementing npfctl(8) and a kernel module. Move normalisation and logging functionality into their own extensions. More improvements to come.
|
1.16 |
| 21-Jul-2012 |
rmind | branches: 1.16.2; - npf_fetch_tcpopts: fix off-by-one when validating TCP option length against the maximum allowed. - npf_tcp_inwindow: be more liberal with npf_fetch_tcpopts(). - Few minor improvements to npftest.
|
1.15 |
| 19-Jul-2012 |
spz | teach npf ipv6-icmp reviewed by rmind@
|
1.14 |
| 15-Jul-2012 |
rmind | - Rework NPF tables and fix support for IPv6. Implement tree table type using radix / Patricia tree. Universal IPv4/IPv6 comparator for ptree(3) was contributed by Matt Thomas. - NPF tables: update regression tests, improve npfctl(8) error messages. - Fix few bugs when using kernel modules and handle module autounloader. - Few other fixes and misc cleanups. - Bump the version.
|
1.13 |
| 01-Jul-2012 |
rmind | NPF improvements: - Add NPF_OPCODE_PROTO to match the address and/or protocol only. - Update parser to support arbitrary "pass proto <name/number>". - Fix IPv6 address and protocol handling (add a regression test). - Fix few theorethical races in session handling module. - Misc fixes, simplifications and some clean up.
|
1.12 |
| 22-Jun-2012 |
rmind | NPF: - Rename some functions for consistency and de-inline them. - Fix few invalid asserts (add regressoin test). - Use pserialize(9) for ALG interface. - Minor fixes, sprinkle many comments.
|
1.11 |
| 20-Feb-2012 |
rmind | - Add NPF_DECISION_BLOCK and NPF_DECISION_PASS. Be more defensive in the packet handler. Change the default policy to block when the config is loaded and set it to pass when flush operation is performed. - Use kmem_zalloc(9) instead of kmem_alloc(9) in few places. - npf_rproc_{create,release}: use kmem_intr_{alloc,free} as the destruction of rule procedure might happen in the interrupt handler (under a very rare condition, if config reload races with the handler). - npf_session_establish: check whether layer 3 and 4 are cached. - npfctl_build_group: do not make groups as passing rules. - Remove some unecessary header inclusion.
|
1.10 |
| 29-Nov-2011 |
rmind | branches: 1.10.2; 1.10.4; - Rework and improve TCP state tracking. - Fix regressions after IPv6 patch merge.
Note: npfctl(8) rework will come soon.
|
1.9 |
| 12-Nov-2011 |
jakllsch | Make a comment consistent with the code.
|
1.8 |
| 06-Nov-2011 |
rmind | Few fixes, KNF/style, bump the NPF version.
|
1.7 |
| 04-Nov-2011 |
zoltan | Add IPv6 support for NPF.
|
1.6 |
| 18-Jan-2011 |
rmind | branches: 1.6.4; 1.6.8; NPF checkpoint: - Add the concept of rule procedure: separate normalization, logging and potentially other functions from the rule structure. Rule procedure can be shared amongst the rules. Separation is both at kernel level (npf_rproc_t) and configuration ("procedure" + "apply"). - Fix portmap sharing for NAT policy. - Update TCP state tracking logic. Use TCP FSM definitions. - Add if_byindex(), OK by matt@. Use in logging for the lookup. - Fix traceroute ALG and many other bugs; misc clean-up.
|
1.5 |
| 18-Dec-2010 |
rmind | branches: 1.5.2; NPF checkpoint: - Add support for session saving/restoring. - Add packet logging support (can tcpdump a pseudo-interface). - Support reload without flushing of sessions; rework some locking. - Revisit session mangement, replace linking with npf_sentry_t entries. - Add some counters for statistics, using percpu(9). - Add IP_DF flag cleansing. - Fix various bugs; misc clean-up.
|
1.4 |
| 11-Nov-2010 |
rmind | NPF checkpoint: - Add proper TCP state tracking as described in Guido van Rooij paper, plus handle TCP Window Scaling option. - Completely rework npf_cache_t, reduce granularity, simplify code. - Add npf_addr_t as an abstraction, amend session handling code, as well as NAT code et al, to use it. Now design is prepared for IPv6 support. - Handle IPv4 fragments i.e. perform packet reassembly. - Add support for IPv4 ID randomization and minimum TTL enforcement. - Add support for TCP MSS "clamping". - Random bits for IPv6. Various fixes and clean-up.
|
1.3 |
| 25-Sep-2010 |
rmind | branches: 1.3.2; 1.3.4; Add nbuf_advfetch() and simplify some code slightly.
|
1.2 |
| 16-Sep-2010 |
rmind | NPF checkpoint: - Add support for bi-directional NAT and redirection / port forwarding. - Finish filtering on ICMP type/code and add filtering on TCP flags. - Add support for TCP reset (RST) or ICMP destination unreachable on block. - Fix a bunch of bugs; misc cleanup.
|
1.1 |
| 22-Aug-2010 |
rmind | Import NPF - a packet filter. Some features:
- Designed to be fully MP-safe and highly efficient.
- Tables/IP sets (hash or red-black tree) for high performance lookups.
- Stateful filtering and Network Address Port Translation (NAPT). Framework for application level gateways (ALGs).
- Packet inspection engine called n-code processor - inspired by BPF - supporting generic RISC-like and specific CISC-like instructions for common patterns (e.g. IPv4 address matching). See npf_ncode(9) manual.
- Convenient userland utility npfctl(8) with npf.conf(8).
NOTE: This is not yet a fully capable alternative to PF or IPFilter. Further work (support for binat/rdr, return-rst/return-icmp, common ALGs, state saving/restoring, logging, etc) is in progress.
Thanks a lot to Matt Thomas for various useful comments and code review. Aye by: board@
|
1.3.4.2 |
| 22-Oct-2010 |
uebayasi | Sync with HEAD (-D20101022).
|
1.3.4.1 |
| 25-Sep-2010 |
uebayasi | file npf_inet.c was added on branch uebayasi-xip on 2010-10-22 09:23:15 +0000
|
1.3.2.2 |
| 09-Oct-2010 |
yamt | sync with head
|
1.3.2.1 |
| 25-Sep-2010 |
yamt | file npf_inet.c was added on branch yamt-nfs-mp on 2010-10-09 03:32:37 +0000
|
1.5.2.1 |
| 06-Jun-2011 |
jruoho | Sync with HEAD.
|
1.6.8.6 |
| 22-May-2014 |
yamt | sync with head.
for a reference, the tree before this commit was tagged as yamt-pagecache-tag8.
this commit was splitted into small chunks to avoid a limitation of cvs. ("Protocol error: too many arguments")
|
1.6.8.5 |
| 23-Jan-2013 |
yamt | sync with head
|
1.6.8.4 |
| 16-Jan-2013 |
yamt | sync with (a bit old) head
|
1.6.8.3 |
| 30-Oct-2012 |
yamt | sync with head
|
1.6.8.2 |
| 17-Apr-2012 |
yamt | sync with head
|
1.6.8.1 |
| 10-Nov-2011 |
yamt | sync with head
|
1.6.4.2 |
| 05-Mar-2011 |
rmind | sync with head
|
1.6.4.1 |
| 18-Jan-2011 |
rmind | file npf_inet.c was added on branch rmind-uvmplock on 2011-03-05 20:55:55 +0000
|
1.10.4.11 |
| 17-May-2018 |
martin | Pull up following revision(s) via patch (requested by maxv in ticket #1549):
sys/net/npf/npf_inet.c: revision 1.45 sys/net/npf/npf_alg_icmp.c: revision 1.27,1.28
Fix use-after-free.
The nbuf can be reallocated as a result of caching 'enpc', so it is necessary to recache 'npc', otherwise it contains pointers to the freed mbuf - pointers which are then used in the ruleset machinery.
We recache 'npc' when we are sure we won't use 'enpc' anymore, because 'enpc' can be clobbered as a result of caching 'npc' (in other words, only one of the two can be cached at the same time).
Also, we recache 'npc' unconditionally, because there is no way to know whether the nbuf got clobbered relatively to it. We can't use the NBUF_DATAREF_RESET flag, because it is stored in the nbuf and not in the cache.
Discussed with rmind@.
Change npf_cache_all so that it ensures the potential ICMP Query Id is in the nbuf. In such a way that we don't need to ensure that later. Change npfa_icmp4_inspect and npfa_icmp6_inspect so that they touch neither the nbuf nor npc. Adapt their callers accordingly.
In the end, if a packet has a Query Id, we set NPC_ICMP_ID in npc and leave right away, without recaching npc (not needed since we didn't touch the nbuf).
This fixes the handling of Query Id packets (that I broke in my previous commit), and also fixes another possible use-after-free.
|
1.10.4.10 |
| 13-Sep-2013 |
msaitoh | Pull up following revision (requested by riz in ticket #942): /sys/net/npf/npf_inet.c revision 1.23 Fix bugs to prevent panic: - npf_cache_ip: re-fetch IPv6 header since nbufs might have been reallocated. - npf_cache_all: clear NBUF_DATAREF_RESET since npf_cache_ip() handles it.
|
1.10.4.9 |
| 11-Feb-2013 |
riz | branches: 1.10.4.9.2; Pull up following revision(s) (requested by rmind in ticket #817): usr.sbin/npf/npfctl/npfctl.8: revision 1.12 usr.sbin/npf/npfctl/npf.conf.5: revision 1.27 usr.sbin/npf/npfctl/npf_parse.y: revision 1.18 usr.sbin/npf/npfctl/npf_build.c: revision 1.20 usr.sbin/npf/npfctl/npfctl.c: revision 1.28 lib/libnpf/npf.c: revision 1.16 usr.sbin/npf/npfctl/npfctl.c: revision 1.29 lib/libnpf/npf.c: revision 1.17 sys/modules/npf/Makefile: revision 1.12 sys/net/npf/npf_rproc.c: revision 1.6 usr.sbin/npf/npftest/README: revision 1.4 sys/net/npf/npf_tableset.c: revision 1.17 sys/net/npf/npf_ctl.c: revision 1.21 sys/net/npf/npf_ctl.c: revision 1.22 usr.sbin/npf/npfctl/npfctl.h: revision 1.25 lib/libnpf/npf.h: revision 1.13 usr.sbin/npf/npftest/npftest.conf: revision 1.2 usr.sbin/npf/npfctl/npfctl.h: revision 1.26 sys/net/npf/npf_ruleset.c: revision 1.17 lib/libnpf/npf.h: revision 1.14 sys/net/npf/npf_ruleset.c: revision 1.18 sys/net/npf/npf_conf.c: revision 1.1 usr.sbin/npf/npfctl/npf_scan.l: revision 1.10 sys/net/npf/npf_conf.c: revision 1.2 sys/net/npf/npf_instr.c: revision 1.16 sys/net/npf/npf_handler.c: revision 1.26 sys/net/npf/npf_impl.h: revision 1.26 usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.14 sys/net/npf/npf_processor.c: revision 1.15 sys/net/npf/npf_impl.h: revision 1.27 sys/net/npf/npf_alg_icmp.c: revision 1.15 usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.15 usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.16 sys/net/npf/npf_ncode.h: revision 1.11 sys/net/npf/files.npf: revision 1.10 usr.sbin/npf/npftest/Makefile: revision 1.4 usr.sbin/npf/npfctl/npfctl.c: revision 1.30 lib/libnpf/npf.3: revision 1.8 usr.sbin/npf/npftest/libnpftest/npf_rule_test.c: revision 1.4 sys/net/npf/npf_session.c: revision 1.21 usr.sbin/npf/npftest/libnpftest/npf_rule_test.c: revision 1.5 usr.sbin/npf/npfctl/npf_build.c: revision 1.18 usr.sbin/npf/npfctl/npf_build.c: revision 1.19 sys/net/npf/npf_alg.c: revision 1.7 usr.sbin/npf/npfctl/Makefile: revision 1.10 sys/net/npf/npf_inet.c: revision 1.21 sys/net/npf/npf.h: revision 1.26 sys/net/npf/npf.h: revision 1.27 usr.sbin/pf/ftp-proxy/Makefile: revision 1.8 sys/net/npf/npf_nat.c: revision 1.19 sys/net/npf/npf.c: revision 1.15 sys/net/npf/npf_state.c: revision 1.14 sys/net/npf/npf_sendpkt.c: revision 1.14 sys/rump/net/lib/libnpf/Makefile: revision 1.4 IPv6 linklocal address printing cosmetics NPF: - Implement dynamic NPF rules. Controlled through npf(3) library of via npfctl rule command. A rule can be removed using a unique identifier, returned on addition, or using a key which is SHA1 hash of the rule. Adjust npftest and add a regression test. - Improvements to rule inspection mechanism. - Initial BPF support as an alternative to n-code. - Minor fixes; bump the version. Disable -DWITH_NPF for now; will be converted to BPF mechanism. - Fix NPF config reload with dynamic rules present. - Implement list and flush commands on a dynamic ruleset. Allow filtering on IP addresses even if the L4 protocol is unknown. Patch from spz@. npftest: adjust for recent change.
|
1.10.4.8 |
| 08-Feb-2013 |
riz | Pull up following revision(s) (requested by rmind in ticket #777): usr.sbin/npf/npfctl/npfctl.c: revision 1.27 sys/net/npf/npf_session.c: revision 1.19 usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c: revision 1.4 sys/net/npf/npf_rproc.c: revision 1.5 usr.sbin/npf/npftest/README: revision 1.3 sys/sys/mbuf.h: revision 1.151 sys/net/npf/npf_ruleset.c: revision 1.15 usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c: revision 1.3 sys/net/npf/npf_ruleset.c: revision 1.16 usr.sbin/npf/npftest/libnpftest/npf_state_test.c: revision 1.4 usr.sbin/npf/npftest/libnpftest/npf_nbuf_test.c: revision 1.4 sys/net/npf/npf_inet.c: revision 1.19 sys/net/npf/npf_instr.c: revision 1.15 sys/net/npf/npf_handler.c: revision 1.24 sys/net/npf/npf_handler.c: revision 1.25 sys/net/npf/npf_state_tcp.c: revision 1.12 sys/net/npf/npf_processor.c: revision 1.13 sys/net/npf/npf_impl.h: revision 1.25 sys/net/npf/npf_processor.c: revision 1.14 sys/net/npf/npf_mbuf.c: revision 1.10 sys/net/npf/npf_alg_icmp.c: revision 1.14 sys/net/npf/npf_mbuf.c: revision 1.9 usr.sbin/npf/npftest/libnpftest/npf_nat_test.c: revision 1.2 usr.sbin/npf/npftest/libnpftest/npf_rule_test.c: revision 1.3 sys/net/npf/npf_session.c: revision 1.20 sys/net/npf/npf_alg.c: revision 1.6 sys/kern/uipc_mbuf.c: revision 1.148 sys/net/npf/npf_inet.c: revision 1.20 sys/net/npf/npf.h: revision 1.25 sys/net/npf/npf_nat.c: revision 1.18 sys/net/npf/npf_state.c: revision 1.13 sys/net/npf/npf_sendpkt.c: revision 1.13 sys/net/npf/npf_ext_log.c: revision 1.2 usr.sbin/npf/npftest/libnpftest/npf_processor_test.c: revision 1.4 sys/net/npf/npf_ext_normalise.c: revision 1.2 - Rework NPF's nbuf interface: use advancing and ensuring as a main method. Eliminate unnecessary copy and simplify. Adapt regression tests. - Simplify ICMP ALG a little. While here, handle ICMP ECHO for traceroute. - Minor fixes, misc cleanup. Silence gcc in npf_recache(). Add m_ensure_contig() routine, which is equivalent to m_pullup, but does not destroy the mbuf chain on failure (it is kept valid). - nbuf_ensure_contig: rework to use m_ensure_contig(9), which will not free the mbuf chain on failure. Fixes some corner cases. Improve regression test and sprinkle some asserts. - npf_reassembly: clear nbuf on IPv6 reassembly failure path (partial fix). The problem was found and fix provided by Anthony Mallet.
|
1.10.4.7 |
| 16-Dec-2012 |
riz | Pull up following revision(s) (requested by rmind in ticket #746): sys/net/npf/npf_inet.c: revision 1.18 sys/net/npf/npf_mbuf.c: revision 1.8 sys/net/npf/npf.h: revision 1.23 npf_rwrcksum: handle delayed checksums in the network stack; also fix non-NPF_NAT_PORTS case and add some comments. PR/47235.
|
1.10.4.6 |
| 18-Nov-2012 |
riz | Pull up following revision(s) (requested by rmind in ticket #693): lib/npf/ext_normalise/shlib_version: revision 1.1 lib/libnpf/npf.c: revision 1.13 distrib/sets/lists/modules/mi: revision 1.48 sys/net/npf/npf_rproc.c: revision 1.3 sys/net/npf/npf_rproc.c: revision 1.4 sys/modules/npf/Makefile: revision 1.11 usr.sbin/npf/npfctl/npfctl.h: revision 1.20 lib/npf/ext_log/npfext_log.c: revision 1.1 lib/libnpf/npf.h: revision 1.11 sys/net/npf/npf_inet.c: revision 1.17 sys/net/npf/npf_log.c: file removal sys/net/npf/npf_handler.c: revision 1.22 distrib/sets/lists/base/shl.mi: revision 1.636 sys/net/npf/npf_impl.h: revision 1.23 usr.sbin/npf/npfctl/Makefile: revision 1.8 lib/npf/Makefile: revision 1.1 lib/npf/ext_log/shlib_version: revision 1.1 lib/Makefile: revision 1.189 distrib/sets/lists/comp/shl.mi: revision 1.236 usr.sbin/npf/npfctl/npf_build.c: revision 1.14 distrib/sets/lists/base/mi: revision 1.1007 usr.sbin/npf/npfctl/npf_scan.l: revision 1.6 distrib/sets/lists/base/mi: revision 1.1009 sys/net/npf/npf.h: revision 1.21 lib/npf/ext_normalise/npfext_normalise.c: revision 1.1 etc/mtree/NetBSD.dist.base: revision 1.105 lib/libnpf/Makefile: revision 1.3 etc/mtree/NetBSD.dist.base: revision 1.106 usr.sbin/npf/npfctl/npf_extmod.c: revision 1.1 sys/net/npf/npf_ctl.c: revision 1.18 lib/npf/ext_log/Makefile: revision 1.1 distrib/sets/lists/comp/mi: revision 1.1781 usr.sbin/npf/npfctl/npf_var.h: revision 1.4 sys/net/npf/npf.c: revision 1.13 sys/modules/Makefile: revision 1.111 sys/net/npf/npf_ext_log.c: revision 1.1 lib/npf/Makefile.inc: revision 1.1 sys/net/npf/npf_ext_normalise.c: revision 1.1 sys/net/npf/files.npf: revision 1.8 sys/rump/net/lib/libnpf/Makefile: revision 1.2 sys/modules/npf_ext_log/Makefile: revision 1.1 lib/npf/ext_normalise/Makefile: revision 1.1 usr.sbin/npf/npfctl/npfctl.c: revision 1.20 usr.sbin/npf/npfctl/npf_parse.y: revision 1.13 sys/modules/npf_ext_normalise/Makefile: revision 1.1 Implement dynamic NPF extensions interface. An extension consists of dynamically loaded module (.so) supplementing npfctl(8) and a kernel module. Move normalisation and logging functionality into their own extensions. More improvements to come. Add /usr/lib/npf. Add ./usr/libdata/debug/usr/lib/npf for rmind Fix MKDEBUG set lists ext_ops does not change during the life cycle and can be fetched without the mutex held. This avoids confusion in the compiler about an uninitialized variable ext_ops. ok rmind@
|
1.10.4.5 |
| 25-Jul-2012 |
jdc | branches: 1.10.4.5.4; Pull up revisions: src/usr.sbin/npf/npfctl/npfctl.c revisions 1.16,1.17 src/sys/net/npf/npf.h revision 1.20 src/sys/net/npf/npf_alg_icmp.c revision 1.11 src/sys/net/npf/npf_impl.h revision 1.19 src/sys/net/npf/npf_inet.c revisions 1.15,1.16 src/sys/net/npf/npf_instr.c revision 1.14 src/sys/net/npf/npf_ncode.h revision 1.10 src/sys/net/npf/npf_processor.c revision 1.12 src/sys/net/npf/npf_session.c revision 1.16 src/usr.sbin/npf/npfctl/npf_build.c revision 1.12 src/usr.sbin/npf/npfctl/npf_data.c revisions 1.16,1.17 src/usr.sbin/npf/npfctl/npf_disassemble.c revision 1.8 src/usr.sbin/npf/npfctl/npf_ncgen.c revision 1.13 src/usr.sbin/npf/npfctl/npf_parse.y revision 1.11 src/usr.sbin/npf/npfctl/npf_scan.l revision 1.5 src/usr.sbin/npf/npfctl/npf_var.h revision 1.3 src/usr.sbin/npf/npfctl/npfctl.h revision 1.18 src/sys/net/npf/npf_state.c revision 1.10 src/sys/net/npf/npf_state_tcp.c revision 1.10 src/usr.sbin/npf/npftest/npfstream.c revision 1.2 src/usr.sbin/npf/npftest/libnpftest/npf_test_subr.c revision 1.2 (requested by rmind in ticket #435).
Add missing __dead.
teach npf ipv6-icmp reviewed by rmind@
- npfctl_print_stats: beautification a la French style. - npfctl_icmpcode: fix the build break.
- npf_fetch_tcpopts: fix off-by-one when validating TCP option length against the maximum allowed. - npf_tcp_inwindow: be more liberal with npf_fetch_tcpopts(). - Few minor improvements to npftest.
|
1.10.4.4 |
| 16-Jul-2012 |
riz | Pull up following revision(s) (requested by rmind in ticket #421): lib/libnpf/npf.c: revision 1.10 sys/net/npf/npf_session.c: revision 1.15 sys/net/npf/npf_tableset.c: revision 1.13 sys/net/npf/npf_state_tcp.c: revision 1.9 usr.sbin/npf/npfctl/npf_data.c: revision 1.15 sys/net/npf/npf_inet.c: revision 1.14 sys/net/npf/npf_ruleset.c: revision 1.13 sys/net/npf/npf.h: revision 1.19 usr.sbin/npf/npfctl/npf_ncgen.c: revision 1.12 sys/net/npf/npf_instr.c: revision 1.13 sys/net/npf/npf_handler.c: revision 1.20 usr.sbin/npf/npftest/libnpftest/npf_table_test.c: revision 1.4 sys/net/npf/npf_alg_icmp.c: revision 1.10 usr.sbin/npf/npfctl/npfctl.c: revision 1.15 usr.sbin/npf/npfctl/npf_build.c: revision 1.11 lib/libnpf/npf.h: revision 1.9 sys/net/npf/npf_alg.c: revision 1.5 sys/rump/dev/lib/libnpf/Makefile: revision 1.4 usr.sbin/npf/npfctl/npfctl.h: revision 1.17 sys/net/npf/npf_ctl.c: revision 1.16 sys/net/npf/npf_nat.c: revision 1.15 sys/net/npf/npf_tableset_ptree.c: revision 1.1 sys/net/npf/npf.c: revision 1.12 sys/net/npf/npf_sendpkt.c: revision 1.12 usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.7 sys/net/npf/npf_impl.h: revision 1.18 sys/net/npf/files.npf: revision 1.7 usr.sbin/npf/npfctl/npf_parse.y: revision 1.10 - Rework NPF tables and fix support for IPv6. Implement tree table type using radix / Patricia tree. Universal IPv4/IPv6 comparator for ptree(3) was contributed by Matt Thomas. - NPF tables: update regression tests, improve npfctl(8) error messages. - Fix few bugs when using kernel modules and handle module autounloader. - Few other fixes and misc cleanups. - Bump the version.
|
1.10.4.3 |
| 05-Jul-2012 |
riz | Pull up following revision(s) (requested by rmind in ticket #399): sys/net/npf/npf_session.c: revision 1.14 sys/net/npf/npf_tableset.c: revision 1.12 sys/net/npf/npf_state_tcp.c: revision 1.8 usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c: revision 1.3 usr.sbin/npf/npfctl/npf_data.c: revision 1.14 sys/net/npf/npf_inet.c: revision 1.13 sys/net/npf/npf_ruleset.c: revision 1.12 sys/net/npf/npf.h: revision 1.18 usr.sbin/npf/npfctl/npf_ncgen.c: revision 1.11 usr.sbin/npf/npfctl/npfctl.8: revision 1.7 usr.sbin/npf/npfctl/npf_parse.y: revision 1.9 usr.sbin/npf/npftest/libnpftest/npf_state_test.c: revision 1.2 usr.sbin/npf/npfctl/npfctl.8: revision 1.8 sys/net/npf/npf_instr.c: revision 1.12 usr.sbin/npf/npftest/libnpftest/npf_table_test.c: revision 1.3 usr.sbin/npf/npfctl/npf.conf.5: revision 1.13 usr.sbin/npf/npfctl/npf.conf.5: revision 1.14 sys/net/npf/npf_state.c: revision 1.9 sys/net/npf/npf_processor.c: revision 1.11 usr.sbin/npf/npfctl/npfctl.c: revision 1.13 usr.sbin/npf/npfctl/npfctl.c: revision 1.14 usr.sbin/npf/npfctl/npf_build.c: revision 1.10 lib/libnpf/npf.3: revision 1.5 lib/libnpf/npf.h: revision 1.8 share/man/man9/npf_ncode.9: revision 1.9 usr.sbin/npf/npfctl/npf_scan.l: revision 1.4 lib/libnpf/npf.c: revision 1.9 usr.sbin/npf/npfctl/npfctl.h: revision 1.16 sys/net/npf/npf_nat.c: revision 1.14 usr.sbin/npf/npftest/libnpftest/npf_processor_test.c: revision 1.2 usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.6 sys/net/npf/npf_impl.h: revision 1.17 sys/net/npf/npf_handler.c: revision 1.18 sys/net/npf/npf_handler.c: revision 1.19 usr.sbin/npf/npftest/libnpftest/npf_test.h: revision 1.4 sys/net/npf/npf_ncode.h: revision 1.9 Fix and update npf.conf(5), npfctl(8) and its usage message. npf_state_tcp: fix for FIN retransmission and out-of-order ACK case. NPF improvements: - Add NPF_OPCODE_PROTO to match the address and/or protocol only. - Update parser to support arbitrary "pass proto <name/number>". - Fix IPv6 address and protocol handling (add a regression test). - Fix few theorethical races in session handling module. - Misc fixes, simplifications and some clean up. npf_packet_handler: fix gcc unused warning.
|
1.10.4.2 |
| 26-Jun-2012 |
riz | Pull up following revision(s) (requested by rmind in ticket #365): sys/rump/librump/rumpkern/rumpcpu_generic.c: revision 1.4 sys/net/npf/npf_session.c: revision 1.13 sys/net/npf/npf_tableset.c: revision 1.11 sys/net/npf/npf_state_tcp.c: revision 1.7 sys/net/npf/npf_inet.c: revision 1.12 sys/net/npf/npf.h: revision 1.17 sys/net/npf/npf_instr.c: revision 1.11 usr.sbin/npf/npftest/libnpftest/npf_table_test.c: revision 1.2 sys/net/npf/npf_state.c: revision 1.8 sys/net/npf/npf_log.c: revision 1.4 sys/net/npf/npf_alg.c: revision 1.4 sys/rump/librump/rumpkern/Makefile.rumpkern: revision 1.118 sys/net/npf/npf_nat.c: revision 1.13 sys/net/npf/npf.c: revision 1.11 sys/net/npf/npf_sendpkt.c: revision 1.11 sys/net/npf/npf_impl.h: revision 1.16 sys/rump/librump/rumpkern/scheduler.c: revision 1.28 rumpkern: - Add subr_kcpuset.c and subr_pserialize.c modules. - Add kcpuset_{running,attached} for RUMP env. NPF: - Rename some functions for consistency and de-inline them. - Fix few invalid asserts (add regressoin test). - Use pserialize(9) for ALG interface. - Minor fixes, sprinkle many comments.
|
1.10.4.1 |
| 03-Apr-2012 |
riz | Pull up following revision(s) (requested by rmind in ticket #158): sys/net/npf/npf_session.c: revision 1.12 sys/net/npf/npf_tableset.c: revision 1.10 sys/net/npf/npf_rproc.c: revision 1.2 usr.sbin/npf/npfctl/npf_parse.y: revision 1.4 sys/net/npf/npf_inet.c: revision 1.11 sys/net/npf/npf.h: revision 1.15 usr.sbin/npf/npfctl/npf_build.c: revision 1.5 sys/net/npf/npf_ruleset.c: revision 1.11 sys/net/npf/npf_instr.c: revision 1.10 usr.sbin/npf/npfctl/Makefile: revision 1.6 sys/net/npf/npf_processor.c: revision 1.10 sys/net/npf/npf_log.c: revision 1.3 lib/libnpf/npf.h: revision 1.7 sys/net/npf/npf_alg.c: revision 1.3 sys/net/npf/npf_sendpkt.c: revision 1.9 lib/libnpf/npf.c: revision 1.8 usr.sbin/npf/npfctl/npfctl.h: revision 1.13 sys/net/npf/npf_ctl.c: revision 1.13 usr.sbin/npf/npfctl/npf_ncgen.c: revision 1.8 sys/net/npf/npf_ctl.c: revision 1.14 sys/net/npf/npf_nat.c: revision 1.11 sys/net/npf/npf_nat.c: revision 1.12 sys/net/npf/npf_impl.h: revision 1.11 usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.1 sys/net/npf/npf_impl.h: revision 1.12 usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.2 sys/net/npf/npf_handler.c: revision 1.14 usr.sbin/npf/npfctl/npf_disassemble.c: revision 1.3 sys/net/npf/npf_handler.c: revision 1.15 sys/net/npf/npf_ncode.h: revision 1.6 sys/net/npf/npf.c: revision 1.8 sys/net/npf/npf.c: revision 1.9 sys/net/npf/npf_alg_icmp.c: revision 1.9 sys/net/npf/npf_session.c: revision 1.11 - Add NPF_DECISION_BLOCK and NPF_DECISION_PASS. Be more defensive in the packet handler. Change the default policy to block when the config is loaded and set it to pass when flush operation is performed. - Use kmem_zalloc(9) instead of kmem_alloc(9) in few places. - npf_rproc_{create,release}: use kmem_intr_{alloc,free} as the destruction of rule procedure might happen in the interrupt handler (under a very rare condition, if config reload races with the handler). - npf_session_establish: check whether layer 3 and 4 are cached. - npfctl_build_group: do not make groups as passing rules. - Remove some unecessary header inclusion. Simplify slightly: merge iface into addr_or_iface, use it in filt_addr. Add a small disassembler. definitions used by the disassembler. - better printing of type/code flags/mask - pass the instruction start pointer, instead of subtracting 1 to account for it - Save active config in proplib dictionary; add GETCONF ioctl to retrieve. - Few fixes. Improve some comments. don't leak the branch target array. Add NPF config retrieval routines.
|
1.10.4.9.2.2 |
| 17-May-2018 |
martin | Pull up following revision(s) via patch (requested by maxv in ticket #1549):
sys/net/npf/npf_inet.c: revision 1.45 sys/net/npf/npf_alg_icmp.c: revision 1.27,1.28
Fix use-after-free.
The nbuf can be reallocated as a result of caching 'enpc', so it is necessary to recache 'npc', otherwise it contains pointers to the freed mbuf - pointers which are then used in the ruleset machinery.
We recache 'npc' when we are sure we won't use 'enpc' anymore, because 'enpc' can be clobbered as a result of caching 'npc' (in other words, only one of the two can be cached at the same time).
Also, we recache 'npc' unconditionally, because there is no way to know whether the nbuf got clobbered relatively to it. We can't use the NBUF_DATAREF_RESET flag, because it is stored in the nbuf and not in the cache.
Discussed with rmind@.
Change npf_cache_all so that it ensures the potential ICMP Query Id is in the nbuf. In such a way that we don't need to ensure that later. Change npfa_icmp4_inspect and npfa_icmp6_inspect so that they touch neither the nbuf nor npc. Adapt their callers accordingly.
In the end, if a packet has a Query Id, we set NPC_ICMP_ID in npc and leave right away, without recaching npc (not needed since we didn't touch the nbuf).
This fixes the handling of Query Id packets (that I broke in my previous commit), and also fixes another possible use-after-free.
|
1.10.4.9.2.1 |
| 13-Sep-2013 |
msaitoh | Pull up following revision (requested by riz in ticket #942): /sys/net/npf/npf_inet.c revision 1.23 Fix bugs to prevent panic: - npf_cache_ip: re-fetch IPv6 header since nbufs might have been reallocated. - npf_cache_all: clear NBUF_DATAREF_RESET since npf_cache_ip() handles it.
|
1.10.4.5.4.1 |
| 16-Dec-2012 |
riz | Pull up following revision(s) (requested by rmind in ticket #746): sys/net/npf/npf_inet.c: revision 1.18 sys/net/npf/npf_mbuf.c: revision 1.8 sys/net/npf/npf.h: revision 1.23 npf_rwrcksum: handle delayed checksums in the network stack; also fix non-NPF_NAT_PORTS case and add some comments. PR/47235.
|
1.10.2.1 |
| 24-Feb-2012 |
mrg | sync to -current.
|
1.16.2.5 |
| 03-Dec-2017 |
jdolecek | update from HEAD
|
1.16.2.4 |
| 20-Aug-2014 |
tls | Rebase to HEAD as of a few days ago.
|
1.16.2.3 |
| 23-Jun-2013 |
tls | resync from head
|
1.16.2.2 |
| 25-Feb-2013 |
tls | resync with head
|
1.16.2.1 |
| 20-Nov-2012 |
tls | Resync to 2012-11-19 00:00:00 UTC
|
1.22.2.2 |
| 18-May-2014 |
rmind | sync with head
|
1.22.2.1 |
| 28-Aug-2013 |
rmind | sync with head
|
1.30.2.1 |
| 10-Aug-2014 |
tls | Rebase.
|
1.32.10.1 |
| 14-May-2018 |
martin | Pull up following revision(s) (requested by maxv in ticket #1605):
sys/net/npf/npf_inet.c: revision 1.45 sys/net/npf/npf_alg_icmp.c: revision 1.27-1.29
Fix use-after-free.
The nbuf can be reallocated as a result of caching 'enpc', so it is necessary to recache 'npc', otherwise it contains pointers to the freed mbuf - pointers which are then used in the ruleset machinery. We recache 'npc' when we are sure we won't use 'enpc' anymore, because 'enpc' can be clobbered as a result of caching 'npc' (in other words, only one of the two can be cached at the same time). Also, we recache 'npc' unconditionally, because there is no way to know whether the nbuf got clobbered relatively to it. We can't use the NBUF_DATAREF_RESET flag, because it is stored in the nbuf and not in the cache. Discussed with rmind@.
Change npf_cache_all so that it ensures the potential ICMP Query Id is in the nbuf. In such a way that we don't need to ensure that later. Change npfa_icmp4_inspect and npfa_icmp6_inspect so that they touch neither the nbuf nor npc. Adapt their callers accordingly. In the end, if a packet has a Query Id, we set NPC_ICMP_ID in npc and leave right away, without recaching npc (not needed since we didn't touch the nbuf). This fixes the handling of Query Id packets (that I broke in my previous commit), and also fixes another possible use-after-free.
Ah, fix compilation. I tested my previous change by loading the kernel module from the filesystem, but the Makefile didn't have DIAGNOSTIC enabled, and the two KASSERTs I added did not compile properly.
|
1.32.6.1 |
| 14-May-2018 |
martin | Pull up following revision(s) (requested by maxv in ticket #1605):
sys/net/npf/npf_inet.c: revision 1.45 sys/net/npf/npf_alg_icmp.c: revision 1.27-1.29
Fix use-after-free.
The nbuf can be reallocated as a result of caching 'enpc', so it is necessary to recache 'npc', otherwise it contains pointers to the freed mbuf - pointers which are then used in the ruleset machinery. We recache 'npc' when we are sure we won't use 'enpc' anymore, because 'enpc' can be clobbered as a result of caching 'npc' (in other words, only one of the two can be cached at the same time). Also, we recache 'npc' unconditionally, because there is no way to know whether the nbuf got clobbered relatively to it. We can't use the NBUF_DATAREF_RESET flag, because it is stored in the nbuf and not in the cache. Discussed with rmind@.
Change npf_cache_all so that it ensures the potential ICMP Query Id is in the nbuf. In such a way that we don't need to ensure that later. Change npfa_icmp4_inspect and npfa_icmp6_inspect so that they touch neither the nbuf nor npc. Adapt their callers accordingly. In the end, if a packet has a Query Id, we set NPC_ICMP_ID in npc and leave right away, without recaching npc (not needed since we didn't touch the nbuf). This fixes the handling of Query Id packets (that I broke in my previous commit), and also fixes another possible use-after-free.
Ah, fix compilation. I tested my previous change by loading the kernel module from the filesystem, but the Makefile didn't have DIAGNOSTIC enabled, and the two KASSERTs I added did not compile properly.
|
1.32.4.5 |
| 28-Aug-2017 |
skrll | Sync with HEAD
|
1.32.4.4 |
| 05-Feb-2017 |
skrll | Sync with HEAD
|
1.32.4.3 |
| 05-Dec-2016 |
skrll | Sync with HEAD
|
1.32.4.2 |
| 19-Mar-2016 |
skrll | Sync with HEAD
|
1.32.4.1 |
| 27-Dec-2015 |
skrll | Sync with HEAD (as of 26th Dec)
|
1.32.2.3 |
| 14-May-2018 |
martin | Pull up following revision(s) (requested by maxv in ticket #1605):
sys/net/npf/npf_inet.c: revision 1.45 sys/net/npf/npf_alg_icmp.c: revision 1.27-1.29
Fix use-after-free.
The nbuf can be reallocated as a result of caching 'enpc', so it is necessary to recache 'npc', otherwise it contains pointers to the freed mbuf - pointers which are then used in the ruleset machinery. We recache 'npc' when we are sure we won't use 'enpc' anymore, because 'enpc' can be clobbered as a result of caching 'npc' (in other words, only one of the two can be cached at the same time). Also, we recache 'npc' unconditionally, because there is no way to know whether the nbuf got clobbered relatively to it. We can't use the NBUF_DATAREF_RESET flag, because it is stored in the nbuf and not in the cache. Discussed with rmind@.
Change npf_cache_all so that it ensures the potential ICMP Query Id is in the nbuf. In such a way that we don't need to ensure that later. Change npfa_icmp4_inspect and npfa_icmp6_inspect so that they touch neither the nbuf nor npc. Adapt their callers accordingly. In the end, if a packet has a Query Id, we set NPC_ICMP_ID in npc and leave right away, without recaching npc (not needed since we didn't touch the nbuf). This fixes the handling of Query Id packets (that I broke in my previous commit), and also fixes another possible use-after-free.
Ah, fix compilation. I tested my previous change by loading the kernel module from the filesystem, but the Makefile didn't have DIAGNOSTIC enabled, and the two KASSERTs I added did not compile properly.
|
1.32.2.2 |
| 22-May-2017 |
martin | Pull up missing part of rev 1.33, partly pulled up in ticket #1394: make DDB print ipv6 addresses too
|
1.32.2.1 |
| 12-May-2017 |
snj | Pull up following revision(s) (requested by jnemeth in ticket #1394): sys/net/npf/npf_inet.c: revisions 1.34, 1.35 via patch sys/net/npf/npf_mbuf.c: revision 1.16 sys/net/npf/npf_nat.c: revision 1.40 minimal changes necessary to link into an INET6-less kernel. -- fixup misplaced #endif
|
1.34.2.2 |
| 20-Mar-2017 |
pgoyette | Sync with HEAD
|
1.34.2.1 |
| 07-Jan-2017 |
pgoyette | Sync with HEAD. (Note that most of these changes are simply $NetBSD$ tag issues.)
|
1.36.2.1 |
| 21-Apr-2017 |
bouyer | Sync with HEAD
|
1.37.12.8 |
| 26-Jan-2019 |
pgoyette | Sync with HEAD
|
1.37.12.7 |
| 30-Sep-2018 |
pgoyette | Ssync with HEAD
|
1.37.12.6 |
| 06-Sep-2018 |
pgoyette | Sync with HEAD
Resolve a couple of conflicts (result of the uimin/uimax changes)
|
1.37.12.5 |
| 16-Apr-2018 |
pgoyette | Sync with HEAD, resolve some conflicts
|
1.37.12.4 |
| 07-Apr-2018 |
pgoyette | Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
|
1.37.12.3 |
| 30-Mar-2018 |
pgoyette | Resolve conflicts between branch and HEAD
|
1.37.12.2 |
| 22-Mar-2018 |
pgoyette | Synch with HEAD, resolve conflicts
|
1.37.12.1 |
| 15-Mar-2018 |
pgoyette | Synch with HEAD
|
1.37.6.2 |
| 14-May-2018 |
martin | Pull up following revision(s) (requested by maxv in ticket #823):
sys/net/npf/npf_inet.c: revision 1.45-1.47 sys/net/npf/npf_alg_icmp.c: revision 1.27-1.30 sys/net/npf/npf_sendpkt.c: revision 1.19
Fix use-after-free.
The nbuf can be reallocated as a result of caching 'enpc', so it is necessary to recache 'npc', otherwise it contains pointers to the freed mbuf - pointers which are then used in the ruleset machinery.
We recache 'npc' when we are sure we won't use 'enpc' anymore, because 'enpc' can be clobbered as a result of caching 'npc' (in other words, only one of the two can be cached at the same time). Also, we recache 'npc' unconditionally, because there is no way to know whether the nbuf got clobbered relatively to it. We can't use the NBUF_DATAREF_RESET flag, because it is stored in the nbuf and not in the cache.
Discussed with rmind@.
Change npf_cache_all so that it ensures the potential ICMP Query Id is in the nbuf. In such a way that we don't need to ensure that later. Change npfa_icmp4_inspect and npfa_icmp6_inspect so that they touch neither the nbuf nor npc. Adapt their callers accordingly.
In the end, if a packet has a Query Id, we set NPC_ICMP_ID in npc and leave right away, without recaching npc (not needed since we didn't touch the nbuf).
This fixes the handling of Query Id packets (that I broke in my previous commit), and also fixes another possible use-after-free.
Retrieve the complete IPv4 header right away, and make sure we did retrieve the IPv6 option header we were iterating on.
Ah, fix compilation. I tested my previous change by loading the kernel module from the filesystem, but the Makefile didn't have DIAGNOSTIC enabled, and the two KASSERTs I added did not compile properly.
If we fail to advance inside TCP/UDP/ICMPv4/ICMPv6, stop pretending L4 is unknown, and error out right away.
This prevents bugs in machinery, if a place looks for L4 in 'npc_proto' without checking the cache too. I've seen a ~similar problem already.
In addition to checking L4 in the cache, here we also need to check the protocol. The NPF entry point does not ensure that ICMPv6 can be set only in IPv6 ICMPv4 can be set only in IPv4 So we could have ICMPv6 in IPv4.
apply some INET6 so this compiles in INET6-less kernels again.
|
1.37.6.1 |
| 09-May-2018 |
martin | Pull up following revision(s) (requested by maxv in ticket #817):
sys/net/npf/npf_inet.c: revision 1.38-1.44 sys/net/npf/npf_handler.c: revision 1.38-1.39 sys/net/npf/npf_alg_icmp.c: revision 1.26 sys/net/npf/npf.h: revision 1.56 sys/net/npf/npf_sendpkt.c: revision 1.17-1.18
Declare NPC_FMTERR, and use it to kick malformed packets. Several sanity checks are added in IPv6; after we see the first IPPROTO_FRAGMENT header, we are allowed to fail to advance, otherwise we kick the packet. Sent on tech-net@ a few days ago, no response, but I'm committing it now anyway.
Switch nptr to uint8_t, and use nbuf_ensure_contig. Makes us use fewer magic values.
Remove dead branches, 'npc' can't be NULL (and it is dereferenced earlier).
Fix two consecutive mistakes.
The first mistake was npf_inet.c rev1.37: "Don't reassemble ipv6 fragments, instead treat the first fragment as a regular packet (subject to filtering rules), and pass subsequent fragments in the same group unconditionally."
Doing this was entirely wrong, because then a packet just had to push the L4 payload in a secondary fragment, and NPF wouldn't apply rules on it - meaning any IPv6 packet could bypass >=L4 filtering. This mistake was supposed to be a fix for the second mistake.
The second mistake was that ip6_reass_packet (in npf_reassembly) was getting called with npc->npc_hlen. But npc_hlen pointed to the last encountered header in the IPv6 chain, which was not necessarily the fragment header. So ip6_reass_packet was given garbage, and would fail, resulting in the packet getting kicked. So basically IPv6 was broken by NPF.
The first mistake is reverted, and the second one is fixed by doing: - hlen = sizeof(struct ip6_frag); + hlen = 0;
Now the iteration stops on the fragment header, and the call to ip6_reass_packet is valid.
My npf_inet.c rev1.38 is partially reverted: we don't need to worry about failing properly to advance; once the packet is reassembled npf_cache_ip gets called again, and this time the whole chain should be there.
Tested with a simple UDPv6 server - send a 3000-byte-sized buffer, the packet gets correctly reassembled by NPF now.
Mmh, put back the RFC6946 check (about dummy fragments), otherwise NPF is not happy in npf_reassembly, because NPC_IPFRAG is again returned after the packet was reassembled.
I'm wondering whether it would not be better to just remove the fragment header in frag6_input directly.
Fix the "return-rst" rule on IPv6 packets. The scopes needed to be set on the addresses before invoking ip6_output, because ip6_output needs them. The reason they are not here already is because pfil_run_hooks (in ip6_input) is called _before_ the kernel initializes the scopes.
Until now ip6_output was always failing, and the IPv6-TCP-RST packet was never actually sent.
Perhaps it would be better to have the kernel initialize the scopes before invoking pfil_run_hooks, but several things will need to be fixed in several places.
Tested with a simple TCPv6 server. Until now the client would block waiting for an answer that never came; now it receives an RST right away and closes the connection, as expected. I believe that the same problem exists in the "return-icmp" rules, but I can't investigate this right now (some problems with wireshark).
Fix the IPv6 payload computation in npf_tcpsaw. It was incorrect, and this caused the "return-rst" rules to send back an RST with the wrong ACK when the received SYN had an IPv6 option.
Set the scopes before calling icmp6_error(). This fixes a bug similar to the one I fixed in rev1.17: since the scopes were not set the packet was never actually sent.
Tested with wireshark, now the ICMPv6 reply is correctly sent, as expected.
Don't read the L4 payload after IPPROTO_AH when handling IPv6 packets. AH must be considered as the payload, otherwise a
block all pass in proto ah from any pass out proto ah from any
configuration will actually block everything, because NPF checks the protocol against the one found after AH, and not AH itself.
In addition it may have been a problem for stateful connections; an AH packet sent by an attacker with an incorrect authentication and a correct TCP/UDP/whatever payload from an active connection could manage to change NPF's FSM state, which would perhaps have altered the legitimate connection with the authenticated remote IPsec host.
Note that IPv4 already doesn't go beyond AH, which is the correct behavior.
Add XXX (we don't handle IPv6 Jumbograms), and whitespace.
|
1.50.2.2 |
| 13-Apr-2020 |
martin | Mostly merge changes from HEAD upto 20200411
|
1.50.2.1 |
| 10-Jun-2019 |
christos | Sync with HEAD
|
1.54.2.3 |
| 20-Jun-2020 |
martin | Pull up following revision(s) (requested by rmind in ticket #956):
usr.sbin/npf/npf-params.7: revision 1.4 sys/net/npf/npf_worker.c: revision 1.9 usr.sbin/npf/npftest/npftest.h: revision 1.17 usr.sbin/npf/npfctl/npf_bpf_comp.c: revision 1.16 usr.sbin/npf/npf-params.7: revision 1.5 sys/net/npf/npf_state_tcp.c: revision 1.21 usr.sbin/npf/npfctl/npf_build.c: revision 1.55 usr.sbin/npf/npf-params.7: revision 1.6 sys/net/npf/npfkern.h: revision 1.5 lib/libnpf/npf.c: revision 1.49 usr.sbin/npf/npf-params.7: revision 1.7 sys/net/npf/npf_impl.h: revision 1.81 sys/net/npf/npf_ext_log.c: revision 1.17 usr.sbin/npf/npfctl/npfctl.h: revision 1.53 usr.sbin/npf/npftest/libnpftest/npf_mbuf_subr.c: revision 1.11 sys/net/npf/npf_nat.c: revision 1.50 sys/net/npf/npf_mbuf.c: revision 1.24 sys/net/npf/npf_alg.c: revision 1.22 usr.sbin/npf/npftest/libnpftest/npf_nat_test.c: revision 1.14 usr.sbin/npf/npftest/libnpftest/npf_conn_test.c: file removal usr.sbin/npf/npftest/libnpftest/npf_state_test.c: revision 1.10 sys/net/npf/npf.h: revision 1.63 usr.sbin/npf/npftest/libnpftest/npf_test.h: revision 1.21 usr.sbin/npf/npfctl/npf_var.c: revision 1.13 sys/net/npf/files.npf: revision 1.23 usr.sbin/npf/npfctl/npf_show.c: revision 1.32 usr.sbin/npf/npfctl/npf.conf.5: revision 1.91 sys/net/npf/npf_os.c: revision 1.18 sys/net/npf/npf_connkey.c: revision 1.2 sys/net/npf/npf_conf.c: revision 1.17 lib/libnpf/libnpf.3: revision 1.12 usr.sbin/npf/npftest/npftest.c: revision 1.25 usr.sbin/npf/npftest/libnpftest/npf_gc_test.c: revision 1.1 usr.sbin/npf/npfctl/npf_parse.y: revision 1.51 sys/net/npf/npf_tableset.c: revision 1.35 usr.sbin/npf/npftest/npftest.conf: revision 1.9 sys/net/npf/npf_sendpkt.c: revision 1.22 usr.sbin/npf/npfctl/npf_var.h: revision 1.10 sys/net/npf/npf_state.c: revision 1.23 sys/net/npf/npf_conn.h: revision 1.20 usr.sbin/npf/npfctl/npfctl.c: revision 1.64 usr.sbin/npf/npfctl/npf_cmd.c: revision 1.1 sys/net/npf/npf_portmap.c: revision 1.5 sys/net/npf/npf_params.c: revision 1.3 usr.sbin/npf/npfctl/npf_scan.l: revision 1.32 tests/net/npf/t_npf.sh: revision 1.4 sys/net/npf/npf_ext_rndblock.c: revision 1.9 lib/libnpf/npf.h: revision 1.39 sys/net/npf/npf_ruleset.c: revision 1.51 sys/net/npf/npf_alg_icmp.c: revision 1.33 sys/net/npf/npf.c: revision 1.43 usr.sbin/npf/npftest/libnpftest/npf_test_subr.c: revision 1.17 usr.sbin/npf/npfctl/npfctl.8: revision 1.25 sys/net/npf/npf_ctl.c: revision 1.60 usr.sbin/npf/npftest/libnpftest/npf_test_subr.c: revision 1.18 usr.sbin/npf/npftest/libnpftest/Makefile: revision 1.11 sys/net/npf/npf_handler.c: revision 1.49 sys/net/npf/npf_inet.c: revision 1.57 sys/net/npf/npf_ifaddr.c: revision 1.7 sys/net/npf/npf_conndb.c: revision 1.9 sys/net/npf/npf_if.c: revision 1.13 usr.sbin/npf/npfctl/Makefile: revision 1.15 sys/net/npf/npf_conn.c: revision 1.32 sys/net/npf/npf_ext_normalize.c: revision 1.10 sys/net/npf/npf_rproc.c: revision 1.20 sys/net/npf/npf_worker.c: revision 1.8
Major NPF improvements (merge from upstream): - Switch to the C11-style atomic primitives using atomic_loadstore(9). - npfkern: introduce the 'state.key.interface' and 'state.key.direction' settings. Users can now choose whether the connection state should be strictly per-interface or global at the configuration level. Keep NAT logic to be always per-interface, though. - npfkern: rewrite the G/C worker logic and make it self-tuning. - npfkern and libnpf: multiple bug fixes; add param exporting; introduce more parameters. Remove npf_nvlist_{copyin,copyout}() functions and refactor npfctl_load_nvlist() with others; add npfctl_run_op() to have a single entry point for operations. Introduce npf_flow_t and clean up some code. - npfctl: lots of fixes for the 'npfctl show' logic; make 'npfctl list' more informative; misc usability improvements and more user-friendly error messages. - Amend and improve the manual pages.
npf_worker_sys{init,fini}: initialize/destroy the exit_cv condvar.
npftest -- npf_test_init(): add a workaround for NetBSD.
npf-params(7): fix the state.key defaults.
npf-params.7: s/filer/filter/
Adjust to "npfctl debug" command line changes, from rmind@.
Use more markup.
|
1.54.2.2 |
| 25-May-2020 |
martin | Pull up following revision(s) (requested by rmind in ticket #930):
usr.sbin/npf/npfctl/npf_build.c: revision 1.54 sys/net/npf/npf_conn.h: revision 1.19 usr.sbin/npf/npfctl/npfctl.h: revision 1.52 usr.sbin/npf/npfctl/npf_show.c: revision 1.31 sys/net/npf/npf_conf.c: revision 1.16 sys/net/npf/npf_nat.c: revision 1.49 sys/net/npf/npf_inet.c: revision 1.56 sys/net/npf/npf_conndb.c: revision 1.8 sys/net/npf/npf_conn.c: revision 1.31
Backport selected NPF fixes from the upstream (to be pulled up):
- npf_conndb_lookup: protect the connection lookup with pserialize(9), instead of incorrectly assuming that the handler always runs at IPL_SOFNET. Should fix crashes reported on high load (PR/55182).
- npf_config_destroy: handle partially initialized config; fixes crashes with some invalid configurations.
- NAT policy creation / destruction: set the initial reference and do not wait for reference draining on destruction; destroy the policy on the last reference drop instead. Fixes a lockup with the dynamic NAT rules.
- npf_nat_{export,import}: fix a regression since dynamic NAT rules.
- npfctl: fix a regression and restore the default group behaviour.
- Add npf_cache_tcp() and validate the TCP data offset (from maxv@).
|
1.54.2.1 |
| 13-Aug-2019 |
martin | Pull up following revision(s) (requested by rmind in ticket #49):
usr.sbin/npf/npf.7: revision 1.7 sys/net/npf/npfkern.h: revision 1.4 sys/net/npf/npf_conn.h: revision 1.18 usr.sbin/npf/npftest/libnpftest/npf_nat_test.c: revision 1.13 sys/net/npf/npf_ctl.c: revision 1.55 sys/net/npf/npf_os.c: revision 1.14 sys/net/npf/npf_conf.c: revision 1.14 usr.sbin/npf/npftest/libnpftest/npf_conn_test.c: revision 1.3 usr.sbin/npf/npftest/libnpftest/npf_perf_test.c: revision 1.9 sys/net/npf/npf_impl.h: revision 1.76 sys/net/npf/npf_portmap.c: revision 1.4 sys/net/npf/npf_params.c: revision 1.2 sys/net/npf/npf.c: revision 1.40 usr.sbin/npf/npftest/libnpftest/npf_test_subr.c: revision 1.16 usr.sbin/npf/npftest/libnpftest/npf_rule_test.c: revision 1.18 sys/net/npf/npf_nat.c: revision 1.47 sys/net/npf/npf_handler.c: revision 1.47 sys/net/npf/npf_inet.c: revision 1.55 sys/net/npf/npf_if.c: revision 1.10 sys/net/npf/npf_worker.c: revision 1.7 usr.sbin/npf/npf-params.7: revision 1.3
npf-params(7): add more bpf.jit details. From David H. Gutteridge.
Adjust some internal NPF APIs: * npfkern: use the npfk_ prefix. * NPF portmap: amend the API so it could be used elsewhere. * Make npf_connkey_t public.
npf.7: add xref to npf-params.7 (Adding directly here since this particular file isn't included in rmind@'s upstream GitHub repo at present.)
|