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 213B6D60D08 for ; Tue, 19 Nov 2024 01:30:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D27D6B0082; Mon, 18 Nov 2024 20:30:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8838A6B0088; Mon, 18 Nov 2024 20:30:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7238D6B0089; Mon, 18 Nov 2024 20:30:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 548376B0082 for ; Mon, 18 Nov 2024 20:30:35 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F16AEAC854 for ; Tue, 19 Nov 2024 01:30:34 +0000 (UTC) X-FDA: 82801112268.07.95DD0DE Received: from mail-ua1-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) by imf26.hostedemail.com (Postfix) with ESMTP id 7B3CA14000B for ; Tue, 19 Nov 2024 01:29:55 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=PqPQCbtL; spf=pass (imf26.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731979652; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dwhbrEEfePVbvJU2Ozddu2A4+flvh6qun9KERWZBa38=; b=MloC1tcO3C46IN/YucOV+/MPSN/VRcQEWzFurIDa4bA7dGGSF2ps/yBLWJS0QVjzyh6A0t 1hyyu/XQFP06G/3u7tQiSpTw8pJHABQ47FWYTYvCHPJfxgfw9NsO1tCsaEUXd2bBFvsVWQ jV1Bx4w3UVQOYaBIdihCT+L8vnhy+9w= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=PqPQCbtL; spf=pass (imf26.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.48 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731979652; a=rsa-sha256; cv=none; b=lfPLeEZkDx63eFZn8eq+19aulbuBHG8DFBXIDVh+VEVzzp3Xfy2xHjDRqD80AKBqp3A46a NnOVHDp6g6VDQzK+u9Fq6kwLAepU8ZBHnWBMnmPrBzzo9ICRfbjMoCJlDtrM+KPQDYGhyH BZ53HQ5g/+uQx91ky/WEwvuAiYc22R0= Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-857004f7846so758317241.2 for ; Mon, 18 Nov 2024 17:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1731979832; x=1732584632; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=dwhbrEEfePVbvJU2Ozddu2A4+flvh6qun9KERWZBa38=; b=PqPQCbtLE8uMUczTbUXCbXHTxJ419kMoFCni/VAbl7QGSRbic+VTV2yAIGRSVXNBGB cDTRVGnykPpgIPeWe6UPR6d0SslYZjMQ5ScGlq6l8tOIyvcdhXgQOYaV6u2eAN1UmNEg 3gK6shq+c0coAJe5lvYALUbJMVHY5dqBc54nrVmv3oYGPcVk836Y0iglooJCJKaWP87x XbMSMi3f0dC0tV9KLYwvt5KrXrQyDwnNbLJ7Hd4Tk7HehCGJh6gq8qvKJ2N8aklX9jlD g0s6SE+oXgohMgWOaBbFK6MvBYdp7ssATuMe5nltJSx0aEPZ0tveeT1nUh+LzHcTHSgl gEXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979832; x=1732584632; h=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=dwhbrEEfePVbvJU2Ozddu2A4+flvh6qun9KERWZBa38=; b=jbNudfr1Rif+9wi8FfbARpjpymWjmWhS/bEQDF2R9M8yo89dIn9YOYwjLWCs3jEc8l CvVelEiPvOZeogakJFoEkDXnoE23cetnOTgM95iWtPAmAQdyxnIBg9x+rj+JkLs/hRKO 978wDvTsKDGhopjnelEZpqGA+UZCURoMWJS4/ajzPL0Sni3JKQSXkj0acTHhCqrCVIYs qJjRgbUD+uetaL1pTIUsxchEu8iLQCNcyjo2Fxm0bhgIcuypIKsNOGEFDSmKVbPLNGK8 Yf9mvBzN7K1sH1G0H/NlTYeAmqrO5238uDLv3MXsW1T6HH+mGtXglO/zaJ+bkDyPt2MQ rJZA== X-Forwarded-Encrypted: i=1; AJvYcCUdP31xyjDHZZOzKIvhHEiW7AdEsxncn5TFMkWrfNjBQH7EgYKRjNfNLn7woG7ofyhYFwk2Oa7+Lg==@kvack.org X-Gm-Message-State: AOJu0Yy1XJU1yKtt0q9VOv8nX/ko7UkOHsD+kkKnuzbaLOYBHJNmUPX/ 7AU4nBvM3wvWfFfT0i8K2oy+n78FJF2I1+pQURKAcxLPcsFs2A2kgBZXIfKx0dEpmi7/st7uXFx 4N6kfGxc2eWNI+46vYFxAm03PUWYubK0EsBWxRA== X-Google-Smtp-Source: AGHT+IEnblF5WP9b6MMjtXTC6Vjj1Iy7OkpDZ4PeMU+Uc4InANfSMt/pice9eNGMRdH2BcrKEejfz0Ajo3xoxrMqxY0= X-Received: by 2002:a05:6102:3f04:b0:4a9:14:3ee9 with SMTP id ada2fe7eead31-4ad62d52711mr12363521137.23.1731979832190; Mon, 18 Nov 2024 17:30:32 -0800 (PST) MIME-Version: 1.0 References: <20241116175922.3265872-1-pasha.tatashin@soleen.com> In-Reply-To: From: Pasha Tatashin Date: Mon, 18 Nov 2024 20:29:55 -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" X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7B3CA14000B X-Stat-Signature: 791xzepd9kyj8h43p9orwdrtpq9ri5x7 X-Rspam-User: X-HE-Tag: 1731979795-832859 X-HE-Meta: U2FsdGVkX19K8PTT1EJEDmHC3sfba23Ps2QeZI+mb0Ls4pLCaLQ0gA6OKL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mt44rFuxUbjYFvBA9EdFjLmJ2uj2WdWti/PWjI2m2UenlqsOOJJSyeFPTOEMUGmVHIZYiYRCk3y2eMNma/SWsy0bzFFHs+W15n0LwZn/XUmwOVApQLUvd3ek X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: > 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 should > > > expose to a userspace-reachable API. > > > > We use dump_page() all over WARN_ONs in MM code where pages might not > > be locked, but this is a good point, that while even the existing > > usage might be racy, providing a user-reachable API potentially makes > > 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(). Thank you, Pasha