Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2626980rwb; Mon, 15 Aug 2022 08:33:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR7q6qW6eH8zXulFD91USyRDCUuMA74M7XTuWnldLlI6fENBYC4nOHX+bwHJzMSuoRXKuPWX X-Received: by 2002:a17:907:9619:b0:730:8ebb:9e45 with SMTP id gb25-20020a170907961900b007308ebb9e45mr11071137ejc.628.1660577606776; Mon, 15 Aug 2022 08:33:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660577606; cv=none; d=google.com; s=arc-20160816; b=zB7Di45dlfaeawdsh7CqNqy1mBJ7xIObIR7je9OK6ITXYh6gQhq0rgfp4g5oCqpoQU jjMZsZh7vAG+EecE2YmMNnmOD+0N+Vm6LF8RetW6j9g14fD9DsTk0to5UZ7J+tfKsCm6 ydmNjH37QpTQJCZnTu9H0YoDdW1g91B7h3TLgWhRNDhEB2y8ZtaX+xfufxQ1l1Km9mCx qe+qf42zoKsWDgancHjjefwT0koXftV/YCPtp4wga5RRMK4WSHrye+qWJopKmhUhMVeE rUBMWrqnKY8Hs1lNJ5Ls4bgJkuFTL+VY371dTl22Pa26Mitd3MO0qIYWE3HivsOaavH+ /dkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=OgmVgkZQ4f9j8kJY1JYsGRyh8hUz7pYvx+5nxAbDqPw=; b=wlzu2+RK7XMyzV44gjifOeIZZMJTXR7j8EdmRX7C6t+l+gmm4azK+bamT7aif4B9fx ZtAq6fN2LXuUfKrTvF5UG756rDwf5RT7R1UxFZshxxGboiVxZwKh7rc3c5Ofn3VxfQd4 wcqmF2rfMB3XmhL/JZHeKnjKHI1NafWeFd5abMFwgBv40DXgtYijT+kEbg9qDrUlVYMz D1Vcts4ujcrO6OG7HxwRduIM+0OXTwiNTevEOzsinA0+hi6KIwBuczTLp1xz/8PoF/KX f2IYd7JV2VVsC8nfLP4jplT97REwKtVh9FFes1IuHfI9UA3FwrDZB2d8HUxJGOhbVbsw N0uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=d6RBhnrK; 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 s23-20020a50ab17000000b0043bca9c457csi8387498edc.396.2022.08.15.08.33.01; Mon, 15 Aug 2022 08:33:26 -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=@infradead.org header.s=casper.20170209 header.b=d6RBhnrK; 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 S230309AbiHOP1C (ORCPT + 99 others); Mon, 15 Aug 2022 11:27:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbiHOP1B (ORCPT ); Mon, 15 Aug 2022 11:27:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE8001261A for ; Mon, 15 Aug 2022 08:26:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=OgmVgkZQ4f9j8kJY1JYsGRyh8hUz7pYvx+5nxAbDqPw=; b=d6RBhnrKAtZIAE2UNvwWOW320t 9WqbrT8nU2ZOLrj3UtbYrXC5Ir9wv3WItoyYZTj8yNquxvxEhGzaHzXz4aREJJXQk166X7EzzcedI l0/olwqn69GsH2OqYJy7bpuu7QuVMd8DkyCfSuQsmWt64vXEn48gCUDSp17+fqHGhhFD7epJJtCjm dN04Q0wWU29eCyhDTIrpuZ4HjE3M2LAm/cBNo9NpjWD9TGI5QY0ZdiEGNcTTre0mOVI/DCKIPd84/ H7p9kBC4HcQccJ+ktCHTlNb88T/tE7IQJVzJ2phFt6A+KhsbHuQ3dIrw2USKz6958+Hzf7u0qI8HL wOmSMtcg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oNbzK-005pDP-3A; Mon, 15 Aug 2022 15:26:46 +0000 Date: Mon, 15 Aug 2022 16:26:46 +0100 From: Matthew Wilcox To: Michal Hocko Cc: Charan Teja Kalla , akpm@linux-foundation.org, david@redhat.com, pasha.tatashin@soleen.com, sieberf@amazon.com, shakeelb@google.com, sjpark@amazon.de, dhowells@redhat.com, quic_pkondeti@quicinc.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH V3] mm: fix use-after free of page_ext after race with memory-offline Message-ID: References: <1660056403-20894-1-git-send-email-quic_charante@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 Mon, Aug 15, 2022 at 05:06:18PM +0200, Michal Hocko wrote: > > + * This function gives proper page_ext of a memory section > > + * during race with the offline operation on a memory block > > + * this section falls into. Not using this function to get > > + * page_ext of a page, in code paths where extra refcount > > + * is not taken on that page eg: pfn walking, can lead to > > + * use-after-free access of page_ext. > > I do not think this is really useful comment, it goes into way too much > detail about memory hotplug yet not enough to actually understand the > interaction because there are no references to the actual > synchronization scheme. I would go with something like: > > /* > * Get a page_ext associated with the given page. Returns NULL if > * no such page_ext exists otherwise ensures that the page_ext will > * stay alive until page_ext_put is called. > * This implies a non-sleeping context. > */ I'd go further and turn this into kernel-doc: /** * page_ext_get() - Get the extended information for a page. * @page: The page we're interested in. * * Ensures that the page_ext will remain valid until page_ext_put() * is called. * * Return: NULL if no page_ext exists for this page. * Context: Any context. Caller may not sleep until they have called * page_ext_put(). */