From patchwork Wed Feb 16 10:43:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1593624 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=bvA/mYXp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JzF7h3ZGQz9sDX for ; Wed, 16 Feb 2022 21:49:04 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=V9/U+liEA/cVlRfzBZ3QVfdDgOexezlBUq6zie5bODg=; b=bvA/mYXptEWK22 4Gd0VtpXRRfOeRyehbIKKrQYrW8ZmL6nhyk6KDIgeBBLIjiELwur1RK8HWQwHNWHEbr4Qnt6CTzId YMKqgQCIIG6yBtPT1aBA+4+qRExiDFn7GfDAnmb29i7KlBG0b9oj/VKM641XAU0zV+EF1F4Bcp0f/ Cav19jSUmZjb/UrjUF6BrdrJ7p1OI42bBFNKa1MiiGEPTq60cmpHePnYwhiaxWG5ZsaVakMt6vnAW WVNRA1OoUHPh6aIELZRysh6ARsr5PdUMm2WxPFW9ynZCgM8HU6cIp5Su1oF1+POda0589jAOWhKtT ql/suKqaY22DZVQY18zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKHnb-006bWM-9V; Wed, 16 Feb 2022 10:44:39 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKHms-006bJe-7C for openwrt-devel@lists.openwrt.org; Wed, 16 Feb 2022 10:43:57 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 10F233D08; Wed, 16 Feb 2022 11:43:49 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 8b31a62c; Wed, 16 Feb 2022 11:43:24 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Cc: Felix Fietkau Subject: [PATCH 19.07 ubus 1/3] libubus: use list_empty/list_first_entry in ubus_process_pending_msg Date: Wed, 16 Feb 2022 11:43:36 +0100 Message-Id: <20220216104338.15704-2-ynezz@true.cz> In-Reply-To: <20220216104338.15704-1-ynezz@true.cz> References: <20220216104338.15704-1-ynezz@true.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220216_024354_484443_30E654A6 X-CRM114-Status: UNSURE ( 7.97 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Felix Fietkau Simplifies checks and avoids potential list corruption on recursive calls Signed-off-by: Felix Fietkau (cherry picked from commit 2099bb3ad9972c6188c38fd885ae74f3323fcacc) --- libubus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Felix Fietkau Simplifies checks and avoids potential list corruption on recursive calls Signed-off-by: Felix Fietkau (cherry picked from commit 2099bb3ad9972c6188c38fd885ae74f3323fcacc) --- libubus.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libubus.c b/libubus.c index 91f317c59867..7ce454eabc64 100644 --- a/libubus.c +++ b/libubus.c @@ -115,12 +115,13 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd) static void ubus_process_pending_msg(struct uloop_timeout *timeout) { struct ubus_context *ctx = container_of(timeout, struct ubus_context, pending_timer); - struct ubus_pending_msg *pending, *tmp; + struct ubus_pending_msg *pending; - list_for_each_entry_safe(pending, tmp, &ctx->pending, list) { + while (!list_empty(&ctx->pending)) { if (ctx->stack_depth) break; + pending = list_first_entry(&ctx->pending, struct ubus_pending_msg, list); list_del(&pending->list); ubus_process_msg(ctx, &pending->hdr, -1); free(pending); From patchwork Wed Feb 16 10:43:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1593623 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=QLNqwVKG; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JzF7b14VBz9sFv for ; Wed, 16 Feb 2022 21:48:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lYnv8Q2m/xvwhJn9rbuOzyMvtGOb0/TUAxkUwqpcZQo=; b=QLNqwVKG7gtTil NovOxvaWC4sNMupSOZQHRUvRLohMTKWuQsswo7JCdxMdpQaIB1LVcPFCmQLgaVrzayM7R04GdpkyD kDMJXzOFC6hsOgD6/E9aKThQZX6Mlz/qnk/UWr5xmIkecmc9LvunP6PUz6RvbASO8mc+f/KeddoB/ lhfStl+rux5P6mwmGnwohUE2uGr/7sPtl62nLfyFtOanvd1jWr77X4j/7Ka/iGNWOM9+JoLfg9qha pg/M5fio2cgwJRRdd8cVkeVfGtYKEbgCWA/HLxa2EXQ6fJT5W2/MQiNMueE6PaIDMyxCX9ewTufKj HqV87nXP3hLLV4XZukQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKHmx-006bMG-RZ; Wed, 16 Feb 2022 10:44:00 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKHms-006bJf-6T for openwrt-devel@lists.openwrt.org; Wed, 16 Feb 2022 10:43:56 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 35F343D0A; Wed, 16 Feb 2022 11:43:49 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 1b981d1d; Wed, 16 Feb 2022 11:43:25 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Cc: Felix Fietkau Subject: [PATCH 19.07 ubus 2/3] libubus: process pending messages in data handler if stack depth is 0 Date: Wed, 16 Feb 2022 11:43:37 +0100 Message-Id: <20220216104338.15704-3-ynezz@true.cz> In-Reply-To: <20220216104338.15704-1-ynezz@true.cz> References: <20220216104338.15704-1-ynezz@true.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220216_024354_469525_912A133D X-CRM114-Status: UNSURE ( 8.78 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Felix Fietkau Process pending messages before attempting to read new ones. After completing the poll, process any remaining pending messages. A previous message processing call which issued a request from within its handler may have left behind more object messages to process. Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Felix Fietkau Process pending messages before attempting to read new ones. After completing the poll, process any remaining pending messages. A previous message processing call which issued a request from within its handler may have left behind more object messages to process. Signed-off-by: Felix Fietkau (cherry picked from commit ef038488edc35f4f671c09276cc3fb4ef706ae34) --- libubus-io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libubus-io.c b/libubus-io.c index 3561ac462eb9..a1fb62b1162f 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -314,12 +314,20 @@ void __hidden ubus_handle_data(struct uloop_fd *u, unsigned int events) struct ubus_context *ctx = container_of(u, struct ubus_context, sock); int recv_fd = -1; - while (get_next_msg(ctx, &recv_fd)) { + while (1) { + if (!ctx->stack_depth) + ctx->pending_timer.cb(&ctx->pending_timer); + + if (!get_next_msg(ctx, &recv_fd)) + break; ubus_process_msg(ctx, &ctx->msgbuf, recv_fd); if (uloop_cancelling() || ctx->cancel_poll) break; } + if (!ctx->stack_depth) + ctx->pending_timer.cb(&ctx->pending_timer); + if (u->eof) ctx->connection_lost(ctx); } From patchwork Wed Feb 16 10:43:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1593621 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=M78FI1oM; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JzF6s11RWz9sDX for ; Wed, 16 Feb 2022 21:48:20 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zzpHIAJlLF+kH+HnAivSBHkPdXWl1u++X1o2LP7iD1g=; b=M78FI1oM8rVye3 nuYU4oFEoBn+B9FGTDuPaLnvUm1aS8B0po2eXp7dWfnXT8EP6euEzcyUSpLmefq4q+FaZ85ZXrXWt 8S36k3TbvAorzDzw2ayVktqNhzPdTwxZ5QgidFqCI7VdnJifQARcXckG2NqBPibEBgyY0L7Z2+YFX nDHMoEknIFrPCXZblxG0RWLA5nhniOIw+EJcrQl0/5m/wJt1gQjYu1Uh9r5lC58VrYMY3nYGrVYfN jLs+BrNtAmj9tI6II8qfuevQg+gCz6VdGU8cid3kKXp9V2DpcKcWaBKYMpTIBs/MoU3YIgo3JoA4b 4Bl9EPXV9yvoj/SJdHJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKHnu-006ba8-OE; Wed, 16 Feb 2022 10:44:58 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKHms-006bJn-7t for openwrt-devel@lists.openwrt.org; Wed, 16 Feb 2022 10:43:57 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 5B17B3D0B; Wed, 16 Feb 2022 11:43:49 +0100 (CET) Received: by meh.true.cz (OpenSMTPD) with ESMTP id 5b0f12e1; Wed, 16 Feb 2022 11:43:25 +0100 (CET) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Cc: Felix Fietkau Subject: [PATCH 19.07 ubus 3/3] libubus: increase stack depth for processing obj msgs Date: Wed, 16 Feb 2022 11:43:38 +0100 Message-Id: <20220216104338.15704-4-ynezz@true.cz> In-Reply-To: <20220216104338.15704-1-ynezz@true.cz> References: <20220216104338.15704-1-ynezz@true.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220216_024354_498275_35694BB8 X-CRM114-Status: UNSURE ( 6.76 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Felix Fietkau Avoid running into an issue where issuing a request from an obj message can lead to recursive message processing and list corruption Signed-off-by: Felix Fietkau (cherry picked from commit a72457b61df045d3c499a6211362b751710590d7) --- libubus.c | 2 ++ 1 file changed, 2 insertions(+) Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Felix Fietkau Avoid running into an issue where issuing a request from an obj message can lead to recursive message processing and list corruption Signed-off-by: Felix Fietkau (cherry picked from commit a72457b61df045d3c499a6211362b751710590d7) --- libubus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libubus.c b/libubus.c index 7ce454eabc64..aee2a3b722a7 100644 --- a/libubus.c +++ b/libubus.c @@ -103,7 +103,9 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd) break; } + ctx->stack_depth++; ubus_process_obj_msg(ctx, buf, fd); + ctx->stack_depth--; break; case UBUS_MSG_MONITOR: if (ctx->monitor_cb)