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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D0F3C43334 for ; Fri, 15 Jul 2022 01:04:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241029AbiGOBE3 (ORCPT ); Thu, 14 Jul 2022 21:04:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232689AbiGOBEX (ORCPT ); Thu, 14 Jul 2022 21:04:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E6615A34 for ; Thu, 14 Jul 2022 18:04:20 -0700 (PDT) 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 3C96D62102 for ; Fri, 15 Jul 2022 01:04:20 +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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?