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 71E202FE583; Tue, 12 Aug 2025 18:05:27 +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=1755021927; cv=none; b=MR2WKRX5Qs7Z5MEj5WrE10rZMfjHMcdy05k826n7HlMMWw5KnfxgH49EpZ8E6lYZZ09PsP+Fr58ZHzTvvEZ/nCkKspvlQ9AOMhEP7YYN6yqDWaSvmjeKtJqULDcrpDnETPvD4FXLMtpdiRck4DjimUmQH9+pDKzGJj2rJECUQp4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755021927; c=relaxed/simple; bh=dQ3FXcvi35p77fNOQLuKbQOLNN1UfEkWHyaobFU9E6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nZn4Sgzxrl6A0PrUNqeYx6a+IWggk2RNG6xPtFpSf5i9W0BYuRwVV50EF9/STfQJnRU3sybisC2CO7+4tAvtTJY11kwg9uQnWctdpV8zAGyulVMI/S74RTahu8DrzHa+GAotaHsvCtTOOYUzZeiW2AvVjuJnhfjW1L9IyOi9GVc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bT+xJwj5; 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="bT+xJwj5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0A3EC4CEF0; Tue, 12 Aug 2025 18:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755021927; bh=dQ3FXcvi35p77fNOQLuKbQOLNN1UfEkWHyaobFU9E6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bT+xJwj5q9lK0YxSMzKvj3p5CFUcgz1hGUanP2THl5aIVqFiVFA44daVAziWrpy69 L1JKW/ZNk0OzaKxjaV0xSwiNq5DMRjKWZxMvpDjRli7lwL4p9HzN/tb9SkNtnV71Nh W7K3TH9LyrOwjHHDhSKmWqLbB4rD4jTO7nRuH5v0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thomas Gleixner , Lorenzo Stoakes , Arnaldo Carvalho de Melo , Vlastimil Babka , zdi-disclosures@trendmicro.com Subject: [PATCH 6.6 233/262] perf/core: Prevent VMA split of buffer mappings Date: Tue, 12 Aug 2025 19:30:21 +0200 Message-ID: <20250812173003.079837145@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250812172952.959106058@linuxfoundation.org> References: <20250812172952.959106058@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Gleixner commit b024d7b56c77191cde544f838debb7f8451cd0d6 upstream. The perf mmap code is careful about mmap()'ing the user page with the ringbuffer and additionally the auxiliary buffer, when the event supports it. Once the first mapping is established, subsequent mapping have to use the same offset and the same size in both cases. The reference counting for the ringbuffer and the auxiliary buffer depends on this being correct. Though perf does not prevent that a related mapping is split via mmap(2), munmap(2) or mremap(2). A split of a VMA results in perf_mmap_open() calls, which take reference counts, but then the subsequent perf_mmap_close() calls are not longer fulfilling the offset and size checks. This leads to reference count leaks. As perf already has the requirement for subsequent mappings to match the initial mapping, the obvious consequence is that VMA splits, caused by resizing of a mapping or partial unmapping, have to be prevented. Implement the vm_operations_struct::may_split() callback and return unconditionally -EINVAL. That ensures that the mapping offsets and sizes cannot be changed after the fact. Remapping to a different fixed address with the same size is still possible as it takes the references for the new mapping and drops those of the old mapping. Fixes: 45bfb2e50471 ("perf/core: Add AUX area to ring buffer for raw data streams") Reported-by: zdi-disclosures@trendmicro.com # ZDI-CAN-27504 Signed-off-by: Thomas Gleixner Reviewed-by: Lorenzo Stoakes Acked-by: Arnaldo Carvalho de Melo Acked-by: Vlastimil Babka Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/events/core.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6499,11 +6499,21 @@ out_put: ring_buffer_put(rb); /* could be last */ } +static int perf_mmap_may_split(struct vm_area_struct *vma, unsigned long addr) +{ + /* + * Forbid splitting perf mappings to prevent refcount leaks due to + * the resulting non-matching offsets and sizes. See open()/close(). + */ + return -EINVAL; +} + static const struct vm_operations_struct perf_mmap_vmops = { .open = perf_mmap_open, .close = perf_mmap_close, /* non mergeable */ .fault = perf_mmap_fault, .page_mkwrite = perf_mmap_fault, + .may_split = perf_mmap_may_split, }; static int perf_mmap(struct file *file, struct vm_area_struct *vma)