Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2629510rwb; Mon, 15 Aug 2022 08:36:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Zg7x43oIi2ojAgRh3UxJwWH97K76614XYM1Vuc4plxq/T8CJDXUavayVhLyRr8sLz9xxD X-Received: by 2002:a05:6402:428c:b0:440:8259:7a2b with SMTP id g12-20020a056402428c00b0044082597a2bmr14709390edc.329.1660577760411; Mon, 15 Aug 2022 08:36:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660577760; cv=none; d=google.com; s=arc-20160816; b=iCC0OoTcBEC6TevLZE3zfMWcA+orZEwnq2A4oVyIUJV6PFE7WPNfrhpFbLH9HjlDXu azSRV7XfN9C9C77tptl/CFf3QmYafhVN6q8EijI5hTphn7N/hAugxOuihGQhZJ92t11g IYw02GnbLnnGYU1vKTLzIUVDsJWWOG73G2o9IFRibJS4bq+SpHKEH/W85iJNIvnh7ZcT Qnt0yH65McsuAtXPYdcPRQCjPrT02qybJQWo8cMxEs+zR/uHqOGt0HcvQm4f6epvU0X4 hGOmRlW8tKDblgfoxjv7b8DTGtkrfp5wBTjrEMV+IVBB/bDbqdt0WM0PN+tdr+zHzaNR +nWw== 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=qQIOXmfE/L8EhIOJ9ReiZ9YnlR5Vz7KbQm21zp/yjg0=; b=VO+CdMsmRiRXB5U0hXyDag4by7r503PDYmWdzfjtgIe2DKbxVxqpvFyOoGIuzT12bD pX/Mk8R3LYZ4Ns22XyqCFFWPbn0UT7HUfV+9QvJB+fQ9AACMyPbBFqdK9qKdRDd89hfe p/N0CQmp13ZuYLUvIwuRkMavHZy4POHFnSQxaxt1r2IxrZzqG+ol0gGtL95gNocMb3wX uqrBFNNi0dh8aLZOfmeH3USuhT2xslYWSL+e83DuG+GvHw+DdIf72T/7zDFvILtLwAzM aIqF0xg004fVrExP31H8+BCjHjIZTLdKsLw5RGJdI6NwP/p7JdMgpFIiygNXAO9EHLye XeNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="clwT/hpM"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt34-20020a1709072da200b00731010c202dsi8636042ejc.764.2022.08.15.08.35.35; Mon, 15 Aug 2022 08:36:00 -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=@suse.com header.s=susede1 header.b="clwT/hpM"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231126AbiHOPb1 (ORCPT + 99 others); Mon, 15 Aug 2022 11:31:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230510AbiHOPbY (ORCPT ); Mon, 15 Aug 2022 11:31:24 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D212FDF85 for ; Mon, 15 Aug 2022 08:31:23 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 88CC3375E5; Mon, 15 Aug 2022 15:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1660577482; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=qQIOXmfE/L8EhIOJ9ReiZ9YnlR5Vz7KbQm21zp/yjg0=; b=clwT/hpMZi+m26eag1S3oGAGpDMumThrxYmxxSDuyqgQgoCTJJTI3Lm4vBxUlPXE8CQ79z aONVfEkSt0FinytEeCT1IdToULSYS+MwT7hv0Kyc02DijN4kiB9Dfjy+hHLPqS4Gu9LD84 1I5XUaBlachjXXF40UzxodSXftB8P7M= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 66AFB13A93; Mon, 15 Aug 2022 15:31:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bnc+Fspm+mK/ewAAMHmgww (envelope-from ); Mon, 15 Aug 2022 15:31:22 +0000 Date: Mon, 15 Aug 2022 17:31:21 +0200 From: Michal Hocko To: Matthew Wilcox 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_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 Mon 15-08-22 16:26:46, Matthew Wilcox wrote: > 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(). > */ Yes, thanks! -- Michal Hocko SUSE Labs