From patchwork Tue Sep 1 00:01:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jann Horn X-Patchwork-Id: 11747125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D19E814E5 for ; Tue, 1 Sep 2020 00:02:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8751220866 for ; Tue, 1 Sep 2020 00:02:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Rp5RQjtH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8751220866 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9BC456B0003; Mon, 31 Aug 2020 20:02:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 96D616B0037; Mon, 31 Aug 2020 20:02:34 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AA9D6B0055; Mon, 31 Aug 2020 20:02:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 73F0E6B0003 for ; Mon, 31 Aug 2020 20:02:34 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3A62F180AD807 for ; Tue, 1 Sep 2020 00:02:34 +0000 (UTC) X-FDA: 77212541028.07.kite09_2e0c2ec27093 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin07.hostedemail.com (Postfix) with ESMTP id 0D3B71803F9A1 for ; Tue, 1 Sep 2020 00:02:34 +0000 (UTC) X-Spam-Summary: 10,1,0,26b01cd3b1e09a8d,d41d8cd98f00b204,3mi9nxwukco0ypccwvddvat.rdbaxcjm-bbzkprz.dgv@flex--jannh.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:968:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2691:2909:3138:3139:3140:3141:3142:3152:3352:3865:3867:3868:3870:3871:3872:3874:4250:5007:6261:6653:8660:9969:10004:10400:11026:11232:11658:11914:12043:12114:12266:12296:12297:12438:12555:12663:12679:12895:13069:13148:13161:13229:13230:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21433:21444:21451:21611:21627:21889:21939:21987:21990:30016:30054:30070,0,RBL:209.85.219.202:@flex--jannh.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yr3ozttyj8bcxj66kjhyhez9wziyptjgcu9jfc34otgsfinsk5tnkekhd8nwx.9p8eeaqs5wegfdsu4scz7dohiu1bfdybt153kmzkm1insbkaxfgt85dt3txbgee.w-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF X-HE-Tag: kite09_2e0c2ec27093 X-Filterd-Recvd-Size: 4021 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Sep 2020 00:02:33 +0000 (UTC) Received: by mail-yb1-f202.google.com with SMTP id a14so10885800ybm.13 for ; Mon, 31 Aug 2020 17:02:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=/WK1I/ZsCqLXTjRuojbNjOezx7X+DvJD8ltypu8xs/g=; b=Rp5RQjtHdrOV9oOAdw+rlYP2b8FmTtHIgndUhzBsN6m2ht3rZ2dwnn8NuxI3w4UGT8 0J1LvrZkq4Lbr+l2dtcWKk+8RLUmXANtSDp10Uj9+GdaIMrkQu8TnpXfaQgWMcg93dej MIqACyfGvzUbrr5quNyAz+OwT49UB7EXJMfC91936uBlOeeDzjZkjTxvE7fXXhyhYhcX liBOmUqrs7fmCKcXilVo1NsHB6vvjsU2Kuy60NsXLe4saEIomU1vLqMoDK9cdIor/P0M iuTlHQW0c8U+yeM0rjV0VZ0otUkH4w/kl/1e/P8iES0nrVbuhU3CW1EEwdMGB2btJGoI gSug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=/WK1I/ZsCqLXTjRuojbNjOezx7X+DvJD8ltypu8xs/g=; b=I0m4h0F1CLvh7gWegWnRRgZJLYAk2hehyhsdn6idgvlIOTuzYaoI0lqkhXd0Mopvbp ngQ1qwtF/zXe7iDF2D4yyj0Yie6SXIpITEJJiYcEJT8SsCZUivUtVO5RT0dr+OIetF0V nFpeBd5pzBB4wFzx+tCIjBihiuxxKs3ksGupBnJVaEco+GZMzuIbk5viPNYoXusUmdNC tgC/o3S4+avUi2/e0ipojNH4lCtPvxw5IbSHrzrMKUDAQCQFVUF0LlfCIx9KKlEpdgK1 6IEyW9vep9jcjLYZBBYX1I/XsE8+gJJ9VQ1uYKVBGjbB7bvce5fMvcHbWAnl7poYuks7 JiSQ== X-Gm-Message-State: AOAM531Mn2+2kME36dOsb9zh6j7UCukotgleXfefdn0Ui0qDQmLIHbeq yTj+ypfGU5X25HL6Nzfh1ot2lmzeCw== X-Google-Smtp-Source: ABdhPJwa8OHde2lQYnBK4sl7X9zvZNhHYLqhFJDFsng0d53MBPOB6RRRkl9jFfyBnOl/wZCGnBHzMaDZTg== X-Received: from jannh2.zrh.corp.google.com ([2a00:79e0:1b:201:1a60:24ff:fea6:bf44]) (user=jannh job=sendgmr) by 2002:a25:40cb:: with SMTP id n194mr6162269yba.7.1598918552892; Mon, 31 Aug 2020 17:02:32 -0700 (PDT) Date: Tue, 1 Sep 2020 02:01:43 +0200 Message-Id: <20200901000143.207585-1-jannh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.28.0.402.g5ffc5be6b7-goog Subject: [PATCH] mm/mmu_notifier: Fix mmget() assert in __mmu_interval_notifier_insert From: Jann Horn To: Andrew Morton Cc: linux-mm@kvack.org, Jason Gunthorpe , John Hubbard , Christoph Hellwig , linux-kernel@vger.kernel.org, " =?utf-8?q?Christian_K=C3=B6nig?= " X-Rspamd-Queue-Id: 0D3B71803F9A1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The comment talks about having to hold mmget() (which means mm_users), but the actual check is on mm_count (which would be mmgrab()). Given that MMU notifiers are torn down in mmput() -> __mmput() -> exit_mmap() -> mmu_notifier_release(), I believe that the comment is correct and the check should be on mm->mm_users. Fix it up accordingly. Fixes: 99cb252f5e68 ("mm/mmu_notifier: add an interval tree notifier") Signed-off-by: Jann Horn Reviewed-by: Jason Gunthorpe --- Can someone please double-check this? I'm like 90% sure that I fixed this the right way around, but it'd be good if someone more familiar with mmu notifiers could confirm. mm/mmu_notifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) base-commit: 15bc20c6af4ceee97a1f90b43c0e386643c071b4 diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 4fc918163dd3..5654dd19addc 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -913,7 +913,7 @@ static int __mmu_interval_notifier_insert( return -EOVERFLOW; /* Must call with a mmget() held */ - if (WARN_ON(atomic_read(&mm->mm_count) <= 0)) + if (WARN_ON(atomic_read(&mm->mm_users) <= 0)) return -EINVAL; /* pairs with mmdrop in mmu_interval_notifier_remove() */