From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E3DCC18E5B for ; Wed, 11 Mar 2020 09:19:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C536C20848 for ; Wed, 11 Mar 2020 09:19:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=shutemov-name.20150623.gappssmtp.com header.i=@shutemov-name.20150623.gappssmtp.com header.b="MeiG0ySx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C536C20848 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 8B72D6B0003; Wed, 11 Mar 2020 05:19:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 867566B0006; Wed, 11 Mar 2020 05:19:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72F8B6B0007; Wed, 11 Mar 2020 05:19:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 586276B0003 for ; Wed, 11 Mar 2020 05:19:45 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D79624DC4 for ; Wed, 11 Mar 2020 09:19:44 +0000 (UTC) X-FDA: 76582533888.11.work14_37f5b37950512 X-HE-Tag: work14_37f5b37950512 X-Filterd-Recvd-Size: 5579 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Wed, 11 Mar 2020 09:19:44 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id u12so1492491ljo.2 for ; Wed, 11 Mar 2020 02:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=qFoY1cRa0baFLB6iQfLGKlgiwVVq7ztIL3DzH5QG8uA=; b=MeiG0ySxJV+NwAAkF72C8YzIeVy3/2sDU+RKIyPNYmmdJc7Yt6NECQA4/lvV+IVtGt G011pAR/VXcOdI7nv6K3ls9DIViIKy6FTxDXp6/dhJ6VO2P+jPAguUMmaa/3S13gc77k ECriDsEsQF96qHC2nqmMHKmhQZj/JwJyTR6Oim41zXN/pLGhGxPOCUja4sEm7mmncmFm Ic6HrEHxxSxofwdICl9gBil7YRVV9Iz0inbiwmFgx+dz3xerSOSBhkiUH+q1KZO2cIPd 3pQhxMOhpneI9n3hPdW5uwS2JdljfV8FM1cQBZRbVBdaOCfdJ+RXiWyqsxnHsg7YbpCe CTIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=qFoY1cRa0baFLB6iQfLGKlgiwVVq7ztIL3DzH5QG8uA=; b=CS161+Oz4QBneyChic3FcNuPfStUt+EMWbhxnGhdyMSxkIjj8+gXAumjBpcUXf0kGD 3+bHYgfG0qdRnJqGI1y335b6ex39hkxvHVMYh648x+AbfSXiRy2NYSwJOzLeDkpR//SY vPtDZgYJTAtPVoHkdYn0CQhk2+z68Xbbn/rLCiy9b7YDGVrtxDw+YoRp/4CFqI75rEjf jWVoDLwFFXWUOcLyU/2hGEZhvf18P/8rUsv5qt/NM9+zR2dEh3ze8IGEht1RmOLNmdei CDGXE2IfOIIyrRuHnkfaAb3Ne3nPdgt4nn51KlKVAMo0njgjRLT6oUj/pLzDwIskm8dW 4WtA== X-Gm-Message-State: ANhLgQ0dUvgH+x9PvNEM4HPJOtQKIf+WUGAJ+hsZl+8Jblo30tJsBD/v ivqQIdWeGuaTdEB6e41vnfIvBw== X-Google-Smtp-Source: ADFU+vvjbow58EUhRem1mZuZUdEm0U/1AWqPIq5gPVweuiqCd4UkXeShJ85sAfmlOpReC/P8DI5C4g== X-Received: by 2002:a05:651c:1026:: with SMTP id w6mr1501965ljm.168.1583918382846; Wed, 11 Mar 2020 02:19:42 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id 124sm8942925lfb.28.2020.03.11.02.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2020 02:19:42 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 688E210142E; Wed, 11 Mar 2020 12:19:43 +0300 (+03) Date: Wed, 11 Mar 2020 12:19:43 +0300 From: "Kirill A. Shutemov" To: qiwuchen55@gmail.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, chenqiwu Subject: Re: [PATCH] mm/rmap: ensure the validity of mapping vma which referenced an anon page Message-ID: <20200311091943.szpvgb3tsc6ss74z@box> References: <1583912713-30778-1-git-send-email-qiwuchen55@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1583912713-30778-1-git-send-email-qiwuchen55@gmail.com> 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: On Wed, Mar 11, 2020 at 03:45:13PM +0800, qiwuchen55@gmail.com wrote: > From: chenqiwu > > When finding all the mapping vmas for an anon page by anon_vma, there > is a panic risk that one mapping vma or its vm_mm has been released by > someone. What? Who would be able to release the VMA or the mm_struct? We hold anon_vma lock. It doesn't make sense to me. Something else is broken. > Like the following crash during kswapd reclaiming pages: > > Unable to handle kernel NULL pointer dereference at virtual address > 00000048 > PC is at page_vma_mapped_walk+0x54/0x16c > LR is at page_referenced_one+0x44/0x140 > [......] > CPU: 1 PID: 161 Comm: kswapd0 > Call trace: > [] el1_da+0x24/0x3c > [] page_vma_mapped_walk+0x54/0x16c > [] page_referenced_one+0x44/0x140 > [] rmap_walk_anon+0x124/0x168 > [] page_referenced+0x144/0x190 > [] shrink_active_list+0x25c/0x478 > [] kswapd+0x7b0/0x9c8 > [] kthread+0x154/0x18c > [] ret_from_fork+0x10/0x18 > > The PC is pointed to the following code line: > bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) > { > struct mm_struct *mm = pvmw->vma->vm_mm; > ...... > pgd = pgd_offset(mm, pvmw->address); //PC > ...... > } > > Because the current pvmw->vma->vm_mm is a kernel NULL pointer, which > causing crash when pgd_offset() dereferences the mm pointer. > > This patch fixes the problem by ensuring that both the mapping vma > and its vm_mm are valid. If not, we just continue to traverse the > anon_vma->rb_root to avoid the potential junk pointer dereference. > > Signed-off-by: chenqiwu > --- > mm/rmap.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/mm/rmap.c b/mm/rmap.c > index b3e3819..fc42ca2 100644 > --- a/mm/rmap.c > +++ b/mm/rmap.c > @@ -1863,6 +1863,9 @@ static void rmap_walk_anon(struct page *page, struct rmap_walk_control *rwc, > if (rwc->invalid_vma && rwc->invalid_vma(vma, rwc->arg)) > continue; > > + if (!vma && !vma->vm_mm) > + continue; > + Even if the premis of the patch is true, 'vma' got used twice in the loop iteration before you check if it's non-NULL. > if (!rwc->rmap_one(page, vma, address, rwc->arg)) > break; > if (rwc->done && rwc->done(page)) > -- > 1.9.1 > > -- Kirill A. Shutemov