From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6830940DFDC for ; Sun, 5 Apr 2026 04:47:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775364478; cv=none; b=uJDsDfzdOpviicIpgvWQlMGbBUm2raHhzcUJeweIe3GrHAHx45aH/2BZijcVOttlUMmIP2G5WRYGxX6qakAtwDZSwoQ+7dT5vRKIzelTGj3eHc69aGM3WKZt+ufcv9mAAvvcBP7ZP70xM2EuK8Qvn5HNnusbro7JbmWQtLnI8/Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775364478; c=relaxed/simple; bh=tKaJUCcEZcfascPJ5/OsCfMWCI+/hcBinURwAGIvqaE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZF41pzCWCEVfkehbwTODD2xZ+6ixdzFsxKLR1ufVZspiu1G+ZGrvW/0X4P6EwW9VCS31Rf1jSF6H7pQ55x8hj9Gq5PYlTONsyU9j0Y+pUgviBtrJe2TMf9FfPnJbDXnl1r8FC3gQXX2dUzjHmdXCgFfKT48TzFgV7HsM2VLgmEg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=IuP2PMuS; arc=none smtp.client-ip=95.215.58.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IuP2PMuS" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1775364474; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kDt9N5g6D4SCWCX4TwS2U1BYH8gHEqTdtRgHFVI32PM=; b=IuP2PMuS2U8srTZc94C4wdOggHU278UEqT5k+APawMKeUWxCzz2giMReCPaG2P9yAkqLAF 7qUidZ8lco7cqgjBUqW5qiDv8Am2qwaiRz8hU2sUxsDTR6UPlfUXfKxFM7b8GyCANrgfj1 oM0IGccgRwKuOi1M3oySQYJ6xEF7Lgg= Date: Sun, 5 Apr 2026 12:47:40 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 1/3] lib: test_hmm: evict device pages on file close to avoid use-after-free To: Alistair Popple Cc: linux-mm@kvack.org, Liam.Howlett@oracle.com, akpm@linux-foundation.org, david@kernel.org, jgg@ziepe.ca, leon@kernel.org, linux-kernel@vger.kernel.org, ljs@kernel.org, mhocko@suse.com, rppt@kernel.org, surenb@google.com, vbabka@kernel.org, dri-devel@lists.freedesktop.org, balbirs@nvidia.com References: <20260331063445.3551404-1-apopple@nvidia.com> <20260331063445.3551404-2-apopple@nvidia.com> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Zenghui Yu In-Reply-To: <20260331063445.3551404-2-apopple@nvidia.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 3/31/26 2:34 PM, Alistair Popple wrote: > When dmirror_fops_release() is called it frees the dmirror struct but > doesn't migrate device private pages back to system memory first. This > leaves those pages with a dangling zone_device_data pointer to the freed > dmirror. > > If a subsequent fault occurs on those pages (eg. during coredump) the > dmirror_devmem_fault() callback dereferences the stale pointer causing a > kernel panic. This was reported [1] when running mm/ksft_hmm.sh on > arm64, where a test failure triggered SIGABRT and the resulting coredump > walked the VMAs faulting in the stale device private pages. > > Fix this by calling dmirror_device_evict_chunk() for each devmem chunk > in dmirror_fops_release() to migrate all device private pages back to > system memory before freeing the dmirror struct. The function is moved > earlier in the file to avoid a forward declaration. > > Fixes: b2ef9f5a5cb3 ("mm/hmm/test: add selftest driver for HMM") > Reported-by: Zenghui Yu > Closes: https://lore.kernel.org/linux-mm/8bd0396a-8997-4d2e-a13f-5aac033083d7@linux.dev/ > Signed-off-by: Alistair Popple Tested-by: Zenghui Yu (Huawei) Thanks, Zenghui