From patchwork Sat Jun 24 12:34:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Christian Marangi (Ansuel)" X-Patchwork-Id: 1799399 X-Patchwork-Delegate: ansuelsmth@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: legolas.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=4wXDpDYo; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=OP0qJoBT; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QpDCr4QRRz20XS for ; Sat, 24 Jun 2023 22:37:58 +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=f0OK9jO01S2TOkdLaO9nMZjnrqX1d3P2iy2sKLwXTYg=; b=4wXDpDYoxRPhbS PJNglv55MiGR6m9N1gZp57gaKEoVNE6/mzxQa8iArjy62FUQ1MfJxzT0tmOZ05wfcVmAUAuA34WWe +RYCDcNZPPNkkzPUSibTTHp2ow1zKCN/dsn52smui827jcvC6WESXyGKBAc7nzXxa+YshW42hNrfe brXOv7TdGNx6YyyoVuVQkngLfyr79oiuPBozi8F8bVxOtqgdGgDHsePppZ2MCtY4SsVMEBQVooyh6 S8zmS1GMD+DzCjQmJ/E6K9P8XD+f/OGjyWEDSr77gBlSaM6ITsWeFp5ytHbRuUyErEpCxA09OAoii f3ONGvbjvFGnialeFGcA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qD2TJ-005yQd-2L; Sat, 24 Jun 2023 12:34:33 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qD2TF-005yQC-14 for openwrt-devel@lists.openwrt.org; Sat, 24 Jun 2023 12:34:30 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-3113dabc549so2166132f8f.1 for ; Sat, 24 Jun 2023 05:34:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687610066; x=1690202066; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8fpMcD/y20dZJmDd6rYNSn8hfynP5wXMEYr/mLsS4oM=; b=OP0qJoBTjbmItNfPwTn7ghDQE4bionZTlM6AwGK+T437ZurvjCitCPnoD5d2Fi+2Jm JUFX58uoO7c2v0akqcGcD2tDzJRRjTdVmWntUORv9kaK1Cy5+yJmApq3DiNiMZbIQt3O s+l6MAwFtVkAEppAE6fq2LA5cgzeDx1NIDkJywk7WP5YAAjswkfvLHjVfTLZDGePrB7E e3CIpQB0ebVOdYlBGHOQf4nEopVitzHu+b0r7dst6f9zttvnDNk+4c/vs3sB2QEs2OKB bIIV1YlSO09XCur0FCj2pUAh/Np9+H9i7rFSW+XZuqbmBLPYjIWGAPOKGEUUIjHA9wg9 zHEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687610066; x=1690202066; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8fpMcD/y20dZJmDd6rYNSn8hfynP5wXMEYr/mLsS4oM=; b=kEgM3wl/hlE+wUMGaLY+3vntxCFeXNzJi5YuZuXrOCL8/5NnGtvgGHdl56545ApcQ+ qMXSJSkeifbOTJk2ppnWFIcPDkgqQ678hWNDDTh44WxUl+6rPoarKTaTBJ9h0JvwJltR 19P0RvcK0t7ygpdkSNp3ibnla5w1q0MW8rD5oE5YcbW4a9JlIZTQtL1n5BqluwFBWf1T dIi98hWL+ut+YzPEfudFsAt0VB+Lf+2NpaSKNlshVssgJRJYWME8S0on5TcroE4RZARX g977w5OmvN9utj+QKxnLze74bvwA9wCMI4c9Tm1jY8F4ymVr470LLKdLY7seUMD+3QsA oWQg== X-Gm-Message-State: AC+VfDyaOYUJBmPWcKRoDTooF99tCJjT3nbMxK2tNRt17jMFE/giyLo+ y5NsqTNLT+udethoKZYQkWCHxbtXdR0= X-Google-Smtp-Source: ACHHUZ6m+vhj5cbfPXhyeGQJ8gu39/4gW5u+L/43eIZof3lqdDQQAh4VoNt0NRy9ne+qMtCALu8+Mw== X-Received: by 2002:a5d:54cd:0:b0:311:958:7d0b with SMTP id x13-20020a5d54cd000000b0031109587d0bmr25240012wrv.10.1687610065895; Sat, 24 Jun 2023 05:34:25 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id o7-20020adfeac7000000b003095bd71159sm2065993wrn.7.2023.06.24.05.34.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jun 2023 05:34:25 -0700 (PDT) From: Christian Marangi To: OpenWrt Development List , Felix Fietkau Cc: Christian Marangi Subject: [netifd PATCH] bridge: always insert new member if allocated on hotplug add Date: Sat, 24 Jun 2023 14:34:12 +0200 Message-Id: <20230624123412.856-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230624_053429_368379_48EA0082 X-CRM114-Status: GOOD ( 12.06 ) X-Spam-Score: -0.2 (/) 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: Fix Coverity Defect 1532481 reporting a Resource leak when !bm->node.avl.key is false in bridge_hotplug_add. While this situation is almost impossible, code can be refactored to mute the defect and make it clear that we insert only when a new member is allocated. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ansuelsmth[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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 -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:42e listed in] [list.dnswl.org] 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 Fix Coverity Defect 1532481 reporting a Resource leak when !bm->node.avl.key is false in bridge_hotplug_add. While this situation is almost impossible, code can be refactored to mute the defect and make it clear that we insert only when a new member is allocated. Fixes: edf3aced9f9a ("bridge: add support for adding vlan ranges via hotplug") Signed-off-by: Christian Marangi --- bridge.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bridge.c b/bridge.c index 471c651..202b69b 100644 --- a/bridge.c +++ b/bridge.c @@ -930,12 +930,15 @@ bridge_hotplug_add(struct device *dev, struct device *member, struct blob_attr * { struct bridge_state *bst = container_of(dev, struct bridge_state, dev); struct bridge_member *bm; + bool to_insert = false; bm = vlist_find(&bst->members, member->ifname, bm, node); - if (!bm) + if (!bm) { + to_insert = true; bm = bridge_alloc_member(bst, member->ifname, member, true); + } bridge_hotplug_set_member_vlans(bst, vlan, member->ifname, bm, true); - if (!bm->node.avl.key) + if (to_insert) bridge_insert_member(bm, member->ifname); return 0;