From patchwork Thu Oct 17 17:47:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13840550 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 2EA6CD3C52A for ; Thu, 17 Oct 2024 17:47:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B74D66B0083; Thu, 17 Oct 2024 13:47:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B26276B0085; Thu, 17 Oct 2024 13:47:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A12C16B0088; Thu, 17 Oct 2024 13:47:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 841B26B0083 for ; Thu, 17 Oct 2024 13:47:23 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7A371A01B7 for ; Thu, 17 Oct 2024 17:47:02 +0000 (UTC) X-FDA: 82683825672.10.971F384 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf13.hostedemail.com (Postfix) with ESMTP id 0F52620002 for ; Thu, 17 Oct 2024 17:47:10 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ul9Gm+sw; spf=pass (imf13.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729187095; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=mFK/3r+8uKAfEBkvR3vMYR8OnbdEbHYRsZsyWYgKB5I=; b=b9WxR15ht3RBVg6mhQBi7w877w737MDWtFfEgPlF/blthqpCbstqb1obCmN5T9XyMATdnm jbgjlr7o4b3HUDcXt/H5yFMRFmXL5M9IP63u9JO95RlNj1wCKJjNnHYvuCHhFy8hkn/ZhR ZWHmDrLraV3czaVJyqcNS55BhUgmF48= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729187095; a=rsa-sha256; cv=none; b=mNUd99Z+KsvtEnlY96t+Koc74/t7MFb66A7LsEr4RW5Ksl65G5hQHb8JGAcsKLd04bm6cV P7sOXX1Uz5XxPXsLWecnMaw6yFurIo/YUMz8VsF2qJJoUeUKjl0iaI254zYE/Md24Tvq09 AJJ8ozdRu5QoVSHaa6DNTD8BnNvnyGs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ul9Gm+sw; spf=pass (imf13.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=andrii@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id F1A3D5C6185; Thu, 17 Oct 2024 17:47:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7866C4CECD; Thu, 17 Oct 2024 17:47:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729187240; bh=Cn02DK1/ZKdE3wGTEZWm4ta7PBaonJHJ5BZuMYejZuw=; h=From:To:Cc:Subject:Date:From; b=ul9Gm+swfBq9t+bm2ovTgBpErgP2OVJ/5GGOqe6Qnpzbyc1jWUPTanfu6Bl9I55xV yEvLuLFo6X1fh6xHTapCWNNTaRiUmEKIgvECXK/mK98legWTEtTWNyvFX2jTXzYhj6 aSpa8TRyctmNZXopFXwozbZ5KQRHZK40y5H9cfAoAQCTUzPoXHj14RLh7qav9U/CQp M+pNbaxesW8A5rXFsc64yqfmYq/MtKnJDIkLkSiLxi5IgdgCy+kjfBJpK8ZFoKqHKp +R8+/yPp509MdssDi6mmKN+aTRqZ0EIErXSXuuGPIa3Kk0bEMfDFqr9w6X3MDxCX7P HSFU+N3gkCrwA== From: Andrii Nakryiko To: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, martin.lau@kernel.org Cc: linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, rppt@kernel.org, david@redhat.com, yosryahmed@google.com, shakeel.butt@linux.dev, Andrii Nakryiko , Yi Lai Subject: [PATCH v3 bpf] lib/buildid: handle memfd_secret() files in build_id_parse() Date: Thu, 17 Oct 2024 10:47:13 -0700 Message-ID: <20241017174713.2157873-1-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 X-Stat-Signature: 3sew5db7p64rsuk349quxitjoqz9zsxo X-Rspamd-Queue-Id: 0F52620002 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1729187230-230832 X-HE-Meta: U2FsdGVkX18k+3HvKwEoFOYn9X9i7hHKRz0GpOOhc/ZqsIzSPSbv9AfHj/dXLP1zr/U7Y1wvsvLm0X2UMIkYd6L2mCr7PNA8B/gvsg6ypxVjtfnht2YkZfHwDHPl2ciCciX4ZLOveDd2vnlOdDwpAvYfAEiiUAhVjSF1406LR5bsBQ6ItLDCK70JmQt78F+ciA+Qcqg4351boYMSx4YpBvnOE2qoO+e8YDQ2FHsRISr1ZolPZzuuo+zi7P0f03vUEKiFbE+P5NSraJKFJEyNvJPa7oFN0hnlpCj4aeYVuYYgg8XUtXJCpbgNSgZ3mJZ2I4ea9kt2HeX2unRjtc104Hk4YmFKhDee2MKzOCeh3Wn8Uwx4ad3tymmFJ3nsIpYsnyCCvgmi3RkpW5FISW7GucsJu88zFFV2WkDWHoks+cFYMVdWCJz3UC28MLlv3UBxgpsw7YUb6MjRLMsdhdWS275FNyXtu7mE7kxFwwd1AokNb0vDiRIeOgK9rmbDVEpYvFO5Sry3K0E7hq9gXGDWQgmMahxQfXNTDg8mn0xCUn5Vu69h3U0WLrgogxgIhURK+KCC+TFTbDqPuNdxpiEW9m8+yyl3khEnUmphc2VzD5UwS5TpPnuP1k73Ocjn0/2+B3rNyYej87I5FlrV0K7VYGoOBYHEEGPCyNhqUDENVYY5gi7VgJI4IxHMecSPD6L/nwPd3DVpRDHt/n7iyjv/jnLdwL7HC6FFUpFazTEqb0uUn3PM/cciIyUGHs4kA+KOQlm+598/MYuGR0QhwX0vexgJ23djzaU0+uxkr/kf0I5iBUYBxF7k/FkzqKDdz5yy6ztL6iGtj0ERd0bNwXVXsMl99LNJTsulofqzr4qyGW9nelygedAEtUHLZl6fKFxsheSux7c2vKac4dEOy5NkOshk4AL57zEca0nVKaWy1DmAM6AzNQ0KeBupdPyye4l9OKWUOQgM7tahPc6LHib H/R24kL5 5XL8Ds1UOfwWBDaD7Rr7YSZ/7eBY1noVpS6y/uXGM34nVSmF5wrInJ6750n9/h58SY2shbHlyBD15mVIG/o7NrdPIG/HThtxnTMaI+xyegsdVJ7Dg+/r9ODFYt9m/Z7YB7sBhj1mBNBSdPpXktW1nEvbJx64duKj8IOwqdnJD9GzRhMsylUC4FfUtLNUMZdnNjdVLEEauqkxjrVecxGVVYTpPzSEHAKtMgTxPm55/sxnOVXODqBqz+25aej29WEeTFBMvneERoMbzBBej3RxgS/pDcC3E6eCQaVKQD4Dfv6V1Jspt/0i/4hqtlQ== 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: 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 -EFAULT 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/ Acked-by: Shakeel Butt 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..c4b0f376fb34 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 -EFAULT; + r->folio = filemap_get_folio(r->file->f_mapping, file_off >> PAGE_SHIFT); /* if sleeping is allowed, wait for the page, if necessary */