summaryrefslogtreecommitdiff
path: root/ubusd_main.c
Commit message (Collapse)AuthorAgeFilesLines
* ubusd: convert tx_queue to linked listArnout Vandecappelle (Essensium/Mind)2021-05-311-24/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ubusd maintains a per-client tx_queue containing references to message buffers that have not been sent yet (due to the socket blocking). This is a fixed-size, 64-element queue. When more than 64 elements are queued, subsequent elements are simply dropped. Thus, a client that is waiting for those messages will block indefinitely. In particular, this happens when more than +- 250 objects are registered on the bus and either "ubus list" or "ubus wait_for" is called. The responses to these requests consist of a message buffer per object. Since in practice, ubusd will not yield between the sends of these message buffers, the client has no time to process them and eventually the output socket blocks. After 64 more objects, the rest is dropped, including the final message that indicates termination. Thus, the client waits indefinitely for the termination message. To solve this, turn the tx_queue into a variable-sized linked list instead of a fixed-size queue. To maintain the linked list, an additional structure ubus_msg_buf_list is created. It is not possible to add the linked list to ubus_msg_buf, because that is shared between clients. Note that this infinite tx_queue opens the door to a DoS attack. You can open a client and a server connection, then send messages from the client to the server without ever reading anything on the server side. This will eventually lead to an out-of-memory. However, such a DoS already existed anyway, it just requires opening multiple server connections and filling up the fixed-size queue on each one. To protect against such DoS attacks, we'd need to: - keep a global maximum queue size that applies to all rx and tx queues together; - stop reading from any connection when the maximum is reached; - close any connection when it hasn't become writeable after some timeout. Fixes: https://bugs.openwrt.org/index.php?do=details&task_id=1525 Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
* ubusd: attempt to create socket folderDaniel Golle2020-12-041-0/+16
| | | | | | | | | | | When ubus is running as root, /var/run/ubus most likely hasn't been created as well (as that's the homedir of user ubus, and if a user ubus was found, then ubus would run being that user). Blindly attempt to create the directory (which won't do any harm if it does exist and/or ubus is not running as root) to still be able to start ubus in case of user ubus not existing. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* ubusd/libubus-io: fix socket descriptor passingPetr Štetiar2019-12-271-19/+22
| | | | | | | | | | | | | | | In commit 5d7ca8309d0a ("ubusd/libubus-io: fix variable sized struct position warning") the position of cmsghdr struct has been changed in order to fix clang-9 compiler warning, but it has introduced regression in at least `logread` which hanged indefinitely. So this patch reworks the socket descriptor passing in a way recommended in the `cmsg(3)` manual page. Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-December/020840.html Fixes: 5d7ca8309d0a ("ubusd/libubus-io: fix variable sized struct position warning") Reported-by: Hannu Nyman <hannu.nyman@welho.com> Signed-off-by: Petr Štetiar <ynezz@true.cz>
* refactor ubusd.c into reusable ubusd_libraryPetr Štetiar2019-12-161-0/+271
In order to allow reusability in unit testing & fuzzing. Signed-off-by: Petr Štetiar <ynezz@true.cz>