mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: davem@davemloft.net, kuba@kernel.org, edumazet@kernel.org,
	 jmaloy@redhat.com, pabeni@redhat.com
Cc: horms@kernel.org, tipc-discussion@lists.sourceforge.net,
	 tung.quang.nguyen@est.tech, linux-kernel@vger.kernel.org,
	 netdev@vger.kernel.org
Subject: [PATCH net] tipc: restore write readiness when a socket's group goes away
Date: Thu, 19 Nov 2026 21:39:02 +0000	[thread overview]
Message-ID: <20261119-tipc-group-open-v1-1-cb725145da51@gmail.com> (raw)

From: Suyuan Wang <stevewong@hust.edu.cn>

tipc_group_create() sets tsk->group_is_open to false, and tipc_poll()
only reports EPOLLOUT for a socket in TIPC_OPEN state when that flag is
true. Commit 1b22bcad7e39 ("tipc: correct initial value for group
congestion flag") made sure the flag is true for sockets that never
join a group, since otherwise "SOCK_RDM/DGRAM sockets sending datagrams
never receive POLLOUT".

The flag is not set back when the group goes away again, though:

- tipc_group_create() clears the flag and then fails when the topology
  subscription cannot be created, for example when TIPC_MAX_SUBSCR
  subscriptions exist already;
- tipc_sk_join() deletes the new group when tipc_sk_publish() fails,
  for example when the node's publication limit is reached;
- tipc_sk_leave() deletes the group while the flag may still be false,
  e.g. because of group congestion, or because the group has no other
  members yet.

In all three cases the socket is back to an ordinary RDM/DGRAM socket,
but poll() never reports EPOLLOUT for it again. Before commit
60c253069632 ("tipc: fix race between poll() and setsockopt()"),
tipc_poll() also reported EPOLLOUT when tsk->group was NULL, so
deleting the group was enough; since then the flag has to be reset.

Set tsk->group_is_open to true in these three places, as it is for a
socket that never had a group, and call sk_write_space() so that a
task already waiting for EPOLLOUT is woken up, as tipc_sk_filter_rcv()
does when a group becomes open again.

Found with a static analysis tool and checked by hand.

Fixes: 60c253069632 ("tipc: fix race between poll() and setsockopt()")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Tested in QEMU (x86_64, KASAN), on next-20261109 (net/tipc/ is the same
as in net):
- empty group, no loopback: JOIN, a thread waits in epoll_wait() for
  EPOLLOUT, then TIPC_GROUP_LEAVE. Before: no EPOLLOUT, the waiter times
  out. After: the waiter is woken and poll() reports POLLOUT.
- 65535 topology subscriptions open, then TIPC_GROUP_JOIN fails with
  -ENOMEM: no POLLOUT before, POLLOUT after.
- bind until the publication limit, then TIPC_GROUP_JOIN fails with
  -EINVAL: no POLLOUT before, POLLOUT after.
---
 net/tipc/socket.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 65cc0c4964b3..26771a98dc7a 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -3096,8 +3096,12 @@ static int tipc_sk_join(struct tipc_sock *tsk, struct tipc_group_req *mreq)
 	if (grp)
 		return -EACCES;
 	grp = tipc_group_create(net, tsk->portid, mreq, &tsk->group_is_open);
-	if (!grp)
+	if (!grp) {
+		/* tipc_group_create() may have cleared it before failing */
+		tsk->group_is_open = true;
+		tsk->sk.sk_write_space(&tsk->sk);
 		return -ENOMEM;
+	}
 	tsk->group = grp;
 	msg_set_lookup_scope(hdr, mreq->scope);
 	msg_set_nametype(hdr, mreq->type);
@@ -3109,6 +3113,8 @@ static int tipc_sk_join(struct tipc_sock *tsk, struct tipc_group_req *mreq)
 	if (rc) {
 		tipc_group_delete(net, grp);
 		tsk->group = NULL;
+		tsk->group_is_open = true;
+		tsk->sk.sk_write_space(&tsk->sk);
 		return rc;
 	}
 	/* Eliminate any risk that a broadcast overtakes sent JOINs */
@@ -3132,7 +3138,9 @@ static int tipc_sk_leave(struct tipc_sock *tsk)
 	ua.scope = scope;
 	tipc_group_delete(net, grp);
 	tsk->group = NULL;
+	tsk->group_is_open = true;
 	tipc_sk_withdraw(tsk, &ua);
+	tsk->sk.sk_write_space(&tsk->sk);
 	return 0;
 }
 





                 reply	other threads:[~2026-11-19 21:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261119-tipc-group-open-v1-1-cb725145da51@gmail.com \
    --to=devnull+shyckless.gmail.com@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jmaloy@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shyckless@gmail.com \
    --cc=tipc-discussion@lists.sourceforge.net \
    --cc=tung.quang.nguyen@est.tech \
    /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

all inboxes | Powered by JetHome®