All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: netdev@vger.kernel.org
Cc: syzbot+3538a6a72efa8b059c38@syzkaller.appspotmail.com,
	Marc Dionne <marc.dionne@auristor.com>,
	Hillf Danton <hdanton@sina.com>,
	dhowells@redhat.com, linux-afs@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH net 4/9] rxrpc: Fix I/O thread startup getting skipped
Date: Thu, 15 Dec 2022 16:20:13 +0000	[thread overview]
Message-ID: <167112121304.152641.6427798169346167745.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <167112117887.152641.6194213035340041732.stgit@warthog.procyon.org.uk>

When starting a kthread, the __kthread_create_on_node() function, as called
from kthread_run(), waits for a completion to indicate that the task_struct
(or failure state) of the new kernel thread is available before continuing.

This does not wait, however, for the thread function to be invoked and,
indeed, will skip it if kthread_stop() gets called before it gets there.

If this happens, though, kthread_run() will have returned successfully,
indicating that the thread was started and returning the task_struct
pointer.  The actual error indication is returned by kthread_stop().

Note that this is ambiguous, as the caller cannot tell whether the -EINTR
error code came from kthread() or from the thread function.

This was encountered in the new rxrpc I/O thread, where if the system is
being pounded hard by, say, syzbot, the check of KTHREAD_SHOULD_STOP can be
delayed long enough for kthread_stop() to get called when rxrpc releases a
socket - and this causes an oops because the I/O thread function doesn't
get started and thus doesn't remove the rxrpc_local struct from the
local_endpoints list.

Fix this by using a completion to wait for the thread to actually enter
rxrpc_io_thread().  This makes sure the thread can't be prematurely
stopped and makes sure the relied-upon cleanup is done.

Fixes: a275da62e8c1 ("rxrpc: Create a per-local endpoint receive queue and I/O thread")
Reported-by: syzbot+3538a6a72efa8b059c38@syzkaller.appspotmail.com
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Hillf Danton <hdanton@sina.com>
Link: https://lore.kernel.org/r/000000000000229f1505ef2b6159@google.com/
---

 net/rxrpc/ar-internal.h  |    1 +
 net/rxrpc/io_thread.c    |    2 ++
 net/rxrpc/local_object.c |    2 ++
 3 files changed, 5 insertions(+)

diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
index e7dccab7b741..37f3aec784cc 100644
--- a/net/rxrpc/ar-internal.h
+++ b/net/rxrpc/ar-internal.h
@@ -287,6 +287,7 @@ struct rxrpc_local {
 	struct hlist_node	link;
 	struct socket		*socket;	/* my UDP socket */
 	struct task_struct	*io_thread;
+	struct completion	io_thread_ready; /* Indication that the I/O thread started */
 	struct rxrpc_sock __rcu	*service;	/* Service(s) listening on this endpoint */
 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
 	struct sk_buff_head	rx_queue;	/* Received packets */
diff --git a/net/rxrpc/io_thread.c b/net/rxrpc/io_thread.c
index d83ae3193032..e460e4151c16 100644
--- a/net/rxrpc/io_thread.c
+++ b/net/rxrpc/io_thread.c
@@ -426,6 +426,8 @@ int rxrpc_io_thread(void *data)
 	struct rxrpc_call *call;
 	struct sk_buff *skb;
 
+	complete(&local->io_thread_ready);
+
 	skb_queue_head_init(&rx_queue);
 
 	set_user_nice(current, MIN_NICE);
diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c
index 24ee585d9aaf..270b63d8f37a 100644
--- a/net/rxrpc/local_object.c
+++ b/net/rxrpc/local_object.c
@@ -97,6 +97,7 @@ static struct rxrpc_local *rxrpc_alloc_local(struct rxrpc_net *rxnet,
 		local->rxnet = rxnet;
 		INIT_HLIST_NODE(&local->link);
 		init_rwsem(&local->defrag_sem);
+		init_completion(&local->io_thread_ready);
 		skb_queue_head_init(&local->rx_queue);
 		INIT_LIST_HEAD(&local->call_attend_q);
 		local->client_bundles = RB_ROOT;
@@ -189,6 +190,7 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
 		goto error_sock;
 	}
 
+	wait_for_completion(&local->io_thread_ready);
 	local->io_thread = io_thread;
 	_leave(" = 0");
 	return 0;



  parent reply	other threads:[~2022-12-15 16:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20221218120951.1212-1-hdanton@sina.com>
     [not found] ` <20221216001958.1149-1-hdanton@sina.com>
2022-12-15 16:19   ` [PATCH net 0/9] rxrpc: Fixes for I/O thread conversion/SACK table expansion David Howells
2022-12-15 16:19     ` [PATCH net 1/9] rxrpc: Fix missing unlock in rxrpc_do_sendmsg() David Howells
2022-12-15 16:19     ` [PATCH net 2/9] rxrpc: Fix security setting propagation David Howells
2022-12-15 16:20     ` [PATCH net 3/9] rxrpc: Fix NULL deref in rxrpc_unuse_local() David Howells
2022-12-15 16:20     ` David Howells [this message]
2022-12-15 16:20     ` [PATCH net 5/9] rxrpc: Fix locking issues in rxrpc_put_peer_locked() David Howells
2022-12-15 16:20     ` [PATCH net 6/9] rxrpc: Fix switched parameters in peer tracing David Howells
2022-12-15 16:20     ` [PATCH net 7/9] rxrpc: Fix I/O thread stop David Howells
2022-12-15 16:20     ` [PATCH net 8/9] rxrpc: rxperf: Fix uninitialised variable David Howells
2022-12-15 16:20     ` [PATCH net 9/9] rxrpc: Fix the return value of rxrpc_new_incoming_call() David Howells
2022-12-15 19:48     ` [PATCH net 0/9] rxrpc: Fixes for I/O thread conversion/SACK table expansion Marc Dionne
2022-12-16  6:46     ` [PATCH net 7/9] rxrpc: Fix I/O thread stop David Howells
2022-12-18 19:59     ` David Howells
2022-12-19  0:20     ` David Howells
2022-12-19 10:20     ` [PATCH net 0/9] rxrpc: Fixes for I/O thread conversion/SACK table expansion patchwork-bot+netdevbpf

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=167112121304.152641.6427798169346167745.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=hdanton@sina.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=netdev@vger.kernel.org \
    --cc=syzbot+3538a6a72efa8b059c38@syzkaller.appspotmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.