From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 E51B6305660 for ; Sat, 25 Jul 2026 13:22:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784985750; cv=none; b=AErgisN1VSOUyF1LOdR2MLm1toKpdspjGHQTnpGml4HVa48Q0IP/CIbHLHlQgjs8mWg4LQp/M7Dhc7iYx6uvoEsMGYW3w2iLglyOXtgg+uPkkv6iMHLGmSyyfN1zj9j0ZCxLM2K67zhi8efxscFfWZDJIl1hoNePngntCjDLaLQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784985750; c=relaxed/simple; bh=bLg1OoymlSeU0d94++1UkJcf0jWBlsDXa271NnAK1u4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BAY/K+QEmLcVf/GVNV6iYobVMuDvESDywkbiu/2urbcazKYrXTELvkWTBxPS3/rnCcv30FcuCtalzDjWbxgZeOfnmbU55CKHQdQlAup2Y87nMj6ZxelvIuXczf1HxOA2mGhvt4Jcr0ENIbX56uq3ijUVcdab2XUxg7XmB4anijo= 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=hrvUEKAn; arc=none smtp.client-ip=209.85.167.47 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="hrvUEKAn" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5b021916bd3so1430296e87.3 for ; Sat, 25 Jul 2026 06:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784985747; x=1785590547; 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:content-type; bh=8V6nDAFq04ExKfk2MYmWny5A/bytyCIfag+WKXl4F4I=; b=hrvUEKAnFUHP7dkulAJEXZgfpHYD5RswLsS42+iRUNKZTlIz5b4sZwJjZ/RljGg2Fu KQxANKmTcQ90AEzNeAKmuJYAleUPRoqAYyi+ZmNeJtwdFGcdWBQTLW861YWjQKhw4JQ+ 1CyCVFk9zIFGvvulNLoyq6jlPfDMlxSNFWq2Sr3plFC0xPXVKRp+f4lDC50yDwRSiLlh CFsz3oToln8i3FeZt6T8ogky+BDLFT3QIhDqWM4KlNPG5OfO9ulEijk4cg3mvUH5GAph ngHQ9sU11zYDp+/Te6Vdplwlu9hXFkChYzKnQjn/q+QLVryJ4LwWNnvCWqU0wh9DFYUi GZXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784985747; x=1785590547; 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:content-type; bh=8V6nDAFq04ExKfk2MYmWny5A/bytyCIfag+WKXl4F4I=; b=IAjr0Nan1q5KL3wyZAQvm/b03mGa4Y1Go3QW/rA5qD2ZMbyPmzdIXBNXf9yFWCoNHy em9rIk2bKnlVVoVlWasxLR9SJ5eKpidk9Ob15OGGPXgocf6hBUI0eq/wmeyb0Ozk2Q6E QtJM/mRnDEO4Al6iyIqMZZP9WD+c5ctTzYW8xeIaNPaMdRVMAA2/5NxlHmCDvQPAvhQC bL17pjMUq691FfY4T6O7w8cWQOwR93agz0ZCZm6jp6kHrftUEysFM5CBJpS6JZTSpSEx vTyPqIZu+7nLaZhBE2Rv6iL+c+Uydljl1rwSOI6BYd2PWtkWQRCYvajKEGsrVb2+rggN dUhQ== X-Forwarded-Encrypted: i=1; AHgh+RooPdvKaB6hshyYO+vkqcMRHZYYUzvVnRUycbOABWcJ99/CHLJAJAXt+DwzaOstRintm72XNE6z5aQCtao=@vger.kernel.org X-Gm-Message-State: AOJu0YxQv9Bi5u9s5wDUUn4FiciW6J5vWY2emYxdomnPMure6Q9Huuos JhjRA16ow1ilAQkbJXsE8gOzxBANSlMr44zaCDe4fhpK9l95Vb+CABkUnWjs0u/O9Qo= X-Gm-Gg: AR+sD118dh+LE6dSiX+QX7RipJZyltMbxBjms/0q9kDbVE0dffnu6qRMF3EbtKkRsXN 4wdyDT5kONsma5nPNT4vGYz4oUTqlQKo4F44YQJMeXOs0oCBU/dMmx7wSAI2fVAogvL+Dt/gxNx aWmmnurGGlnKbJzsWQdP42yzahRYOwAcLK4K0U7UiUfpM8G4ARSNm8+1V4h0woNuAcAYIvTKdrm NwLX9DMv6cwsxYNzrN0EuTqkH+xFZvLWqiwfodD8axOHQbHIk9R9S6TxuV8GWlUbgFVBoZb6ozB Z0hTM0q+YonPBHpYVcsYc5eA02bqm3EcjT5jPjccqtKFqiWzgYWYW/DhhHLS6kA8fFd863Y25kr ysn1/CocEjyaEWzjixstnwP/LBycBIz3LqGA4BsDavAfb8VasSyArNX4vJBsHeMqS114/gxUpPN sazcUhab0JUuzx5U1KWDRciv+Qy0jT8ZY+0yLPdbXNiVcA7215hulq/+yi/X0rW9LvtOuGocA= X-Received: by 2002:a05:6512:31d4:b0:5b1:5e05:31df with SMTP id 2adb3069b0e04-5b2c1af7890mr413460e87.13.1784985746780; Sat, 25 Jul 2026 06:22:26 -0700 (PDT) Received: from localhost.localdomain (46-138-176-102.dynamic.spd-mgts.ru. [46.138.176.102]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b2be1d8509sm417670e87.38.2026.07.25.06.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2026 06:22:26 -0700 (PDT) From: Artem Lytkin To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, urezki@gmail.com, shivamkalra98@zohomail.in, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] mm/vmalloc: fix 32-bit truncation in the vrealloc() grow-in-place check Date: Sat, 25 Jul 2026 16:22:01 +0300 Message-ID: <20260725132201.88279-2-iprintercanon@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Commit d57ac904ffdc ("mm/vmalloc: use physical page count for vrealloc() grow-in-place check") introduced if (size <= vm->nr_pages << PAGE_SHIFT) { in place of a comparison against a size_t. As vm->nr_pages is an unsigned int and a shift is evaluated in the type of its promoted left operand, the right hand side is computed in 32-bit arithmetic and wraps for areas of 4 GiB or more. Twelve lines above, in the same function, four expressions cast for exactly this reason: kmemleak_free_part((void *)addr + ((unsigned long)new_nr_pages << PAGE_SHIFT), ...); The consequence here is benign. Truncation only ever makes the right hand side smaller than the real capacity, so the test can only fail when it should have succeeded: vrealloc() then falls through to need_realloc, allocates a new area, copies min(size, old_size) bytes and frees the old one. That is correct, only wasteful, and no in-tree caller currently grows an allocation past 4 GiB, so this is a latent fix rather than a user-visible one. Widen the shift to match the surrounding code. Note that comparing page counts instead, as in PAGE_ALIGN(size) >> PAGE_SHIFT <= vm->nr_pages, would avoid the cast but introduce a real bug: PAGE_ALIGN() wraps to 0 for sizes within a page of ULONG_MAX and the test would then wrongly succeed. Fixes: d57ac904ffdc ("mm/vmalloc: use physical page count for vrealloc() grow-in-place check") Assisted-by: Claude:claude-fable-5 Signed-off-by: Artem Lytkin --- mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 44647e189f7d6..baf7e396e3fc7 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4415,7 +4415,7 @@ void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align /* * We already have the bytes available in the allocation; use them. */ - if (size <= vm->nr_pages << PAGE_SHIFT) { + if (size <= (unsigned long)vm->nr_pages << PAGE_SHIFT) { /* * No need to zero memory here, as unused memory will have * already been zeroed at initial allocation time or during -- 2.43.0