From nobody Mon Dec 1 21:33:27 2025 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 2E0892FE057 for ; Mon, 1 Dec 2025 09:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764581873; cv=none; b=ggfOxNbI4c9aVOmDU7UAuHXWPxIKLYWV7PhPxbJ9NhyV3prZ9swgmvW3F3XBJ0C++8IhoJIDqwCAiGcwVUFDgRQxKMyi3fIay16lLCCguy+OKfmOCOyWAT/3iHwfVqWVrql9CWhJQmKNCPmb6pm3PAsT8YHC9CgDUQdPVQsUmBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764581873; c=relaxed/simple; bh=K1ZpFcDSyoQ9N7BQa9z7DknwMS77afwv/RX2QlLRnHc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VDtYlUVWeMV6hKHMcZ6WSgTKS+tYNw0zDI1h394i27WLQLPfulOJbSb6uUkvFRCKsF6dEMvyXa1oMypnI7Dw4gWiQR8tBi3/2ew+FgjVSdHJLE/8bwxDMbHFU5BFtj9F95LPJMUIxwOmCKY/9uU7vluf1RMqdvlL4puvhiSioMQ= 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=BWN9AKjq; arc=none smtp.client-ip=209.85.216.41 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="BWN9AKjq" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-343dfb673a8so3696527a91.0 for ; Mon, 01 Dec 2025 01:37:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764581871; x=1765186671; 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=ZmBZg/AspfJwMWAbHxQpw6xsi94+/nXp0+CAmFuqGK0=; b=BWN9AKjqBQe6NY6fPhV3ZUZGZeSf7guStQT6YsHY4nZAHUJaJh90/rKGvugT0o8qD4 v7tpJSnKcNjaKwT9p2rSTXdQMhiSu2XjnywqZD3tpYJyRlH2pOW9xYm++lmGJG6H6fnI tJhjQcwbQpzSiW9BO1yuxpo0SL7iNJzts4DcSftEIn6IxtY4qBeGUpBs0ZB5u+YUP25/ 8boWxC+zMtQ39mrrJNBPxfF/THvovOdwxsbNBSSWVj5XqbEyEt++7K+92vgfYuv5jN/F 8Ta/uvtjHX9LYjBbmhztO1uEZnkqIW1xmA6KoP6l6P7+Rvrr4WNHDsViYqGdDND4zUJ9 AYKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764581871; x=1765186671; 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=ZmBZg/AspfJwMWAbHxQpw6xsi94+/nXp0+CAmFuqGK0=; b=ETMBjqpkb628UK3sqeOQjNZjnZn6tP3KrWo8Nn368ARZzmaXXAgaV8WCthk9TLGlX8 aeRNi4yVlLO3Ury2zqbYnzDawYJM6bFqtw9ja2QrOJIrzRaH5THRZTU3IeFkLBiF8cqa viHE9ogBNyE5ZyhQKF9skHk5hhLoG+aGHFDFCQTKhDL+EVgtaMEVfnCt2zhD1okI3ekY 4A+f1kWfsAbr87hkWIxorfsFPgATBKSD9loZBHH9Q2EjXQ5rWZrbhBP5xVd8ihn6Tmr2 p9TGuH+0Rz292HZZXTUPcjxQB3r4JpR3Q0IKk7VGKDwoI6v28pC/+C9x8G4P6PUAGnJx 61kw== X-Forwarded-Encrypted: i=1; AJvYcCXZcEm3qSOqLLyGL83o0ucMy9o5FaKHuUtB0mU/PlrJDpJ2e5m5PDRDjrkTvSsG1NL2vK1Yp8eeFWSsw7E=@vger.kernel.org X-Gm-Message-State: AOJu0YyQ+YZTwgNaCIlD2iGH/rkPspYeu7GlTOtEFGgOqOrinq9wR38w 0R8t/U1p0WIiquv0TLTlSgJ2EJLVZEuH8B0xfv/u/B7pqvvEMJqGr1nc X-Gm-Gg: ASbGnctIXA2QsR9NRDfDsOeuXn+gDPTZRfreh+svKnuYCzoZMTwByjU2PeLF46lc0uq hKFd3KaclfZJipRighs3jAvZ7G8/BlQGQHjARoKoLB2eCuHzPCm7q4hGqUjJ12eZhtx0cEN0dW0 WWUzrPSKoO8bWBkFGL9lKqepmEg5eVEpVrQM9Ugb5ljbZVf8ToTQz8K+LIh6IudB74GF0nwIQYd JUoYbCyJcOndIu/GBajkrOcd+EHbSrEQ5OE0QVhY4JfHPtCJjqfnz28goD8JQKIz7zel4B5dJBJ ssWaQ2n2LgGEUyMjYb89RCreipnseN90owTjgyxIpAFRLG3JcBhAqKsad8CbxwfLQdYx4q8Yrl2 o3lQiOEB234Jilsh1XwtbtlGXCKFzRd+p5up19xNCHc0pdrjtBDCYEV+wnmq3fwcWVh64MSNJ9M /IucWONrA751SqHIoPNMeztBa2wRUyWcCK4CA= X-Google-Smtp-Source: AGHT+IFf85uva3wpenRB3RxU/SNOc74eGJ+nNFpIeeLMOSNaFOcoROiKut/1RQOxS8DLJPCUktgPbQ== X-Received: by 2002:a17:90b:2dc4:b0:340:f05a:3ecb with SMTP id 98e67ed59e1d1-34733f3f1cbmr35208363a91.28.1764581871380; Mon, 01 Dec 2025 01:37:51 -0800 (PST) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:9368:c4de:5396:f915]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3476a5603bdsm16502947a91.8.2025.12.01.01.37.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 01:37:50 -0800 (PST) From: Deepanshu Kartikey To: akpm@linux-foundation.org, chrisl@kernel.org, kasong@tencent.com, shikemeng@huaweicloud.com, nphamcs@gmail.com, bhe@redhat.com, baohua@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+d7bc9ec4a100437aa7a2@syzkaller.appspotmail.com Subject: [PATCH] mm/swapfile: validate swap offset in unuse_pte_range() Date: Mon, 1 Dec 2025 15:07:41 +0530 Message-ID: <20251201093741.730884-1-kartikey406@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: quoted-printable Content-Type: text/plain; charset="utf-8" syzbot reported a WARNING in __swap_offset_to_cluster() triggered by an invalid swap offset during swapoff: WARNING: CPU: 0 PID: 9861 at mm/swap.h:87 swap_cache_get_folio+0x186/0x200 The issue occurs because unuse_pte_range() extracts a swap entry from a PTE and uses the offset without validating it is within bounds of the swap area. While the existing swp_type() check filters entries for other swap areas, it cannot catch cases where the type bits are valid but the offset is corrupted or stale - for example, due to a race condition during PTE updates or memory corruption. Add validation to ensure offset < si->max before using the swap entry. Reported-by: syzbot+d7bc9ec4a100437aa7a2@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Dd7bc9ec4a100437aa7a2 Signed-off-by: Deepanshu Kartikey --- mm/swapfile.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 46d2008e4b99..fdf358df7116 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2277,6 +2277,8 @@ static int unuse_pte_range(struct vm_area_struct *vma= , pmd_t *pmd, continue; =20 offset =3D swp_offset(entry); + if (offset >=3D si->max) + continue; pte_unmap(pte); pte =3D NULL; =20 --=20 2.43.0