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 9898ED2A53E for ; Wed, 16 Oct 2024 18:39:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11DE66B009A; Wed, 16 Oct 2024 14:39:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A5D06B009B; Wed, 16 Oct 2024 14:39:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9D786B009C; Wed, 16 Oct 2024 14:39:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B029B6B009A for ; Wed, 16 Oct 2024 14:39:31 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 2FEC51A0A3D for ; Wed, 16 Oct 2024 18:39:13 +0000 (UTC) X-FDA: 82680327996.17.DAC3241 Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) by imf06.hostedemail.com (Postfix) with ESMTP id EF3F2180013 for ; Wed, 16 Oct 2024 18:39:22 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=couV03Du; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.183 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729103852; a=rsa-sha256; cv=none; b=3bERKTM+EhFtSRXmZWTpbIJ0iTGrQHWxF1AoWvrCMrkvuVAUonaB/hWZIRtGH1AAGvJHW5 byF3A5Iiq2Q+4IijMHvi8ktsubq1K16e7aMkdlOaUTPYxN5k27DDmxHEh+r9zSSLDKB3Qp 9ugDkaJoCR+P2M21ewN1Sk0EdOKIGec= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=couV03Du; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf06.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.183 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729103852; 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=OkGfnCJC40BXTXZ4ezhnm9p+y9W4JJIUfai7cW4RZ2I=; b=sbzg2A2FJ4KsFPguY/DpuFy3DqVkq6dLxeHccHpFwYVvauiAKGKvSYL5w4TQIXH1Eer6yS djDTgI1Cb2fu5thFBeIs9tBL1G3DTO49wuC6qwTki4TmofMK4cUYndNRePmxmJjKEPAjmg PfYW4cEdls5UhZE8uchmhUua6jHfngs= Date: Wed, 16 Oct 2024 11:39:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1729103967; h=from:from:reply-to:subject:subject: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=OkGfnCJC40BXTXZ4ezhnm9p+y9W4JJIUfai7cW4RZ2I=; b=couV03Du4sIlAoaWoVxoUUiovpfGfwbMASMQ0cOtuREiDGX8HNFj88TBDIspJEn1Q3epTb KGtGXH26jFctcgbBa71xVWNK9MQwE7hzCnZkWQLw5Qi7dLzGNfJvy6G/Uqe7JKoZH6KPVb QEKZ5CZiXiiIg3ufMaZTalPj8J0WKQM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Andrii Nakryiko Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, Yi Lai , pbonzini@redhat.com, seanjc@google.com, tabba@google.com, david@redhat.com, jackmanb@google.com, yosryahmed@google.com, jannh@google.com, rppt@kernel.org Subject: Re: [PATCH bpf] lib/buildid: handle memfd_secret() files in build_id_parse() Message-ID: <2rweiiittlxcio6kknwy45wez742mlgjnfdg3tq3xdkmyoq5nn@g7bfoqy4vdwt> References: <20241014235631.1229438-1-andrii@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241014235631.1229438-1-andrii@kernel.org> X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EF3F2180013 X-Stat-Signature: bu15t3wry8pftxc1wwuygt96hnm9qz6s X-Rspam-User: X-HE-Tag: 1729103962-417679 X-HE-Meta: U2FsdGVkX1/vhnVrJSeosOXUgbaE1GIF06ex1bcC8D/W0yEbNJNOy9hk6zT2I7Iv98DjKVf6lN5yfyWxgSg+axciL79EhCtG5aIw0Uc1qFSnhO7cygjD7IkzWVzWcHTAjcTqfZb9xKI7Ae7gPelb81m7can1P6ATz0AfkeaOkDkGIInEbNs551Ii5eJm/6eFrKUkEFrWJ/vrX/9RjeHrnsoGhiYyyBVK1DyA81dB1f3ViZqsXLl6V2kXAhxfkhc74tlKFzAiDi5DZu4qYD4gmOGpeapwW5ah3vhX+PdSGXQYp2qLbctr+bpzBM2NmM3le/N/7lDhmQCxGXeON+bPh6WbZnJdpKhbvCZ9pbDx4YGCEaV2fvqrE3/PDIe8vFqg1MBEAWxPc12ec3v2swxQ49P/cMGEHiDmBIYG/9nRI2ZtOj5noir8UwGZK0ofHekTt5q6D6Zx4bKGvv/MH45rzvAAPb3U1NR5boxht5jaucFNg20PDc0gosoh0zlUdF7hPbTQYHhpVszlKCChLQb3CvRhntrXy265D+TkVM3N/Hh9Sd7RMy9mEBFPKBKkvVr0zE1N7gwawPVN+FmRu/VW8n8/bMr/XltTJdWCAKkhspdOnTNDbrI3aVivQ0Z6u3NlmodxSsLSmdHCwjheouFks90ZdByLQjLYRpzWEcY4HAPeo4ynfUcYMx5JJzxO5E9VtFrAqaCoCZ2t6aYQtLR6fT3kCXsHG3vlLcNTsLoeuSrdlBD71JNplaoBzEDiokAcKg5RLf23YWkLIg+Vifm1Ja3N7MuIOpUAGdStiUorc6F6VCa0Biy13jlT7mBt2xTZxeXpl1gBs9fxIs4dYxmQ1S9p2wc0KSdyanDIqnyjdZxkSvcnH/qoXR+5bDcymYDehZiYxyg85iWJfVMxZqFefr0hemcjZ4Ok5LzH6JULyHogeHo1sR0HvG3Hjxnd7lHupqT5ol4xd31fMDO/isW obqqcVXp SaTfIa4aGXcpRnyodVMQdSCLZVQQ84Xk1w8BELSTDmDj962Ti5PeLWUz9ElzkCiHdEhQMplBgmvneazsQj0en0MMcoJ+SDNTS/POGntUSCePUXdxZR0b8v+6qWhZi9x9poXkGagi2qXY8n3B2h9Dgpy7bw7kZH5DRRgTpY7NMfA0kwmnxJKihzbEOtjeus45NkjJqnbgpduQ+RX+wrKeCgFhxm3Ko4f++2yYDscb2RHWLRGF3ZhwcDy/s4g== 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: Ccing couple more folks who are doing similar work (ASI, guest_memfd) Folks, what is the generic way to check if a given mapping has folios unmapped from kernel address space? On Mon, Oct 14, 2024 at 04:56:31PM GMT, Andrii Nakryiko wrote: > From memfd_secret(2) manpage: > > The memory areas backing the file created with memfd_secret(2) are > visible only to the processes that have access to the file descriptor. > The memory region is removed from the kernel page tables and only the > page tables of the processes holding the file descriptor map the > corresponding physical memory. (Thus, the pages in the region can't be > accessed by the kernel itself, so that, for example, pointers to the > region can't be passed to system calls.) > > We need to handle this special case gracefully in build ID fetching > code. Return -EACCESS whenever secretmem file is passed to build_id_parse() > family of APIs. Original report and repro can be found in [0]. > > [0] https://lore.kernel.org/bpf/ZwyG8Uro%2FSyTXAni@ly-workstation/ > > Reported-by: Yi Lai > Suggested-by: Shakeel Butt > Fixes: de3ec364c3c3 ("lib/buildid: add single folio-based file reader abstraction") > Signed-off-by: Andrii Nakryiko > --- > lib/buildid.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/lib/buildid.c b/lib/buildid.c > index 290641d92ac1..f0e6facf61c5 100644 > --- a/lib/buildid.c > +++ b/lib/buildid.c > @@ -5,6 +5,7 @@ > #include > #include > #include > +#include > > #define BUILD_ID 3 > > @@ -64,6 +65,10 @@ static int freader_get_folio(struct freader *r, loff_t file_off) > > freader_put_folio(r); > > + /* reject secretmem folios created with memfd_secret() */ > + if (secretmem_mapping(r->file->f_mapping)) > + return -EACCES; > + > r->folio = filemap_get_folio(r->file->f_mapping, file_off >> PAGE_SHIFT); > > /* if sleeping is allowed, wait for the page, if necessary */ > -- > 2.43.5 >