Commit Graph

163 Commits

Author SHA1 Message Date
maxv 1201edd951 Add sanity check, only sat_len bytes got copied in, the rest is
uninitialized. Found by KMSAN.
2019-11-29 17:40:16 +00:00
maxv 385203089c Memset to prevent stack info leak. 2019-10-09 14:15:40 +00:00
maxv d26f60da72 RIP, RIP6, DDP, SCTP and SCTP6 lack a length check in their _connect()
functions. Fix the first three, and add a big XXX in the SCTP ones.

Found by KASAN, triggered by SyzKaller.

Reported-by: syzbot+9eaf98dad6ca738c250d@syzkaller.appspotmail.com
2019-02-24 07:20:33 +00:00
martin dc194ae5f0 Fix memory leaks pointed out by Ilja Van Sprundel: all
sendoob() functions are expted to free both passed
mbuf chains.
2019-01-28 12:53:01 +00:00
maxv 5b040abec8 Replace M_ALIGN and MH_ALIGN by m_align. 2018-12-22 14:28:56 +00:00
maxv 90aec87ff9 Remove aarp_clean, unused. By the way this function was probably buggy
since it didn't reset aat_hold to NULL.
2018-05-29 16:29:47 +00:00
christos 87fd18f8e5 s/static inline/static __inline/g for consistency. 2018-04-19 21:50:06 +00:00
roy 38d01a8d5e Sprinkle more soroverflow(). 2018-03-21 14:23:54 +00:00
rjs 6f874b8157 Add NETATALKDEBUG to the option header and include that in the main source
files.
2018-02-17 19:10:18 +00:00
maxv 012aa161d5 Mmh, pull up the packet to ether_aarp, otherwise we're reading past the
end of the mbuf.
2017-12-09 10:14:04 +00:00
ozaki-r 0092eb7df6 Invalidate rtcache based on a global generation counter
The change introduces a global generation counter that is incremented when any
routes have been added or deleted. When a rtcache caches a rtentry into itself,
it also stores a snapshot of the generation counter. If the snapshot equals to
the global counter, the cache is still valid, otherwise invalidated.

One drawback of the change is that all rtcaches of all protocol families are
invalidated when any routes of any protocol families are added or deleted.
If that matters, we should have separate generation counters based on
protocol families.

This change removes LIST_ENTRY from struct route, which fixes a part of
PR kern/52515.
2017-09-21 07:15:34 +00:00
ozaki-r 4c25fb2f83 Add rtcache_unref to release points of rtentry stemming from rtcache
In the MP-safe world, a rtentry stemming from a rtcache can be freed at any
points. So we need to protect rtentries somehow say by reference couting or
passive references. Regardless of the method, we need to call some release
function of a rtentry after using it.

The change adds a new function rtcache_unref to release a rtentry. At this
point, this function does nothing because for now we don't add a reference
to a rtentry when we get one from a rtcache. We will add something useful
in a further commit.

This change is a part of changes for MP-safe routing table. It is separated
to avoid one big change that makes difficult to debug by bisecting.
2016-12-08 05:16:33 +00:00
ozaki-r 8f4376cb6f Fix race condition on ifqueue used by traditional netisr
If a underlying network device driver supports MSI/MSI-X, RX interrupts
can be delivered to arbitrary CPUs. This means that Layer 2 subroutines
such as ether_input (softint) and subsequent Layer 3 subroutines (softint)
which are called via traditional netisr can be dispatched on an arbitrary
CPU. Layer 2 subroutines now run without any locks (expected) and so a
Layer 2 subroutine and a Layer 3 subroutine can run in parallel.

There is a shared data between a Layer 2 routine and a Layer 3 routine,
that is ifqueue and IF_ENQUEUE (from L2) and IF_DEQUEUE (from L3) on it
are racy now.

To fix the race condition, use ifqueue#ifq_lock to protect ifqueue
instead of splnet that is meaningless now.

The same race condition exists in route_intr. Fix it as well.

Reviewed by knakahara@
2016-10-03 11:06:06 +00:00
ozaki-r a403cbd4f5 Apply pserialize and psref to struct ifaddr and its variants
This change makes struct ifaddr and its variants (in_ifaddr and in6_ifaddr)
MP-safe by using pserialize and psref. At this moment, pserialize_perform
and psref_target_destroy are disabled because (1) we don't need them
because of softnet_lock (2) they cause a deadlock because of softnet_lock.
So we'll enable them when we remove softnet_lock in the future.
2016-08-01 03:15:30 +00:00
ozaki-r 9e4c2bda8a Switch the address list of intefaces to pslist(9)
As usual, we leave the old list to avoid breaking kvm(3) users.
2016-07-07 09:32:01 +00:00
knakahara 95fc145695 apply if_output_lock() to L3 callers which call ifp->if_output() of L2(or L3 tunneling). 2016-06-20 06:46:37 +00:00
ozaki-r fe6d427551 Avoid storing a pointer of an interface in a mbuf
Having a pointer of an interface in a mbuf isn't safe if we remove big
kernel locks; an interface object (ifnet) can be destroyed anytime in any
packet processing and accessing such object via a pointer is racy. Instead
we have to get an object from the interface collection (ifindex2ifnet) via
an interface index (if_index) that is stored to a mbuf instead of an
pointer.

The change provides two APIs: m_{get,put}_rcvif_psref that use psref(9)
for sleep-able critical sections and m_{get,put}_rcvif that use
pserialize(9) for other critical sections. The change also adds another
API called m_get_rcvif_NOMPSAFE, that is NOT MP-safe and for transition
moratorium, i.e., it is intended to be used for places where are not
planned to be MP-ified soon.

The change adds some overhead due to psref to performance sensitive paths,
however the overhead is not serious, 2% down at worst.

Proposed on tech-kern and tech-net.
2016-06-10 13:31:43 +00:00
riastradh 7c7b1739c8 Revert previous: ran cvs commit when I meant cvs diff. Sorry!
Hit up-arrow one too few times.
2016-01-21 15:41:29 +00:00
riastradh b41d562bd0 Give proper prototype to ip_output. 2016-01-21 15:27:48 +00:00
riastradh d33ecd31cb Give proper prototype to ddp_output. 2016-01-20 21:59:19 +00:00
riastradh 65a8f527af Eliminate struct protosw::pr_output.
You can't use this unless you know what it is a priori: the formal
prototype is variadic, and the different instances (e.g., ip_output,
route_output) have different real prototypes.

Convert the only user of it, raw_send in net/raw_cb.c, to take an
explicit callback argument.  Convert the only instances of it,
route_output and key_output, to such explicit callbacks for raw_send.
Use assertions to make sure the conversion to explicit callbacks is
warranted.

Discussed on tech-net with no objections:
https://mail-index.netbsd.org/tech-net/2016/01/16/msg005484.html
2016-01-20 21:43:59 +00:00
dholland 1fbab01a93 More on PR 41200: headers that declare ioctls should include sys/ioccom.h.
This covers (I think) all the MI headers outside of external/ (and dist/).
2015-09-06 06:00:59 +00:00
rtr fd12cf39ee make connect syscall use sockaddr_big and modify pr_{send,connect}
nam parameter type from buf * to sockaddr *.

final commit for parameter type changes to protocol user requests

* bump kernel version to 7.99.15 for parameter type changes to pr_{send,connect}
2015-05-02 17:18:03 +00:00
rtr d2aa9dd71f remove pr_generic from struct pr_usrreqs and all implementations of
pr_generic in protocols.

bump to 7.99.13

approved by rmind@
2015-04-26 21:40:48 +00:00
rtr a031e45cd5 make at_pcbconnect() take sockaddr_at * instead of mbuf *.
move m_len check into callers which results in small duplication of
code that will go away when the callers are converted to receive
sockaddr * instead of mbuf *.
2015-04-24 23:36:48 +00:00
rtr eddf3af3c6 make accept, getsockname and getpeername syscalls use sockaddr_big and modify
pr_{accept,sockname,peername} nam parameter type from mbuf * to sockaddr *.

* retained use of mbuftypes[MT_SONAME] for now.
* bump to netbsd version 7.99.12 for parameter type change.

patch posted to tech-net@ 2015/04/19
2015-04-24 22:32:37 +00:00
rtr a2ba5e69ab * change pr_bind to accept struct sockaddr * instead of struct mbuf *
* update protocol bind implementations to use/expect sockaddr *
  instead of mbuf *
* introduce sockaddr_big struct for storage of addr data passed via
  sys_bind; sockaddr_big is of sufficient size and alignment to
  accommodate all addr data sizes received.
* modify sys_bind to allocate sockaddr_big instead of using an mbuf.
* bump kernel version to 7.99.9 for change to pr_bind() parameter type.

Patch posted to tech-net@
  http://mail-index.netbsd.org/tech-net/2015/03/15/msg005004.html

The choice to use a new structure sockaddr_big has been retained since
changing sockaddr_storage size would lead to unnecessary ABI change. The
use of the new structure does not preclude future work that increases
the size of sockaddr_storage and at that time sockaddr_big may be
trivially replaced.

Tested by mrg@ and myself, discussed with rmind@, posted to tech-net@
2015-04-03 20:01:07 +00:00
uebayasi a25d53f107 Define netatalk module. 2014-12-08 07:18:45 +00:00
christos 30c78a595e - s/u_intX/uintX/
- add routines to print sockaddr_at and ataddr.
2014-12-02 19:33:44 +00:00
snj f0a7346d21 src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
2014-10-18 08:33:23 +00:00
rmind 436f757159 Eliminate IFAREF() and IFAFREE() macros in favour of functions. 2014-09-09 20:16:12 +00:00
rtr 8cf67cc6d5 split PRU_CONNECT2 & PRU_PURGEIF function out of pr_generic() usrreq
switches and put into separate functions

  - always KASSERT(solocked(so)) even if not implemented
    (for PRU_CONNECT2 only)

  - replace calls to pr_generic() with req = PRU_CONNECT2 with calls to
    pr_connect2()

  - replace calls to pr_generic() with req = PRU_PURGEIF with calls to
    pr_purgeif()

put common code from unp_connect2() (used by unp_connect() into
unp_connect1() and call out to it when needed

patch only briefly reviewed by rmind@
2014-08-09 05:33:00 +00:00
rtr 822872eada split PRU_RCVD function out of pr_generic() usrreq switches and put into
separate functions

  - always KASSERT(solocked(so)) even if not implemented

  - replace calls to pr_generic() with req = PRU_RCVD with calls to
    pr_rcvd()
2014-08-08 03:05:44 +00:00
rtr d81cfbe806 suppress possibly used uninitialized warning on sgimips
from martin@
2014-08-07 07:51:28 +00:00
rtr 4a16f1ce0d remove KASSERT(nam != NULL) from ddp_send() the following code makes
the validity of it questionable.  we'll investigate later whether it
can be put back and the code simplified.
2014-08-07 01:02:30 +00:00
rtr 651e5bd3f8 split PRU_SEND function out of pr_generic() usrreq switches and put into
separate functions

   xxx_send(struct socket *, struct mbuf *, struct mbuf *,
       struct mbuf *, struct lwp *)

  - always KASSERT(solocked(so)) even if not implemented

  - replace calls to pr_generic() with req = PRU_SEND with calls to
    pr_send()

rename existing functions that operate on PCB for consistency (and to
free up their names for xxx_send() PRUs

  - l2cap_send() -> l2cap_send_pcb()
  - sco_send() -> sco_send_pcb()
  - rfcomm_send() -> rfcomm_send_pcb()

patch reviewed by rmind
2014-08-05 07:55:31 +00:00
rtr ce6a5ff64f revert the removal of struct lwp * parameter from bind, listen and connect
user requests.

this should resolve the issue relating to nfs client hangs presented
recently by wiz on current-users@
2014-08-05 05:24:26 +00:00
rtr 892163b8e9 split PRU_DISCONNECT, PRU_SHUTDOWN and PRU_ABORT function out of
pr_generic() usrreq switches and put into separate functions

   xxx_disconnect(struct socket *)
   xxx_shutdown(struct socket *)
   xxx_abort(struct socket *)

   - always KASSERT(solocked(so)) even if not implemented
   - replace calls to pr_generic() with req =
PRU_{DISCONNECT,SHUTDOWN,ABORT}
     with calls to pr_{disconnect,shutdown,abort}() respectively

rename existing internal functions used to implement above functionality
to permit use of the names for xxx_{disconnect,shutdown,abort}().

   - {l2cap,sco,rfcomm}_disconnect() ->
{l2cap,sco,rfcomm}_disconnect_pcb()
   - {unp,rip,tcp}_disconnect() -> {unp,rip,tcp}_disconnect1()
   - unp_shutdown() -> unp_shutdown1()

patch reviewed by rmind
2014-07-31 03:39:35 +00:00
rtr ad6ae402db split PRU_CONNECT function out of pr_generic() usrreq switches and put
into seaparate functions

  xxx_listen(struct socket *, struct mbuf *)

  - always KASSERT(solocked(so)) and KASSERT(nam != NULL)
  - replace calls to pr_generic() with req = PRU_CONNECT with
    pr_connect()
  - rename existin {l2cap,sco,rfcomm}_connect() to
    {l2cap,sco,rfcomm}_connect_pcb() respectively to permit
    naming consistency with other protocols functions.
  - drop struct lwp * parameter from unp_connect() and at_pcbconnect()
    and use curlwp instead where appropriate.

patch reviewed by rmind
2014-07-30 10:04:25 +00:00
rtr 6dd8eef044 split PRU_BIND and PRU_LISTEN function out of pr_generic() usrreq
switches and put into separate functions
  xxx_bind(struct socket *, struct mbuf *)
  xxx_listen(struct socket *)

  - always KASSERT(solocked(so)) even if not implemented

  - replace calls to pr_generic() with req = PRU_BIND with call to
    pr_bind()

  - replace calls to pr_generic() with req = PRU_LISTEN with call to
    pr_listen()

  - drop struct lwp * parameter from at_pcbsetaddr(), in_pcbbind() and
    unp_bind() and always use curlwp.

rename existing functions that operate on PCB for consistency (and to
free up their names for xxx_{bind,listen}() PRUs

  - l2cap_{bind,listen}() -> l2cap_{bind,listen}_pcb()
  - sco_{bind,listen}() -> sco_{bind,listen}_pcb()
  - rfcomm_{bind,listen}() -> rfcomm_{bind,listen}_pcb()

patch reviewed by rmind

welcome to netbsd 6.99.48
2014-07-24 15:12:03 +00:00
rtr 35b22fa96a split PRU_SENDOOB and PRU_RCVOOB function out of pr_generic() usrreq
switches and put into separate functions
  xxx_sendoob(struct socket *, struct mbuf *, struct mbuf *)
  xxx_recvoob(struct socket *, struct mbuf *, int)

  - always KASSERT(solocked(so)) even if request is not implemented

  - replace calls to pr_generic() with req = PRU_{SEND,RCV}OOB with
    calls to pr_{send,recv}oob() respectively.

there is still some tweaking of m_freem(m) and m_freem(control) to come
for consistency.  not performed with this commit for clarity.

reviewed by rmind
2014-07-23 13:17:18 +00:00
rtr d27b133d27 * split PRU_ACCEPT function out of pr_generic() usrreq switches and put
into a separate function xxx_accept(struct socket *, struct mbuf *)

note: future cleanup will take place to remove struct mbuf parameter
type and replace it with a more appropriate type.

patch reviewed by rmind
2014-07-09 14:41:42 +00:00
rtr d575eb5454 * split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
usrreq switches and put into separate functions
  xxx_{peer,sock}addr(struct socket *, struct mbuf *).

    - KASSERT(solocked(so)) always in new functions even if request
      is not implemented

    - KASSERT(pcb != NULL) and KASSERT(nam) if the request is
      implemented and not for tcp.

* for tcp roll #ifdef KPROF and #ifdef DEBUG code from tcp_usrreq() into
  easier to cut & paste functions tcp_debug_capture() and
tcp_debug_trace()

    - functions provided by rmind
    - remaining use of PRU_{PEER,SOCK}ADDR #define to be removed in a
      future commit.

* rename netbt functions to permit consistency of pru function names
  (as has been done with other requests already split out).

    - l2cap_{peer,sock}addr()  -> l2cap_{peer,sock}_addr_pcb()
    - rfcomm_{peer,sock}addr() -> rfcomm_{peer,sock}_addr_pcb()
    - sco_{peer,sock}addr()    -> sco_{peer,sock}_addr_pcb()

* split/refactor do_sys_getsockname(lwp, fd, which, nam) into
  two functions do_sys_get{peer,sock}name(fd, nam).

    - move PRU_PEERADDR handling into do_sys_getpeername() from
      do_sys_getsockname()
    - have svr4_stream directly call do_sys_get{sock,peer}name()
      respectively instead of providing `which' & fix a DPRINTF string
      that incorrectly wrote "getpeername" when it meant "getsockname"
    - fix sys_getpeername() and sys_getsockname() to call
      do_sys_get{sock,peer}name() without `which' and `lwp' & adjust
      comments
    - bump kernel version for removal of lwp & which parameters from
      do_sys_getsockname()

note: future cleanup to remove struct mbuf * abuse in
xxx_{peer,sock}name()
still to come, not done in this commit since it is easier to do post
split.

patch reviewed by rmind

welcome to 6.99.47
2014-07-09 04:54:03 +00:00
rtr ff90c29d04 * sprinkle KASSERT(solocked(so)); in all pr_stat() functions.
* fix remaining inconsistent struct socket parameter names.
2014-07-07 17:13:56 +00:00
rtr 909a1fc699 backout change that made pr_stat return EOPNOTSUPP for protocols that
were not filling in struct stat.

decision made after further discussion with rmind and investigation of
how other operating systems behave.  soo_stat() is doing just enough to
be able to call what gets returned valid and thus justifys a return of
success.

additional review will be done to determine of the pr_stat functions
that were already returning EOPNOTSUPP can be considered successful with
what soo_stat() is doing.
2014-07-07 15:13:21 +00:00
rtr 183fc9ab77 * have pr_stat return EOPNOTSUPP consistently for all protocols that do
not fill in struct stat instead of returning success.

* in pr_stat remove all checks for non-NULL so->so_pcb except where the
  pcb is actually used (i.e. cases where we don't return EOPNOTSUPP).

proposed on tech-net@
2014-07-07 07:09:58 +00:00
rtr a60320ca07 * split PRU_SENSE functionality out of xxx_usrreq() switches and place into
separate xxx_stat(struct socket *, struct stat *) functions.
* replace calls using pr_generic with req == PRU_SENSE with pr_stat().

further change will follow that cleans up the pattern used to extract the
pcb and test for its presence.

reviewed by rmind
2014-07-06 03:33:33 +00:00
rtr 0dedd9772f fix parameter types in pr_ioctl, called xx_control() functions and remove
abuse of pointer to struct mbuf type.

param2 changed to u_long type and uses parameter name 'cmd' (ioctl command)
param3 changed to void * type and uses parameter name 'data'
param4 changed to struct ifnet * and uses parameter name 'ifp'
param5 has been removed (formerly struct lwp *) and uses of 'l' have been
       replaced with curlwp from curproc(9).

callers have had (now unnecessary) casts to struct mbuf * removed, called
code has had (now unnecessary) casts to u_long, void * and struct ifnet *
respectively removed.

reviewed by rmind@
2014-07-01 05:49:18 +00:00
rtr c5cb349386 where appropriate rename xxx_ioctl() struct mbuf * parameters from
`control' to `ifp' after split from xxx_usrreq().

sys_socket.c
    fix wrapping of arguments to be consistent with other function calls
    in the file after replacing pr_usrreq() call with pr_ioctl() which
    required one less argument.

link_proto.c
    fix indentation of parameters in link_ioctl() prototype to be
    consistent with the rest of the file.

discussed with rmind@
2014-06-23 17:18:45 +00:00
rtr d54d7ab24a * split PRU_CONTROL functionality out of xxx_userreq() switches and place
into separate xxx_ioctl() functions.
* place KASSERT(req != PRU_CONTROL) inside xxx_userreq() as it is now
  inappropriate for req = PRU_CONTROL in xxx_userreq().
* replace calls to pr_generic() with req = PRU_CONTROL with pr_ioctl().
* remove & fixup references to PRU_CONTROL xxx_userreq() function comments.
* fix various comments references for xxx_userreq() that mentioned
  PRU_CONTROL as xxx_userreq() no longer handles the request.

a further change will follow to fix parameter and naming inconsistencies
retained from original code.

Reviewed by rmind@
2014-06-22 08:10:18 +00:00