From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 28E131E0493; Tue, 17 Dec 2024 17:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734456128; cv=none; b=DAyFxVbd4/ihEbuzqQgBDGpTmfsT8dY4Mjgula5lbBoLgDbjAXsvQtbxI/yoW+QuNv1pxl4otxnrDpzL8kemwJvdmj7xl3EmT4PKiSK8EtyfUnHXytt42KeDxbqZKImVAW4/qfIZannyaCBzKrltCMWhJk5SmSCPPRhkMbX2EQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734456128; c=relaxed/simple; bh=RfG76ZPFFzy9X0ZJ0mNYBn6wQ/ngg8LhUJoUNcefcO0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J2UHlaeJONCDlhGB7NsDTy7OKD5SwsDDJb5RF9KXGZ+CERJ3y+UFhJLEbxYtV8tU5F6WRoJ/qiwQbIF1RxmZXXe+nspF/xXYHU5P2Rvfn5ElniHJfr+hcjD7WlRNW6g05XfL6VILelHZFKuXy52QEmTb+dj2vs+rwmBF3nSZcuk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=m5gkz+r4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="m5gkz+r4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5DE6C4CED3; Tue, 17 Dec 2024 17:22:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734456128; bh=RfG76ZPFFzy9X0ZJ0mNYBn6wQ/ngg8LhUJoUNcefcO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m5gkz+r4S+Nb4pUQMZeBAq0EbeFhLOLV4dKp6GtRTRDKQWo6V8eQHL6NTkZvTOlEo jZ9ii6wAVDsFsnC1c5CaKPBjuTQLNKQ7ZTce7Hx+GiquUD2Qcr0DkBsHOYH4wnjLHA gPgnElWxBjGjRSJV/noUYBe9BN/AOpvrImGcNnPA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+7534f060ebda6b8b51b3@syzkaller.appspotmail.com, Suraj Sonawane , Alison Schofield , Dave Jiang , Ira Weiny , Sasha Levin Subject: [PATCH 6.6 039/109] acpi: nfit: vmalloc-out-of-bounds Read in acpi_nfit_ctl Date: Tue, 17 Dec 2024 18:07:23 +0100 Message-ID: <20241217170535.005426341@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241217170533.329523616@linuxfoundation.org> References: <20241217170533.329523616@linuxfoundation.org> User-Agent: quilt/0.67 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: Suraj Sonawane [ Upstream commit 265e98f72bac6c41a4492d3e30a8e5fd22fe0779 ] Fix an issue detected by syzbot with KASAN: BUG: KASAN: vmalloc-out-of-bounds in cmd_to_func drivers/acpi/nfit/ core.c:416 [inline] BUG: KASAN: vmalloc-out-of-bounds in acpi_nfit_ctl+0x20e8/0x24a0 drivers/acpi/nfit/core.c:459 The issue occurs in cmd_to_func when the call_pkg->nd_reserved2 array is accessed without verifying that call_pkg points to a buffer that is appropriately sized as a struct nd_cmd_pkg. This can lead to out-of-bounds access and undefined behavior if the buffer does not have sufficient space. To address this, a check was added in acpi_nfit_ctl() to ensure that buf is not NULL and that buf_len is less than sizeof(*call_pkg) before accessing it. This ensures safe access to the members of call_pkg, including the nd_reserved2 array. Reported-by: syzbot+7534f060ebda6b8b51b3@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=7534f060ebda6b8b51b3 Tested-by: syzbot+7534f060ebda6b8b51b3@syzkaller.appspotmail.com Fixes: ebe9f6f19d80 ("acpi/nfit: Fix bus command validation") Signed-off-by: Suraj Sonawane Reviewed-by: Alison Schofield Reviewed-by: Dave Jiang Link: https://patch.msgid.link/20241118162609.29063-1-surajsonawane0215@gmail.com Signed-off-by: Ira Weiny Signed-off-by: Sasha Levin --- drivers/acpi/nfit/core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/nfit/core.c b/drivers/acpi/nfit/core.c index 7d88db451cfb..7918923e3b74 100644 --- a/drivers/acpi/nfit/core.c +++ b/drivers/acpi/nfit/core.c @@ -454,8 +454,13 @@ int acpi_nfit_ctl(struct nvdimm_bus_descriptor *nd_desc, struct nvdimm *nvdimm, if (cmd_rc) *cmd_rc = -EINVAL; - if (cmd == ND_CMD_CALL) + if (cmd == ND_CMD_CALL) { + if (!buf || buf_len < sizeof(*call_pkg)) + return -EINVAL; + call_pkg = buf; + } + func = cmd_to_func(nfit_mem, cmd, call_pkg, &family); if (func < 0) return func; -- 2.39.5