Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3422138pxk; Mon, 28 Sep 2020 17:54:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwC0X9E+obF2KmkBrRp2oYowSD/kfb/oEcurfeZcBENEJUAXR1LmALxtGeMgVCTosihUWkj X-Received: by 2002:a50:d94d:: with SMTP id u13mr613618edj.365.1601340884039; Mon, 28 Sep 2020 17:54:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601340884; cv=none; d=google.com; s=arc-20160816; b=URIeYsvihgydBDEqASAHCzElkzMsi2VUiH8r2nUZkuBwEv1ksIxHTaEqHcQUsKvJi2 3uwNQ9pgA9eVDyKPMA8N8vODa+EmBZZ5D4Vn6xhRZzNEfqJKrEiqerWTVXr72+E4ck8t vB/7G+VeRosCopH3psfmUlph3jnNEdDDF1MmKDeOW5suVjeob73rvqRSRtW1/CxByx5S 3Fw/lG4PmarWK3kc95N5dxlvc5OZHG3L4MAf3B1UQ3lb7yklFSfuS/pPlb7QTBBoz7Ox GaWHxjqTnOFMEjmvGDvCSmvjqT1/UOkAL8GvW9GnjZOZQxD8BlVrBYf+j0aKqHYy5+3r 1oUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=iIqx90sL6QQUstHq3ZoY1fK421Z7nvowmGlIoml3H7M=; b=kQ2JbJsbEwQzLzw6mhVam9umks/Llvzun5updhmnTpxMKJBwyiJpB8ylzmq1naPhIG ny7VMOvKjsZM2DMXADkbGIcVgCve39EKCVJ880oE1DCEvBW5mVG5muINEUnBAuESvj0n ADR+xHGjFGDLSgHh1oYGwHIQQgRukBYiny7PDBatzM+I6IIfvws2ytLfJUbdmiJDYJtt VcfR1CD+++uhkZrs3e8zfsq8gs+kkq9AtzP2A3HQlk5q9e3pfn71S3iwGV6eJ0zT4BCf k1bwP+k0WkB/zDzUKTKA4/kRHPN08hxF4ZLWtHaOwnZu3/8XpvegoyB84yV6TSSDioDP qt8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Efa/bidO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x13si1696483ejj.368.2020.09.28.17.54.14; Mon, 28 Sep 2020 17:54:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Efa/bidO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727058AbgI2Awi (ORCPT + 99 others); Mon, 28 Sep 2020 20:52:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:55596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbgI2Awi (ORCPT ); Mon, 28 Sep 2020 20:52:38 -0400 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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'"