From nobody Thu Oct 2 04:47:04 2025 Received: from pdx-out-014.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-014.esa.us-west-2.outbound.mail-perimeter.amazon.com [35.83.148.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46351277CBF; Mon, 22 Sep 2025 08:17:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.83.148.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758529053; cv=none; b=diuOSdMxH/Ly30pUJL7G0KLGyqG1II5rwoxV/QHRCWHL4ynJlLEwncHOG6m4P7a+MgmXnsuXH1LgOS7MEt4xlbCm/QibNogjM+j2zaRzk/c6rYnTo753mCue8KCMiMp6RTWrFcJ/HggkWW+9bs6LaP83Ag1g2TUrV19pQOymwp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758529053; c=relaxed/simple; bh=ojhBJOxHhGb0SD01wdfc89xOlCTZBkPkITxJQOsz22U=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=e5v82T9CHcSoSng2BvMe6a6YzQP1wf3SYOKNQyZqF/kR3hcuhUsA5+tJ6bWeEQkLqtmp0ptFv6N/QUu2jeXlvwVf1o7l5AKhCQE8txdP4s2BA6J6RxTOT1RKdcE/IuVqSuPoigxkKw0ddXP+4Ob/oI+wpcOvDaY9y7NbU0dsq6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=N2AD/avK; arc=none smtp.client-ip=35.83.148.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="N2AD/avK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1758529051; x=1790065051; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ojhBJOxHhGb0SD01wdfc89xOlCTZBkPkITxJQOsz22U=; b=N2AD/avKphuxD/FakiUcMR+tWl0dFTNVv4YXqUPe4gIxweWlbccdxocI OwONHQ0X+9d1OfWMaeznF204KXyBKjdlHtWTzyrIXqLOA6agC7l+UuFR2 C0xINl7QI0vAE8sVJNdDc0zx+UBrwXU5qS08sLF6E196QkIer3L9OwxA2 L4gQmq5yO1relmclBPEhHaluaWcda4fCCnHXdRe7rBxaLXpRHp2kC6ciy qlepgNdk0xTrA7dpihCjPkj3B5KzfQ7cBcRSQJci9jqcqlELx4K0mszlL zpqnM529TB421RunDIjPWycss295TSt8awy71NStJuwJv91GIcTKGkILX A==; X-CSE-ConnectionGUID: K9Z+0Zg9R9y8wImayrYigw== X-CSE-MsgGUID: NyDjXeDGQeioh0WBkX8VTQ== X-IronPort-AV: E=Sophos;i="6.18,284,1751241600"; d="scan'208";a="3343833" Received: from ip-10-5-9-48.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.9.48]) by internal-pdx-out-014.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2025 08:17:29 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.38.20:31320] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.25.189:2525] with esmtp (Farcaster) id 9a698592-8561-49e5-b6d8-e6c1950d1a64; Mon, 22 Sep 2025 08:17:29 +0000 (UTC) X-Farcaster-Flow-ID: 9a698592-8561-49e5-b6d8-e6c1950d1a64 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 08:17:28 +0000 Received: from dev-dsk-acsjakub-1b-6f9934e2.eu-west-1.amazon.com (172.19.75.107) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Mon, 22 Sep 2025 08:17:26 +0000 From: Jakub Acs To: CC: , Andrew Morton , "David Hildenbrand" , Vlastimil Babka , "Lorenzo Stoakes" , Jinjiang Tu , Suren Baghdasaryan , Penglei Jiang , Mark Brown , Baolin Wang , Ryan Roberts , "Andrei Vagin" , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Stephen Rothwell , "Muhammad Usama Anjum" , , Subject: [PATCH v2] fs/proc: check p->vec_buf for NULL Date: Mon, 22 Sep 2025 08:17:13 +0000 Message-ID: <20250922081713.77303-1-acsjakub@amazon.de> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D043UWC001.ant.amazon.com (10.13.139.202) To EX19D001UWA001.ant.amazon.com (10.13.138.214) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When PAGEMAP_SCAN ioctl invoked with vec_len =3D 0 reaches pagemap_scan_backout_range(), kernel panics with null-ptr-deref: [ 44.936808] Oops: general protection fault, probably for non-canonical a= ddress 0xdffffc0000000000: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN NOPTI [ 44.937797] KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000= 000000007] [ 44.938391] CPU: 1 UID: 0 PID: 2480 Comm: reproducer Not tainted 6.17.0-= rc6 #22 PREEMPT(none) [ 44.939062] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS = rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 [ 44.939935] RIP: 0010:pagemap_scan_thp_entry.isra.0+0x741/0xa80 [ 44.946828] Call Trace: [ 44.947030] [ 44.949219] pagemap_scan_pmd_entry+0xec/0xfa0 [ 44.952593] walk_pmd_range.isra.0+0x302/0x910 [ 44.954069] walk_pud_range.isra.0+0x419/0x790 [ 44.954427] walk_p4d_range+0x41e/0x620 [ 44.954743] walk_pgd_range+0x31e/0x630 [ 44.955057] __walk_page_range+0x160/0x670 [ 44.956883] walk_page_range_mm+0x408/0x980 [ 44.958677] walk_page_range+0x66/0x90 [ 44.958984] do_pagemap_scan+0x28d/0x9c0 [ 44.961833] do_pagemap_cmd+0x59/0x80 [ 44.962484] __x64_sys_ioctl+0x18d/0x210 [ 44.962804] do_syscall_64+0x5b/0x290 [ 44.963111] entry_SYSCALL_64_after_hwframe+0x76/0x7e vec_len =3D 0 in pagemap_scan_init_bounce_buffer() means no buffers are allocated and p->vec_buf remains set to NULL. This breaks an assumption made later in pagemap_scan_backout_range(), that page_region is always allocated for p->vec_buf_index. Fix it by explicitly checking p->vec_buf for NULL before dereferencing. Other sites that might run into same deref-issue are already (directly or transitively) protected by checking p->vec_buf. Note: From PAGEMAP_SCAN man page, it seems vec_len =3D 0 is valid when no output is requested and it's only the side effects caller is interested in, hence it passes check in pagemap_scan_get_args(). This issue was found by syzkaller. Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optional= ly clear info about PTEs") Signed-off-by: Jakub Acs Cc: Andrew Morton Cc: David Hildenbrand Cc: Vlastimil Babka Cc: Lorenzo Stoakes Cc: Jinjiang Tu Cc: Suren Baghdasaryan Cc: Penglei Jiang Cc: Mark Brown Cc: Baolin Wang Cc: Ryan Roberts Cc: Andrei Vagin Cc: "Micha=C5=82 Miros=C5=82aw" Cc: Stephen Rothwell Cc: Muhammad Usama Anjum Cc: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: stable@vger.kernel.org Acked-by: Andrei Vagin Acked-by: David Hildenbrand --- fs/proc/task_mmu.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 29cca0e6d0ff..b26ae556b446 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2417,6 +2417,9 @@ static void pagemap_scan_backout_range(struct pagemap= _scan_private *p, { struct page_region *cur_buf =3D &p->vec_buf[p->vec_buf_index]; =20 + if (!p->vec_buf) + return; + if (cur_buf->start !=3D addr) cur_buf->end =3D addr; else --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597