From nobody Wed Jun 17 07:22:58 2026 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4574A390C95 for ; Mon, 27 Apr 2026 08:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777277951; cv=none; b=LsQgXQO+5hO7Xfcg/Q8yOUP6CMKWCXznVjRSWTFRl5sAURd+o1rqBVwo6BBXTBuWNNcaxWuU1TEXQF4FFZTCDkURu/LMDJthde/1tTY5/SiN4v6oX1LOnPBdcN0Dcm0iBS03JfspnoFxy4wmOoIer5Fk8cBDAHbF4gvWkvAbTUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777277951; c=relaxed/simple; bh=UbK58Vzg9w7sWB5SY0szpeu7+MJi5WYw4Hn1wlYoJG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F4pyj5goJCCmLMJeOpqwpp3KPiLKVbEb1Hkyhe5YZLJFD0E7DVPqelVkKjThvuFjaTD+MEUTmRYl4mqpZ5jOrvLZbXDaUZvSvyQq1GmpzUPuoPscr2I4Vvy2bSHpxcBowm5+Jit2q2EovC97uALMr8reXGscoC33agpd7sD85S0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=dAkO4Nvb; arc=none smtp.client-ip=209.85.221.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dAkO4Nvb" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-43fe608cb92so6716865f8f.2 for ; Mon, 27 Apr 2026 01:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777277949; x=1777882749; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gcNAF/r3YODfVeip91vVmIe5J4y4IySQb1pjlKeU7P0=; b=dAkO4NvbgDEZwv9QfwjUujcPkKm6zJd9g883uXar4SC17YtpLWYJ8OTL6oHObDji7j RFJeOIZ0W+nMKlHZcm6qcQZCCwmExMeO8I5ySEqQBgLqM//Kre0ZgjoB/EBRk9HKoMfB TqXGi/yia2XkkNWNNdmAXT8dT1q00FZh2YwtgFBpOiIRW7Wka0kD0+47UaQDS8EGHyJR uw3Itm/6Yuz4n40+byPTU9mZr4Swi0pGIItm7DSMRnJPL+IoFLAVoRMUm6zLBxjF8eUs NwogvFAs0gwv4IZGVw+txyfagkOfJob7iVzxnVs5HT2tgllB6g3R/dLb1eQzOYnsBIZI /IlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777277949; x=1777882749; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gcNAF/r3YODfVeip91vVmIe5J4y4IySQb1pjlKeU7P0=; b=co3p92jFgVvneHSsRbeuA9VHOAm9gJQfeeuaH6tWn9CHX7savLY1oDgxrTQ+89AeGg Wl6nTZfEQxHQWYHCuDfvL2PhkiPkcETo4vb9VEytEHUy5J9gG31sh21lh6TELMDVDhIn k0qH3cKZcR2Z/7uVBkqR05lIgdeF0GFpK8ycBOuJPWw9F6fVb932mqvEDds7jVMlfi8S 4zS73qB7vybr/Yod+bE2ftaRrLFA21kMq9Qw6PjP14eC9Ze3iTAFKfjBzrxNLj4Z+nyV WcJ3NR9g6NJfVotu6yEHDnxjXJV2aNarpXLaIyfhFlfqxehCc4jws6s4SnwtD1rfNQQM gaBw== X-Forwarded-Encrypted: i=1; AFNElJ8xOF54tsZIv3a46N38VdXUtrBn1JYEg2F8Uc4MxZaq0biVIXFjjQyQHb0AtP3Kfwpo7a8A+z4C4q+yFQg=@vger.kernel.org X-Gm-Message-State: AOJu0Yxz2NQJtOak5kqVUh5B2j/+dFIP+sFwuyCe8Z323DVPmQ8hirVg BccSo2Z5YOajzkFs2QbsVQP9b0OVnQqlxLeT0RCf4Dy702a39C8iqr/x X-Gm-Gg: AeBDieuwhOkKB4VV5f7s5kI1LkhDyiM0JV3hIrR5xgWZId0thSBr/Kc7tARhOteT7+E ddJDYDXKu2rAYSTaX013SDF50G1/lOJR6jjyNV6cpyOiQrA1l/kaPMUkrpWzO6eVWqZZ8bw4WSa 7FDNbs3UK361u/Ho5Q/rKbMnzBul6Rp39Z6M72nMGBK9CbAENeIxNxrSi2z4XeWgmbeK4i8U9Uu jzrKPsawkhYHeYf80TN4M7svhzqeieqm/q5JoN0Y0btxgoaLiKEnLkWIkH/JmAsbPeqNvGIGDlm bC4efPmP6o3ykaaHBrhOLhDf8dbl2LTMLU9Ahu/GzVbqP2vxAYlual35IuPTsZ6qqqXprkPStT4 D7JE6sFzd6OBApmV0vJ2Lm1hxxjdPNLyIabe2ag7ieFxeeQiuHv2bxBYYCkTaD02G+JiggjxU9P DEJxYjFsibCqd9hz5YY3P11/fjWU5zSoyCikuJ7NXOM27sIgPRyIboj+q8a/TudFbM5X7cfw4fo IVEEJDIYCOqOrisSVb9Gr4stVR/eK0Yh0VZWho1sZiolio4ZRCFwtk9/EtLET3PYdqSOFU= X-Received: by 2002:a05:6000:2dc2:b0:441:2473:c30a with SMTP id ffacd0b85a97d-4412473c325mr35101080f8f.31.1777277948556; Mon, 27 Apr 2026 01:19:08 -0700 (PDT) Received: from ahossu.localdomain ([82.78.232.184]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4cc375dsm69920019f8f.14.2026.04.27.01.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 01:19:08 -0700 (PDT) From: Alexandru Hossu To: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Cc: marvin24@gmx.de, error27@gmail.com, Alexandru Hossu Subject: [PATCH v4 1/2] staging: nvec: fix use-after-free in nvec_rx_completed() Date: Mon, 27 Apr 2026 10:17:12 +0200 Message-ID: <20260427081713.3401874-2-hossu.alexandru@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427081713.3401874-1-hossu.alexandru@gmail.com> References: <20260427081713.3401874-1-hossu.alexandru@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In nvec_rx_completed(), when an incomplete RX transfer is detected, nvec_msg_free() is called to return the message back to the pool by clearing its 'used' atomic flag. Immediately after this, the code accesses nvec->rx->data[0] to check the message type. Since nvec_msg_free() marks the pool slot as available via atomic_set(), any concurrent or subsequent call to nvec_msg_alloc() could claim that same slot and overwrite its data[] array. Reading nvec->rx->data[0] after freeing the message is therefore a use-after-free. Fix this by saving the message type byte before calling nvec_msg_free(), then using the saved value for the battery quirk check. Fixes: d6bdcf2e1019 ("staging: nvec: Add battery quirk to ignore incomplete= responses") Reviewed-by: Dan Carpenter Signed-off-by: Alexandru Hossu --- drivers/staging/nvec/nvec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c index 952c5a849a56..2a3499dd4d63 100644 --- a/drivers/staging/nvec/nvec.c +++ b/drivers/staging/nvec/nvec.c @@ -494,6 +494,8 @@ static void nvec_tx_completed(struct nvec_chip *nvec) static void nvec_rx_completed(struct nvec_chip *nvec) { if (nvec->rx->pos !=3D nvec_msg_size(nvec->rx)) { + unsigned char msg_type =3D nvec->rx->data[0]; + dev_err(nvec->dev, "RX incomplete: Expected %u bytes, got %u\n", (uint)nvec_msg_size(nvec->rx), (uint)nvec->rx->pos); @@ -502,7 +504,7 @@ static void nvec_rx_completed(struct nvec_chip *nvec) nvec->state =3D 0; =20 /* Battery quirk - Often incomplete, and likes to crash */ - if (nvec->rx->data[0] =3D=3D NVEC_BAT) + if (msg_type =3D=3D NVEC_BAT) complete(&nvec->ec_transfer); =20 return; --=20 2.53.0 From nobody Wed Jun 17 07:22:58 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3DE539936F for ; Mon, 27 Apr 2026 08:19:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777277959; cv=none; b=GabJS7fqunx+ByskRc63A789NHXF9h33gxe4DSCF4GlETVRtIVTQDTOaLoyTr2dTpXLQfMqCc+Matk4xzHXncoRzd0dIr28FnEZksq5reGmGW/zBq0PdIHVuDOOCtezqZX7a2zBSA8cdj/z8nNqm+SkUvpNCL3Tpr+ZFdzlIh9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777277959; c=relaxed/simple; bh=kA12S5ceLFq7aTYPKmMulJyt/Aty2VxK8Ge3SmlcZxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EFAceQsURNqiL4a/Zpg2HaW/LRoLL0JOtB3MdbwO1QIqedw6mw+RXda66iL63ptx4MUOxnBOLRwat6aSyqn86Qa0V99y9Ga/aXK0lJwxKgBlBfGI77gcI75OirFSNtpKgD7RBAH5LjFu7yvARh2hzrXa7/0Ni9mbq3soq+IHpNw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BOUhTCno; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BOUhTCno" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-43d43e09de5so5451159f8f.1 for ; Mon, 27 Apr 2026 01:19:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777277956; x=1777882756; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BKuYbRG/YW/8TeEIKBYjuEmOZ3fK4A9BxisB2qvbDhg=; b=BOUhTCnoyMFnVqNbKkAWZ1WRXsoj3tRc0SZy6VB0Au1xxza3V47hQCEQx/DWWuXxJI aUufsx/jcGIBbxxABkfaOQdb2NpfYPf2BWyble2Dz7IgEius5Xir0xLFU4+06FQFXvfK iyALkDTIVcvrz1KcCfVHdfxaiDZEhBgZZg9jCwLarhM5T952QWGq1NnJ4o6fjtHuxulw 7WojWKF4CIO/6HG5ALXOAJ5qbkQv2OeqOrt/n2a8l5zgUEHWSo1hA0O4xTS1/8vnhGob J8oN14rTN1tvcfmh1AGGfOOmIIbe5K02HTkqe70JUj7Eozu3CZnbG0YkKlzNQt6LqXau xAyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777277956; x=1777882756; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BKuYbRG/YW/8TeEIKBYjuEmOZ3fK4A9BxisB2qvbDhg=; b=hyzaHSn1yez2DKJ82R/ELY5EgJ42vABdRB6WohGQX2Mr4C6j3IJacVbx5pR7RK/Odo yfOdKaHToa3vSk5h7pv1OfkQgE44fKVQB0S8KBd8yI34UbHX4kUiwKFgbFvcpp+/U3Iz YsixPF5tanrcCOZyvolEk2daxsADJn3ONHZwHMFQBrpQoiZj+FKRR+jcIXsFMAEDfeKm l/gN5uHUc1l3naKXRzMprtUeqcn2RZ1A6tMiRcCYZSpgS48mwoac/asAPrPFxcEYCIRS ke943m4F8O4v8o4xbwqPNnySTgHSPQ/zm8he8OM5Zp8ystpk7Vu5nN/nZGrjMC0SMFbc rA0Q== X-Forwarded-Encrypted: i=1; AFNElJ8IzwWA7liWUirwuaoZouCXtMQvhJi7HarcWdsxXQZ5+gvNZdB97ln5itzaNNQIaWYfK07/pCz5QODIrc4=@vger.kernel.org X-Gm-Message-State: AOJu0YxH1uXCC24rwmj2dUd0G/PY9DVEj26GBUcq6ONywLwY4QTVzOVX Cp7hRZ8pzhlPYTgv0eOWIZuGtvL/3xmOyUlMuTs2cmgYCPw79hJfoME8 X-Gm-Gg: AeBDieshDBJ1IWvIDvYh99vyC4Riq4OZgv4FIbkWdIRfmEq3vaS5GKzlHSGHTJ6cS2U Yyxvtr8NqrAEJM7x2FDVn0l2cQao3HBN8qAdpp66Paa75bHF/lM3GRceW+52071sIA5txDNFBRF pknKiNga9FGFZpUgMhkimWIWwVOwdIiujuQAQ40BAnqZXTVdqyDu178TKnoBWr7+58qG0niIRWE Mcd2O6Nwe8PfrqEch8Gwd7ffPJOi4KUFEKqQMJnpitoyBMFhILK0C6EqtNsDL0iDaaktX3Si7dv EZLpwbN+8RWdxS9CloTiuAWVMprxg1nBp0RxphkUp9+hyBQiRCi7kApeZIZ1GERYq/iO5uO9KOo zNYskeXfaA3YQWkDBetpyBZ87b0YQk3H/UhgouzffzpCDhyhvqQPkYphz4MBRjVQhiLYcnuRofc NTSecbPkbTKkDx2jfAv/lSLODiPnjMIbnEOVqt784O58BnMIoEBCqZvxm8wzF3jDZKJmjM/pgpI nIKvvWUEPyfOgse2gexr3qz7SAas7d+f6dQ9iCo7whDv1sf6ffwfxZXh7s9ylUiHPlcwaw= X-Received: by 2002:a05:6000:2dc4:b0:441:37b5:c2f6 with SMTP id ffacd0b85a97d-44137b5c365mr14126935f8f.23.1777277956084; Mon, 27 Apr 2026 01:19:16 -0700 (PDT) Received: from ahossu.localdomain ([82.78.232.184]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4cc375dsm69920019f8f.14.2026.04.27.01.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Apr 2026 01:19:15 -0700 (PDT) From: Alexandru Hossu To: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, linux-tegra@vger.kernel.org Cc: marvin24@gmx.de, error27@gmail.com, Alexandru Hossu Subject: [PATCH v4 2/2] staging: nvec: fix unconditional pm_power_off teardown Date: Mon, 27 Apr 2026 10:17:13 +0200 Message-ID: <20260427081713.3401874-3-hossu.alexandru@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260427081713.3401874-1-hossu.alexandru@gmail.com> References: <20260427081713.3401874-1-hossu.alexandru@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" tegra_nvec_remove() unconditionally sets pm_power_off =3D NULL, even if nvec was not the one that registered it. This breaks any other driver that may have set pm_power_off to its own handler. Replace the unconditional assignment with a guarded check so that pm_power_off is only cleared if nvec was the one that set it. Also remove the stale FIXME comment, as the guard addresses exactly what it was asking for. Reviewed-by: Dan Carpenter Signed-off-by: Alexandru Hossu --- drivers/staging/nvec/nvec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c index 2a3499dd4d63..88c416ee0381 100644 --- a/drivers/staging/nvec/nvec.c +++ b/drivers/staging/nvec/nvec.c @@ -906,8 +906,8 @@ static void tegra_nvec_remove(struct platform_device *p= dev) nvec_unregister_notifier(nvec, &nvec->nvec_status_notifier); cancel_work_sync(&nvec->rx_work); cancel_work_sync(&nvec->tx_work); - /* FIXME: needs check whether nvec is responsible for power off */ - pm_power_off =3D NULL; + if (pm_power_off =3D=3D nvec_power_off) + pm_power_off =3D NULL; } =20 #ifdef CONFIG_PM_SLEEP --=20 2.53.0