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 23DF7D44162 for ; Tue, 19 Nov 2024 15:14:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EDFD6B0098; Tue, 19 Nov 2024 10:14:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8761D6B009E; Tue, 19 Nov 2024 10:14:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7170B6B009F; Tue, 19 Nov 2024 10:14:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 514366B009E for ; Tue, 19 Nov 2024 10:14:53 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F3CA31C6A8C for ; Tue, 19 Nov 2024 15:14:52 +0000 (UTC) X-FDA: 82803190974.18.3F3D212 Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by imf08.hostedemail.com (Postfix) with ESMTP id 9948E16001A for ; Tue, 19 Nov 2024 15:14:17 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=B6gP1fQS; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf08.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732029107; a=rsa-sha256; cv=none; b=GEYy8+nTqcbJTIGCLSvydp4f8CTHly424uvwSy2M3SYThdtfm7y52iXT31hg+/I1le5Ob1 xiGPvd0gpu6Iw/pY3orU+eMtza+XAHXftBH8YGHLyqub3EYppNtw4CAovNTJvGt48+ienT GhYfAEc5SaABu5KStLPOUHFvW7r/KzI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=B6gP1fQS; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf08.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.160.179 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732029107; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RHwDnKru70pWnl/9WBuQ20Iik4fo0kZl81qP2ypGaJI=; b=P6qGr/X4VGDnb+a06L5/C1DjabvPgcPylw2CKoej3qrIHu8RyjowwrqglscfXodoCzCWRi iG1Yx5uNL2TBBPN5H0hcbh2m7esLDsACyDAHGODy3ia7TpLct+IsprBXiWRrypgibyWA1i 0N2cUIfDOInP0ic4qhR2oo3iNmeFA+E= Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-4635760725cso51731761cf.1 for ; Tue, 19 Nov 2024 07:14:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1732029290; x=1732634090; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=RHwDnKru70pWnl/9WBuQ20Iik4fo0kZl81qP2ypGaJI=; b=B6gP1fQSYy+WU35tBJyWtkRIp0TwheE52hfiOFhI6UoDe4yQx8Ef2NecumENuURlrx rpM5gUFZ51w0hbvsTno3qwsGr1klqF6cCJQ0+MQmtBIm/bvcOJiibuxxBX5DHVuOV2qw 5QoxfMR2fFF29o5GC+bYei1TGn55Fi+oF8xOC6W1eA/tloeqeGqJ68t6AtjjLWrcZ6HF Qa0eSTw+ACr6TaOCfsCxjdQt20WoY178FvuwCUsPQTko9rA52bW/IR3foSzHjfQEgzZp V7W7MLPHV3YNo2GPI8jVnaYKG/PLUvKMQOA8c1HoZP57hpIDwsmfc3GCOqNNjT2j93e7 nVQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732029290; x=1732634090; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RHwDnKru70pWnl/9WBuQ20Iik4fo0kZl81qP2ypGaJI=; b=LfLb89hIeswXi6BsgzPW9BPdubrhPnDuna0RqPDEAzMM1ge0xlJPuKPtmoGTdFZc7C D+0R5yZiTiymU+QOil6mjw1k0uhd90MjKZ1kAu+kDRGtQ33tcvZ3MLwc2JJ5vsdAslPr vB/qKLSEqw/mjmeOE4fj6SwFdXesnuOFjX+detFoKRIc80uTRVeWV/7PHmPAi68n4WeL vvuCqId3MWEyJXdyVipGhD4SZjxsBSmmB8u1n7DcF8jhjioQhwF8iwWdNmcsLriRXXf7 21oGgD14GlPYibvma1xGkdtQ0gD31hlTU+ZMu6hT9PE2hzwbias68DKVVI5nOiB+I+7h aUaA== X-Forwarded-Encrypted: i=1; AJvYcCV9ChdbqLRYEqZizn3NHOoDiLKYkBA1s55a3cYpQCU8OPZ8RBhmESN1h+U5Sktsx9nsUh1XVUd9sA==@kvack.org X-Gm-Message-State: AOJu0YzW7BoZFf69Nf/onnw6kZ9giyGmjBuu74vmwtrlKFFp9QJ9gE+t 46bKFiP1QXe8Ik2lXppAR55S5a1XRJR+DG1zijg+V7G1SWkHsQGE6SN9Ia0ogVFAOWS/BGsTNF6 TC3G+XCVguayuz0vjKrNBKh0RVqqvO8/srIlsrQ== X-Google-Smtp-Source: AGHT+IEJwBZlUovcinMC2W5fFA797qZwYwLBmxYXTBNzEM0XjyLH7M5le4TEh6FQXiXxZ5fybascQvNQ8dVlyHK3oWk= X-Received: by 2002:a05:622a:1b06:b0:462:b856:c8fe with SMTP id d75a77b69052e-46392d511bcmr58315681cf.1.1732029290306; Tue, 19 Nov 2024 07:14:50 -0800 (PST) MIME-Version: 1.0 References: <20241116175922.3265872-1-pasha.tatashin@soleen.com> In-Reply-To: From: Pasha Tatashin Date: Tue, 19 Nov 2024 10:14:12 -0500 Message-ID: Subject: Re: [RFCv1 0/6] Page Detective To: Jann Horn Cc: Lorenzo Stoakes , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org, linux-kselftest@vger.kernel.org, akpm@linux-foundation.org, corbet@lwn.net, derek.kiernan@amd.com, dragan.cvetic@amd.com, arnd@arndb.de, gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, tj@kernel.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, muchun.song@linux.dev, Liam.Howlett@oracle.com, vbabka@suse.cz, shuah@kernel.org, vegard.nossum@oracle.com, vattunuru@marvell.com, schalla@marvell.com, david@redhat.com, willy@infradead.org, osalvador@suse.de, usama.anjum@collabora.com, andrii@kernel.org, ryan.roberts@arm.com, peterx@redhat.com, oleg@redhat.com, tandersen@netflix.com, rientjes@google.com, gthelen@google.com, linux-hardening@vger.kernel.org, Kernel Hardening Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: s69pgog5jocbbjkbuggtzzeop1wry7iw X-Rspamd-Queue-Id: 9948E16001A X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1732029257-477815 X-HE-Meta: U2FsdGVkX1+Wawvcm9E/s5+8+tTYLg4SEdxXEokE7fdTRv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N+NXMPVk2gr2Xe7QO5S2offup47ovhZ4HzXtJLGEBfMQ67gEa3KjjkIQUTjO52GiqmA+vHPLAED1L525wwZda0/AJdV2MLPDsJ+qdL/zVwrgWWKjERyu+HRd9f14wEZ31Ga3VWC3nzU2Bwf29XFVw+l8fjHd0rY98RNJ5AuRjgG32ExeuY+zbSMAUOwtcF041w== 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: List-Subscribe: List-Unsubscribe: On Tue, Nov 19, 2024 at 7:52=E2=80=AFAM Jann Horn wrote: > > On Tue, Nov 19, 2024 at 2:30=E2=80=AFAM Pasha Tatashin > wrote: > > > Can you point me to where a refcounted reference to the page comes > > > from when page_detective_metadata() calls dump_page_lvl()? > > > > I am sorry, I remembered incorrectly, we are getting reference right > > after dump_page_lvl() in page_detective_memcg() -> folio_try_get(); I > > will move the folio_try_get() to before dump_page_lvl(). > > > > > > > So I think dump_page() in its current form is not something we sh= ould > > > > > expose to a userspace-reachable API. > > > > > > > > We use dump_page() all over WARN_ONs in MM code where pages might n= ot > > > > be locked, but this is a good point, that while even the existing > > > > usage might be racy, providing a user-reachable API potentially mak= es > > > > it worse. I will see if I could add some locking before dump_page()= , > > > > or make a dump_page variant that does not do dump_mapping(). > > > > > > To be clear, I am not that strongly opposed to racily reading data > > > such that the data may not be internally consistent or such; but this > > > is a case of racy use-after-free reads that might end up dumping > > > entirely unrelated memory contents into dmesg. I think we should > > > properly protect against that in an API that userspace can invoke. > > > Otherwise, if we race, we might end up writing random memory contents > > > into dmesg; and if we are particularly unlucky, those random memory > > > contents could be PII or authentication tokens or such. > > > > > > I'm not entirely sure what the right approach is here; I guess it > > > makes sense that when the kernel internally detects corruption, > > > dump_page doesn't take references on pages it accesses to avoid > > > corrupting things further. If you are looking at a page based on a > > > userspace request, I guess you could access the page with the > > > necessary locking to access its properties under the normal locking > > > rules? > > > > I will take reference, as we already do that for memcg purpose, but > > have not included dump_page(). > > Note that taking a reference on the page does not make all of > dump_page() fine; in particular, my understanding is that > folio_mapping() requires that the page is locked in order to return a > stable pointer, and some of the code in dump_mapping() would probably > also require some other locks - probably at least on the inode and > maybe also on the dentry, I think? Otherwise the inode's dentry list > can probably change concurrently, and the dentry's name pointer can > change too. Agreed, once reference is taken, the page identity cannot change (i.e. if it is a named page it will stay a named page), but dentry can be renamed. I will look into what can be done to guarantee consistency in the next version. There is also a fallback if locking cannot be reliably resolved (i.e. for performance reasons) where we can make dump_mapping() optionally disabled from dump_page_lvl() with a new argument flag. Thank you, Pasha