From mboxrd@z Thu Jan 1 00:00:00 1970 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 9EDCE3B42F7; Fri, 4 Sep 2026 05:50:25 +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=1788501026; cv=none; b=SEuWZPkwNNmkDZRmT03/Y1AT2oAuFEAeAh4EKvHi2PvvUVwQ6ksyeNf0F3o8NrvE6Nf4HHPVniXYjXJsPSuVFBsx792qrltqRNDl8eVN7B3EzW5oApUYBbb3ioHu6lbVxxJjzLSLTRRv9nbaIXwZUm4uP4/1USjyhmbEfabtklw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788501026; c=relaxed/simple; bh=IXgeWI9v8snBlfczADKYsgqHRtGhXNuRo+OCYjt4Dlo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F678YWBCv802tHKoK1oVlAwPlZ/NuaAcuU/vv/AJQj9TDpBNODh2hCTf6nlLTqWiuHAwIwrG3T/04XPeWuRG0V+CyTkafJi7VOMKVCf+c8baVxztwOgCcZWrWaIbwNmhkZGC1N7KF4AuqK/M6+XUZ3V0YDSaF8RcU/erOVfJITo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=j1p7y+Cw; 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="j1p7y+Cw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED64B1F00A3D; Fri, 4 Sep 2026 05:50:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788501025; bh=rwpbhCVgUkz5oNePBUxrdneVnbv8Kr3Jtn0pTR0DBy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j1p7y+CwoivDp5QO0smuUPMG60/4R5sKXMhFCiRWXXcbdNiucaCSrVoV8ISlE2MvO AYtpOLHbqztV+MSxtpB3UwJ0fGJ3lXhpoIJN4zXOn1aJquwa6I6VSJKRdunNkuJ7tD 1Fj0ahofH0+JfeD2LSXa6pUlbSIsD3NMlwdpLOOc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alison Schofield , Bryam Vargas Subject: [PATCH 6.18 265/552] libnvdimm/labels: Prevent integer overflow in __nd_label_validate() Date: Fri, 4 Sep 2026 06:57:02 +0200 Message-ID: <20260904045755.928565311@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260904045747.813364717@linuxfoundation.org> References: <20260904045747.813364717@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bryam Vargas commit 037770686126155eafc44501312989e2837b9659 upstream. The on-media namespace index field nslot is a u32 read from the DIMM label storage area. __nd_label_validate() bounds it against the config area size, but sizeof_namespace_label() returns unsigned, so the product nslot * label_size is evaluated in 32-bit and wraps modulo 2^32 before the comparison. A crafted nslot passes the bound and is then used as the loop trip count in nd_label_data_init(), whose memset() walks off the end of the config_size buffer: an out-of-bounds write. The field is not trusted -- it comes from the medium, or from userspace via ND_CMD_SET_CONFIG_DATA. Evaluate the product in 64-bit so the bound check is exact; conforming labels are unaffected. The check was safe when introduced by commit 4a826c83db4e ("libnvdimm: namespace indices: read and validate"): it multiplied by sizeof(struct nd_namespace_label), a size_t, so on a 64-bit build the product did not wrap. Commit 564e871aa66f ("libnvdimm, label: add v1.2 nvdimm label definitions") narrowed it to 32 bits when the label size became a runtime value read via sizeof_namespace_label(). Fixes: 564e871aa66f ("libnvdimm, label: add v1.2 nvdimm label definitions") Cc: stable@vger.kernel.org Reviewed-by: Alison Schofield Signed-off-by: Bryam Vargas Link: https://patch.msgid.link/20260624-b4-disp-d8279485-v3-1-cdb6cab28b41@proton.me Signed-off-by: Alison Schofield Signed-off-by: Greg Kroah-Hartman --- drivers/nvdimm/label.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -202,7 +202,7 @@ static int __nd_label_validate(struct nv } nslot = __le32_to_cpu(nsindex[i]->nslot); - if (nslot * sizeof_namespace_label(ndd) + if ((u64)nslot * sizeof_namespace_label(ndd) + 2 * sizeof_namespace_index(ndd) > ndd->nsarea.config_size) { dev_dbg(dev, "nsindex%d nslot: %u invalid, config_size: %#x\n",