From nobody Fri Oct 30 13:52:35 2026 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 4jGMwz70W6z6wvQp for ; Fri, 30 Oct 2026 13:52:35 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jGMwz4fygz4kMx for ; Fri, 30 Oct 2026 13:52:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793368355; 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=FcMX/gu5mR4Vl7JH69DGBiTVUnN6pwosFYmFA2fG3ls=; b=TD3PxgaVCxAK5pY+02XZtbZPwXQACiyxI8UltHOH8tXl9TGKlfb44KoTRRdIVi6rJq5Sbs SP3htgTZ6Qan979y4/ra2M1k0AR2P5GxZGy4w5fdFd+h7yLdGXv9CASVEGF6oasvt/oV0i QgMOveX2xmzWvB6k/0NELg0QaIU6NbiuMXQGfQZxICZY3eBRElvR9ADW+HefZXmuf77n2g h3kCFySvW/FYhKFrBjD9iUHPV8PIA+RgnDGiXKJa2LQT26sHojdY4R0JE7C+A2+a6Kqp+R x6MFmSUHLwnkno+T+sAetLwLMS4aHG1Vo81lK4Et2ihehzrUUaTSTzxpDb89Hw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793368355; b=QzZ1wTQBG+qvr1o+opQscG7n5L5PcT+zHVdZv3zklqPTDmO7bZgWy2U8AbteSlMCJGKvlq UmF8YJPNYcEHmmI6oTd2l2zhyd/bkg76+Cw9FdGKcLpE76VQKk8UsugDJAAgPJwPmTpw4R Pd/vs27ckO4zuB6+uL9HBRKJ3dBTwjMJ87XpP6qXZ/CuG8HYLexCZZATSumM0fppbD2gb4 uYnfaiT8rHqNcA7f1Blm9OQiBNp4IZUB279D+uC7wl5camaH8qcmxg8E3Z/lxxfU1kS0mH WaIMTv37ZW1Dm0zTiYWqx2lSj46RWQ95bftM7uiZt6tThqUITa8oa9GS5EXrZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793368355; 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=FcMX/gu5mR4Vl7JH69DGBiTVUnN6pwosFYmFA2fG3ls=; b=BtvD+aSgzzkeTgJ6h73dSjDPwjSzEYlwm7PCRv4m7BB5/Sr4X6bIpXQrI5rpMcmn/e5rNK oDFzWRC9M/ZMzLGGe8ku8I2h/IqvbH+NiY4OXMKZ1wdNy9ttkUUgKhbdygIK2PBqLTcCnj 2gwBm7COUTdPc6klwJjCoQ1LNJRsOI3DlES+JS6yNVtJdvBAJkh1Vuerdbg2Ys9bYUPJnL SQO6rZCGknBj3H3HXGkFxv9v+3I3GI7h3Z0Zx1lOIaVS1kj4o6Ly5yEqAo6VDsFz4vk0d2 dpLqEJpVGjpHyiyZknMe2sr/XT1XsUZsg+KGmfzUk+6JjQJeKBVEO1NISJV5Jw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jGMwz4L8bzT3h for ; Fri, 30 Oct 2026 13:52:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1f9cb by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Oct 2026 13:52:35 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 49e0c6270c73 - main - libthr: fix the race between pthread_getname_np() and thread exit List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 49e0c6270c73f1570efc67028004db9da56da2d1 Auto-Submitted: auto-generated Date: Fri, 30 Oct 2026 13:52:35 +0000 Message-Id: <6ae4a123.1f9cb.1cb5d45f@gitrepo.freebsd.org> The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=49e0c6270c73f1570efc67028004db9da56da2d1 commit 49e0c6270c73f1570efc67028004db9da56da2d1 Author: Konstantin Belousov AuthorDate: 2026-10-19 21:59:52 +0000 Commit: Konstantin Belousov CommitDate: 2026-10-30 13:51:02 +0000 libthr: fix the race between pthread_getname_np() and thread exit The exiting thread frees the thread name in exit_thread() without holding the thread lock. This makes it possible for a thread doing pthread_getname_np() to observe the non-null thread->name and try to copy its content, accessing the memory after free. Set the thread->name to NULL under the thread lock. Note that other thread might still set the exiting thread name, until the PS_DEAD state is assigned. Since code should not call free() after _malloc_thread_cleanup(), re-check thread->name in _thr_free(). Reviewed by: aokblast, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D60838 --- lib/libthr/thread/thr_exit.c | 2 ++ lib/libthr/thread/thr_list.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/libthr/thread/thr_exit.c b/lib/libthr/thread/thr_exit.c index 5a9dcf99fa21..4c9692ccf1a5 100644 --- a/lib/libthr/thread/thr_exit.c +++ b/lib/libthr/thread/thr_exit.c @@ -278,8 +278,10 @@ exit_thread(void) { struct pthread *curthread = _get_curthread(); + THR_LOCK(curthread); free(curthread->name); curthread->name = NULL; + THR_UNLOCK(curthread); /* Check if there is thread specific data: */ if (curthread->specific != NULL) { diff --git a/lib/libthr/thread/thr_list.c b/lib/libthr/thread/thr_list.c index cbf16179f619..62fb6e3a3b45 100644 --- a/lib/libthr/thread/thr_list.c +++ b/lib/libthr/thread/thr_list.c @@ -203,6 +203,10 @@ _thr_free(struct pthread *curthread, struct pthread *thread) _tcb_dtor(thread->tcb); } thread->tcb = NULL; + if (thread->name != NULL) { + free(thread->name); + thread->name = NULL; + } if ((curthread == NULL) || (free_thread_count >= MAX_CACHED_THREADS)) { thr_destroy(curthread, thread); atomic_add_int(&total_threads, -1);