From nobody Thu Dec 18 09:24:42 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 7AD6A1B0F30 for ; Mon, 13 Jan 2025 22:39:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736807984; cv=none; b=PvV+I3+FgmR0BC40YY5wLtxdikKwSt6owH7TL1KQ8GEiTdTP/r5lYwvWIaaEnfNgHy+G1X+spElXj+C2DbHZA52ouOpO+bjTknXEfYmbrg7xgDUirT4pSOWURX5ESBmmJYLB7QN1bsdvcmK7FsMAepmmTJGeFxu52j5P3ODs2ys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736807984; c=relaxed/simple; bh=RxErtiYMUazEmoYmh5FZmHVVMAScn+qRuNOxqhFnq0s=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=iG5OmpxZVq51A6+Uhh+bkU6BJETuEwffuLmWd4dyQOjgUGmSieFO2xrJ48Uk0ZLrQE0Jh1DV5uSajvdXzybSG35rW3jbrxkNGd24S7k7+OrCtXYqZmMKgnwDoL2FSzYMrjND3IOzj4MPuxlUp2vUzwyDjlC4ZtOCQ69P3OO8I/U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NUTcOpWX; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NUTcOpWX" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4361dc6322fso34101555e9.3 for ; Mon, 13 Jan 2025 14:39:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736807981; x=1737412781; 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=rta55Y0uNleLFD95WQHH7zhK/RaF2A6MCC0b6AuR85E=; b=NUTcOpWXxBuvWcJu06S6PlqpDvllpmLVEplLiv8cqjkRh9v6nG4ALvZyhJR+QaF3+N CWmkMqad8/QGUGw7SF7Gwwgao2eH7RCKoRTZzCPhzcmUxdXjSkePrlcFGr+tG8M4eRHy rP6hjU58w97wIdvCb4WVpjKdDkvb2zbs8eD+vgm7hVRG05wa/O/JcMpuMdIYnparDORJ HW4YSZXIvrL4amzRHRp1ghVqhJVNREY51AtFdf5ZyTA/sECVp3oC52O0V5biLwcMParX 9OXfWZzZxFeXe+bspp2Iv4RLl88pqT0vB3k/1ajFGlon6WpZPR/JTc5dlRypw8gVTCXV m62Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736807981; x=1737412781; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rta55Y0uNleLFD95WQHH7zhK/RaF2A6MCC0b6AuR85E=; b=HqOs7H4kU45IPggz0+mnVlhNDrtJSBK4XxGcHHkLxhC+Z33tU1KkyWlx6AGZdSZKlO OTDU0/u0kcXApIkAN/aUHGnp42zBLU5wNYyJ/L0mcRGBJLREHPDcc34ZRZNZ48kkOOb+ Zb4WwsJ/ToEDvlRGJ8YGOihlhpCqEIqCZAA7zTCac9Az7q74kalz2I8+P9jrXmKd1xW/ fr6Nq0cLra0NOxzZVqwyd90kmwzt+5XHNGwqcoRVZTWic1lGjnRLbeijld1l5IFqSyez xSfjDxYlCIV/Q5wnBgGnxSrz8C1Z4cZk8Perc81rU0OHCiAZSLrA2Zig66Fr1Iizo8T5 sPxQ== X-Forwarded-Encrypted: i=1; AJvYcCWMiZL5T2Omj7etEzt6DTNP7BO1fQjvzwKV3SIYGyA7CKGpnxhSQZZKJ65wm+uLB/1ITff0vEVz9jAdzoM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0jiiu1vjxtSSNrH29RBFOe1k/j5x7KDu21Zoj5Q4x7l2uaib/ MDTbpEVV1NvSciJy7aIr4BmTwyrxLNWu1ft20Qf0nN5SN4djuihW X-Gm-Gg: ASbGncvfyuF2LqYjYWh9ytxE6fyUT1p5kMkcr7ISDq8OfYHRLfjvKAqCaNe3tZc9Y2y 4aTrVJB3LL4i7gFtZ0o2Ux/8JUM57nENwH9FlgHiWTf3/mHCyogRHygRS3qOQY0c6nAocPCGb1I Yv7CtIupHRv2eZccrGxds6B/vxhPPcrAiiCZd7CKlvxSMS6SNAZ9CdB1v3E28IHA67M0z7SL9X2 h+5xjGPvDLeTjlFtqgzbj7phQAUBxi+8OMRPNIGh/KDAVxR8H974Mpbbg== X-Google-Smtp-Source: AGHT+IFGzq5og6YanPrPwl8l/ZTISokVsIZVxIjPlr/KZ8ekAKdPyzYlE1WUdc0CNq53L3tThF1YJw== X-Received: by 2002:a05:600c:1884:b0:436:f960:3427 with SMTP id 5b1f17b1804b1-436f960357dmr58577895e9.22.1736807980577; Mon, 13 Jan 2025 14:39:40 -0800 (PST) Received: from qasdev.Home ([2a02:c7c:6696:8300:af9a:68cc:e070:12c7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e2dc08bbsm189024365e9.12.2025.01.13.14.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jan 2025 14:39:39 -0800 (PST) From: Qasim Ijaz To: jgg@ziepe.ca, kevin.tian@intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, syzbot Subject: [PATCH v2] iommufd/iova_bitmap: Fix shift-out-of-bounds in iova_bitmap_offset_to_index() Date: Mon, 13 Jan 2025 22:38:20 +0000 Message-Id: <20250113223820.10713-1-qasdev00@gmail.com> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Resolve a UBSAN shift-out-of-bounds issue in iova_bitmap_offset_to_index() = where shifting the constant "1" (of type int) by bitmap->mapped.pgshift=20 (an unsigned long value) could result in undefined behavior.=20 The constant "1" defaults to a 32-bit "int", and when "pgshift" exceeds 31 = (e.g., pgshift =3D 63) the shift operation overflows, as the result cannot be represented in a 32-= bit type. To resolve this, the constant is updated to "1UL", promoting it to an unsig= ned long type=20 to match the operand's type. Reported-by: syzbot Closes: https://syzkaller.appspot.com/bug?extid=3D85992ace37d5b7b51635 Fixes: 58ccf0190d19 ("vfio: Add an IOVA bitmap support") Signed-off-by: Qasim Ijaz --- drivers/iommu/iommufd/iova_bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/iova_bitmap.c b/drivers/iommu/iommufd/io= va_bitmap.c index ab665cf38ef4..39a86a4a1d3a 100644 --- a/drivers/iommu/iommufd/iova_bitmap.c +++ b/drivers/iommu/iommufd/iova_bitmap.c @@ -130,7 +130,7 @@ struct iova_bitmap { static unsigned long iova_bitmap_offset_to_index(struct iova_bitmap *bitma= p, unsigned long iova) { - unsigned long pgsize =3D 1 << bitmap->mapped.pgshift; + unsigned long pgsize =3D 1UL << bitmap->mapped.pgshift; =20 return iova / (BITS_PER_TYPE(*bitmap->bitmap) * pgsize); } --=20 2.39.5