From nobody Sat Feb 7 18:20:40 2026 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD5402BEC5A for ; Mon, 2 Feb 2026 07:51:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770018690; cv=none; b=CBHqhiK5+ZNmBOyzXnL+u4SdW6FdZWKVjUP44xiREd9ViOjXoYuRXFF6FT3avv1yXYqZMNG6LFDy+UCiezFD4Wl6+/WB9lXa76yaAjjgugep3Fzhd1hQAqCxQJiW9boxAQlRKfMftgqGXOtwjrQtln4bq+vjTPWZDxcpdlJ5A+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770018690; c=relaxed/simple; bh=9VdcutY/1HtuM0eOblIVyvBoIezSx1Mw/CCfmtVy3Xk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kAzvVhSLiH2L72IpO+t7/t7fiRyxIz//+eOEmGv5foOrhExiJPxjU/+MCjJGIid8IUGB8cpsKLhdsAxlCNf9G1/I/5eLAUGruzvWce534Oe58htmU0Eo27kj2x58fJobSOqDjsa5DUMzugAg6fEXI/sJB6UEEcFTIP+/iCVs5Fk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gdFW3wb2; arc=none smtp.client-ip=209.85.210.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gdFW3wb2" Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-81e9d0cd082so3345483b3a.0 for ; Sun, 01 Feb 2026 23:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770018688; x=1770623488; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oiA8iwxfevRzDtj5meYZoNEt0fOR2pKNa2ks4Nm0b2o=; b=gdFW3wb2F4xYmBr1spYhAOHN+ARLh9s/0AZbF0sGvmUFfDYfY0vrdCGopN+3a8pUph IhKgyzE0EOGU8kQLD405N2S8mSQIg0eXDkyCdEcVuOMrTyavJMu9UgZIDz5pi+UqCkcZ 2Ii+vvPxJKgjLkocXyqjwtEA91/lLh+gqLHLj1G6xEvuvWdMe4iMJzf+tY6WkgB7t0at T2ecVzXbEG8W2fuh1OUlFEpGBLu9wzMhxbnfmlE+ZfqHM+ChsNze5bumVrc0RgfXKmWa Ckc5OOF3h1WqOEx+FFGQJNivua6NSbyf0IBX07u1EiZedkUhv3Qmztx8I+4oO765DO+H q18A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770018688; x=1770623488; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oiA8iwxfevRzDtj5meYZoNEt0fOR2pKNa2ks4Nm0b2o=; b=B9i5HUUBDoLHB5l2HJKSH2O22tccgEezxdfsixfkKPdtxHaJkIooRI/Igfponl35G9 Q1ceAZWeDfX4JTCckYXd6VqbBlr3/Inu/havXRSKXLIoepuGEsq4ka2J39Qx5+t0/mi6 BS9c3jCmMWT5jvLzqzHcI41ciIJxKW9kupSfqD6QI5qcVTYvev93gGwKix3Is7mKPHQo Vnyq0FH850tKzrzj+nJ9UaBum71p5stnvupq1gvUO3PTQNo/e7iNJfQo/0J3g3wk3D38 nFLO/OE/CJvVqNXFgX0aXW8t/KIfStjHDZoV7xZOe+8jK+xSTmC6SayaXHCTSs9kHJ28 g/Vw== X-Forwarded-Encrypted: i=1; AJvYcCU1xbqi4hw7uqu6a/OnZpMtGJYUr9ku0LCk2Op13KPbgQEiluBqt54IYAS2lYyEszp/HI2fkeqLDUdzSjU=@vger.kernel.org X-Gm-Message-State: AOJu0YxB0vTfKKRz8mbhpunLKJfZpFQZsO0Ep8+R/AybnrfocKypkKE0 UhBArCl4B+nxY4YCv9qAlVidE8JWfNNbeGMmvu7Vl+/HPrrsOX8H+gz/ X-Gm-Gg: AZuq6aL9Rye9gI7Tk+e5dgpmwOdu1Sjt0HL6/drQxrqylu5753EPgiYfRiUD1dXoCt2 6HVODBOYiLkhczxo6kySzxBFPYdWf4W5PCwPz9MsKsrS8S44dP3cJaRTzFSs81IgU1BoM9KMJiU PARDf/SuZfmBwEd9J4PDdDREc6iAztlihi6sec8DoH2fr01u2r291ToQv9RmHsQQxx3luon4qR2 CCG6mKXYsJy5bGsgU8YwTjWdx+sxS6nVHi5YAbpR/IEK/tpgD86iRxQzSYqjE+vpmtjVGwuxMu/ 5W3hjBsSkKJ1cH1u8a5rwDHicyGG8oFmigg7XJvR6HToOKhGhv/n73jHQqORzC6/BZQ9CQAmTWy MdqjU40YplHLm5awL8dJP3KQLYhIibdR4jbsX8pOzXTUbE2eBy/OqiX88VtqVUtm6lU56vuJHSG 5HXTPxlJeys7yoqEbh1OaGrraUrjdFUA+753Y= X-Received: by 2002:a05:6a00:1c88:b0:81c:785e:1216 with SMTP id d2e1a72fcca58-823ab317d52mr10655676b3a.0.1770018687976; Sun, 01 Feb 2026 23:51:27 -0800 (PST) Received: from LAPTOP-1HUHJV8R.localdomain ([222.205.46.87]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82379b1d024sm15299686b3a.12.2026.02.01.23.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Feb 2026 23:51:27 -0800 (PST) From: Haocheng Yu To: acme@kernel.org Cc: security@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH] perf/core: Fix refcount bug and potential UAF in perf_mmap Date: Mon, 2 Feb 2026 15:44:35 +0800 Message-ID: <20260202075120.4005-1-yuhaocheng035@gmail.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026020157-crayfish-distract-7da1@gregkh> References: <2026020157-crayfish-distract-7da1@gregkh> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Syzkaller reported a refcount_t: addition on 0; use-after-free warning in perf_mmap. The issue is caused by a race condition between mmap() and event teardown. In perf_mmap(), the ring_buffer (rb) is accessed via map_range() after the mmap_mutex is released. If another thread closes the event or detaches the buffer during this window, the reference count of rb can drop to zero, leading to a UAF or refcount saturation when map_range() or subsequent logic attempts to use it. Fix this by extending the scope of mmap_mutex to cover the entire setup process, including map_range(), ensuring the buffer remains valid until the mapping is complete. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202602020208.m7KIjdzW-lkp@int= el.com/ Signed-off-by: Haocheng Yu --- kernel/events/core.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 2c35acc2722b..abefd1213582 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7167,28 +7167,28 @@ static int perf_mmap(struct file *file, struct vm_a= rea_struct *vma) ret =3D perf_mmap_aux(vma, event, nr_pages); if (ret) return ret; - } =20 - /* - * Since pinned accounting is per vm we cannot allow fork() to copy our - * vma. - */ - vm_flags_set(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_DONTDUMP); - vma->vm_ops =3D &perf_mmap_vmops; + /* + * Since pinned accounting is per vm we cannot allow fork() to copy our + * vma. + */ + vm_flags_set(vma, VM_DONTCOPY | VM_DONTEXPAND | VM_DONTDUMP); + vma->vm_ops =3D &perf_mmap_vmops; =20 - mapped =3D get_mapped(event, event_mapped); - if (mapped) - mapped(event, vma->vm_mm); + mapped =3D get_mapped(event, event_mapped); + if (mapped) + mapped(event, vma->vm_mm); =20 - /* - * Try to map it into the page table. On fail, invoke - * perf_mmap_close() to undo the above, as the callsite expects - * full cleanup in this case and therefore does not invoke - * vmops::close(). - */ - ret =3D map_range(event->rb, vma); - if (ret) - perf_mmap_close(vma); + /* + * Try to map it into the page table. On fail, invoke + * perf_mmap_close() to undo the above, as the callsite expects + * full cleanup in this case and therefore does not invoke + * vmops::close(). + */ + ret =3D map_range(event->rb, vma); + if (ret) + perf_mmap_close(vma); + } =20 return ret; } base-commit: 7d0a66e4bb9081d75c82ec4957c50034cb0ea449 --=20 2.51.0