From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f176.google.com (mail-pd0-f176.google.com [209.85.192.176]) by kanga.kvack.org (Postfix) with ESMTP id EDFC16B0031 for ; Fri, 14 Feb 2014 08:05:01 -0500 (EST) Received: by mail-pd0-f176.google.com with SMTP id w10so11903259pde.7 for ; Fri, 14 Feb 2014 05:05:01 -0800 (PST) Received: from mga09.intel.com (mga09.intel.com. [134.134.136.24]) by mx.google.com with ESMTP id b4si5716560pbe.358.2014.02.14.05.05.00 for ; Fri, 14 Feb 2014 05:05:00 -0800 (PST) Date: Fri, 14 Feb 2014 21:04:50 +0800 From: Fengguang Wu Subject: [mmotm:master 97/220] fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037) Message-ID: <20140214130450.GA14755@localhost> References: <52fdd350.dwn4aII31EyWlDq9%fengguang.wu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <52fdd350.dwn4aII31EyWlDq9%fengguang.wu@intel.com> Sender: owner-linux-mm@kvack.org List-ID: To: Naoya Horiguchi Cc: kbuild-all@01.org, Johannes Weiner , Andrew Morton , Linux Memory Management List Hi Naoya, FYI, there are new smatch warnings show up in tree: git://git.cmpxchg.org/linux-mmotm.git master head: 0363f94bc1c9b81f23ee7d2446331eb288568ea7 commit: 81272031cc2831a3d1abb3c681f1188aa36a1454 [97/220] pagewalk: remove argument hmask from hugetlb_entry() fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037) vim +/vma +1042 fs/proc/task_mmu.c d9104d1c Cyrill Gorcunov 2013-09-11 1031 int flags2; 16fbdce6 Konstantin Khlebnikov 2012-05-10 1032 pagemap_entry_t pme; 81272031 Naoya Horiguchi 2014-02-13 1033 unsigned long hmask; 5dc37642 Naoya Horiguchi 2009-12-14 1034 d9104d1c Cyrill Gorcunov 2013-09-11 1035 WARN_ON_ONCE(!vma); d9104d1c Cyrill Gorcunov 2013-09-11 1036 d9104d1c Cyrill Gorcunov 2013-09-11 @1037 if (vma && (vma->vm_flags & VM_SOFTDIRTY)) d9104d1c Cyrill Gorcunov 2013-09-11 1038 flags2 = __PM_SOFT_DIRTY; d9104d1c Cyrill Gorcunov 2013-09-11 1039 else d9104d1c Cyrill Gorcunov 2013-09-11 1040 flags2 = 0; d9104d1c Cyrill Gorcunov 2013-09-11 1041 21a2f342 Naoya Horiguchi 2014-02-13 @1042 hmask = huge_page_mask(hstate_vma(vma)); 5dc37642 Naoya Horiguchi 2009-12-14 1043 for (; addr != end; addr += PAGE_SIZE) { 116354d1 Naoya Horiguchi 2010-04-06 1044 int offset = (addr & ~hmask) >> PAGE_SHIFT; d9104d1c Cyrill Gorcunov 2013-09-11 1045 huge_pte_to_pagemap_entry(&pme, pm, *pte, offset, flags2); --- 0-DAY kernel build testing backend Open Source Technology Center http://lists.01.org/mailman/listinfo/kbuild Intel Corporation -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by kanga.kvack.org (Postfix) with ESMTP id 649366B0031 for ; Fri, 14 Feb 2014 10:10:27 -0500 (EST) Received: by mail-wi0-f172.google.com with SMTP id e4so562671wiv.11 for ; Fri, 14 Feb 2014 07:10:26 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTP id k10si4114348wjb.29.2014.02.14.07.10.24 for ; Fri, 14 Feb 2014 07:10:25 -0800 (PST) Date: Fri, 14 Feb 2014 10:09:58 -0500 From: Naoya Horiguchi Message-ID: <52fe31e1.ca0ac20a.5647.5e12SMTPIN_ADDED_BROKEN@mx.google.com> In-Reply-To: <20140214130450.GA14755@localhost> References: <52fdd350.dwn4aII31EyWlDq9%fengguang.wu@intel.com> <20140214130450.GA14755@localhost> Subject: [PATCH] fs/proc/task_mmu.c: assume non-NULL vma in pagemap_hugetlb() (Re: [mmotm:master 97/220] fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037)) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit Content-Disposition: inline Sender: owner-linux-mm@kvack.org List-ID: To: Fengguang Wu Cc: kbuild-all@01.org, Johannes Weiner , Andrew Morton , Linux Memory Management List Hi Fengguang, On Fri, Feb 14, 2014 at 09:04:50PM +0800, Fengguang Wu wrote: ... > FYI, there are new smatch warnings show up in > > tree: git://git.cmpxchg.org/linux-mmotm.git master > head: 0363f94bc1c9b81f23ee7d2446331eb288568ea7 > commit: 81272031cc2831a3d1abb3c681f1188aa36a1454 [97/220] pagewalk: remove argument hmask from hugetlb_entry() > > fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037) > > vim +/vma +1042 fs/proc/task_mmu.c > > d9104d1c Cyrill Gorcunov 2013-09-11 1031 int flags2; > 16fbdce6 Konstantin Khlebnikov 2012-05-10 1032 pagemap_entry_t pme; > 81272031 Naoya Horiguchi 2014-02-13 1033 unsigned long hmask; > 5dc37642 Naoya Horiguchi 2009-12-14 1034 > d9104d1c Cyrill Gorcunov 2013-09-11 1035 WARN_ON_ONCE(!vma); > d9104d1c Cyrill Gorcunov 2013-09-11 1036 > d9104d1c Cyrill Gorcunov 2013-09-11 @1037 if (vma && (vma->vm_flags & VM_SOFTDIRTY)) > d9104d1c Cyrill Gorcunov 2013-09-11 1038 flags2 = __PM_SOFT_DIRTY; > d9104d1c Cyrill Gorcunov 2013-09-11 1039 else > d9104d1c Cyrill Gorcunov 2013-09-11 1040 flags2 = 0; > d9104d1c Cyrill Gorcunov 2013-09-11 1041 > 21a2f342 Naoya Horiguchi 2014-02-13 @1042 hmask = huge_page_mask(hstate_vma(vma)); > 5dc37642 Naoya Horiguchi 2009-12-14 1043 for (; addr != end; addr += PAGE_SIZE) { > 116354d1 Naoya Horiguchi 2010-04-06 1044 int offset = (addr & ~hmask) >> PAGE_SHIFT; > d9104d1c Cyrill Gorcunov 2013-09-11 1045 huge_pte_to_pagemap_entry(&pme, pm, *pte, offset, flags2); Thanks for reporting, here is a patch. We never have NULL vma in pagemap_hugetlb(), I added the BUG_ON check. Thanks, Naoya Horiguchi --- From: Naoya Horiguchi Date: Fri, 14 Feb 2014 09:35:06 -0500 Subject: [PATCH] fs/proc/task_mmu.c: assume non-NULL vma in pagemap_hugetlb() Fengguang reported smatch error about potential NULL pointer access. In updated page table walker, we never run ->hugetlb_entry() callback on the address without vma. This is because __walk_page_range() checks it in advance. So we can assume non-NULL vma in pagemap_hugetlb(). Reported-by: Fengguang Wu Signed-off-by: Naoya Horiguchi --- fs/proc/task_mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index f819d0d4a0e8..69aed7192254 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1032,9 +1032,9 @@ static int pagemap_hugetlb(pte_t *pte, unsigned long addr, unsigned long end, pagemap_entry_t pme; unsigned long hmask; - WARN_ON_ONCE(!vma); + BUG_ON(!vma); - if (vma && (vma->vm_flags & VM_SOFTDIRTY)) + if (vma->vm_flags & VM_SOFTDIRTY) flags2 = __PM_SOFT_DIRTY; else flags2 = 0; -- 1.8.5.3 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pb0-f43.google.com (mail-pb0-f43.google.com [209.85.160.43]) by kanga.kvack.org (Postfix) with ESMTP id 0E7146B0031 for ; Tue, 18 Feb 2014 15:44:02 -0500 (EST) Received: by mail-pb0-f43.google.com with SMTP id md12so17211249pbc.16 for ; Tue, 18 Feb 2014 12:44:02 -0800 (PST) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org. [140.211.169.12]) by mx.google.com with ESMTP id l8si19423721paa.315.2014.02.18.12.44.01 for ; Tue, 18 Feb 2014 12:44:02 -0800 (PST) Date: Tue, 18 Feb 2014 12:44:00 -0800 From: Andrew Morton Subject: Re: [PATCH] fs/proc/task_mmu.c: assume non-NULL vma in pagemap_hugetlb() (Re: [mmotm:master 97/220] fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037)) Message-Id: <20140218124400.c173bdbf42c5a32848da2f76@linux-foundation.org> In-Reply-To: <52fe31de.89cfe00a.338f.ffff9a19SMTPIN_ADDED_BROKEN@mx.google.com> References: <52fdd350.dwn4aII31EyWlDq9%fengguang.wu@intel.com> <20140214130450.GA14755@localhost> <52fe31de.89cfe00a.338f.ffff9a19SMTPIN_ADDED_BROKEN@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Naoya Horiguchi Cc: Fengguang Wu , kbuild-all@01.org, Johannes Weiner , Linux Memory Management List On Fri, 14 Feb 2014 10:09:58 -0500 Naoya Horiguchi wrote: > Fengguang reported smatch error about potential NULL pointer access. > > In updated page table walker, we never run ->hugetlb_entry() callback > on the address without vma. This is because __walk_page_range() checks > it in advance. So we can assume non-NULL vma in pagemap_hugetlb(). > > ... > > --- a/fs/proc/task_mmu.c > +++ b/fs/proc/task_mmu.c > @@ -1032,9 +1032,9 @@ static int pagemap_hugetlb(pte_t *pte, unsigned long addr, unsigned long end, > pagemap_entry_t pme; > unsigned long hmask; > > - WARN_ON_ONCE(!vma); > + BUG_ON(!vma); Let's just remove it altogether. > - if (vma && (vma->vm_flags & VM_SOFTDIRTY)) > + if (vma->vm_flags & VM_SOFTDIRTY) The null deref oops will provide us the same info as the BUG_ON. It will require a *little* more thinking to work out that `vma' was NULL, but it will be pretty obvious. This requires knowing offsetof(vm_area_struct, vm_flags). I use a gdb macro: define offsetof set $off = &(((struct $arg0 *)0)->$arg1) printf "%d 0x%x\n", $off, $off end akpm3:/usr/src/25> gdb fs/proc/task_mmu.o ... (gdb) offsetof vm_area_struct vm_flags 80 0x50 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ee0-f48.google.com (mail-ee0-f48.google.com [74.125.83.48]) by kanga.kvack.org (Postfix) with ESMTP id 805F06B0031 for ; Tue, 18 Feb 2014 16:01:43 -0500 (EST) Received: by mail-ee0-f48.google.com with SMTP id t10so7976878eei.7 for ; Tue, 18 Feb 2014 13:01:42 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTP id 43si42681405eeh.136.2014.02.18.13.01.40 for ; Tue, 18 Feb 2014 13:01:41 -0800 (PST) Date: Tue, 18 Feb 2014 16:01:15 -0500 From: Naoya Horiguchi Message-ID: <5303ca35.c3030e0a.3e0a.2a2aSMTPIN_ADDED_BROKEN@mx.google.com> In-Reply-To: <20140218124400.c173bdbf42c5a32848da2f76@linux-foundation.org> References: <52fdd350.dwn4aII31EyWlDq9%fengguang.wu@intel.com> <20140214130450.GA14755@localhost> <52fe31de.89cfe00a.338f.ffff9a19SMTPIN_ADDED_BROKEN@mx.google.com> <20140218124400.c173bdbf42c5a32848da2f76@linux-foundation.org> Subject: Re: [PATCH] fs/proc/task_mmu.c: assume non-NULL vma in pagemap_hugetlb() (Re: [mmotm:master 97/220] fs/proc/task_mmu.c:1042 pagemap_hugetlb() error: we previously assumed 'vma' could be null (see line 1037)) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit Content-Disposition: inline Sender: owner-linux-mm@kvack.org List-ID: To: akpm@linux-foundation.org Cc: fengguang.wu@intel.com, kbuild-all@01.org, hannes@cmpxchg.org, linux-mm@kvack.org On Tue, Feb 18, 2014 at 12:44:00PM -0800, Andrew Morton wrote: > On Fri, 14 Feb 2014 10:09:58 -0500 Naoya Horiguchi wrote: > > > Fengguang reported smatch error about potential NULL pointer access. > > > > In updated page table walker, we never run ->hugetlb_entry() callback > > on the address without vma. This is because __walk_page_range() checks > > it in advance. So we can assume non-NULL vma in pagemap_hugetlb(). > > > > ... > > > > --- a/fs/proc/task_mmu.c > > +++ b/fs/proc/task_mmu.c > > @@ -1032,9 +1032,9 @@ static int pagemap_hugetlb(pte_t *pte, unsigned long addr, unsigned long end, > > pagemap_entry_t pme; > > unsigned long hmask; > > > > - WARN_ON_ONCE(!vma); > > + BUG_ON(!vma); > > Let's just remove it altogether. > > > - if (vma && (vma->vm_flags & VM_SOFTDIRTY)) > > + if (vma->vm_flags & VM_SOFTDIRTY) > > The null deref oops will provide us the same info as the BUG_ON. It > will require a *little* more thinking to work out that `vma' was NULL, > but it will be pretty obvious. Yes, I agree. pagemap_hugetlb() is callback and never inlined, so we will have an info like 'NULL pointer access on pagemap_hugetlb()' with call trace, which is enough to pinpoint the problem. > > This requires knowing offsetof(vm_area_struct, vm_flags). I use a gdb macro: > > define offsetof > set $off = &(((struct $arg0 *)0)->$arg1) > printf "%d 0x%x\n", $off, $off > end > > akpm3:/usr/src/25> gdb fs/proc/task_mmu.o > ... > (gdb) offsetof vm_area_struct vm_flags > 80 0x50 Nice note, thank you. Naoya -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org