[{"id":3676534,"web_url":"http://patchwork.ozlabs.org/comment/3676534/","msgid":"<adykjx57doahzkWH@stanley.mountain>","list_archive_url":null,"date":"2026-04-13T08:08:47","subject":"Re: [PATCH 3/5] staging: nvec: fix use-after-free in\n nvec_rx_completed()","submitter":{"id":389,"url":"http://patchwork.ozlabs.org/api/people/389/","name":"Dan Carpenter","email":"error27@gmail.com"},"content":"On Sun, Apr 12, 2026 at 10:51:16PM +0200, Alexandru Hossu wrote:\n> In nvec_rx_completed(), when an incomplete RX transfer is detected,\n> nvec_msg_free() is called to return the message back to the pool by\n> clearing its 'used' atomic flag. Immediately after this, the code\n> accesses nvec->rx->data[0] to check the message type.\n> \n> Since nvec_msg_free() marks the pool slot as available via atomic_set(),\n> any concurrent or subsequent call to nvec_msg_alloc() could claim that\n> same slot and overwrite its data[] array. Reading nvec->rx->data[0] after\n> freeing the message is therefore a use-after-free.\n> \n> Fix this by saving the message type byte before calling nvec_msg_free(),\n> then using the saved value for the battery quirk check.\n> \n> Signed-off-by: Alexandru Hossu <hossu.alexandru@gmail.com>\n\nAdd a Fixes tag.\n\n> ---\n>  drivers/staging/nvec/nvec.c | 5 ++++-\n>  1 file changed, 4 insertions(+), 1 deletion(-)\n> \n> diff --git a/drivers/staging/nvec/nvec.c b/drivers/staging/nvec/nvec.c\n> index 952c5a849a56..75877038847f 100644\n> --- a/drivers/staging/nvec/nvec.c\n> +++ b/drivers/staging/nvec/nvec.c\n> @@ -498,11 +498,14 @@ static void nvec_rx_completed(struct nvec_chip *nvec)\n>  \t\t\t(uint)nvec_msg_size(nvec->rx),\n>  \t\t\t(uint)nvec->rx->pos);\n>  \n> +\t\t/* Save before freeing to avoid use-after-free */\n\nDelete this comment.  (Obvious).\n\n> +\t\tunsigned char msg_type = nvec->rx->data[0];\n\nMove this declaration to the start of the block.\n\nOtherwise, it looks good.\n\nregards,\ndan carpenter\n\n> +\n>  \t\tnvec_msg_free(nvec, nvec->rx);\n>  \t\tnvec->state = 0;\n>  \n>  \t\t/* Battery quirk - Often incomplete, and likes to crash */\n> -\t\tif (nvec->rx->data[0] == NVEC_BAT)\n> +\t\tif (msg_type == NVEC_BAT)\n>  \t\t\tcomplete(&nvec->ec_transfer);\n>  \n>  \t\treturn;","headers":{"Return-Path":"\n <linux-tegra+bounces-13737-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-tegra@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=ebu2IRcz;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c04:e001:36c::12fc:5321; helo=tor.lore.kernel.org;\n envelope-from=linux-tegra+bounces-13737-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"ebu2IRcz\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.128.48","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from tor.lore.kernel.org (tor.lore.kernel.org\n [IPv6:2600:3c04:e001:36c::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvKp35449z1xtJ\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 18:10:03 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 78E1F30173B0\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 08:08:56 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 9EDA839A046;\n\tMon, 13 Apr 2026 08:08:55 +0000 (UTC)","from mail-wm1-f48.google.com (mail-wm1-f48.google.com\n [209.85.128.48])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FF9A36308B\n\tfor <linux-tegra@vger.kernel.org>; Mon, 13 Apr 2026 08:08:54 +0000 (UTC)","by mail-wm1-f48.google.com with SMTP id\n 5b1f17b1804b1-488ab2db91aso64635765e9.3\n        for <linux-tegra@vger.kernel.org>;\n Mon, 13 Apr 2026 01:08:54 -0700 (PDT)","from localhost ([196.207.164.177])\n        by smtp.gmail.com with ESMTPSA id\n 5b1f17b1804b1-488d68712casm91433755e9.30.2026.04.13.01.08.49\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Mon, 13 Apr 2026 01:08:50 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776067735; cv=none;\n b=mUDpF5Wu1uouXQVuBZl1jPXVMgRnPXwZfME72G67YLjGi0RO5q0MPr7qpLfdK3I6qs0x8khZXPemjZ8V9fQtKll+Q6ncSX3p/08lohQ6N4S755c/z308c0t0b9LRxcqgvVpFaPkq1UshfrP3LgPhPhIZjEelxgUfq4Ix5uY4FHw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776067735; c=relaxed/simple;\n\tbh=07XUjGti6c23bhhuDREuvLhUWrCtiIEv05+fAHNkL7g=;\n\th=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:\n\t Content-Type:Content-Disposition:In-Reply-To;\n b=MXvo+kwwZHP2A8tvdaDlgRMSpTUUY5/hLyeCg4GTfT6MZJY2RunCVr/Z7D7eNm8rw8CbQ/NR3zB7aGdZ+SAUTWnuesnj/aGYp4IM1q5sO3PYtorV0IMfJBsmMFzPNg2QfPkBeKzDoSGeBUGT5H+Zb7q+cduhIXHwuVcA3SI0ISY=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=ebu2IRcz; arc=none smtp.client-ip=209.85.128.48","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1776067733; x=1776672533;\n darn=vger.kernel.org;\n        h=in-reply-to:content-disposition:mime-version:references:message-id\n         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;\n        bh=bqvPWwnQajWp/ZMSh8mExyk1McDwKxudtQ4kJAZDswY=;\n        b=ebu2IRcze+SbOFrNtx8fz/7PV4WyK8UCVUDHJ+n5u0BsucIci8s3LTyo8WRmKH2lwH\n         nIdn5jgaNuNTkvELpjjQ6u4MJEohE6mhKMd3kQW7/4Yt1owyHIbHHaEoJ2nz9nn4jOtp\n         r4hwv49BFS0PB5hNjHhY9tqEwSu3FJ7f5xD+KZgs4HV7NVch0fvENGFvHmRbPN5SCSiF\n         UJHo9LgMBfAIAVfKF2O2bK/0ZI/ewHoIQeNv5CURdHwdvvKSDTZw0/x7NY3DLwx/pLbw\n         VPeDfiqPqpnrbP/hI+I4x73lLpb342SCuEJEXTpGDXeuZY/GchosKRA8k4htW1e/pfP4\n         nbjA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776067733; x=1776672533;\n        h=in-reply-to:content-disposition:mime-version:references:message-id\n         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc\n         :subject:date:message-id:reply-to;\n        bh=bqvPWwnQajWp/ZMSh8mExyk1McDwKxudtQ4kJAZDswY=;\n        b=HFYqewU7mfD6fGOjOXMdeTtH5ihmHNTKqR/UfaRowpNF8jG5IpD3jRJW+3/wwFZ4v5\n         X8JYl3o6jvdounnvGyB9i/IiEhJDyZ6CDmg8YOB63YWbvpHFC45q66LfA/sSugMjutnn\n         WkMmX/oXUSKPmcrtaAAAr2DuBtn3OuE/0HdeTN7yVBGmuNV0QExYB7vnohWN+xatY3SC\n         OvuecCOzHaC4zZwBEMTX1za/H39QPgngYhuvmAeASAyUrlKwrjUpEoojJsSkmVp8caiL\n         zK92LaHRighKr6/Hnkhvq+6qivDYEIxZJ9H61tdhToGgOjyVGYDQE94/wqP5QrfRq7O+\n         f8iQ==","X-Gm-Message-State":"AOJu0YwjwGTarMRviw5ZJWeyo/rrRaJJjxJyBqQMrTzhL/7zAURbOYFd\n\tToxBmigXzhT0OkXWE7cKaVqHTENWZK1UE/EupCOFdtlsQgXsNelPQLeu","X-Gm-Gg":"AeBDievNCUtSAYrpNpbMoJiP2sPoVvU5jm8bGLkjzl8fihKWEsAMzjPSXsORBxADfCH\n\tS0eZN5SlfSjhaiQyUAJ8ILcMhhPJ5F9qjb9DWhh7NstxkrpfXWtBxJnj0TvfVYJ/0dY797ZEqZo\n\tbOC19rBvRXwC0OkcqZWRfvshxp/Wdov9reMYrqzRH5io4shrYqVXIsIiZBPJBcFv1qGK20P6mom\n\tMxdsZZra1t63YU1NaMZoMmw9jICn44qKaUWbKgkeYGxYzWMYVqM1eodWxsGQdYjuoWHpZRkp47I\n\tYeQKpabhHMFRFc7iFsrniP0S2HjtOpACqVs35PODqgZmJquIhB6o1yCkDQDpwgAwlHPCWbhCYeW\n\tnhJCkf3HFxeUNAuSsALvkcmOOYuog93KDR9/TtTzfK6jvE1/GOEVavyLcsd+VgA5M47MnguYmCk\n\tdSMzHTu/Tl/YgHdSFPrvI=","X-Received":"by 2002:a05:600c:3150:b0:486:fcc7:d6a with SMTP id\n 5b1f17b1804b1-488d67f4c4dmr185375045e9.13.1776067732487;\n        Mon, 13 Apr 2026 01:08:52 -0700 (PDT)","Date":"Mon, 13 Apr 2026 11:08:47 +0300","From":"Dan Carpenter <error27@gmail.com>","To":"Alexandru Hossu <hossu.alexandru@gmail.com>","Cc":"linux-tegra@vger.kernel.org, marvin24@gmx.de,\n\tgregkh@linuxfoundation.org, linux-staging@lists.linux.dev,\n\tlinux-kernel@vger.kernel.org","Subject":"Re: [PATCH 3/5] staging: nvec: fix use-after-free in\n nvec_rx_completed()","Message-ID":"<adykjx57doahzkWH@stanley.mountain>","References":"<20260412205117.387125-1-hossu.alexandru@gmail.com>","Precedence":"bulk","X-Mailing-List":"linux-tegra@vger.kernel.org","List-Id":"<linux-tegra.vger.kernel.org>","List-Subscribe":"<mailto:linux-tegra+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-tegra+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20260412205117.387125-1-hossu.alexandru@gmail.com>"}}]