History log of /haiku/src/system/kernel/fs/socket.cpp
Revision Date Author Comments
# 1bde6f6c 08-Jan-2024 Augustin Cavalier <waddlesplash@gmail.com>

kernel/fs: Standardize AutoDeleters for file_descriptor on FileDescriptorPutter.

No functional change intended.


# 00f1e7c5 03-Jun-2022 Augustin Cavalier <waddlesplash@gmail.com>

kernel: Rework iovec copying from userland.

Create a utility function which performs all necessary checks,
allocates memory, and copies the structures, and then make use of it
in the three places in the kernel which did all this manually.

None of them were previously complete: the fd and socket code only
checked iov_base and not iov_len, while the port code did not check
anything at all.

Part of #14961.


# e52da6c7 03-Jun-2022 Augustin Cavalier <waddlesplash@gmail.com>

kernel/fs: Invoke the new is_user_address_range on more I/O buffers.

We do not access these buffers directly here but pass them deeper
into the kernel, where they may be used in IO operations that do
not invoke user_* functions at all, so we have to validate them fully here.

Part of #14961.


# 0424248d 01-May-2020 Jérôme Duval <jerome.duval@gmail.com>

kernel/fs: allow sendto to be called with a NULL address

POSIX says: If the socket is connection-mode, dest_addr shall be ignored.

Change-Id: Ic75de473173e3795066beeac9a9f2404418d94da
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2547
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# 6a231205 08-Aug-2019 Augustin Cavalier <waddlesplash@gmail.com>

kernel/fs: Fix another instance of free() being called on a FD.

Fixes the second panic in #15213.


# 35cc5c98 30-Aug-2013 Pawel Dziepak <pdziepak@quarnos.org>

vfs: Allow non-null-terminated UNIX socket pathnames

This patch fix one of the compatibility issues mentioned in #3255. It
allows applications to call bind() or connect() passing an sockaddr_un
structure with a pathname that is not null-terminated.

Some systems did not require pathname in sockaddr_un::sun_path to be
null-terminated, instead the end of the string is determined by the size
of the structure passed as an argument of bind() or connect().

The standard is a bit vague in this matter but suggest that the path
should be null-terminated and the functions bind() and connect() should
be given sizeof(sockaddr_un) as a structure size.


# 4be4fc6b 15-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

More 64-bit compilation/safety fixes.


# 00400fd6 27-Aug-2010 Axel Dörfler <axeld@pinc-software.de>

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38389 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9d570af7 24-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Changed the type of the "op" parameter of the fs_vnode_ops::ioctl() hook and
the _kern_ioctl() syscall from ulong to uint32.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36927 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 273dbd09 13-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* The network syscalls now check if you try to pass a non-userland address to
them (which you previously could use to easily crash/take over Haiku).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33570 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fa00207c 15-Jun-2009 Axel Dörfler <axeld@pinc-software.de>

* Made the internal file systems correctly handle the timespec struct stat
times.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31059 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9431509f 30-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Fixed broken socket_get_next_stat() that was responsible for bug #3830.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30500 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 09a60e4b 16-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Since we moved the socket stuff into the kernel, we lost the ability to
unload the network stack. This now works again, although I didn't manage to
do it without another lock.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c33667d4 01-Feb-2009 Michael Lotz <mmlr@mlotz.ch>

Fixing warnings under GCC4 in preparation to enable -Werror there as well:
* Replaced the use of offsetof() for structs that aren't PODs. Add a
offset_of_member() macro to util/khash.h because that's what it's used for
in our cases.
* Change the signature of add_debugger_command()/remove_debugger_command() on
GCC > 2 to avoid the depricated conversion from string constants to char *.
* Adding some "suggested" parenthesis. I know that not everyone likes that, but
it pointed out at least one bug that is fixed here as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29113 a95241bf-73f2-0310-859d-f6bbb57e9c96


# de33b3be 04-Oct-2008 Axel Dörfler <axeld@pinc-software.de>

* connect() and bind() now make sure that sockaddr::sa_len is set correctly.
* Renamed MAX_SOCKET_ADDRESS_LEN to MAX_SOCKET_ADDRESS_LENGTH.
* Whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27865 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a8f9741c 04-Jul-2008 Michael Lotz <mmlr@mlotz.ch>

* Removed -Wno-unused from all KernelMergeObjects in kernel Jamfiles.
* Fixed most of the warnings resulting from that by removing actually not used
variables or moving declaration into the #IF. Left unused functions there
though, as I wouldn't know if they are supposed to be used again.
* Fixed two statements with no effect (clamping to MAX_ANCILLARY_DATA_LEN in
socket.cpp and unsetting fCounterSem in MessagingService.cpp).
* Some style cleanups.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26253 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3134e718 02-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Also check whether the data pointers of provided userland iovecs are
actually pointing to userland. This saves checks in the net stack.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25298 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6f57d9d0 01-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

When creating a socket file descriptor fetch the SO_NONBLOCK value from
the socket first, so the FD open flags are in sync with that. Fixes
situations where a socket accept()ed from a non-blocking listener socket
wouldn't have O_NONBLOCK set.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25288 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f13ba039 12-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed SyscallRestartWrapper comparison operators. They are not
needed, since we've got a cast operator.
* Reverted r24927-r24929. There's no potential ambiguity anymore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24949 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 460c990c 12-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

The syscalls that were returning an address always copied back the full
address back to userland, even if the provided buffer was smaller. Fixes
a problem with Firefox, which is for some reason providing a buffer
smaller than our sockaddr_in.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24948 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5f2d64a2 12-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* _user_{send,recf}msg() no longer copy iovecs on the stack. They use
the heap and the IOV_MAX limit.
* They also take the responsibility of copying the ancillary data in and
out.
* These syscalls were badly broken. They used a member of an
uninitialized structure instead of the iovec pointer passed from
userland. sendmsg() would thus fail or send arbitrary data, recvmsg()
would overwrite arbitrary memory.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24939 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6cb51e58 12-Apr-2008 Jérôme Duval <korli@users.berlios.de>

better cast to the good type to avoid confusing gcc


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24929 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3118b3a7 11-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added fd_ops::set_flags() hook. It's only implemented by socket FDs
ATM.
* Changed common_fcntl() to also work for non-vnode-based FDs. Only the
operations that require a vnode do fail now. F_SETFL uses the new
fd_ops::set_flags() if available, falling back to the vnode respective
operation.
* Changed some direct accesses to file_descriptor::u::vnode. It was safe
in those cases, but might not be anymore if we ever change fd_vnode().

ftp can at least connect to servers again, now, but apparently we still
have a problem with syscall restarts -- downloads fail after one second,
when the timer goes off.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24917 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75015ff5 11-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed THREAD_FLAGS_IOCTL_SYSCALL to THREAD_FLAGS_SYSCALL,
syscall_restart_ioctl_is_restarted() to syscall_restart_is_restarted,
IoctlSyscallFlagUnsetter to SyscallFlagUnsetter, and
IoctlSyscallRestartWrapper to SyscallRestartWrapper, as they are no
longer only used for ioctl().
* Removed unused syscall_restart_ioctl_handle_post().
* Made SyscallRestartWrapper a lot fancier. Instead of storing a
reference to the result value, it stores the value itself, and it
features all the interesting operators that make it appear like that
value. This simplifies the use of the class quite a bit.
* THREAD_FLAGS_SYSCALL is now set for all socket function and the
read[v](), write[v]() syscalls.
* Added is_syscall() function and net_stack hook to the net stack.
* Removed "kernel" parameter from all net_stack_interface and net_socket
module hooks. They aren't need any longer, since is_syscall() can be
used instead.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24914 a95241bf-73f2-0310-859d-f6bbb57e9c96


# df50f7a9 10-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed the way the socket functions work:
- The net_stack driver is no longer used. Instead we have a kernel
module which is directly used by syscall implementations in the
kernel. I.e. we no longer tunnel those functions through ioctls, but
have normal syscalls.
- Removed the superfluous net starter module.
- Implemented the FDTYPE_SOCKET type file_descriptors, that is sockets
are no longer vnode based.
- Adjusted libnetwork (the socket function implementations)
accordingly.
- Adjusted netstat accordingly.
* Socket module:
- Implemented socketpair().
- Added "kernel" parameter to the control hook. Quite a few more hooks
would actually need the parameter, but I didn't change those yet,
since that would probably also require changes to the protocol
module interface.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24908 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 35cc5c98978812bb7837dafbdd124ce70549c719 30-Aug-2013 Pawel Dziepak <pdziepak@quarnos.org>

vfs: Allow non-null-terminated UNIX socket pathnames

This patch fix one of the compatibility issues mentioned in #3255. It
allows applications to call bind() or connect() passing an sockaddr_un
structure with a pathname that is not null-terminated.

Some systems did not require pathname in sockaddr_un::sun_path to be
null-terminated, instead the end of the string is determined by the size
of the structure passed as an argument of bind() or connect().

The standard is a bit vague in this matter but suggest that the path
should be null-terminated and the functions bind() and connect() should
be given sizeof(sockaddr_un) as a structure size.


# 4be4fc6b1faddbd037146214a0011d320842b4f3 15-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

More 64-bit compilation/safety fixes.


# 00400fd6839f05e645a604e4e155bb17aa9a2e6a 27-Aug-2010 Axel Dörfler <axeld@pinc-software.de>

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38389 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9d570af7c878ba30043b23e6dce5f3ae5578aa7c 24-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Changed the type of the "op" parameter of the fs_vnode_ops::ioctl() hook and
the _kern_ioctl() syscall from ulong to uint32.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36927 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 273dbd0916f75f57639a9bdbfcc6d28c275d091a 13-Oct-2009 Axel Dörfler <axeld@pinc-software.de>

* The network syscalls now check if you try to pass a non-userland address to
them (which you previously could use to easily crash/take over Haiku).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33570 a95241bf-73f2-0310-859d-f6bbb57e9c96


# fa00207c50d24a0c867ec4123c351f85256fcbbf 15-Jun-2009 Axel Dörfler <axeld@pinc-software.de>

* Made the internal file systems correctly handle the timespec struct stat
times.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31059 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9431509f5c1c661a6f6f4665198f5d3b24826d9d 30-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Fixed broken socket_get_next_stat() that was responsible for bug #3830.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30500 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 09a60e4bd4c41ffc9d9672f00ce55de1a498233a 16-Apr-2009 Axel Dörfler <axeld@pinc-software.de>

* Since we moved the socket stuff into the kernel, we lost the ability to
unload the network stack. This now works again, although I didn't manage to
do it without another lock.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c33667d400856680a8e0122300861eda77d1847a 01-Feb-2009 Michael Lotz <mmlr@mlotz.ch>

Fixing warnings under GCC4 in preparation to enable -Werror there as well:
* Replaced the use of offsetof() for structs that aren't PODs. Add a
offset_of_member() macro to util/khash.h because that's what it's used for
in our cases.
* Change the signature of add_debugger_command()/remove_debugger_command() on
GCC > 2 to avoid the depricated conversion from string constants to char *.
* Adding some "suggested" parenthesis. I know that not everyone likes that, but
it pointed out at least one bug that is fixed here as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29113 a95241bf-73f2-0310-859d-f6bbb57e9c96


# de33b3bed0822adbe42aa53946498221de3dfa28 04-Oct-2008 Axel Dörfler <axeld@pinc-software.de>

* connect() and bind() now make sure that sockaddr::sa_len is set correctly.
* Renamed MAX_SOCKET_ADDRESS_LEN to MAX_SOCKET_ADDRESS_LENGTH.
* Whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27865 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a8f9741c8c2815234e87b78167738057b976b537 04-Jul-2008 Michael Lotz <mmlr@mlotz.ch>

* Removed -Wno-unused from all KernelMergeObjects in kernel Jamfiles.
* Fixed most of the warnings resulting from that by removing actually not used
variables or moving declaration into the #IF. Left unused functions there
though, as I wouldn't know if they are supposed to be used again.
* Fixed two statements with no effect (clamping to MAX_ANCILLARY_DATA_LEN in
socket.cpp and unsetting fCounterSem in MessagingService.cpp).
* Some style cleanups.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26253 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3134e71811d73ba55a0070cb299e6099d91cd78b 02-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Also check whether the data pointers of provided userland iovecs are
actually pointing to userland. This saves checks in the net stack.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25298 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6f57d9d066f142a4e9217ecb0d48803f8d9bd531 01-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

When creating a socket file descriptor fetch the SO_NONBLOCK value from
the socket first, so the FD open flags are in sync with that. Fixes
situations where a socket accept()ed from a non-blocking listener socket
wouldn't have O_NONBLOCK set.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25288 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f13ba03959f6227a75ff8c2e129058215dea380f 12-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Removed SyscallRestartWrapper comparison operators. They are not
needed, since we've got a cast operator.
* Reverted r24927-r24929. There's no potential ambiguity anymore.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24949 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 460c990c5d6a93df10d0b16480874c634c9b3884 12-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

The syscalls that were returning an address always copied back the full
address back to userland, even if the provided buffer was smaller. Fixes
a problem with Firefox, which is for some reason providing a buffer
smaller than our sockaddr_in.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24948 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5f2d64a25ed43ebf6cab7f588ac3ead0cfeb4ddf 12-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* _user_{send,recf}msg() no longer copy iovecs on the stack. They use
the heap and the IOV_MAX limit.
* They also take the responsibility of copying the ancillary data in and
out.
* These syscalls were badly broken. They used a member of an
uninitialized structure instead of the iovec pointer passed from
userland. sendmsg() would thus fail or send arbitrary data, recvmsg()
would overwrite arbitrary memory.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24939 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6cb51e58bc5559117b23d35b19db8d3d1a3c7984 12-Apr-2008 Jérôme Duval <korli@users.berlios.de>

better cast to the good type to avoid confusing gcc


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24929 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3118b3a7cbf56fb77ab7ceb02eae609a664c6d6f 11-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added fd_ops::set_flags() hook. It's only implemented by socket FDs
ATM.
* Changed common_fcntl() to also work for non-vnode-based FDs. Only the
operations that require a vnode do fail now. F_SETFL uses the new
fd_ops::set_flags() if available, falling back to the vnode respective
operation.
* Changed some direct accesses to file_descriptor::u::vnode. It was safe
in those cases, but might not be anymore if we ever change fd_vnode().

ftp can at least connect to servers again, now, but apparently we still
have a problem with syscall restarts -- downloads fail after one second,
when the timer goes off.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24917 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 75015ff525050d1d716f499732c566956c6078ad 11-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed THREAD_FLAGS_IOCTL_SYSCALL to THREAD_FLAGS_SYSCALL,
syscall_restart_ioctl_is_restarted() to syscall_restart_is_restarted,
IoctlSyscallFlagUnsetter to SyscallFlagUnsetter, and
IoctlSyscallRestartWrapper to SyscallRestartWrapper, as they are no
longer only used for ioctl().
* Removed unused syscall_restart_ioctl_handle_post().
* Made SyscallRestartWrapper a lot fancier. Instead of storing a
reference to the result value, it stores the value itself, and it
features all the interesting operators that make it appear like that
value. This simplifies the use of the class quite a bit.
* THREAD_FLAGS_SYSCALL is now set for all socket function and the
read[v](), write[v]() syscalls.
* Added is_syscall() function and net_stack hook to the net stack.
* Removed "kernel" parameter from all net_stack_interface and net_socket
module hooks. They aren't need any longer, since is_syscall() can be
used instead.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24914 a95241bf-73f2-0310-859d-f6bbb57e9c96


# df50f7a9b4b0bbe77413d722875b0a346c61d527 10-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed the way the socket functions work:
- The net_stack driver is no longer used. Instead we have a kernel
module which is directly used by syscall implementations in the
kernel. I.e. we no longer tunnel those functions through ioctls, but
have normal syscalls.
- Removed the superfluous net starter module.
- Implemented the FDTYPE_SOCKET type file_descriptors, that is sockets
are no longer vnode based.
- Adjusted libnetwork (the socket function implementations)
accordingly.
- Adjusted netstat accordingly.
* Socket module:
- Implemented socketpair().
- Added "kernel" parameter to the control hook. Quite a few more hooks
would actually need the parameter, but I didn't change those yet,
since that would probably also require changes to the protocol
module interface.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24908 a95241bf-73f2-0310-859d-f6bbb57e9c96