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 E41B8C00140 for ; Mon, 15 Aug 2022 15:31:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 704CB8D0001; Mon, 15 Aug 2022 11:31:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B25A6B0075; Mon, 15 Aug 2022 11:31:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A1A98D0001; Mon, 15 Aug 2022 11:31:36 -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 4DA5C6B0073 for ; Mon, 15 Aug 2022 11:31:36 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9098C120E2A for ; Mon, 15 Aug 2022 15:31:35 +0000 (UTC) X-FDA: 79802216550.08.193231D Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf20.hostedemail.com (Postfix) with ESMTP id BCDE91C01AF for ; Mon, 15 Aug 2022 15:31:23 +0000 (UTC) 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-Stat-Signature: f58w7agf7srf4pjeaw4j9ii3oh5sa7ck X-Rspamd-Queue-Id: BCDE91C01AF Authentication-Results: imf20.hostedemail.com; dkim=temperror ("DNS error when getting key") header.d=suse.com header.s=susede1 header.b="clwT/hpM"; spf=temperror (imf20.hostedemail.com: error in processing during lookup of mhocko@suse.com: DNS error) smtp.mailfrom=mhocko@suse.com; dmarc=temperror reason="query timed out" header.from=suse.com (policy=temperror) X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1660577483-485183 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 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