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=1796181740; b=oeKe3kKi5YVYQPntGEx5OXgBW2m783/pfRycd/noxoPXhaJR2hUj7l17Bl0hx417ldET 9JJmWjw95nJ2vLOmDh3Pf/NSHAdDHKwE8AAqBNq+Pd0nxhLsghnToZY/0ur5O4T+JVaaH N+UxtS6RDo+JVqx5H05RHeHlx8ZASYiwOzSFxQzx3AXUJhzoEpA9eQYWfVXTy5kQS0hDK dQoLQx6xhjvB98NFtGm33ToKm5I8qtaqaJyt0osv6rBW3HXMbBgm2rDu7f9JPe2MQGwnu x3NV2h9B3ckMCE6Xx9sLgUGiNfL2DBRG1DMzZ33A6Kk7vWp4o/Vx0314OQZe1EUAHkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181740; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=hZtL17j8+EiV5s5pNQw/j58wcRKVYZQM0Cwim31elww=; b=eYAPziwXvu+cEXwkQT3gP1jGS7bMtfH/ECQ30bJ40M+k/Ar0EsWBLVRSa7zb0DYuqbpZ 5GnbkKHR+YM7Q6wKDNyWuNLa6phFkHeN1H+bcfPWxN3SMq4x6lRE/t/IMXM0QbI+/TM07 5Z0jI5aie8HWVE2fwkhr608+pBAxcBC0AnrLpRuMhILPlzUqEJB0hZN6mgpmF2G9IG6xC eKQR3PtSrsIIaVXlVC/CmrouBUlWCD8wewGc0bHAU9o++7Z0fMaHzZLSLtk084FUcc6Zs V+VlWiTuFqGGcY/ampDdV/MRJXj38f5Fxy58Pb6c/BZGgGqzY2A0WYu/XDKhQHj0OUw== 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=FQ54mEZA; 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 32C9A606A32D for ; Wed, 2 Dec 2026 03:22:19 +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=FQ54mEZA Received: by smtp.kernel.org (Postfix) with ESMTPSA id B69A91F000C1; Wed, 2 Dec 2026 03:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796181739; bh=hZtL17j8+EiV5s5pNQw/j58wcRKVYZQM0Cwim31elww=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=FQ54mEZAcq1jFsdvfCbQ3UZ+Ll1xKnaJ008PD1I6zvmldpmtLqhjz9AxrmLHdQvQP FplToMPRF9pMxlKVr/BhdX5RJ/hAyBCoEms2QwbDuDCiheirXe3EcAWSYWvXm23z0E C5DX9cm+nNbxMTKtII+Z11sWakBTF2LQ076FNrS997XM4u9zdOIsjLm2czJ/IhpyvG Svctjd4Me5r6xQUPUlTiEpKnCIzKeKn37d9jxigzA+hsUiSHy/B20vbz4GhNyNl7u+ u4/UXAc8JCqQC/yJLSO0O2TT0sg1BNGFofe6jYbhyJyIzq/Y1aadeooxM4J2JKz0dL 9qsIJsGAiJpNw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ALSA: hwdep: do not free a still-open hwdep on single-device teardown Reply-To: sashiko-reviews@lists.linux.dev To: "Hanxiang Xu" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202100703.1-1-xuhx@hust.edu.cn> References: <20261202100703.1-1-xuhx@hust.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 03:22:19 +0000 X-Mailing-List: linux-sound@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 3 potential issues to consider: - [High] ALSA: hwdep: permanent memory and device leak in snd_hwdep_free() on -EBUSY - [High] ALSA: hwdep: racy hwdep->used check in snd_hwdep_free() vs open and release - [High] ALSA: hwdep: UAF of hwdep->private_data on open fds after snd_device_free() -- commit 18518a58d07618a159e9b439a7a6de2178ecf5de Author: Hanxiang Xu ALSA: hwdep: do not free a still-open hwdep on single-device teardown This commit changes snd_hwdep_free() to return -EBUSY when hwdep->used is non-zero so that single-device teardown does not free a still-open struct snd_hwdep. > diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c > index fb9034897c561..0d22c305e242f 100644 > --- a/sound/core/hwdep.c > +++ b/sound/core/hwdep.c > @@ -337,14 +337,17 @@ static const struct file_operations snd_hwdep_f_ops= =3D { > .mmap =3D snd_hwdep_mmap, > }; > =20 > -static void snd_hwdep_free(struct snd_hwdep *hwdep) > +static int snd_hwdep_free(struct snd_hwdep *hwdep) > { > if (!hwdep) > - return; > + return 0; > + if (hwdep->used) > + return -EBUSY; > if (hwdep->private_free) > hwdep->private_free(hwdep); > put_device(hwdep->dev); > kfree(hwdep); > + return 0; > } [Severity: High] Does returning -EBUSY here permanently leak struct snd_hwdep, hwdep->dev, a= nd any resources released by hwdep->private_free()? In __snd_device_free(), dev is unconditionally unlinked from card->devices = and freed even when dev->ops->dev_free() fails. When the remaining file descriptors later close, snd_hwdep_release() only decrements hw->used and h= as no path to free the orphaned hwdep object, and later card teardown never revisits it either. [Severity: High] Can reading hwdep->used without synchronization race with snd_hwdep_release= () or snd_hwdep_open() and cause a use-after-free? In snd_hwdep_release(), hw->used is decremented to 0 before open_mutex is unlocked, open_wait is woken, and snd_card_file_remove() reads hw->card: CPU0 CPU1 snd_hwdep_release() mutex_lock(&hw->open_mutex) hw->used--; /* drops to 0 */ snd_device_free() ... snd_hwdep_free() if (hwdep->used) /* 0 */ kfree(hwdep) mutex_unlock(&hw->open_mutex) wake_up(&hw->open_wait) snd_card_file_remove(hw->card, ...) <-- use-after-free Similarly, an in-flight snd_hwdep_open() that has already looked up the min= or data still has hw->used =3D=3D 0 until after hw->ops.open() and snd_card_file_add() complete, so snd_hwdep_free() can free hwdep while open= is still using it. [Severity: High] Does leaving struct snd_hwdep alive while snd_device_free() returns to its caller still leave hwdep->private_data vulnerable to use-after-free on open descriptors? During single-device teardown, snd_emux_free() calls snd_emux_delete_hwdep() -> snd_device_free() and then immediately frees emu: sound/synth/emux/emux.c:snd_emux_free() { ... snd_emux_delete_hwdep(emu); snd_sf_free(emu->sflist); kfree(emu->voices); kfree_const(emu->name); kfree(emu); return 0; } Because file->f_op and hwdep->ops remain active when snd_hwdep_free() retur= ns -EBUSY, a subsequent ioctl on the open file descriptor invokes snd_emux_hwdep_ioctl() and dereferences the freed struct snd_emux through hw->private_data. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202100703.1-1-= xuhx@hust.edu.cn?part=3D1