-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: socket: syscall for socketpair(2) #24367
net: socket: syscall for socketpair(2) #24367
Conversation
Some checks failed. Please fix and resubmit. checkpatch issues
Gitlint issuesCommit a9eb4efd6f: Commit 83c433af0c: Commit 1b1b0ca382: Commit 9f6ff50e8a: Commit 0db21791af: Commit c069a91aea: Commit 2e14682ea7: Identity/Emails issuesa9eb4efd6f5102cd52cee8c16db16ad038d2c44c: author email (Christopher Friedt [email protected]) needs to match one of the signed-off-by entries. 83c433af0ce81758c47eead22f457daf5d510e88: author email (Christopher Friedt [email protected]) needs to match one of the signed-off-by entries. 1b1b0ca382ba6fd91d22c5a43b65be10a340e149: author email (Christopher Friedt [email protected]) needs to match one of the signed-off-by entries. 9f6ff50e8a7134d87c91714b7a67e1d1e8e9d772: author email (Christopher Friedt [email protected]) needs to match one of the signed-off-by entries. 0db21791afb81c1c4f70e94cbee09445f89b03e7: author email (Christopher Friedt [email protected]) needs to match one of the signed-off-by entries. c069a91aea9748d871549eb4b86f7fe8bffbf6f5: author email (Christopher Friedt [email protected]) needs to match one of the signed-off-by entries. Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, minor nits. We also need to add more tests.
@@ -0,0 +1,8 @@ | |||
# SPDX-License-Identifier: Apache-2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put the tests to separate commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an obvious security issue with this patch, see inline comment.
If it's ok with you all (@pfalcon, @jukkar, @ceolin, @tbursztyka), I will leave this PR open and implement pipe(2) separately. I believe this review will be fairly cut & dry once pipe(2) is implemented. Also, do you know of a simple way I can run my tests natively or in Qemu? So far all I have been contributing to is BLE. Sorry for all of the whitespace issues - clang-format does not do the trick (#23823) but uncrustify might (#21392) |
It's probably better to not use pipe(2) for socketpair(2) since a pair of sockets form a bidirectional channel rather than a unidirectional channel. Likely, will use a pair of k_fifo. Technically, it is possible using pipe(2) but that would mean 4 file descriptors would need to be created instead of only 2. So from that perspective, maybe it is better to just keep socketpair(2) exclusively in net and even reuse much of the existing socket machinery. |
Provide an implementation for socketpair(2). Currently, this is limited to the AF_UNIX address family, SOCK_STREAM, SOCK_RAW, and protocol 0. Fixes #24366 Signed-off-by: Christopher Friedt <[email protected]>
diff --git a/kernel/pipes.c b/kernel/pipes.c index efd2855c5e..c6ae71555d 100644 --- a/kernel/pipes.c +++ b/kernel/pipes.c @@ -135,10 +135,11 @@ void k_pipe_init(struct k_pipe *pipe, unsigned char *buffer, size_t size) pipe->bytes_used = 0; pipe->read_index = 0; pipe->write_index = 0; - pipe->flags = 0; + pipe->lock = (struct k_spinlock){}; z_waitq_init(&pipe->wait_q.writers); z_waitq_init(&pipe->wait_q.readers); SYS_TRACING_OBJ_INIT(k_pipe, pipe); + pipe->flags = 0; z_object_init(pipe); }
Except write / read need to be macro'ed out to send / recv due to Zephyr's POSIX naming, otherwise they attempt to use write / read from stdio. Currently only working in the sv[0] -> sv[1] direction. If I attempt to write in the sv[1] -> sv[0] direction, I encounter the same error that I encountered before when there was an assertion verifying the pipe's spinlock. Output: ninja: Entering directory `build' [0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: cortex-m3 qemu-system-arm: warning: nic stellaris_enet.0 has no peer *** Booting Zephyr OS build zephyr-v2.2.0-1661-g0cc6bdf36c5c *** Running test suite socket_socketpair =================================================================== starting test - test_socket_socketpair_happy_path calling socketpair(AF_LOCAL, SOCK_STREAM, 0, sv) data direction: 0 -> 1 testing write(2) testing read(2) testing send(2) testing recv(2) testing sendto(2) testing recvfrom(2) data direction: 1 -> 0 testing write(2) ASSERTION FAIL [z_spin_lock_valid(l)] @ ../include/spinlock.h:44 Recursive spinlock 0x20000bf4 E: r0/a1: 0x00000004 r1/a2: 0x0000002c r2/a3: 0x0000000a E: r3/a4: 0x00000000 r12/ip: 0x01010101 r14/lr: 0x00017c39 E: xpsr: 0x41000000 E: Faulting instruction address (r15/pc): 0x0001d002 E: >>> ZEPHYR FATAL ERROR 4: Kernel panic on CPU 0 E: Current thread: 0x200009c0 (unknown) E: Halting system qemu-system-arm: terminating on signal 2 ninja: build stopped: interrupted by user. Stack Trace: #0 arch_irq_lock () at ../include/arch/arm/aarch32/asm_inline_gcc.h:56 #1 k_spin_lock (l=0x20000bf4 <kheap_poolheap.heap_mem_pool+104>) at ../include/spinlock.h:41 #2 z_pipe_put_internal (pipe=0x20000be0 <kheap_poolheap.heap_mem_pool+84>, async_desc=0x0 <crc32_ieee>, data=0x2879c "Hello, socketpair(2) world!", bytes_to_write=27, bytes_written=0x20001e90 <ztest_thread_stack+648>, min_xfer=0, timeout=0) at /home/cfriedt/workspace/zephyrproject/zephyr/kernel/pipes.c:449 #3 0x000261da in z_impl_k_pipe_put (pipe=0x20000be0 <kheap_poolheap.heap_mem_pool+84>, data=0x2879c, bytes_to_write=27, bytes_written=0x20001e90 <ztest_thread_stack+648>, min_xfer=0, timeout=0) at /home/cfriedt/workspace/zephyrproject/zephyr/kernel/pipes.c:741 #4 0x0001d24e in k_pipe_put (pipe=0x20000be0 <kheap_poolheap.heap_mem_pool+84>, data=0x2879c, bytes_to_write=27, bytes_written=0x20001e90 <ztest_thread_stack+648>, min_xfer=0, timeout=0) at zephyr/include/generated/syscalls/kernel.h:908 #5 0x0000808a in spair_write (obj=0x20000bec <kheap_poolheap.heap_mem_pool+96>, buffer=0x2879c, count=27) at /home/cfriedt/workspace/zephyrproject/zephyr/subsys/net/lib/sockets/socketpair.c:217 #6 0x0001d442 in spair_sendto (obj=0x20000bec <kheap_poolheap.heap_mem_pool+96>, buf=0x2879c, len=27, flags=0, dest_addr=0x0 <crc32_ieee>, addrlen=0) at /home/cfriedt/workspace/zephyrproject/zephyr/subsys/net/lib/sockets/socketpair.c:294 #7 0x0001d1d2 in z_impl_zsock_sendto (sock=1, buf=0x2879c, len=27, flags=0, dest_addr=0x0 <crc32_ieee>, addrlen=0) at /home/cfriedt/workspace/zephyrproject/zephyr/subsys/net/lib/sockets/sockets.c:566 #8 0x0001c1f0 in zsock_sendto (sock=1, buf=0x2879c, len=27, flags=0, dest_addr=0x0 <crc32_ieee>, addrlen=0) at zephyr/include/generated/syscalls/socket.h:137 #9 0x0001bf88 in zsock_send (sock=1, buf=0x2879c, len=27, flags=0) at /home/cfriedt/workspace/zephyrproject/zephyr/include/net/socket.h:293 #10 0x00006c18 in happy_path_inner (family=6, family_s=0x28ee8 "AF_LOCAL", type=1, type_s=0x28efc "SOCK_STREAM", proto=0, proto_s=0x28f14 "0") at /home/cfriedt/workspace/zephyrproject/zephyr/tests/net/socket/socketpair/src/main.c:58 #11 0x0000700c in test_socket_socketpair_happy_path () at /home/cfriedt/workspace/zephyrproject/zephyr/tests/net/socket/socketpair/src/main.c:185
@cfriedt: Same comment as for the other PR - please deal with checkstyle issues. (Also, to set expectations right - there was a talk about release readiness meeting. Which reminds that we may be approaching a pre-release freeze. Whatever isn't merged before it, may need to wait a month or so until next devel window is open. Surely feel free to work at you pace. What I wanted to say is that if you don't get a prompt review (once CI passes), don't hesitate to ping me. Thanks.) |
Going to close the PR for the next while. Will reopen soon. |
Provide an implementation for socketpair(2). Currently, this is limited to the AF_UNIX address family, SOCK_STREAM, SOCK_RAW, and protocol 0.
Please feel free to suggest additional testing in
tests/net/socket/socketpair/
or to suggest improvements in the implementation.Fixes #24366