summaryrefslogtreecommitdiff
path: root/sys/kern/uipc_socket.c
AgeCommit message (Collapse)Author
2022-04-09unix(4): Convert membar_exit to membar_release.riastradh
Use atomic_load_consume or atomic_load_relaxed where necessary. Comment on why unlocked nonatomic access is valid where it is done.
2022-03-12kern: m_copym(M_DONTWAIT) can fail; handle that case gracefully.riastradh
Not sure if this should truncate the result or just fail with nonzero error code (ENOBUFS?). Feel free to change this the other way if you know better! Reported-by: syzbot+54c34f25d1e4124eb85d@syzkaller.appspotmail.com
2021-10-23Add support for the EVFILT_EMPTY filter, which is activated when thethorpej
write buffer associated with the file descriptor is empty. This is currently implemented only for sockets, and is intended primarily to provide visibility to applications that all previously written data has been acknowledged by the TCP layer on the receiver. Compatible with the same filter in FreeBSD.
2021-10-11Setting EV_EOF requires modifying kn->kn_flags. However, that relies onthorpej
holding the kq_lock of that note's kq. Rather than exposing this directly, add new knote_set_eof() and knote_clear_eof() functions that handle the necessary locking and don't leak as many implementation details to modules. NetBSD 9.99.91
2021-09-29The kq filterops that interact with sockets are MPSAFE.thorpej
2021-09-29- Change selremove_knote() from returning void to bool, and returnthorpej
true if the last knote was removed and there are no more knotes on the selinfo. - Use this new return value in filt_sordetach(), filt_sowdetach(), filt_fifordetach(), and filt_fifowdetach() to know when to clear SB_KOTE without having to know select/kqueue implementation details.
2021-09-26Change the kqueue filterops::f_isfd field to filterops::f_flags, andthorpej
define a flag FILTEROP_ISFD that has the meaning of the prior f_isfd. Field and flag name aligned with OpenBSD. This does not constitute a functional or ABI change, as the field location and size, and the value placed in that field, are the same as the previous code, but we're bumping __NetBSD_Version__ so 3rd-party module source code can adapt, as needed. NetBSD 9.99.89
2021-08-03in sbsavetimestamp(), initialize struct timeval to 0 with memset() so thatchs
the implicit padding is initialized. this avoids later copying uninitialized memory out to user space. detected by KMSAN.
2020-12-11Use sel{record,remove}_knote().thorpej
2020-11-23Restore correct functioning of SIOCATMARK by removing the previouschs
change that was done to fix poll(POLLPRI | POLLRDBAND) and instead add a separate flag to track when poll() should indicate that a MSG_OOB byte is available. Re-fixes PR 54435 properly.
2020-10-17Setting a socket buffer size stops autoscaling. Add a sysctl tomlelstv
prevent this behaviour. The default is not changed.
2020-08-26add socket info for user and group for unix sockets in fstat.christos
2020-06-07Fix bohr bug triggered only once by syzkaller 2,5 months ago.maxv
In sockopt_alloc(), 'sopt' may already have been initialized with 'sopt->sopt_data = sopt->sopt_buf'. If the allocation fails, we end up with 'sopt->sopt_data = NULL', and later try to free this NULL pointer in sockopt_destroy(). Fix that by not modifying 'sopt_data' if the allocation failed. Difficult to reproduce in normal times, but fault(4) makes it easy. Reported-by: syzbot+380cb5d518742f063ad2@syzkaller.appspotmail.com
2020-04-26Implement SCTP bug fixes found by maxv@.jakllsch
Adding these seems to improve the SCTP situation.
2020-02-22Zero out 'tv', to prevent uninitialized bytes in its padding from leakingmaxv
to userland. Found by kMSan. Reported-by: syzbot+8134380511a82c8f5fd7@syzkaller.appspotmail.com
2020-02-21Explicitly cast pointers to uintptr_t before casting to enums. They arejoerg
not necessarily the same size. Don't cast pointers to bool, check for NULL instead.
2020-02-18PR/54435: Valery Ushakov: Clear urgent status after reading urgent data, sochristos
that poll(2) works.
2019-10-14Add a check before the memcpy. memcpy is defined to never take NULL asmaxv
second argument, and the compiler is free to perform optimizations knowing that this argument is never NULL. In this particular case, it was harmless. But still good to fix. Reported-by: syzbot+6f504255accb795eb6b7@syzkaller.appspotmail.com
2019-09-27Actually return the updated pointer-to-mbuf-pointer to the callerpgoyette
rather than discarding-after-assignment. Introduced from the [pgoyette-compat] branch work. Welcome to 9.99.14 !!! (Module hook routine prototype changed.) Found by the lgtm bot, reported via private Email from maxv@
2019-09-14Fix build.mlelstv
2019-09-14PT/54527: Anthony Mallet: Don't clear socket errors for MSG_PEEK.christos
2019-07-16Move the assignment of SCTP-specific function hooks/pointers.pgoyette
Without this, a rumpkernel (appropriately modified) built with SCTP enabled will try to assign the function pointers, but the targets are only available in rumpnet. We cannot link the rumpkernel against rumpnet because rumpnet is already linked against rumpkernel and we would end up with a circular dependency. As reported in private Email by rjs@
2019-06-01Add XXXs for SCTP bugs.maxv
2019-05-08PR/54176: Anthony Mallet:christos
getsockopt(2) does not silently truncate returned optval
2019-04-15Clean up this mess and simplify, so that all the socket options getpgoyette
handled correctly whether or not the compat_50 module is loaded.
2019-04-15If the compat code successfully handled an option, don't return an error.pgoyette
2019-04-15Actually update the timeout value for the compability sockopspgoyette
2019-04-15Split the COMPAT_50 socket-timeout stuff out of kern/uipc_socket.cpgoyette
and into its own source file, which is now included in the compat_50 module. (Not sure how this got missed during the original [pgoyette-compat] work)
2019-04-14Add more checks, if the values are negative we hit a KASSERT later in themaxv
timeout. Reported-by: syzbot+662dbeb526303f458255@syzkaller.appspotmail.com
2019-04-08Reset so_cred to NULL after freeing it, because close() may leave the PCBmaxv
in pcblist, and we don't want a future lookup (via eg netstat) to read freed data. Detected by KASAN, reported by Alexander Nasonov.
2019-03-31Also check for MT_CONTROL, and end the receive operation if we see one. Itmaxv
is possible to get an MT_CONTROL if we sleep in MSG_WAITALL. The other BSDs do the same. Reported-by: syzbot+e8aa26ad551c649227b4@syzkaller.appspotmail.com
2019-03-07Remove getsombuf(), unused.maxv
2019-03-07stylemaxv
2019-02-04add a couple of fallthru comments.mrg
2018-12-22Replace M_ALIGN and MH_ALIGN by m_align.maxv
2018-11-07Update getsockopt(SO_ERROR) to behave like soreceive() andhannken
return and clear so->so_rerror if so->so_error is zero. Ok: christos@
2018-11-04- Introduce a new SO_RERROR socket option to explicitly turn onchristos
receive overflow errors re-instating the default behavior to silently ignore them as before 2018-03-19. - Introduce a new kern.sooptions sysctl to control the default behavior of socket options. Setting this to 0x4000 (SO_RERROR), turns on receive overflow error reporting for all sockets. - Change dhcpcd to turn on SO_RERROR on all its sockets. As discussed in tech-net.
2018-09-03Rename min/max -> uimin/uimax for better honesty.riastradh
These functions are defined on unsigned int. The generic name min/max should not silently truncate to 32 bits on 64-bit systems. This is purely a name change -- no functional change intended. HOWEVER! Some subsystems have #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) even though our standard name for that is MIN/MAX. Although these may invite multiple evaluation bugs, these do _not_ cause integer truncation. To avoid `fixing' these cases, I first changed the name in libkern, and then compile-tested every file where min/max occurred in order to confirm that it failed -- and thus confirm that nothing shadowed min/max -- before changing it. I have left a handful of bootloaders that are too annoying to compile-test, and some dead code: cobalt ews4800mips hp300 hppa ia64 luna68k vax acorn32/if_ie.c (not included in any kernels) macppc/if_gm.c (superseded by gem(4)) It should be easy to fix the fallout once identified -- this way of doing things fails safe, and the goal here, after all, is to _avoid_ silent integer truncations, not introduce them. Maybe one day we can reintroduce min/max as type-generic things that never silently truncate. But we should avoid doing that for a while, so that existing code has a chance to be detected by the compiler for conversion to uimin/uimax without changing the semantics until we can properly audit it all. (Who knows, maybe in some cases integer truncation is actually intended!)
2018-06-06Separate receive socket errors from general socket errors.roy
2018-04-26Stop using m_copy(), use m_copym() directly. m_copy is useless,maxv
undocumented and confusing.
2018-04-26Remove unused mbuf argument from sbsavetimestamp.maxv
2018-03-19socket: remove now incorrect comment that so_error is only udproy
As it can be affected by route(4) sockets which are raw.
2018-03-19socket: clear error even when peekingroy
The error has already been reported and it's pointless requiring another recv(2) call just to clear it.
2018-01-04Add a new sockopt member to keep track of the actual size of the optionchristos
that should be returned to the caller in getsockopt(2). (Tom Ivar Helbekkmo)
2018-01-01make sure that we have enough space, don't require the exact sizechristos
(Tom Ivar Helbekkmo)
2017-10-25Use C99 initializer for filteropsmaya
Mostly done with spatch with touchups for indentation @@ expression a; identifier b,c,d; identifier p; @@ const struct filterops p = - { a, b, c, d + { + .f_isfd = a, + .f_attach = b, + .f_detach = c, + .f_event = d, };
2017-07-06move the timestamp stuff to uipc_socket.c because it already has the compatchristos
includes.
2017-05-27merge the bouyer-socketcan branch to HEAD.bouyer
CAN stands for Controller Area Network, a broadcast network used in automation and automotive fields. For example, the NMEA2000 standard developped for marine devices uses a CAN network as the link layer. This is an implementation of the linux socketcan API: https://www.kernel.org/doc/Documentation/networking/can.txt you can also see can(4). This adds a new socket family (AF_CAN) and protocol (PF_CAN), as well as the canconfig(8) utility, used to set timing parameter of CAN hardware. Also inclued is a driver for the CAN controller found in the allwinner A20 SoC (I tested it with an Olimex lime2 board, connected with PIC18-based CAN devices). There is also the canloop(4) pseudo-device, which allows to use the socketcan API without CAN hardware. At this time the CANFD part of the linux socketcan API is not implemented. Error frames are not implemented either. But I could get the cansend and canreceive utilities from the canutils package to build and run with minimal changes. tcpudmp(8) can also be used to record frames, which can be decoded with etherreal.
2017-05-25switch to a switchchristos
2017-05-01whitespace policeryo