Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3473955imu; Sun, 11 Nov 2018 15:56:16 -0800 (PST) X-Google-Smtp-Source: AJdET5dFfyjcU3Q2dLb5CzRCv/HZ+UaddyZtj6XVvGC1FD1lnEkh51CSzIgFZ2wTynypvazplGnf X-Received: by 2002:a62:6143:: with SMTP id v64-v6mr18205995pfb.125.1541980576552; Sun, 11 Nov 2018 15:56:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980576; cv=none; d=google.com; s=arc-20160816; b=jpU2DrFiiH8k6vgT/smNQsGmfR0uN9eZ+LpVfwq8SR5facLETdIW6Nxe3Tb6zgsBvC 5yfHqBZWFxuEkQ6dt7QdHQGmWpfruVpgagOfL9V9b+6ZFrohN0LX9u3iSVkpXnP4ugID jIwij5s8GqyYD9kaDyXn6CLUQJQIREG7D9qCEOQU7IgXhXgjWKu3oY5BG7z5jgiPgFhq SAoMyUp3a7fXp8ora7QzgyDz8isay/pzUCvP5W/u5dDCKZl3sAwR7VTTmZJqBQJEtSUn KnD/H9qj4PNvEPyI3LxlO1s5H3wpZlvBnmyjFJ0xjRiUch7fZiuW6eTCXkKMFn3SDmPx WDtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qvDKwj5CogpKVuOh0U4h4U95x1v2SSAX4cgXxlZjqfg=; b=MR1BI9TGAh4X7eZOEDu2ORN0OYk4WaZ+knhGbhwJ5nfCMQKEkGJbxMJ7h449XrRtrt nfYKKz6+UavSnvXmUNENYTy5VxpTQdmueRL3FsX5us1+2UKSu9h/rlyMkn/oibXPewH/ 433t22pyOkevyeKACPKoM4mhVdAeAO8zNMFScTBZXXthkPrqPuPehFrHs1yMzObVLkOa V8ktgScrk4DsGsXuhG+K1x4AvamuBUbp40UMcttjW+UIG4/ogD89k95FI+/0u6kJl2lL LZWpPJhsGQideXr6XVHQZzpioAoZSwokBQaMYhIa3jopyXemeUu9lpNjGAgKygAcjHZA t3Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DkIRbDnG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u35si12405432pga.226.2018.11.11.15.56.01; Sun, 11 Nov 2018 15:56:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DkIRbDnG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732854AbeKLJox (ORCPT + 99 others); Mon, 12 Nov 2018 04:44:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:37256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732672AbeKLISW (ORCPT ); Mon, 12 Nov 2018 03:18:22 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2A8582154B; Sun, 11 Nov 2018 22:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975306; bh=VkCmnoKYV54fUE5TnXfod+7jBVbENISdcoXWz+Uwhi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DkIRbDnG1/xsY3PUD6cqcv9LRgQMqPiJfJK0ZbIcyRp9DvDQ61TXyyjfE30tFiDVS SYflWcEi7MzBclnoQYZu6ekOnCvBo/kYfax582TqV7sdZLLkhhDjqoqszBeQLhCfH8 JerbRXmsBtwR1/qRnxPklikFf0KO7ZqfgqDmyats= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vlastimil Babka , =?UTF-8?q?Leonardo=20Soares=20M=C3=BCller?= , Daniel Colascione , Alexey Dobriyan , Andrew Morton , Linus Torvalds Subject: [PATCH 4.19 248/361] mm: /proc/pid/smaps_rollup: fix NULL pointer deref in smaps_pte_range() Date: Sun, 11 Nov 2018 14:19:55 -0800 Message-Id: <20181111221652.951559960@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vlastimil Babka commit fa76da461bb0be13c8339d984dcf179151167c8f upstream. Leonardo reports an apparent regression in 4.19-rc7: BUG: unable to handle kernel NULL pointer dereference at 00000000000000f0 PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP PTI CPU: 3 PID: 6032 Comm: python Not tainted 4.19.0-041900rc7-lowlatency #201810071631 Hardware name: LENOVO 80UG/Toronto 4A2, BIOS 0XCN45WW 08/09/2018 RIP: 0010:smaps_pte_range+0x32d/0x540 Code: 80 00 00 00 00 74 a9 48 89 de 41 f6 40 52 40 0f 85 04 02 00 00 49 2b 30 48 c1 ee 0c 49 03 b0 98 00 00 00 49 8b 80 a0 00 00 00 <48> 8b b8 f0 00 00 00 e8 b7 ef ec ff 48 85 c0 0f 84 71 ff ff ff a8 RSP: 0018:ffffb0cbc484fb88 EFLAGS: 00010202 RAX: 0000000000000000 RBX: 0000560ddb9e9000 RCX: 0000000000000000 RDX: 0000000000000000 RSI: 0000000560ddb9e9 RDI: 0000000000000001 RBP: ffffb0cbc484fbc0 R08: ffff94a5a227a578 R09: ffff94a5a227a578 R10: 0000000000000000 R11: 0000560ddbbe7000 R12: ffffe903098ba728 R13: ffffb0cbc484fc78 R14: ffffb0cbc484fcf8 R15: ffff94a5a2e9cf48 FS: 00007f6dfb683740(0000) GS:ffff94a5aaf80000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00000000000000f0 CR3: 000000011c118001 CR4: 00000000003606e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: __walk_page_range+0x3c2/0x6f0 walk_page_vma+0x42/0x60 smap_gather_stats+0x79/0xe0 ? gather_pte_stats+0x320/0x320 ? gather_hugetlb_stats+0x70/0x70 show_smaps_rollup+0xcd/0x1c0 seq_read+0x157/0x400 __vfs_read+0x3a/0x180 ? security_file_permission+0x93/0xc0 ? security_file_permission+0x93/0xc0 vfs_read+0x8f/0x140 ksys_read+0x55/0xc0 __x64_sys_read+0x1a/0x20 do_syscall_64+0x5a/0x110 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Decoded code matched to local compilation+disassembly points to smaps_pte_entry(): } else if (unlikely(IS_ENABLED(CONFIG_SHMEM) && mss->check_shmem_swap && pte_none(*pte))) { page = find_get_entry(vma->vm_file->f_mapping, linear_page_index(vma, addr)); Here, vma->vm_file is NULL. mss->check_shmem_swap should be false in that case, however for smaps_rollup, smap_gather_stats() can set the flag true for one vma and leave it true for subsequent vma's where it should be false. To fix, reset the check_shmem_swap flag to false. There's also related bug which sets mss->swap to shmem_swapped, which in the context of smaps_rollup overwrites any value accumulated from previous vma's. Fix that as well. Note that the report suggests a regression between 4.17.19 and 4.19-rc7, which makes the 4.19 series ending with commit 258f669e7e88 ("mm: /proc/pid/smaps_rollup: convert to single value seq_file") suspicious. But the mss was reused for rollup since 493b0e9d945f ("mm: add /proc/pid/smaps_rollup") so let's play it safe with the stable backport. Link: http://lkml.kernel.org/r/555fbd1f-4ac9-0b58-dcd4-5dc4380ff7ca@suse.cz Link: https://bugzilla.kernel.org/show_bug.cgi?id=201377 Fixes: 493b0e9d945f ("mm: add /proc/pid/smaps_rollup") Signed-off-by: Vlastimil Babka Reported-by: Leonardo Soares Müller Tested-by: Leonardo Soares Müller Cc: Greg Kroah-Hartman Cc: Daniel Colascione Cc: Alexey Dobriyan Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/proc/task_mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -713,6 +713,8 @@ static void smap_gather_stats(struct vm_ smaps_walk.private = mss; #ifdef CONFIG_SHMEM + /* In case of smaps_rollup, reset the value from previous vma */ + mss->check_shmem_swap = false; if (vma->vm_file && shmem_mapping(vma->vm_file->f_mapping)) { /* * For shared or readonly shmem mappings we know that all @@ -728,7 +730,7 @@ static void smap_gather_stats(struct vm_ if (!shmem_swapped || (vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_WRITE)) { - mss->swap = shmem_swapped; + mss->swap += shmem_swapped; } else { mss->check_shmem_swap = true; smaps_walk.pte_hole = smaps_pte_hole;