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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 44422C5519F for ; Wed, 25 Nov 2020 15:03:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8C991206F9 for ; Wed, 25 Nov 2020 15:03:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="UySvLo+p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8C991206F9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A5EAC6B0070; Wed, 25 Nov 2020 10:03:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0C536B0075; Wed, 25 Nov 2020 10:03:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8FAB06B0078; Wed, 25 Nov 2020 10:03:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id 77E836B0070 for ; Wed, 25 Nov 2020 10:03:01 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 2B547181AEF3C for ; Wed, 25 Nov 2020 15:03:01 +0000 (UTC) X-FDA: 77523258162.13.move08_0b01ba527377 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id CBCA7180585C0 for ; Wed, 25 Nov 2020 15:02:27 +0000 (UTC) X-HE-Tag: move08_0b01ba527377 X-Filterd-Recvd-Size: 4509 Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Wed, 25 Nov 2020 15:02:27 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id f27so1769873qtv.6 for ; Wed, 25 Nov 2020 07:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=25kn6N7GAyFuh1GrSD0sVV8oM/l8nQ/U6I2FAAW3FXo=; b=UySvLo+p1sgfBRX1Ny3emjTtqNUn6Vm6JQo0FJdNFg8Q3Qqc/yHWFNS49v0RaAf9nC pgF2DcYoJXm2mKZiHomLnRhriWpvl7ZPFMxvk6wozMC6qYGweFvSjiFWzMJ34jUFKrnE CX9YwKHN+6bfZLI8OjtF7BtMNM9EaJVILtsTMadjJwBap6qcSthzvAdlhvjBQeY/d+MQ t9vdPo9gPY3wEGSbvD3QDqLKZIDv4wqoAUUExWtcJ070RbA41WrWrV3I6sl2zaJ56Jxz 3SaLYgYf77VXkTin4pnk2FEu41w8HWw7ftsBUXF4viUHgTCCUkPy77ncR8fU3CgQhgJH V6xg== 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=25kn6N7GAyFuh1GrSD0sVV8oM/l8nQ/U6I2FAAW3FXo=; b=jeOmTjjZVKJm+euvpOUtSNUryrMMu3vwwl1nZOm9+N3S8B3eS+yfWqc9XlP62WgQTi qTQNcstCIHvpsZRBnzVjoQT1mK+Mx189L3zP3iiYzXHaCYhcrxVMaRpeJNrUdEQkTGOD XSF/572/nUqmOwyPu6snCdbZPxdaq5TvAr50kaUOMWd1nafshWBD15ImJwADNEQ+8cOl FgNW4wu3/35PZmrsFJcmhaiwiW4DS2lr5gb+u7szoPzMc2ndKPpeGEhUwwlOiWufHNPB jwaaN245J2iZR2qgTYWdDs+ETVo/c9Zq3HgZsLNVvx/QPd/76EL5uaBQdLZ90DWOA6R8 n/ow== X-Gm-Message-State: AOAM531A1eGrU++3oLLerDcQWmNS2qwoQj5q/BGa/5L2Wbj2G6+rAT9w GOPfybXxdmvijIzXL0EOXCl+Ew== X-Google-Smtp-Source: ABdhPJyQLe/6Gp/wsh3AE7EaQ1ssDs3UPK9nNbT6gidQ/0VvXM0dsTznYdGuPojqMf+BK6JsV58WCg== X-Received: by 2002:ac8:6943:: with SMTP id n3mr3470171qtr.22.1606316546328; Wed, 25 Nov 2020 07:02:26 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id 8sm2207396qkd.131.2020.11.25.07.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 07:02:24 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1khwJM-001HER-8s; Wed, 25 Nov 2020 11:02:24 -0400 Date: Wed, 25 Nov 2020 11:02:24 -0400 From: Jason Gunthorpe To: Dennis Dalessandro Cc: dledford@redhat.com, linux-rdma@vger.kernel.org, Mike Marciniszyn , stable@vger.kernel.org, linux-mm@kvack.org, Ira Weiny Subject: Re: [PATCH for-rc v4] IB/hfi1: Ensure correct mm is used at all times Message-ID: <20201125150224.GO5487@ziepe.ca> References: <20201123165024.158913.71029.stgit@awfm-01.aw.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201123165024.158913.71029.stgit@awfm-01.aw.intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000194, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Nov 23, 2020 at 11:50:24AM -0500, Dennis Dalessandro wrote: > @@ -133,8 +121,16 @@ void hfi1_mmu_rb_unregister(struct mmu_rb_handler *handler) > unsigned long flags; > struct list_head del_list; > > + /* > + * do_exit() calls exit_mm() before exit_files() which would call close > + * and end up in here. If there is no mm, then its a kernel thread and > + * we need to let it continue the removal. > + */ > + if (current->mm && (handler->mn.mm != current->mm)) > + return; > + > /* Unregister first so we don't get any more notifications. */ > - mmu_notifier_unregister(&handler->mn, handler->mm); > + mmu_notifier_unregister(&handler->mn, handler->mn.mm); This logic cannot be right.. The only caller does: if (pq->handler) hfi1_mmu_rb_unregister(pq->handler); [..] kfree(pq); So this is leaking the mmu_notifier registration if the user manages to trigger hfi1_user_sdma_free_queues() from another process. Since hfi1_user_sdma_free_queues() is called from close() it doesn't look OK. When the object that creates the notifier is destroyed the notifier should be deleted unconditionally. Only accesses to a VA should be qualified to ensure that a notifier is registered on current->mm before touching the VA. Jason