From mboxrd@z Thu Jan 1 00:00:00 1970 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 96B141DDC07 for ; Sun, 21 Jun 2026 01:29:40 +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=1782005381; cv=none; b=mJLHWtJG1jimtJVXgvN/uTdn66/hHDqUgJL/dJUX6twpHxZW1SuX2UK1MT3QpJGaNbKUKPyhORAARKP1nKTJWcu7OlL4nN5kD9wWPjra8JzPvjJNQzH2/7pJQHc6lype4NRT8dVw+pwrjqgviuHelPM0wBzMkQcfrcZSpArEt6M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782005381; c=relaxed/simple; bh=3UBYzeU2dVhBN1XdXgDI32bS+wfwbHsKNgce5dpLOA0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=OShfWgEPdz4RfdVe4n0/E5rVn9Gn7dIzezZR/tPq1FqVgY1+j8BQWmdjv2TCwN5wJERrNOQ3PMWHFvHEwD9sr1y3MO2g0w5G8Ro0WH6bkXIqlz66FPBjbjnjfrNamEojMZMyzHcMl7e76tPv6WHkl8VNPOb3oI6/f0a8ZWJocOQ= 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=W4QhCikS; 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="W4QhCikS" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-36d5fd50d20so2216618a91.1 for ; Sat, 20 Jun 2026 18:29:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782005380; x=1782610180; 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=QIRmNxLSiDs+vGpBgdhj9EfUDMiH5ZJ3syFKf4560AU=; b=W4QhCikSiYvnawsr//q2EUZexVVMLZQKvkytFfLfEjCwyGWuTk/o4mLyG+qYxiKp/k f6eO9UJGljjkt+6gfP8FkgvSG187vq7glxZNKr9Dhpfjvk2gnLiR+mm7jtGHtqwyauwb YOBM5Xabh4eDKJy3rWgY0JAw+VtB6OmIdXom0nqxIZuf7ojDa86eOe6iGzyB3r9SKgfY 2gsoFFuroGPbKuwifGFMXUssjHHTwkR7hBU5ng2h/5Witcpg0D/WIiQoP4xV4yczGq5v ravKhmTUb7FCEETDfk1rXV1hmZ4E0qksdC7OvHrF7V11KLra4hdPDQHHSsSjR3D22dXZ w53Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782005380; x=1782610180; 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=QIRmNxLSiDs+vGpBgdhj9EfUDMiH5ZJ3syFKf4560AU=; b=D5rD8p2bmwsQmnw4gsbfIbwzVAPNoVMBI+UigzHknzSQRX84AwnmkSh7CqJLSFXhpc idXW1tSCh3C1RCXqbCO8Av1RHE+FRHp3xBst+YNBsf2UJtCgwOBhT+0YBzlD95+pJRus GOfsHlsw/0226p1M7EoY33Uv5PMu3zkpUcVmy16yPXXpxPe846deqHwUGIkZgg5LqeRP wpqmoBfOca0e45Wh2IVhng4OCJ8Pvl/IzK40Craqf8Wz2VTfso7noROp4o9kKfGLiark fGP4xX9NtCmzTGaY/eX4X0xSOR70r/z5NI7e+laxVF3D7D0gwKPAeECx1oMb3NcBEAkc 0CZg== X-Forwarded-Encrypted: i=1; AHgh+RqG4u9Sd9Di+KfuRfoXlnOT+Y23FWMKE2L+WE4uNrJ23OcaAplNF2RBS0asVKQQA2hLP+ppzoL+nUdoZqY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3KzB+Jw6XZ0OSa9hgsPfVOp82olgdrnzt0rHzNcfwtihfwh9o f9ATutfLf0BCrYR8ax6NUunnBSm7c5D//mWKNN9+fLsIJASA2nkieuRRJu9uXg== X-Gm-Gg: AfdE7ckMKrTUeLrAgolSiiT0YrrHMg59oBQD4FFpl+7Ah7QTbQauWWfxKPof/m6jM+Q Qw/USAEUqMdTRxEpImq5oGKxqTe2LvNjekWzI1dqQXEO0XwQHMhz6yzr6FZaktqUANp6Ogk+N8T 00okD1Aes2KfUwWHfujYWTG4lNAT9ulxw8WpvWLCWRwGM5HBwrAEydWJG7bEQE8pBp7v3QRc822 cLd9hU/8zEB+PFWcGCpTcGEbjWempkIAO0awclO/DUUAATp64pPaecjShIW+ZCZ9Ijl1rIy2hNi b/vfBhDKi48sulLcIrGhv1XF+1nKHAsBiA8OzHTXnbZEkPCSu1ecToG8Dl6xTYelmqwwQiDnzw3 QXfIMJcZqRxbPHVIiJS4e0gdB9Qi6755epzT83nWqbxMhArBdng9m8u1sn+ju4B0yWU+XwFaIW7 5ffr8b01Q/bkmqw67LB7QnYcQrtkCmA3V6fjIsP5SxCfAxB5UsFRDUHUOVGYk4IzfjiebA X-Received: by 2002:a17:90b:3b44:b0:36b:936e:73c8 with SMTP id 98e67ed59e1d1-37d1e9e7d8emr8043325a91.19.1782005379681; Sat, 20 Jun 2026 18:29:39 -0700 (PDT) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:383f:6622:5068:7fd9:7931]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c7444a9c4fsm34118905ad.75.2026.06.20.18.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jun 2026 18:29:39 -0700 (PDT) From: Deepanshu Kartikey To: axboe@kernel.dk Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+f99b00a963915b6b52c6@syzkaller.appspotmail.com Subject: [PATCH] io_uring/memmap: bound io_pin_pages() by page array byte size Date: Sun, 21 Jun 2026 06:59:33 +0530 Message-ID: <20260621012933.50571-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: 8bit io_pin_pages() checks that nr_pages does not exceed INT_MAX, then allocates a struct page * array of nr_pages entries. kvmalloc() limits allocations to INT_MAX bytes, but the check counts pages, not bytes. On 64-bit each entry is 8 bytes, so the array hits the INT_MAX byte limit at INT_MAX / sizeof(struct page *) pages, well before the page count check fires. Since commit b4e41050b212 ("io_uring/rsrc: raise registered buffer 1GB limit") raised the per-buffer cap to 1TB, a buffer near that cap maps ~2^28 pages, making the array allocation exceed INT_MAX bytes. This passes the page count check, reaches kvmalloc(), and triggers the WARN_ON_ONCE() for oversized allocations in __kvmalloc_node_noprof(). Check nr_pages against INT_MAX / sizeof(struct page *) so the buffer is rejected with -EOVERFLOW before the allocation is attempted. Reported-by: syzbot+f99b00a963915b6b52c6@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=f99b00a963915b6b52c6 Fixes: b4e41050b212 ("io_uring/rsrc: raise registered buffer 1GB limit") Tested-by: syzbot+f99b00a963915b6b52c6@syzkaller.appspotmail.com Signed-off-by: Deepanshu Kartikey --- io_uring/memmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io_uring/memmap.c b/io_uring/memmap.c index 4f9b439319c4..da1f6c5d07f8 100644 --- a/io_uring/memmap.c +++ b/io_uring/memmap.c @@ -53,7 +53,7 @@ struct page **io_pin_pages(unsigned long uaddr, unsigned long len, int *npages) nr_pages = end - start; if (WARN_ON_ONCE(!nr_pages)) return ERR_PTR(-EINVAL); - if (WARN_ON_ONCE(nr_pages > INT_MAX)) + if (nr_pages > INT_MAX / sizeof(struct page *)) return ERR_PTR(-EOVERFLOW); pages = kvmalloc_objs(struct page *, nr_pages, GFP_KERNEL_ACCOUNT); -- 2.43.0