From: Tung Nguyen <tung.quang.nguyen@est.tech>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, edumazet@google.com,
pabeni@redhat.com, jmaloy@redhat.com, horms@kernel.org,
tipc-discussion@lists.sourceforge.net,
Tung Nguyen <tung.quang.nguyen@est.tech>,
Jiakai Xu <xujiakai24@mails.ucas.ac.cn>
Subject: [PATCH net v2] tipc: reject attaching bearer of different media to the same occupied device
Date: Thu, 24 Sep 2026 23:19:32 +0700 [thread overview]
Message-ID: <20260924162016.1258485-1-tung.quang.nguyen@est.tech> (raw)
Currently, two bearers of different media types can be added to the
same device (e.g., "eth:eth0" and "ib:eth0"). This causes a leak
in device->dev_refcnt as follows:
tipc_enable_l2_media()
dev_get_by_name()
dev_hold()
As a result, device->dev_refcnt is incremented twice, but the second
bearer replaces the first one.
Fix this by rejecting a bearer with a different media type when the
device is already occupied.
Fixes: cb30a63384bc ("tipc: refactor function tipc_enable_bearer()")
Reported-by: Jiakai Xu <xujiakai24@mails.ucas.ac.cn>
Closes: http://lore.kernel.org/netdev/20260918013509.1853952-1-xujiakai24@mails.ucas.ac.cn/
Signed-off-by: Tung Nguyen <tung.quang.nguyen@est.tech>
---
v2: only disallow eth and ib to attach to the same device. This avoids
breaking udp-eth or udp-ib combination on the same device as found by sashiko.
v1: https://lore.kernel.org/netdev/20260923091057.375981-1-tung.quang.nguyen@est.tech/
net/tipc/bearer.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 05dcd2f9e887..2c0ceee4aa6b 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -258,6 +258,7 @@ static int tipc_enable_bearer(struct net *net, const char *name,
int bearer_id = 0;
int res = -EINVAL;
char *errstr = "";
+ char *if_name;
u32 i;
if (!bearer_name_validate(name, &b_names)) {
@@ -296,6 +297,21 @@ static int tipc_enable_bearer(struct net *net, const char *name,
goto rejected;
}
+ if (b->media->type_id == TIPC_MEDIA_TYPE_UDP ||
+ !strcmp(b_names.media_name, "udp"))
+ goto priority;
+
+ /* Not allow eth and ib to attach to the same device */
+ if_name = strchr((const char *)b->name, ':') + 1;
+ if (!strcmp(if_name, b_names.if_name) &&
+ strcmp(b->media->name, b_names.media_name)) {
+ errstr = "same device for different media";
+ NL_SET_ERR_MSG(extack,
+ "Same device for different media");
+ goto rejected;
+ }
+
+priority:
if (b->priority == prio &&
(++with_this_prio > 2)) {
pr_warn("Bearer <%s>: already 2 bearers with priority %u\n",
--
2.43.0
next reply other threads:[~2026-09-24 16:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 16:19 Tung Nguyen [this message]
2026-09-25 16:59 ` [PATCH net v2] tipc: reject attaching bearer of different media to the same occupied device netdev-bot+sashiko
2026-09-30 2:49 ` Tung Quang Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260924162016.1258485-1-tung.quang.nguyen@est.tech \
--to=tung.quang.nguyen@est.tech \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jmaloy@redhat.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tipc-discussion@lists.sourceforge.net \
--cc=xujiakai24@mails.ucas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox