From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.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 67CBD34BA33 for ; Thu, 25 Jun 2026 01:47:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782352042; cv=none; b=qdIGvHMBY5XWVxmU+ZU5DUQCPYLS8iupueruhq5VQ1prvsVJqbU0+8pMNZ9IgnnQyIiGoNSm6hVDzXm1jiaZpUZQzpWRGFVops8zQq84YquRHaYiBbdKPwLIu/ePew9AKtW/uW7AhIEjYzhxcB5vJ2LDsq1d82GPNhED+t+Qq4s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782352042; c=relaxed/simple; bh=IBbCmKc8x0ZDgxUVsimOPLBGJB8l5sb4OXz/W0z6igg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=iM9tqbtrTBGNjnkLbb256sR3j/flYqC9F/sfjsP/8HUDrN6f5IEvwU6GQGiYEBraftDhJ285ERbClfNXGoZVlRIS228ltCZa6uk6hSvR7oCK77S+rAKZdFYoDrYhUMmKUt+gD63q/t4YbXO0kDFyLYM1tm5hcpeYRKCUJgE6TCY= 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=X1MO0u0w; arc=none smtp.client-ip=91.218.175.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="X1MO0u0w" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782352036; 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; bh=OM4i1907t/VVrIa2X1MtyNtXBmmD94pG1xktaQRqS5Q=; b=X1MO0u0wVQcI1pkWaKgsuytkFRDqu6nTu9+WiX6i4JpO7LuL81AffECVu/YzneqtyqFHsN TtUDVoQHcjBRWFLInXO19xYJtJbUeD4mt7VJwxSzvKoBgQBSgPmf+A8hNnWSsagCU+rXvn cDkVcFvQbvvE8AaJ3B9McvINX3oWmdQ= From: Ye Liu To: Andrew Morton , Vlastimil Babka Cc: Ye Liu , Suren Baghdasaryan , Michal Hocko , Brendan Jackman , Johannes Weiner , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/2] mm/page_owner: fix TOCTOU races in lockless page state reading Date: Thu, 25 Jun 2026 09:47:03 +0800 Message-ID: <20260625014708.87386-1-ye.liu@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Fix two TOCTOU races found during review of [1]. page_owner reads page state locklessly by design. In two places the code reads the same metadata twice — once as a guard, then again as a use — and the page can be concurrently reallocated between the two: Patch 1: buddy_order_unsafe() in skip_buddy_pages() can return garbage if the page is allocated between PageBuddy() and the private read, causing the PFN to skip past a pfn_valid() boundary. Clamp the advance at MAX_ORDER_NR_PAGES. Patch 2: PageMemcgKmem() in print_page_owner_memcg() re-reads folio->memcg_data and triggers VM_BUG_ON assertions if the page became a tail page or slab page. Use the snapshot taken at entry. [1] https://lore.kernel.org/all/20260623065234.31866-2-ye.liu@linux.dev/ [2] https://sashiko.dev/#/patchset/20260623065234.31866-2-ye.liu@linux.dev Ye Liu (2): mm/page_owner: clamp skip_buddy_pages() PFN advance at MAX_ORDER_NR_PAGES boundary mm/page_owner: use memcg_data snapshot instead of PageMemcgKmem() to avoid TOCTOU VM_BUG_ON mm/page_owner.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) -- 2.43.0