From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 672153C1F for ; Sun, 12 Jan 2025 12:40:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736685643; cv=none; b=CiwfOSBhqx9QCknC4H/H4VhsHbbfyZ8D2bIdgGHBBVuC2AXIME6w9wjh+sY4w6SOa/M1tbDzTZ+qJCBeHcvJWRmn2irgebYErh1ui2t+6D2x4lnJ1n/zBkNSYe+QvUUs24Zug8hNMtFHXvQLQxxkEeKIw4/5VHUAyiecU2kC0uA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736685643; c=relaxed/simple; bh=KIdw/TWwj/6QgkBKt5hfcBPLu+LDU5RSwQCKere/JF0=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=aMQVK2qAiZ3tx5mc59Cn974cY8KcWZhWBSGWPnFVxZAt2HXoGcFxeqyqTzUUeW8zY/d2/6EDlOiISdEJiLUIltqS0w4bXoif2z28n9iK3pbyGTxdQ3TEAOjqYBqONou/gVegkumu2uBsnIMawusCt2nfTJoer3H38zIP8XAX7aE= 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=fqfaxhzA; arc=none smtp.client-ip=209.85.221.42 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="fqfaxhzA" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-385e87b25f0so2844783f8f.0 for ; Sun, 12 Jan 2025 04:40:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736685640; x=1737290440; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=JbaiZjfjmkoAvOH/8vPgWea4VcV4OpYLBCWHnfBUIaI=; b=fqfaxhzACQNErtWmIYsEMtFVLZU6Aab/qr6ZIHY48v8PyDhOTkbq38W1s0PQV71IYg Y8hSQMXIloNZfjQx8GUEnAZ2c6o5pccLYDahsExaSrH7i6PJ7/XctNQojJPuvxBO/+NQ 7zES+6e+WQVo93kO6tagDqotggd/CsgH10tJKpORFzM2GIBpouDa8IzGjDcNUb2XPNmJ +LcWcILz6na5esXvrPxoKgBy1rKPWinQFUUHlYUAu9wxGEuwO3AgtEGs7a+X72wQ7ssM Bd+v8bk+YLp89x+47hiekTsexRombBB3ed3haFYcq4ZZALqW/Xl5c3od+LOmRpVLowL7 yzxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736685640; x=1737290440; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JbaiZjfjmkoAvOH/8vPgWea4VcV4OpYLBCWHnfBUIaI=; b=EB5b2tXicKX13/G72b4Htn7KIASVmG0kpReG3Re1CTCdoQT0hQDfy7Td5r2mgPnDHA EOh9gE1OFZw0FeItCya9NuOJgmXfu4Yr+a1Da1v4lG1FRlaEdQkdHZ3LE2VLkvNyAJqB TF9KuFS/zXdxumthwPXbmiHkstC1GlU+OYfzZAWntBt0zsPFacwxbbgVSjDqLZsv1pWF RCygFvO+2bfzMPhq1vpHuBxPT0+OpDurOMLhsIoTogR/fdThu6ihFwwaU3v8Qc1P4KNz ssYBvsKgr5KfgETupKn1zOpxRnYD1FC2c3hGHt8UjifQ/gqWw0Ps5S+V+rNbm1HFqjkP jyww== X-Forwarded-Encrypted: i=1; AJvYcCWnb3pvDxkC+vCrO1LwAnvqi+feY7dC38r+wHeqS7v9Bqb8hgj+nTBgGtAlpkpws9r+jjWGR0mpYdwUNKY=@vger.kernel.org X-Gm-Message-State: AOJu0YwA0DFWQPNBTxrduOQSJ/AmvMLh013uQHsKY44eAN4UbG+nm6/G L17e+L9kqAFfHFT8IuNkR7/77oZfV4WVZ2oO3SL+JeVGLLrNPueQ X-Gm-Gg: ASbGncuJwEtqsTbG6KPA1xcoCvRQ1ep3/gJaxP3TojDE9nFMtmiB0wRhyCj8mLMR0dH zMBRXpB+gK/5iz8fAbLJD5HOSMEymaTuzFYvP3v3rnMb+nHEoYeNl0O6oMfpSKx+HAJo8uTuBjz 4+wegTmr8UObbrcZNpyv+gTTWsG6YIOyi6Gk3bjrfcGop3KiMRUhtlUZ9o62kkDKNRgNEIKMJ19 6H00y+SjHRgH/3SWl8d6dpcf3z+SgzRNdy8JUQHbtgMZ96c084ZHup+wZ8= X-Google-Smtp-Source: AGHT+IGuvQctO/7DwrvEVnU8Ya73WBjvQrYXc1Io1Uc5/tSlcokPNHvGYQ5wKmF/gCMpUB7cThjUuw== X-Received: by 2002:a5d:47cd:0:b0:38a:88d0:1c9c with SMTP id ffacd0b85a97d-38a8b0e764emr13532902f8f.17.1736685639568; Sun, 12 Jan 2025 04:40:39 -0800 (PST) Received: from qasdev.system ([2a02:c7c:6696:8300:f79a:c247:3ba6:f48]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a8e383654sm9731193f8f.30.2025.01.12.04.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2025 04:40:39 -0800 (PST) Date: Sun, 12 Jan 2025 12:39:42 +0000 From: Qasim Ijaz To: Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] iommu: Fix shift-out-of-bounds in iova_bitmap_offset_to_index() Message-ID: 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=us-ascii Content-Disposition: inline This patch resolves 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 (an unsigned long value) could result in undefined behavior. The constant "1" defaults to a 32-bit "int", and when "pgshift" exceeds 31 (e.g., pgshift = 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 unsigned long type to match the operand's type. Reported-by: syzbot Closes: https://syzkaller.appspot.com/bug?extid=85992ace37d5b7b51635 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/iova_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 *bitmap, unsigned long iova) { - unsigned long pgsize = 1 << bitmap->mapped.pgshift; + unsigned long pgsize = 1UL << bitmap->mapped.pgshift; return iova / (BITS_PER_TYPE(*bitmap->bitmap) * pgsize); } -- 2.39.5