From nobody Thu Apr 25 13:46:44 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VQHFw3D8Bz5Hlm3; Thu, 25 Apr 2024 13:46:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VQHFw2bnTz42mF; Thu, 25 Apr 2024 13:46:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714052804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lOUl1pcMmpXk3NC/P9b+4PNp4eR9dqZd99QG9TjIQZc=; b=jOiWyVW7PzUQn0kJFMllUqAu4tZ54DJ62Dow0e5noYmOjZ518v0i+YaVWILt+rF2Kg3pFs p4A1ufyg0Gse1OOcGhiO8JwB4BFVaLZe24ZQax0zoL/TUfR+4pqEJNJ2EIBiyCTsJO6ka0 xDxZbbDUTf/OBtguYrx+0MfCplTR6Ybxfo96BEKv2OVY/fP+zBAEpjfX/ysWjUHRe8ejpw JU84y9m9VEIxh7EKGk7CYR7BaK6dTR7DypQneWjDb+VeNmWyFdOAEQHc1BLdRg7DeeQ1an VzK5OlPzPF4V/XK7ASiQxkDJx5xKWSjgiSjIgGLUrtNedd5X4o98bLyUjwONvw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1714052804; a=rsa-sha256; cv=none; b=kcIIIK29/uRMC9SK+oibgQs5bZji2iJYdwXET1xL58psxmCL3v+erspIwBGyGJzIOEloWu e4fLc3jbjMyFahqsDSFJ274Jfaz3FZUO8M8eQIInWi77hL5OJHO6Fg5JBKtNFpdofecaeE Qhxa8/CDGlf+nS8orBJX6vn6CPN/gIJIXua3X9/lkNPVA92C8SLTeTjsDiNF7+wOjcDZ36 Q/M5o5+sSTa56Ss1NaAbb2NBV/FElJaS01N1zBKthsldC+rCU5AjCu361Lj1b3kPDwpv9p zE+qgJAlYPQSxe7aRahZGOLtQLA3b660eKOtMeoslqTmwgRzkz7Cp3XgDPbDBw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1714052804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=lOUl1pcMmpXk3NC/P9b+4PNp4eR9dqZd99QG9TjIQZc=; b=RUwz/P01ATS1JFMa8bLUfGNg4qin3N0w+znWpFgY59w/hJAQqNRcF4/7WBQlFPzAkHEomS plcGMZ19EeOTlmqnzp/ed21WYuz7dOPw99W9g1fbqsOTXzLv2Ds1jfrPVBeZPwmti7FE3L QDKLbY8BYaP7Vc+AxBYQkYeNn9kiUVDTre2nVc2imrhhWPSkC9u628xseNg6c0VhGTMJO2 ogdrkuDDjId72CCAL1BnCbSIvPWMQtjWz9TmtXPKdseLFAfMa/V5EdP+/gzPmQhY6LW4ZJ VfW8Iswev+axLYixpQXaEwcuABzZfrwlTWg8bLKwAseoWdmEr7jcQ7xA9AIGdw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VQHFw2Bq2z12C4; Thu, 25 Apr 2024 13:46:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43PDkimW043218; Thu, 25 Apr 2024 13:46:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43PDkihh043215; Thu, 25 Apr 2024 13:46:44 GMT (envelope-from git) Date: Thu, 25 Apr 2024 13:46:44 GMT Message-Id: <202404251346.43PDkihh043215@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: d66399326cb4 - main - kthread: Set *tdptr earlier in kproc_kthread_add() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d66399326cb4f89d1565fb62c1c07974886893c5 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d66399326cb4f89d1565fb62c1c07974886893c5 commit d66399326cb4f89d1565fb62c1c07974886893c5 Author: Mark Johnston AuthorDate: 2024-04-25 13:35:38 +0000 Commit: Mark Johnston CommitDate: 2024-04-25 13:35:38 +0000 kthread: Set *tdptr earlier in kproc_kthread_add() See commit ae77041e0714 ("kthread: Set *newtdp earlier in kthread_add1()") for details. That commit was incomplete since g_init()'s first call to kproc_kthread_add() will cause kproc_kthread_add() to take the `*procptr == NULL` branch, which avoids kthread_create(). To ensure that the thread pointer is initialized before the thread starts running, we have to start the kernel process with RFSTOPPED. We could perhaps go further and use RFSTOPPED only when tdptr != NULL, but it's probably better to have consistent behaviour. Reviewed by: olce, kib Reported by: syzbot+e91e798f3c088215ace6@syzkaller.appspotmail.com MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D44927 --- sys/kern/kern_kthread.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index 8a84fd70918d..97d10fdb394a 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -495,13 +495,21 @@ kproc_kthread_add(void (*func)(void *), void *arg, struct thread *td; if (*procptr == NULL) { + /* + * Use RFSTOPPED to ensure that *tdptr is initialized before the + * thread starts running. + */ error = kproc_create(func, arg, - procptr, flags, pages, "%s", procname); + procptr, flags | RFSTOPPED, pages, "%s", procname); if (error) return (error); td = FIRST_THREAD_IN_PROC(*procptr); if (tdptr) *tdptr = td; + if ((flags & RFSTOPPED) == 0) { + thread_lock(td); + sched_add(td, SRQ_BORING); + } va_start(ap, fmt); vsnprintf(td->td_name, sizeof(td->td_name), fmt, ap); va_end(ap);