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=-7.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 9F187C4727F for ; Tue, 29 Sep 2020 00:52:41 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 06F8A21734 for ; Tue, 29 Sep 2020 00:52:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="Efa/bidO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06F8A21734 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 185A86B005C; Mon, 28 Sep 2020 20:52:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1364A6B005D; Mon, 28 Sep 2020 20:52:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04AD76B0062; Mon, 28 Sep 2020 20:52:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0141.hostedemail.com [216.40.44.141]) by kanga.kvack.org (Postfix) with ESMTP id E27906B005C for ; Mon, 28 Sep 2020 20:52:39 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9756C180AD801 for ; Tue, 29 Sep 2020 00:52:39 +0000 (UTC) X-FDA: 77314273638.30.brass66_2b0383a27186 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 76C04180B3C83 for ; Tue, 29 Sep 2020 00:52:39 +0000 (UTC) X-HE-Tag: brass66_2b0383a27186 X-Filterd-Recvd-Size: 3706 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Tue, 29 Sep 2020 00:52:39 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A171B20773; Tue, 29 Sep 2020 00:52:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601340758; bh=0mD0MAsSQmXLf32VYY8kxZxsnPJYB0TcFxo5l/cuL70=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Efa/bidOdurmZfr9p+9R/k4FZ7AS6e2cwywwVg2KEz3zX8Kk9Ee89Ldc4Zt+Hl2mQ i1lo46/fajIIrxhMyxijl2kIdyCKiH3Mz1xoWdnOYB2Lku5aN3Kk75rii1PbeSHZ4R o5qg6sRE9NF20GUG7peQ7fQkJrWdy2p+fcgTmTDc= Date: Mon, 28 Sep 2020 17:52:37 -0700 From: Andrew Morton To: Jason Gunthorpe Cc: Dan Carpenter , =?ISO-8859-1?Q?J=E9r=F4me?= Glisse , Markus Elfring , Dan Williams , Wei Yongjun , Ralph Campbell , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH v3] mm/hmm/test: use after free in dmirror_allocate_chunk() Message-Id: <20200928175237.6b3024fe6ad96d70c75d5de1@linux-foundation.org> In-Reply-To: <20200926221720.GK9916@ziepe.ca> References: <20200926121402.GA7467@kadam> <20200926221720.GK9916@ziepe.ca> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Sat, 26 Sep 2020 19:17:20 -0300 Jason Gunthorpe wrote: > On Sat, Sep 26, 2020 at 03:14:02PM +0300, Dan Carpenter wrote: > > The error handling code does this: > > > > err_free: > > kfree(devmem); > > ^^^^^^^^^^^^^ > > err_release: > > release_mem_region(devmem->pagemap.range.start, range_len(&devmem->pagemap.range)); > > ^^^^^^^^ > > The problem is that when we use "devmem->pagemap.range.start" the > > "devmem" pointer is either NULL or freed. > > > > Neither the allocation nor the call to request_free_mem_region() has to > > be done under the lock so I moved those to the start of the function. > > > > Fixes: 1f9c4bb986d9 ("mm/memremap_pages: convert to 'struct range'") > > Signed-off-by: Dan Carpenter > > Reviewed-by: Ralph Campbell > > --- > > v2: The first version introduced a locking bug > > v3: Markus Elfring pointed out that the Fixes tag was wrong. This bug > > was in the original commit and then fixed and then re-introduced. I was > > quite bothered by how this bug lasted so long in the source code, but > > now we know. As soon as it is introduced we fixed it. > > > > One problem with the kernel QC process is that I think everyone marks > > the bug as "old/dealt with" so it was only because I was added a new > > check for resource leaks that it was found when it was re-introduced. > > > > lib/test_hmm.c | 44 ++++++++++++++++++++++---------------------- > > 1 file changed, 22 insertions(+), 22 deletions(-) > > Hi Andrew, > > I don't have have any hmm related patches this cycle, can you take > this into your tree? > > Reviewed-by: Jason Gunthorpe Thanks. It's actually a fix against Dan Williams' -mm patch "mm/memremap_pages: convert to 'struct range'"