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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F907C43334 for ; Fri, 15 Jul 2022 01:04:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 935EF9401C0; Thu, 14 Jul 2022 21:04:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F28E9401A5; Thu, 14 Jul 2022 21:04:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7D4649401C0; Thu, 14 Jul 2022 21:04:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6E08D9401A5 for ; Thu, 14 Jul 2022 21:04:21 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 40A244E6 for ; Fri, 15 Jul 2022 01:04:21 +0000 (UTC) X-FDA: 79687538322.20.42FA789 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf18.hostedemail.com (Postfix) with ESMTP id C7BEF1C0075 for ; Fri, 15 Jul 2022 01:04:20 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CB5FB62107; Fri, 15 Jul 2022 01:04:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27C7BC34114; Fri, 15 Jul 2022 01:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1657847059; bh=iC+3ZL16iBagFhzCdlpt5bH1iSUd0rocVNjEoKGCV4o=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fpQp92FOWBykue2b6vHYA0GcjXfSWzoxZ+pN3sSXyvTIKKHyJUhZLn8Fw5p/cXO/y E0KCqNVVQ86nM2YvevqL1wYSKOaRVua2VZFSdGoS66HTBC/aJ7IMWy+kofwD9yNUVq P8AOaoklubL6trtsj2Gs8ARoz1rF8qROuD+DllU4= Date: Thu, 14 Jul 2022 18:04:18 -0700 From: Andrew Morton To: Charan Teja Kalla Cc: , , , , , , , , , , , Subject: Re: [PATCH] mm: fix use-after free of page_ext after race with memory-offline Message-Id: <20220714180418.6d546650b3e5ae745f09814d@linux-foundation.org> In-Reply-To: <1657810063-28938-1-git-send-email-quic_charante@quicinc.com> References: <1657810063-28938-1-git-send-email-quic_charante@quicinc.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657847060; a=rsa-sha256; cv=none; b=vFlEr7YJaEDhEEcQhBL3dW/ZEh0Dp16YS9whmsGGjz7hOGJWgWqozLAWtq7RFnZ5Mahkxl hppP3aH/N8PbaEilPC/fc0JFqgWWmtOy26/8ZvVoLwAS05OEapaHVxPX0LCBXrzfIsOaiw z0O1QafLDmOMu2qT0j4WE0+ERSSDN9I= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=fpQp92FO; dmarc=none; spf=pass (imf18.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657847060; h=from:from:sender: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:dkim-signature; bh=qWjMTGO/usLkHrNt+gw+OvjWGMwnvz9gf03HoexOSso=; b=S5XQpPmvCZc0tpJBzTWdPVWOV6MsgSSyDkqjfAejgmy+ASCYTwI7HtB3O2nHL2CEwO7Q3s xp6SdyVBflT+rAUR8pyctGkxGjCrf5tWBI+/asWCuO4QWVSDJDSMol7st76pe+K0kqvVEr XxhOSeT9z8VvQjo1Mu6hV0ucp5CxcX0= X-Stat-Signature: a7yyoi5snur3eknu3n3q86qo1im7g86m X-Rspam-User: X-Rspamd-Queue-Id: C7BEF1C0075 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=fpQp92FO; dmarc=none; spf=pass (imf18.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam11 X-HE-Tag: 1657847060-836756 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 Thu, 14 Jul 2022 20:17:43 +0530 Charan Teja Kalla wrote: > The below is one path where race between page_ext and offline of the > respective memory blocks will cause use-after-free on the access of > page_ext structure. > > ... > > --- a/include/linux/page_ext.h > +++ b/include/linux/page_ext.h > @@ -64,6 +64,25 @@ static inline struct page_ext *page_ext_next(struct page_ext *curr) > return next; > } > > +static inline struct page_ext *get_page_ext(struct page *page) > +{ > + struct page_ext *page_ext; > + > + rcu_read_lock(); If page_ext.h is to call rcu functions then it will need to include appropriate header files. > + page_ext = lookup_page_ext(page); > + if (!page_ext) { > + rcu_read_unlock(); > + return NULL; > + } > + > + return page_ext; > +} > + > +static inline void put_page_ext(void) > +{ > + rcu_read_unlock(); > +} Better names would be page_ext_get() and page_ext_put(). The rest of the page_ext API appears to have got this right, so let's not mess that up. Also, these aren't really get and put functions - page_ext doesn't have a refcount. But I can't immediately think of a name that better communicates what we're doing here so I guess get and put will do. And are we able to add some comments here explaining why these functions exist and what they do? > #else /* !CONFIG_PAGE_EXTENSION */ > struct page_ext; Are you sure we didn't need CONFIG_PAGE_EXTENSION=n stubs for these two functions?