Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A38D63C0601; Sat, 17 Oct 2026 17:40:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792258834; cv=none; b=dHvmmTA099sILm3wC3v9vwvsp8Fd2v0cCkHtuj3SXhTAmMigG0gedRqyGrFe0nZIGT7KUExiJuOCgeoKhCStaaZY36ZglXKpqYQEFQL3NpoqyEZOSFw6ohq93los3tks/bZc8M5tSzQO25TD/8jUMDHGueVyieowZLF0hlE+gvU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792258834; c=relaxed/simple; bh=Utr38Z7tNmLm3gTXwk7tgOEHQIeMozOffzwz6zQkD5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nERMsQ0xJxLg3Utj+EJ47gNVhbs+P1iyyDr0GJxEm/FBStXpdndOoAaKfNkZyxlIqWq0L317nEi/MtiJsE5sTCN0WaHzS17FTPxwesq31j4tkMvhGOaeZHiq416Vdr3dZyNs557fi3uS0AcWZ5X0krOeJlYXmtTBOrbIvGg10RA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=E0Jo3NhF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="E0Jo3NhF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F31581F000C4; Sat, 17 Oct 2026 17:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792258833; bh=qxbWIroe5DgEAyfa4xdOtdKH6XQ9DH5cEfHOcxXJxIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=E0Jo3NhFJ7LCl4qzAJhT0uUr9fmMqNf+bWNiLykHQQDfscTOrp8qtZ2M3+OdqlsQQ AwhyIumo+qzefMTkaB+AjdMc1nkRLqfbpguG6HF1MkIyLZELEyUKFR/jZuCz//O7gS wogUeXI58yUt7RtbuoqdNMFCGiYpCLxxsXNmXuOE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bartosz Golaszewski , Srinivas Kandagatla , Sasha Levin Subject: [PATCH 6.6 1012/1674] nvmem: core: fix use-after-free bugs in error paths Date: Sat, 17 Oct 2026 17:54:44 +0200 Message-ID: <20261017160457.110654454@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bartosz Golaszewski [ Upstream commit 5b6b6fc491899d583eaa75344e094796ae9b530b ] Fix several instances of error paths in which we call __nvmem_device_put() - which may end up freeing the underlying memory and other resources - and then keep on using the nvmem structure. Always put the reference to the nvmem device as the last step before returning the error code. Cc: stable@vger.kernel.org Fixes: 7ae6478b304b ("nvmem: core: rework nvmem cell instance creation") Fixes: e888d445ac33 ("nvmem: resolve cells from DT at registration time") Signed-off-by: Bartosz Golaszewski Signed-off-by: Srinivas Kandagatla Link: https://patch.msgid.link/20260530204340.116743-3-srini@kernel.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/nvmem/core.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 2df9d04a9fc51..788111fb3495e 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -1355,18 +1355,16 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np); of_node_put(cell_np); if (!cell_entry) { - __nvmem_device_put(nvmem); nvmem_layout_module_put(nvmem); - if (nvmem->layout) - return ERR_PTR(-EPROBE_DEFER); - else - return ERR_PTR(-ENOENT); + ret = nvmem->layout ? -EPROBE_DEFER : -ENOENT; + __nvmem_device_put(nvmem); + return ERR_PTR(ret); } cell = nvmem_create_cell(cell_entry, id, cell_index); if (IS_ERR(cell)) { - __nvmem_device_put(nvmem); nvmem_layout_module_put(nvmem); + __nvmem_device_put(nvmem); } return cell; @@ -1480,8 +1478,8 @@ void nvmem_cell_put(struct nvmem_cell *cell) kfree_const(cell->id); kfree(cell); - __nvmem_device_put(nvmem); nvmem_layout_module_put(nvmem); + __nvmem_device_put(nvmem); } EXPORT_SYMBOL_GPL(nvmem_cell_put); -- 2.53.0