From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45DAD19AD5C; Tue, 8 Apr 2025 11:40:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744112423; cv=none; b=T1aSvPIuGlQj+PQRFbIHFUylCIDllJ0BVvfhnDYjVz6C2DWsITA2zkWe1uDxOKKpBcLGEWy1YVbv1pXdywVbz/eBVeIFwpME81Tqte53SodC606UiXSdlYfso2gyfy0mhwZXGPsRMs0uC5ycQhO0xuN2d5iGmVznGh8Ln/HUPsg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744112423; c=relaxed/simple; bh=vwxPOaxjcZkrEQEDS0rGYVI4TjY7atPH3P6Iq3TaUL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ERcL/rjsO12ydkJ9HhUsVLVnfDOobjLgm6eLaQDEq/4EfrSbLAMCwS2g7l/iWXuTYOCAf1CnawxAUlh+IgmCaFDfucRouCUWtN5nmB2LWGmLEV9D0jQTCkb8d1PjLZO8dRM1EnTC4bTipjz+l1xUx7XoFbkvr8tEGksJWzOtC00= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=okeqMIhK; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="okeqMIhK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8783C4CEE5; Tue, 8 Apr 2025 11:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744112423; bh=vwxPOaxjcZkrEQEDS0rGYVI4TjY7atPH3P6Iq3TaUL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=okeqMIhK6Rlpo3r2RmHNWQzhkJFutxABxSlKCdub98j7SxTJfHS0VTxLNf0cD6XVp iymPvQ1CBJY/vdEh/oJwbAemAL+SwTP81ZtrmwSqkijGS5DSpEQhOjHYQABKHRclnt TDB3AhN6u7hgsfNTPDq5+vw+Uw53DjBgzHUBTD3c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yi Lai , Shakeel Butt , Andrii Nakryiko , Daniel Borkmann , Chen Linxuan Subject: [PATCH 5.15 063/279] lib/buildid: Handle memfd_secret() files in build_id_parse() Date: Tue, 8 Apr 2025 12:47:26 +0200 Message-ID: <20250408104828.046711846@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104826.319283234@linuxfoundation.org> References: <20250408104826.319283234@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrii Nakryiko commit 5ac9b4e935dfc6af41eee2ddc21deb5c36507a9f upstream. >>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/ Fixes: de3ec364c3c3 ("lib/buildid: add single folio-based file reader abstraction") Reported-by: Yi Lai Suggested-by: Shakeel Butt Signed-off-by: Andrii Nakryiko Signed-off-by: Daniel Borkmann Acked-by: Shakeel Butt Link: https://lore.kernel.org/bpf/20241017175431.6183-A-hca@linux.ibm.com Link: https://lore.kernel.org/bpf/20241017174713.2157873-1-andrii@kernel.org [ Chen Linxuan: backport same logic without folio-based changes ] Fixes: 88a16a130933 ("perf: Add build id data in mmap2 event") Signed-off-by: Chen Linxuan Signed-off-by: Greg Kroah-Hartman --- lib/buildid.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/lib/buildid.c +++ b/lib/buildid.c @@ -5,6 +5,7 @@ #include #include #include +#include #define BUILD_ID 3 @@ -157,6 +158,10 @@ int build_id_parse(struct vm_area_struct if (!vma->vm_file) return -EINVAL; + /* reject secretmem folios created with memfd_secret() */ + if (vma_is_secretmem(vma)) + return -EFAULT; + page = find_get_page(vma->vm_file->f_mapping, 0); if (!page) return -EFAULT; /* page not mapped */