Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1123226imw; Thu, 14 Jul 2022 18:12:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vjNk3EfW8Ba0nShypACnoQHWyh94+m610hb2Tl5ZofWEz1bH7AA0sbzeKKJWyXJcxcYS/+ X-Received: by 2002:a17:907:7348:b0:72b:44bf:96b6 with SMTP id dq8-20020a170907734800b0072b44bf96b6mr11527697ejc.7.1657847554596; Thu, 14 Jul 2022 18:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657847554; cv=none; d=google.com; s=arc-20160816; b=S2u9hd9oHPj13DI18fjYZIkBl4zehYSPT1JLPytxOU2+IEGpImMAXHr4iIfrqsYj1a JHCQbwsDkJOiYF/4na+Q+TvYx2HX8yIt4PisJMBKH/1fWJsVQoyCb8go5LgxZQEeRVQy /bxcQjiiXistj2JxgpMBaREFoKJaa5umJItsS3YbQkihXvsqrVtS/X3KIWlbn9FB9hld GKtteoAt+8FeQwS8xC1ZDB2jFy3GfSSL8ZUPQ+jY6titLKpvqcmVFAMXY9MJHlu3dfLO A+Odm6SZbbGH9OVRSKEOwC/rvKUQzEZ+T3/bYcUy9b72nNcuDtnTKNLMJ6n+Lb1/HioG bXDw== 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=qWjMTGO/usLkHrNt+gw+OvjWGMwnvz9gf03HoexOSso=; b=gsnRymReiqD7tf6JKyd2uzTAcTiIlmavU2eqIXzEL/zE0/U+74lcXGY5TSq3yD4F6m Ff7Ym3FWozbJuBHs7BXJsMYRc9+sg5MlNoycSM1pCz6HnT0bGDysYlPfdw2kkGqDhNH2 xDFsgFFynC34NPcmqo7G4mRY1tFK5bb8Fel/NqqRPOkqLynsoi/k/hYF4jaAmNGrBSci RA5+PwBaiH9yvq+ahnxpuyfjcqRkunUNmRvB5oilfVcsxKWTpc2rR9lTELnZ/mSVW6JH ekUauCBl+qW3eW2MLC18pQ7rw2XePkyXuBFiCaQ0xa1dpQ9dHRpQLTiXtK2075QUC3pM wkdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=fpQp92FO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m3-20020a056402050300b0043a6064cee3si3492230edv.69.2022.07.14.18.12.06; Thu, 14 Jul 2022 18:12:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=fpQp92FO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241058AbiGOBE3 (ORCPT + 99 others); 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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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?