From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796401404; b=ZEgFsfaHF1o6j57VuqvIOWjPsblABYcfldqfl8ir4bW+CQQqn5qtgZuNPov0SJ11NfwH 7xYSULXxgTtRnVNDlgllLsSmfdT5JnLWPC7b0yyMkFD0u7YxXAsp8KGQ4O1D3Wq+sRqkx ubQQnUNFSCzP9ArjealAPSXPMDj+5cGPukg1pcZ4/YYKjewK2ukmSE7ku+tTDSsn3zaw0 mjBQ2vGb5Au8AlJf8IJ0aj+QFReMcX7Kmro9EJRcOIBdFfM8Y1XsLo+1Vdr/BjG4CptTG jTFjwvzl9cTLrv3X8zibRhqDic2XotL7OPv4RN5YfFkCMtQ/zS5fwLpgDHmu9+24L1A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796401404; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=clXYic2kO+NOE0xJGyDP6VUSFlidr8MSxm4QgELu9P4=; b=kUz8QIbrhrmsIMPXtbpcnSuw+gpdtEGj6cSYMgvZ3byCK2AVnFqr6UvAwPfepoRVJz+X I49YLRcIGOdSosp4oWquzEN8slZ4WKslT56200tGH3lcXXyq0l3y98FI3R6CKhIn7ZXxH fu/llOhJsuQ+ZsxzZD7QVi/4Y35pT+nhdtCz6WWfqMrfIMqG2uaVo7F9J9dvvmA2OpYmB qFEST1rbysu4uhaOIWAnuK+08WfGkIX9I1fK1K806gopnaxdBP1BjqwEdBbq76uuy+rtq A+nMqXNf3R7DaRlj+StuolJV7IPrjvqhStxoccJ63JqYkWl7Q6HEseM93y780ozc+Hg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lzHuA4hO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3F6E606A32F; Fri, 4 Dec 2026 16:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=lzHuA4hO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 029D11F00897; Fri, 4 Dec 2026 16:23:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796401404; bh=clXYic2kO+NOE0xJGyDP6VUSFlidr8MSxm4QgELu9P4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=lzHuA4hOeSAkjBGAwrmvLP0sDUwmkrKS19JM1IlyL7YmASwxt9bDiwV8aY6o2EolP lZVcCntZMr9vq4kjRPwTBZIHTltu+e5ewAScSpDz2cowu2oSivpN4ufDMXO6ltfCFi KNYAe3yYjA9Bc+cdgnncJQVCnZL9bLgExCaopUmpKclATUR8m1rimG3x6cN+7cEJ2+ BUXIglczaRpCfX8IK1DE557WdwVpx3Ve1rFOGh+qIl0m8VP1J+WXPLIY1WH1rA+d1C zyFIyWyxTL/E3DcdU2GxvkBsQF4cDNMoTvXbdwrgI7QMHw1o0xGWpgTGSkQ2J+VolU GSS0CSLwncwuw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] vhost_task: avoid hanging in vhost_task_stop() when worker is frozen Reply-To: sashiko-reviews@lists.linux.dev To: "Prabhakar Reddy K" Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev, "Michael S. Tsirkin" , "Eugenio Perez" In-Reply-To: <20261203162142.787153-1-K.Prabhakarr84@gmail.com> References: <20261203162142.787153-1-K.Prabhakarr84@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 16:23:23 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Critical] vhost_task: use-after-free of exit_mutex in vhost_task_stop() -- commit a9ac04900e51413d1a9f43439c5bba0416f4c933 Author: Prabhakar Reddy K vhost_task: avoid hanging in vhost_task_stop() when worker is frozen This commit adds a VHOST_TASK_FLAGS_IN_SIGNAL flag under exit_mutex so vhost_task_stop() can return without waiting on vtsk->exited when the worker is inside get_signal(), transferring cleanup of vtsk to the worker. > diff --git a/kernel/vhost_task.c b/kernel/vhost_task.c > index 3717885a5992a..4fd38e0924842 100644 > --- a/kernel/vhost_task.c > +++ b/kernel/vhost_task.c [ ... ] > @@ -33,8 +34,29 @@ static int vhost_task_fn(void *data) > =20 > if (signal_pending(current)) { > struct ksignal ksig; > + bool dead; > =20 > - if (get_signal(&ksig)) > + mutex_lock(&vtsk->exit_mutex); > + if (test_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags)) { > + mutex_unlock(&vtsk->exit_mutex); > + break; > + } > + set_bit(VHOST_TASK_FLAGS_IN_SIGNAL, &vtsk->flags); > + mutex_unlock(&vtsk->exit_mutex); > + > + dead =3D get_signal(&ksig); > + > + mutex_lock(&vtsk->exit_mutex); > + if (test_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags)) { > + mutex_unlock(&vtsk->exit_mutex); > + put_task_struct(vtsk->task); > + kfree(vtsk); > + do_exit(0); > + } > + clear_bit(VHOST_TASK_FLAGS_IN_SIGNAL, &vtsk->flags); > + mutex_unlock(&vtsk->exit_mutex); > + > + if (dead) > break; > } > =20 > @@ -88,13 +110,19 @@ EXPORT_SYMBOL_GPL(vhost_task_wake); > */ > void vhost_task_stop(struct vhost_task *vtsk) > { > + bool in_signal =3D false; > + > mutex_lock(&vtsk->exit_mutex); > if (!test_bit(VHOST_TASK_FLAGS_KILLED, &vtsk->flags)) { > set_bit(VHOST_TASK_FLAGS_STOP, &vtsk->flags); > + in_signal =3D test_bit(VHOST_TASK_FLAGS_IN_SIGNAL, &vtsk->flags); > vhost_task_wake(vtsk); > } > mutex_unlock(&vtsk->exit_mutex); > =20 > + if (in_signal) > + return; [Severity: Critical] Can this cause a use-after-free of vtsk->exit_mutex in vhost_task_stop()? Unlike spinlocks, a mutex must stay alive until mutex_unlock() returns, so mutex_unlock() cannot hand off kfree(vtsk) ownership to another task. When vhost_task_fn() returns from get_signal() (for example on SIGKILL or SIGCONT) and contends on vtsk->exit_mutex while vhost_task_stop() holds it, __mutex_unlock_slowpath() clears lock->owner before acquiring lock->wait_lock: CPU0 (vhost_task_stop) CPU1 (vhost_task_fn) mutex_lock(&vtsk->exit_mutex) set VHOST_TASK_FLAGS_STOP in_signal =3D true vhost_task_wake(vtsk) get_signal() returns mutex_lock(&vtsk->exit_mutex) sets MUTEX_FLAG_WAITERS mutex_unlock(&vtsk->exit_mutex) __mutex_unlock_slowpath() clears lock->owner __mutex_trylock() succeeds mutex_unlock(&vtsk->exit_mutex) kfree(vtsk) raw_spin_lock(&lock->wait_lock) <-- use-after-free The worker can acquire and unlock exit_mutex and free vtsk before __mutex_unlock_slowpath() finishes, leaving vhost_task_stop() to access lock->wait_lock and lock->first_waiter in freed slab memory and risk slab corruption or a kernel crash. Keeping vtsk alive until both mutex_unlock() calls return (for example with= a refcount_t dropped after unlocking), or using a spinlock_t for the handoff instead of a mutex, would avoid this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203162142.7871= 53-1-K.Prabhakarr84@gmail.com?part=3D1