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=unavailable 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 CD5B3C63798 for ; Wed, 25 Nov 2020 15:02:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69352206B5 for ; Wed, 25 Nov 2020 15:02:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="UySvLo+p" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729893AbgKYPC1 (ORCPT ); Wed, 25 Nov 2020 10:02:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729792AbgKYPC1 (ORCPT ); Wed, 25 Nov 2020 10:02:27 -0500 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F80AC0613D4 for ; Wed, 25 Nov 2020 07:02:27 -0800 (PST) Received: by mail-qt1-x841.google.com with SMTP id m65so1750228qte.11 for ; Wed, 25 Nov 2020 07:02:27 -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=iGkkKJ4hdiudib+5IYWtBwXCQnUA4m3vJpIv5jblv7pveQWs/nnL+eIyfbEj+1bMUL f8DgV1xDbYtgyPVl2YvM6KBvje31sehEpe+sVpm6sBIagrwFX+BNzSPfHw6TIt2ptev5 RxyUd5sOhqG1yDrGGUlpCRGHk2Y3Fcb4BU4EufVfnR6HxQhz409LHgiFHYwTPrE9aGQY Ou4O3vPF4YBhttX8ohFbRfvkaVnhaqy+9Z5TJY0I+OK7XnP9Sg6zRq4y3hO4wZeMNn0X cAUlc87B/6XaLMbV/W3TgjdTkx3/i7GndlCehngJb/qtsZ3Buo+BuAGcA9/sXSUt8sGK 3gXg== X-Gm-Message-State: AOAM532rw3PSgKVonsBZcnngl2AFIWVHEn50uO/lK3KvJ3ucu7BNYzTn TLUvUDVKppQNdOEm7tEgiLK3mg== 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> Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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