From patchwork Wed Nov 20 20:11:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13881429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95D16D743D0 for ; Wed, 20 Nov 2024 20:12:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15B7D6B009C; Wed, 20 Nov 2024 15:12:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10B696B00A0; Wed, 20 Nov 2024 15:12:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F148B6B00A1; Wed, 20 Nov 2024 15:12:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D5B6E6B009C for ; Wed, 20 Nov 2024 15:12:06 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8C4D380947 for ; Wed, 20 Nov 2024 20:12:06 +0000 (UTC) X-FDA: 82807567584.27.DD174EB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 89A7D40009 for ; Wed, 20 Nov 2024 20:11:09 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BCH3fpFH; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732133432; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=r/iIx3qM/FiJprXp7nGWe2QnNAvvHTyZi+kXVMR9cYw=; b=i3per3g79aeuEw7O3BvapuW5+vDJhAgsx9felgs4wqjqO4I5GVzLK9L6enjpTmSH4M3fIW mvoe8/fHXDrxhOHV8Qsmb0E7S2bJr8hAoy9jtloTt+J4XenecapxxTSBuRJVghwl++LtAY mbXj0kSMWnXw5rfwMDDkBfIlq0V6sd0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732133432; a=rsa-sha256; cv=none; b=p+fN87f85NeID0fEhMuBY9S0nTWRQNuAmaiM6ONPHTfhFpMV2bKQe0IKr2QaulNvVlIPbx eZiTrZIy50wuvwyzv1KiIm5LTlSuXjKI7IQHxu+7piTYd7v61/3FRTsy24MZU+cEzaGxBw u/j76j6wxZA3ZwXImHWUnK2tTD+o/+8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=BCH3fpFH; spf=pass (imf27.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732133524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=r/iIx3qM/FiJprXp7nGWe2QnNAvvHTyZi+kXVMR9cYw=; b=BCH3fpFHNVOlJsaqqkLQdVahyhHidnCoAcBQMUtzE98f2EqqlU/hBEFb9befD5mTnhPpJa GX+Te5SHkqdaFiVUESeDosUHji6qt8yEgXpGHy/K4qKBcgPnZTAMGyWUFl1qxTRhhWbE7v x2XwtVCuvJ6pJWAvJoqrjH9MW6pfnRE= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-641-W81dEQBSPiCgkHyzCEpD_g-1; Wed, 20 Nov 2024 15:12:01 -0500 X-MC-Unique: W81dEQBSPiCgkHyzCEpD_g-1 X-Mimecast-MFC-AGG-ID: W81dEQBSPiCgkHyzCEpD_g Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7789F195604F; Wed, 20 Nov 2024 20:11:59 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.22.80.45]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 65BCB19560A3; Wed, 20 Nov 2024 20:11:53 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , syzbot+3511625422f7aa637f0d@syzkaller.appspotmail.com, stable@vger.kernel.org, Andrew Morton , Christoph Lameter , "Liam R. Howlett" Subject: [PATCH v1] mm/mempolicy: fix migrate_to_node() assuming there is at least one VMA in a MM Date: Wed, 20 Nov 2024 21:11:51 +0100 Message-ID: <20241120201151.9518-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspamd-Server: rspam10 X-Stat-Signature: ge4zbdt93egzmnwe4zsendbt8t4z51oa X-Rspamd-Queue-Id: 89A7D40009 X-Rspam-User: X-HE-Tag: 1732133469-711626 X-HE-Meta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3lNX7Ih8yRSgAlIRRUY2iIPdMxN+/xRa7tn6Tkuc6QFX3p5q7txCIZf0J5lMTyeRk1iEFzwLwpP/wh+7B66j5G2RvkRyNKN4HIN2X4pkeRo28wzy4ews/XOouV3PPf3y8KRp6oSddA6VBrEZKdAnoE+nSW4kOt+WDuqzmJVUJ6vNMew/O+b6WJExtM+nbnKl5Za2XPS5ldwAiS7iruFfMrs/+VgBsFaum0SeVlLOCFvk3keP7e2D6XHICpx1920B9yS6P28Kg2DkpLx6Yhi8ZivLYEGpFDZWpiVN1H68o5FTQ6LObC0YfwrxBz7Wu4W722arqgUu8Z9H9EUicerS+3HGsk1lWdSYMfCb1BdJl5JhsBcX3t5JOQ4WTTYecM2RT8jnmCpqvmUCbuUELV2WGcBhgtGjh1gFQU0OorvORHhykO+H+njU+N1BHsrCxuql0kpXO0Qo8inC3Z3z0pUytvueRkWQwBDQ50eu/EenoxMhcpoEKhtx6AEGiYY+ezW7wWLBRj9gyXIT4teXN6dMsK6VQxAiKuMRLWDN+p3AmWuWVj7AYk2NhTsG8udc7yBG4EFav9HZCG4AU+QC0WWQcMBLQFTPhhZ0O7vmcqBupza+l5zMryoTDIYTBQZGW5vVGHoueqmyLCh32weKolG1hPap9LODHZk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: We currently assume that there is at least one VMA in a MM, which isn't true. So we might end up having find_vma() return NULL, to then de-reference NULL. So properly handle find_vma() returning NULL. This fixes the report: Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 1 UID: 0 PID: 6021 Comm: syz-executor284 Not tainted 6.12.0-rc7-syzkaller-00187-gf868cd251776 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/30/2024 RIP: 0010:migrate_to_node mm/mempolicy.c:1090 [inline] RIP: 0010:do_migrate_pages+0x403/0x6f0 mm/mempolicy.c:1194 Code: ... RSP: 0018:ffffc9000375fd08 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffffc9000375fd78 RCX: 0000000000000000 RDX: ffff88807e171300 RSI: dffffc0000000000 RDI: ffff88803390c044 RBP: ffff88807e171428 R08: 0000000000000014 R09: fffffbfff2039ef1 R10: ffffffff901cf78f R11: 0000000000000000 R12: 0000000000000003 R13: ffffc9000375fe90 R14: ffffc9000375fe98 R15: ffffc9000375fdf8 FS: 00005555919e1380(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00005555919e1ca8 CR3: 000000007f12a000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: kernel_migrate_pages+0x5b2/0x750 mm/mempolicy.c:1709 __do_sys_migrate_pages mm/mempolicy.c:1727 [inline] __se_sys_migrate_pages mm/mempolicy.c:1723 [inline] __x64_sys_migrate_pages+0x96/0x100 mm/mempolicy.c:1723 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f Fixes: 39743889aaf7 ("[PATCH] Swap Migration V5: sys_migrate_pages interface") Reported-by: syzbot+3511625422f7aa637f0d@syzkaller.appspotmail.com Closes: https://lore.kernel.org/lkml/673d2696.050a0220.3c9d61.012f.GAE@google.com/T/ Cc: Cc: Andrew Morton Cc: Christoph Lameter Cc: Liam R. Howlett Signed-off-by: David Hildenbrand Reviewed-by: Liam R. Howlett --- mm/mempolicy.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b646fab3e45e1..fbb6127e4595a 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1080,6 +1080,10 @@ static long migrate_to_node(struct mm_struct *mm, int source, int dest, mmap_read_lock(mm); vma = find_vma(mm, 0); + if (!vma) { + mmap_read_unlock(mm); + return 0; + } /* * This does not migrate the range, but isolates all pages that