From nobody Sun Feb 8 02:56:04 2026 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 047CE34FF54 for ; Thu, 22 Jan 2026 01:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769045720; cv=none; b=TaC0ZBe0OQINLBagPKNNhuigjvNZM7BaHcwOSucrbFDnopVRsHYbg7I47PQv+f/LmSjkNk8fB2yEte2jnQXvP7Cr3ettaU+1qyQwe3F6XLUrsQ70Xdq3md/oviNzLgLCLiEhQpoQ98RSkey78N6X9E6pWGTO5cSBe5/rNiieqGs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769045720; c=relaxed/simple; bh=8PUZdGSM6Y7B8MR/d4EbzrEy96wGmf7M3+kNQc6Zz+U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=BrnxtM4NS72vEzNJF5suN4mJW5Kuh/pJTO60dNSWXHH5NZVAhao75DWGHX169Gb9BlKBIuYxofU7U2wjfkkNkbfDeCfTG6QJWyp9zCkWPsXcbN6EPJdkLLK4egXNUFB4UGbN+3k1vyggM1zy+3I2jIbq7rL0ENbxncp+LnxJSBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=njit.edu; spf=pass smtp.mailfrom=njit.edu; dkim=pass (2048-bit key) header.d=njit.edu header.i=@njit.edu header.b=Uic55UHc; arc=none smtp.client-ip=209.85.222.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=njit.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=njit.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=njit.edu header.i=@njit.edu header.b="Uic55UHc" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-8c6a0702b86so47427985a.0 for ; Wed, 21 Jan 2026 17:35:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=njit.edu; s=google; t=1769045717; x=1769650517; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MGbhOo8eNWt6MQwoA9ikJePzuNE3mExdUJOE9y2m2Rk=; b=Uic55UHc12DY5kvQJInecK+2xK6FlHFCNR6/ww7VaT1t7fPOemR/RF+Xt1JbN7ZMuA vxff9kmcLBK5WKpmceEo776lwSlYTUAhpmA6gQFuW4NCtm49et6Qw7xHa2ev6KquxS5X 0Nlr67WZCIugUGHdgmQXXs9nVxgVUfZkxqaJFZoFRNa7wsqZnJWh+f8j2WRqv6tORGtB 1H/HXwwTNN2/vPeW6liTykDa2GhpBxxXC/IVo3WGGrYcotO5RBuDMXG0S67Rx3iUq2MW mmrtZC5YJdg+1eCUczRsSYVJewBIH2Ee4lC81BaJzDgLHLQE+AHUw1A/y+f2/ckdYy+P 7fWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769045717; x=1769650517; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MGbhOo8eNWt6MQwoA9ikJePzuNE3mExdUJOE9y2m2Rk=; b=oWRFcnzoFhcMCbmeFL84gZOurk7YoMaAQbcIyhOLNNBjp+qg81ZzkmCeyMjOF3eQS/ hOitx+50DYNY64x6mWjOz35y+wgKLKDDZVieFQiQpWCXepqJ9pVk/m019+Gl3w44gyEE GTyy3Dqqybdj9zhCCFQ5aeAmPxo7CxPbNVqtlOhRRCSDE3WZoOUguqwTAHFPhmeRIacl E1Xlp5widIMtMn1MDMFaWTujJb2YCjEH/KFpLmcKk1q9a2bbubWNpabZgP9NS9OkPc+Y lk+OWpj1UaVisT5Q4SJuc6jBoJaa79rXt5Zbe9BzpxBOvDl3ns4T3+RrV0nnkdUzqgYO 57dQ== X-Gm-Message-State: AOJu0YxVM6VXvs7O7nE/qrjHUB6Y2pgEngi++V51H89TTfINeTBRT1pM RroZEeY94N80EIdlRH03u+m4r0fyNlPmZUzDQXQCmbOToCQjZyrr12IYCw1bicWvFhqoV5iHJtY kaqc= X-Gm-Gg: AZuq6aKeT3YlayjWfdlzzFaJsHfr/9+uXexsWH0aL0UjqXrRSyLEUz8muUnY7oeT1vH eyw2hrvHKB5SP36vFcqdFUExb68rcsuCQd8CFYm6lRndtwvHtcIIxF8i4av2YJFJrR5nlvrZl5o DqDDNXJvsBXcfEBtWCEo7dKP1UnDocRa0/zGI8fkOdyfHkyCW1Dw2K7VwHpMGu9jy9i8CFAQO+Q 0lJE7t0pCASSJr+caCYIkYDRfnnkeuHqDGqbePkegdvSyv5ZaEM21mGfn1lz2HnvYX9a/6D2K9D SfYVTnMNM4iXKg38xoD2qLyONdOAuoTW0B/dh6qTKvUKiPGQNQX3f4+I0ENBY4/ARcj5i1zaxvR tRRjD6ZlaRAtfX5YPQUuFqpR4dbM46K56J4HPXY/Ci4f2GzHBSU09q+DDGqaV4sNoitmr7gsXxE jCqkW/RTQ0noINjatu2jhQyxakuS1bSZT/vqoQccpMnUU= X-Received: by 2002:a05:620a:2988:b0:8c6:b258:dfd6 with SMTP id af79cd13be357-8c6b258e5e6mr2306525385a.87.1769045717580; Wed, 21 Jan 2026 17:35:17 -0800 (PST) Received: from localhost.localdomain ([2600:4041:4152:ba00:4078:c0f9:2328:fb43]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c6a71ad797sm1374444685a.8.2026.01.21.17.35.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 21 Jan 2026 17:35:17 -0800 (PST) From: Chenxi Hou To: linux-kernel@vger.kernel.org Cc: colin.i.king@gmail.com, linux-mtd@lists.infradead.org, miquel.raynal@bootlin.com, richard@nod.at, rk0006818@gmail.com, vigneshr@ti.com, Chenxi Hou , Hui Peng , "Zhihao (Zephyr) Yao" Subject: [PATCH] mtd: jedec_probe: fix shift-out-of-bounds UB in JEDEC ID masking Date: Wed, 21 Jan 2026 20:32:50 -0500 Message-ID: <20260122013250.19384-1-ch395@njit.edu> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable UBSAN reports shift-out-of-bounds in jedec_read_mfr() and jedec_read_id(): =C2=A0 UBSAN: shift-out-of-bounds in drivers/mtd/chips/jedec_probe.c:1924:13 =C2=A0 shift exponent 32 is too large for 32-bit type 'int' =C2=A0 UBSAN: shift-out-of-bounds in drivers/mtd/chips/jedec_probe.c:1940:12 =C2=A0 shift exponent 32 is too large for 32-bit type 'int' The JEDEC manufacturer/device ID masking uses: =C2=A0 (1 << (cfi->device_type * 8)) - 1 When cfi->device_type is 4, this evaluates to 1 << 32. Since the literal '1' has type int, this is a 32-bit shift and is undefined behavior. Fix it by using a 64-bit literal (1ULL) so the shift is performed in a 64-b= it type. Co-developed-by: Hui Peng Signed-off-by: Hui Peng Co-developed-by: Zhihao (Zephyr) Yao Signed-off-by: Zhihao (Zephyr) Yao Signed-off-by: Chenxi Hou --- drivers/mtd/chips/jedec_probe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_prob= e.c index b285962eee2a..3c631608f6d6 100644 --- a/drivers/mtd/chips/jedec_probe.c +++ b/drivers/mtd/chips/jedec_probe.c @@ -1921,7 +1921,7 @@ static inline u32 jedec_read_mfr(struct map_info *map= , uint32_t base, */ do { uint32_t ofs =3D cfi_build_cmd_addr(0 + (bank << 8), map, cfi); - mask =3D (1 << (cfi->device_type * 8)) - 1; + mask =3D (1ULL << (cfi->device_type * 8)) - 1; if (ofs >=3D map->size) return 0; result =3D map_read(map, base + ofs); @@ -1937,7 +1937,7 @@ static inline u32 jedec_read_id(struct map_info *map,= uint32_t base, map_word result; unsigned long mask; u32 ofs =3D cfi_build_cmd_addr(1, map, cfi); - mask =3D (1 << (cfi->device_type * 8)) -1; + mask =3D (1ULL << (cfi->device_type * 8)) - 1; result =3D map_read(map, base + ofs); return result.x[0] & mask; } --=20 2.52.0