Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3430440imu; Sun, 11 Nov 2018 14:56:47 -0800 (PST) X-Google-Smtp-Source: AJdET5d28Ly7TMzP4b+Kas3VS4MbXwn8DqRVZIj0JemU2kCsYShoCvMXymRcIEDC3L63+1lcZGyA X-Received: by 2002:a63:fd53:: with SMTP id m19mr15597568pgj.340.1541977007721; Sun, 11 Nov 2018 14:56:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977007; cv=none; d=google.com; s=arc-20160816; b=HgRfapHcVBKvyIe7Gh7GXbKlyqmaJYGfuyQ35m+z0yRVy6IwuO6nRr0bTv2b2gkl0W K+2FFFejQRa+sjZG7vMPF4j8TA63g5z0iZY9tn7GvcLZmI36Jn7Zzk/b2lHp0LDvSNY3 W3TP00Q8guXp3znplFJYgI+djh/XHAMSl5XOyYhRfhJP+s2iKath2Nb8zz5mOw7Je+WB SB4giMYbbATeOWfGo8LCtF5Rf3rE9SstC1DPB4/UfXSourChjcAkxBcVFzX7lGwY5zQR rt1VHowTCKFFUVvTVahjpGo3pP5m2hc3Z1ljTSWUhmZLaZlXGGDrv6sUoypBCWzArJ/B eTkg== 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=MtpBdFdTx2n1VBoh+peC0+DSYpzuwzeeiekwSxz1y5w=; b=t5qbYEVFYYW/OLJ20g+5Qe1y0beeMcfmobWd9XwQubpuMIGg4wJX19AGoctSoA7u4s mhn6lRXpztOV/be4NkvP8gsG8NleSmQARvS2ZfsGcL17gUHtoav2/cMqYG3CxCllVJc0 g9+NlLQ443hlT4KxTuIHW4/gF087TyAhYGIJG6J/TA5zJeiKjqcKfWKSNUBkDRCBfNQF SOHHYFGw9jcUHhvnXbG+Nqn3+OSvWpewAtX/moCDKxkGDBUwnLG+qrKnAH2WRzdIGXuI i22QJeiVlmk6yUEHlTR6Exx6fIYEFqpm3SgdxZqHX53z46UBHnL88GDshEbXx2ui9IXs CVmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zJFkhb29; 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 cf14-v6si15630151plb.422.2018.11.11.14.56.32; Sun, 11 Nov 2018 14:56:47 -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=zJFkhb29; 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 S2404055AbeKLIqR (ORCPT + 99 others); Mon, 12 Nov 2018 03:46:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:54672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403871AbeKLIWw (ORCPT ); Mon, 12 Nov 2018 03:22:52 -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 73E2F223C8; Sun, 11 Nov 2018 22:32:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975574; bh=KZjLsz0b5dGN/fSW03RPMFHtOGt73g+L+ymvp1RmhXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zJFkhb29Si0pNvQWjUSQtFCbXLYOaBKVG20yIPR33Yc7I6DTYlcQXiJPfXAp4U6y/ JmhpJ+cxl4NwT8XuoKN96517vMQPNUAr9sHO6iSbOulLTF8RMw9OwLvN7nRxCfJeg/ i/8/Xf2KWf3CEnYpZYprL+saOugta9ad1bSIRsEw= 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.14 153/222] mm: /proc/pid/smaps_rollup: fix NULL pointer deref in smaps_pte_range() Date: Sun, 11 Nov 2018 14:24:10 -0800 Message-Id: <20181111221701.045080094@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -768,6 +768,8 @@ static int show_smap(struct seq_file *m, 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 @@ -783,7 +785,7 @@ static int show_smap(struct seq_file *m, 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;