From patchwork Tue Aug 31 10:35:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: adrian.frances@netduma.com X-Patchwork-Id: 1522524 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: 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=eoa3JCVt; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=netduma-com.20150623.gappssmtp.com header.i=@netduma-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=wUYZSRn4; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4GzNvP5Pzwz9sR4 for ; Tue, 31 Aug 2021 20:38:25 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References: List-Owner; bh=Sp4LfAFTQnoryEBdZ3StvQYRbEylJMLNWCNgtCeARK8=; b=eoa3JCVtpVCGKq 2DVH+W/+8enHf0sNv7TZA/H+y/NtDd+gp3Q7YiB9U05CEClN8Lik2befeGf456hjXb/AOPX2Wojl2 LEvHHCGCA7CaohNmYfT5q1jjiEQ2dx5KIIMVyBrCbx5P5o/TFUHxkJ8AREkG/whMwq7CIx9nYXOj/ s1xfQvx9BaSVyxjeEYH7FJBF5yFeloJixmUplE9ZQqKhKcT8IV4bXCPZfFvInVuFxStpbjVLqgYfX Tzld612hbzz5qRacfwRWLn5vdI8Vf8g3wrXMhFOxx45AxPPAhYnzLgt2Fh7irGgWX+7m5sQKkujpw EbomilpqnfoXN32dqrbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mL17J-0023Fw-EQ; Tue, 31 Aug 2021 10:35:45 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mL17F-0023Fa-DJ for openwrt-devel@lists.openwrt.org; Tue, 31 Aug 2021 10:35:43 +0000 Received: by mail-wm1-x334.google.com with SMTP id c8-20020a7bc008000000b002e6e462e95fso1682057wmb.2 for ; Tue, 31 Aug 2021 03:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netduma-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gxbFaOid9sVWQYLp0ezgEPo2KGtQzm0Wz7VQUJ9XNIc=; b=wUYZSRn49FzkLp0f2Jk3tv8Yxtd+tDE2z1pKKyR6m8B8EakijVXK5H5H9AUgoyoa/9 I5znBl/0BRVkL0bWh6T1T0Pky9qvGVQ8CahTHNPbpOSYDSm1AcBodD8b5MZ0LoH4HGdy PMDgZgY00dGhexbajTP+PzV7N9Qj9Tr5NcVqW1P9WNO1MOL4gvvplXD+fYo7pUU8AT49 wpWLhfa0OqDRvv6iT9fAvvXdLx+je00OtUNT4Rs0WEDrjUirXKv/Cn4oPZAycQbbfKGk EC9+RFOPCW+YmXlxvt1//h9djB/WGYSw784f7dpBGF7qoWq9/5aipCNe7K6nEQO3Wlna kBdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gxbFaOid9sVWQYLp0ezgEPo2KGtQzm0Wz7VQUJ9XNIc=; b=qOXrdjZiJ32nJ7IYv4OiuYjiGj29UDrAAENpWFZg7CdTAI4qBdjN5PqflQ0IY4VYFD eglXF4v8fnrmvSpiulax8sxCPxHtcw57TlRSMp0PaAb1BY7ibX3Yn016+yUaYZeDvZIM WJ2mNIWc4YRUwSLsLeFf4TNew1fE/fDokD2b6Bbe3C5+8Uf0uuQN2gsqVIOhVyaskAsR 5L7pTthrw6nmRwFKIstkcPjUr+l8dDBA8ieohsxJ/fQ1OQYQcyLUJB4Mg3DsBfZarevg nO5FtBkOiC0gLQkCsBq60k8NdNOF8tL0LtXSdNSJuSsAxwXFwtLXCeSPgAe9BVH4QYjd S7iQ== X-Gm-Message-State: AOAM531n4iV6tHuv/aFlRgO4cfCr1A/y8rU+V3AfpOJiTAO2Xb48fI1t srKGFJaOvMbfPR4WgFBJ/MJSFo5B+71Ri4ul X-Google-Smtp-Source: ABdhPJyG1zkCkIPjjZJck6ABARgFyb5DEfSZLA90c6ob//BJWqc3xrBsClOOaG8l+/bhNC9Zhy2alw== X-Received: by 2002:a05:600c:3b26:: with SMTP id m38mr3533648wms.155.1630406137724; Tue, 31 Aug 2021 03:35:37 -0700 (PDT) Received: from lin-dev-002.ipa.internal.netduma.com ([77.95.36.54]) by smtp.gmail.com with ESMTPSA id u25sm2105345wmj.10.2021.08.31.03.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Aug 2021 03:35:37 -0700 (PDT) From: adrian.frances@netduma.com To: openwrt-devel@lists.openwrt.org Cc: Adrian Frances Subject: [PATCH v2] ubusd: fix disconnection when sending invalid fd Date: Tue, 31 Aug 2021 11:35:24 +0100 Message-Id: <20210831103524.6431-1-adrian.frances@netduma.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210831_033541_539069_4830796A X-CRM114-Status: GOOD ( 10.38 ) X-Spam-Score: 0.7 (/) 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: Adrian Frances According to man 7 unix, sendmsg returns EBADF when sending an invalid file descriptor as ancillary data. The patch avois ubus disconnecting the client when EBADF is received for the mentioned case. Content analysis details: (0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:334 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.7 SPF_NEUTRAL SPF: sender does not match SPF record (neutral) -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Adrian Frances According to man 7 unix, sendmsg returns EBADF when sending an invalid file descriptor as ancillary data. The patch avois ubus disconnecting the client when EBADF is received for the mentioned case. Signed-off-by: Adrian Frances --- ubusd_main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ubusd_main.c b/ubusd_main.c index d454b1a..35e51e7 100644 --- a/ubusd_main.c +++ b/ubusd_main.c @@ -12,6 +12,7 @@ #endif #include #include +#include #include @@ -67,6 +68,12 @@ static void client_cb(struct uloop_fd *sock, unsigned int events) case EINTR: case EAGAIN: break; + case EBADF: + if(fcntl(sock->fd, F_GETFD) != -1) { + cl->txq_ofs = 0; + ubus_msg_list_free(ubl); + continue; + } default: goto disconnect; }