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 ACC0C3C0A15; Sat, 12 Sep 2026 10:02:30 +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=1789207352; cv=none; b=l76wMEpLvTvylaf2GafXaYvFyeXNBxYlvZvRKEU79WpH3m39A6XicgwskcJgrhzBl8HHnZQYSZXUCKCjkwpPFEKZUbV2vvHjm48r7v3wKDX6FTxraOb3ldw4Xumz+wZmau1y0MQYWjZvHyO0BfjYBrY6EagJRPCfA5SM5lo+CQg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789207352; c=relaxed/simple; bh=AT8x+2pYXW1S7UsfMcv9YDYQ9R8vU+5ZKpGneyeQOUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oo5PT30AjcN9SHWdzxA3MBX3kP16THQZHa5AT1/Oznz2xvtd3e4DNf6fz4cSy/bapDGKF5TJ+UzRf6/f+AiJMSiznnTo8AsG9eY7ZRRIFPxtMD12rb9EEbkkd+bEaN7w0/2W7CnPfEQrYxno0fdGMs8AQPiEz3GcxDG1l9mG5RI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0LfmPM8W; 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="0LfmPM8W" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A69C21F000FF; Sat, 12 Sep 2026 10:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789207350; bh=0wvan/pt+NQRJc1QG54i8B7N1nHxbH1e7HuXi80TX5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=0LfmPM8WXoiHUvDD5Zx1v3T0tPG0IOOBWvjEGS1cp+f94VfmvfUcR8bkpqF8nPuMP 8bNkqSrJKi0LRrpxv2vgi5LQJRORjUFWL61z0RDhdgS/+yVH9VfASJY//qd2ac6SqR RFljWVy/albAGIPgf1SVOYJQI0P5zwflzIwzB5gA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bryam Vargas , Alison Schofield , Sasha Levin Subject: [PATCH 6.18 0395/1518] libnvdimm/labels: Bound the on-media label size before the shift Date: Sat, 12 Sep 2026 08:42:44 +0200 Message-ID: <20260912065632.394373652@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065623.398859879@linuxfoundation.org> References: <20260912065623.398859879@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 [ Upstream commit 18f9124248ed7a9da1c31973b629dceef76a9b0c ] For a v1.2+ index, __nd_label_validate() computes the label size as 1 << (7 + nsindex[i]->labelsize), where labelsize is a u8 read from the label storage medium. A value of 25 or more makes the shift count reach or exceed the width of int -- undefined behavior -- and 24 already shifts into the sign bit. Only 0 (128-byte) and 1 (256-byte) are valid. Reject a labelsize above 1 before the shift. The result was rejected by the following size comparison anyway, so this only removes the undefined shift on a crafted or corrupted medium; conforming labels are unaffected. Fixes: 564e871aa66f ("libnvdimm, label: add v1.2 nvdimm label definitions") Signed-off-by: Bryam Vargas Reviewed-by: Alison Schofield Link: https://patch.msgid.link/20260624-b4-disp-d8279485-v3-2-cdb6cab28b41@proton.me Signed-off-by: Alison Schofield Signed-off-by: Sasha Levin --- drivers/nvdimm/label.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 584a9c27ce4bf..93ff219d91fc5 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -145,10 +145,21 @@ static int __nd_label_validate(struct nvdimm_drvdata *ndd) /* label sizes larger than 128 arrived with v1.2 */ version = __le16_to_cpu(nsindex[i]->major) * 100 + __le16_to_cpu(nsindex[i]->minor); - if (version >= 102) + if (version >= 102) { + /* + * labelsize feeds the shift below; only 0 (128-byte) + * and 1 (256-byte) are valid -- a larger value would + * overflow or exceed the width of int. + */ + if (nsindex[i]->labelsize > 1) { + dev_dbg(dev, "nsindex%d labelsize: %d invalid\n", + i, nsindex[i]->labelsize); + continue; + } labelsize = 1 << (7 + nsindex[i]->labelsize); - else + } else { labelsize = 128; + } if (labelsize != sizeof_namespace_label(ndd)) { dev_dbg(dev, "nsindex%d labelsize %d invalid\n", -- 2.53.0