From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 2288080063 for ; Mon, 30 Nov 2026 13:21:15 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AUDJvkN005222; Mon, 30 Nov 2026 16:19:58 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AUDJvkN005222 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1796044802; bh=N+FAYSYX+Lc9M8sobliThyRc0eSpzOE+zG6FZVsjxVk=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=BwJn78y6xjEzwcmHuwP/EPC1S+9rwCj6392RTCn3WiZL1KElpuJjjGOhB0e3fcr1V HxpNBFo8mmaxqKFe/R6a2WF1FM4p37HbG+6MYoCeyMgSDIP7s6gN9GPErSvBId/awR miVMjsrpHaRvcNm2fqhoMLX0aPtl5Sxg9rPZAgzvpdpuGw2rPFQ4BjmXqZiKflzGOm De3MwviLVnpTue5XrSuxMBIih1t9XNdnMC+tn9CIPrC4lzKADtkyIizLIS1Xyqi+/e HYrmkb/CccVPsbtv/IBSQUizew3mza6sroOsaZImnlbRdGPnogj9a4g8lbC4PF5Y95 ZizLcJOv7Quhg== Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AUDJu43005216 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 30 Nov 2026 16:19:56 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AUDJu43005216 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="JXc5BAcO" Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-492b5408dedso2111774f8f.3 for ; Mon, 30 Nov 2026 05:19:56 -0800 (PST) X-Gm-Message-State: APuU4Z+Zh0RzuGWv60Z+f9EJ2M1DOnVJVDkEq2igtdhv9K9/nS2M0zy4 qPvqes+OHZzvoNRF2aIDZzd76n5x/xepzJPAjT7fTawB3dVHAonh/hruCDUROHAwitYNVEUL8pK b6rw6T/N55OL36JWwgs0ra//9dWW/7TUGE2BYO/ksYPvFQxKOGrqiqg== X-Gm-Gg: AZFdTZfL3UXXxaNivrrBDTFD0uDthOV3b4nws6htjaDQDYqUik5wV0LH8b56h6+aFvD EAZbym4LK4nrqVjgHeRhTDUrfutqmkLiKGtxiuIihj6e8nmTn6n8yLVzqHIlvtl4oMCyXQkire/ c2VMyH23Qr+BEiTN0YCfJy7NBZTyqIt7GsjxJANA1UKiOKRy0B1EtdoQtxTcQAGlE4CJtztXBaY 2lVsHqqQC9bmrt67QfUq4uI9RSvXlP5F6saMbmV9M8DjxiE63cQnWWbRPfFJJReQdfK4xE6UbWb eRKWDAVIqw== X-Received: by 2002:a5d:64c9:0:b0:488:88ec:59c3 with SMTP id ffacd0b85a97d-4abb0f3c071mr67955948f8f.14.1796044796244; Mon, 30 Nov 2026 05:19:56 -0800 (PST) X-Received: by 2002:a5d:64c9:0:b0:488:88ec:59c3 with SMTP id ffacd0b85a97d-4abb0f3c071mr67955894f8f.14.1796044795821; Mon, 30 Nov 2026 05:19:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796044795; cv=none; d=google.com; s=arc-20260327; b=jNDRq3GAOIBGaf4IDM5SZFXdrK2JIA7WtTQPUm+jR6g8By2kEhh7y+1aPvqx0HQqEs Moo0gbqyWRB/gSGybqHEGhxQc1Q9qziwQ3tkTwD52f1SPVQQ70oG8y8+betcUOFVF8tW nK1OtOpuEyoGODSuGpYK/xOWBvv3At4FfRWG+Gt1zG3gmi8XnqOm5w8ASMx3yEeq0jIN pRkEFyAXdlOS6kuPfNohG6f/geweF78/sbNcMaREERmtVce4UqOTmNAMbnMhFv7+TNzC h+btNdsRg8J38HayA6IzwSUPRBBEJEqCyWOj6/lCs5SQ8yxyEPZyy6jcfuXMt3lyupcW yH2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=Md81a/kitK8HTEMJzn5RZr6CoFviu8XP1aqxjeS19Uo=; fh=QlbYpooJoXfuC1kjlVz2kygMYgN9xKYFzeSCoqPlkh8=; b=QFm4hkgta02Y0LHINPeXygJrPnONEHV0EUv+yrIGCHDXBoX4ARg5KircZfPTr7Ri/8 IuJUG6/cY2u4K+x4uTd1+dczH/MIErS5f8TQDUEDyQktMU1QJOL4JWmBoFJiMWh576ra gfgKQRE23dl++7qs6yz3I/ZAbo/ee8oXAjs53CXWJXva/xySvPlUEsexuOZUwSmvJXnz RzxNhToSucccVi/Y7A64vQe7FqzcaQUlSr0TkME48zKXBPdRzdZ147OwW6YG9r/WYWsx +mIHt4OGi7kCEmWqjPBO4JONEYpqr/bFvlx+oE/LnEhQaz1M+rgGQGl8V1x2RYvIC24Y rymw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=JXc5BAcO; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:5748:a9a4:9c41:84f3 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-4ab716882e9sor4613363f8f.7.2026.11.30.05.19.55 for (Google Transport Security); Mon, 30 Nov 2026 05:19:55 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:5748:a9a4:9c41:84f3 as permitted sender) client-ip=2a06:5b06:b600:300:5748:a9a4:9c41:84f3; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=JXc5BAcO; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:5748:a9a4:9c41:84f3 as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1796044795; x=1796649595; darn=openvz.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Md81a/kitK8HTEMJzn5RZr6CoFviu8XP1aqxjeS19Uo=; b=JXc5BAcOiy+5Sza1KjCqEVV1d4sxuyxq8idilijQH4sIcQU0jZWYIXs9zmFZ5Tl796 xH6Y/eX0B6ylCWVlseGaRa6pHvqwdJqdm5PTAz+4qVc4xuTPzeZjEefD2X/HSDI8r3/m PvsccEGHFIY8PxRyMopctlHqaW5emXbSvrBjoPMrn7Y2Smw+rvE9to0LJSK2uDH/kKbm oywr+EriiMbytRNEuqkt8tbijx0gXjNKCQResltrH4uz2QxP82z61yq77UbxM+3Naacn b5cYHoLfCLBGmO4Llsfu4yqo1VDLZCe57yAOGZQn0HbT3oHGD0/wxxpyJvHjE8dvu2pu wNZQ== X-Received: by 2002:a05:6000:186e:b0:487:6f2:1a4c with SMTP id ffacd0b85a97d-4abb225ebacmr66042604f8f.25.1796044795230; Mon, 30 Nov 2026 05:19:55 -0800 (PST) Received: from artemis.sw.ru ([2a06:5b06:b600:300:5748:a9a4:9c41:84f3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6baa3882sm63381879f8f.49.2026.11.30.05.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 05:19:54 -0800 (PST) From: "Denis V. Lunev" To: khorenko@virtuozzo.com, ptikhomirov@virtuozzo.com, vasileios.almpanis@virtuozzo.com Date: Mon, 30 Nov 2026 14:19:52 +0100 Message-ID: <20261130131952.2329425-1-den@openvz.org> X-Mailer: git-send-email 2.55.0 MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2] fs: fix use-after-free in fs_send_uevent_work() X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Denis V. Lunev fs_send_uevent() queues a work item that carries plain pointers to the superblock and to the filesystem kobject. Nothing keeps them alive until the worker runs; each filesystem is expected to flush fs_events_wq before it frees them. That cannot hold for ERROR and ABORT events, which are raised from error handlers, for example by ext4_put_super() when the journal cannot be written on unmount. The event is queued after the only flush, the unmount completes, and the worker walks a freed kobject: BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:strlen+0x4/0x30 fill_kobj_path kobject_get_path kobject_uevent_env fs_send_uevent_work kobject_uevent_env() allocates with GFP_KERNEL between its checks and the path walk, so the worker can sleep there and lose the race even when it has started in time. Take a kobject reference when the event is queued and drop it when the worker is done. ext4 and XFS wait for the release of their registered kobject before freeing the filesystem data (s_kobj_unregister, xfs_sysfs_del), so the superblock stays valid for as long as a reference is held. A kobject in zeroed memory, or one whose last reference is gone, refuses the reference and the event is skipped. That covers the failed mount paths too, where events used to be queued for a superblock about to be destroyed. The reference is taken before the one-shot ERROR and ABORT flags are tested, so a sender that cannot take it does not consume them. An ext4 error raised during mount, before the kobject is registered, used to burn the flag on an event that kobject_uevent_env() rejected for lack of a kset; the first error after the mount is now reported. An ERROR raised after ext4_unregister_sysfs() finds the kobject still alive but already removed from sysfs. Its DEVPATH would be a bare "/", so the worker drops the event instead of sending it. The check is best effort: it can still race with kobject_del(). ERROR and ABORT raised while ext4 unmounts are therefore not delivered. https://virtuozzo.atlassian.net/browse/VSTOR-157864 Feature: fs: udev events support Signed-off-by: Denis V. Lunev --- fs/super.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/fs/super.c b/fs/super.c index c0c067eb2d8e..99f1dcce409b 100644 --- a/fs/super.c +++ b/fs/super.c @@ -2326,10 +2326,8 @@ static void fs_send_uevent_work(struct work_struct *w) int ret; env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL); - if (!env){ - kfree(e); - return; - } + if (!env) + goto out_put; ret = add_uevent_var(env, "FS_TYPE=%s", sb->s_type->name); if (ret) goto out; @@ -2372,13 +2370,24 @@ static void fs_send_uevent_work(struct work_struct *w) } if (ret) goto out; + /* best effort: a removed kobject has no valid DEVPATH */ + if (!e->kobject->state_in_sysfs) + goto out; ret = kobject_uevent_env(e->kobject, kaction, env->envp); out: kfree(env); +out_put: + kobject_put(e->kobject); kfree(e); } -/* fs_send_uevent - prepare and schedule event submission */ +/* + * fs_send_uevent - prepare and schedule event submission + * + * The kobject must sit in zeroed memory until it is initialised, so that + * an unregistered one has no reference to take, and the filesystem must + * wait for its release before it frees sb. + */ void fs_send_uevent(struct super_block *sb, struct kobject *kobj, enum fs_event_type action) { @@ -2386,21 +2395,25 @@ void fs_send_uevent(struct super_block *sb, struct kobject *kobj, if (!fs_events_wq) return; - if (action == FS_UA_ERROR && xchg(&sb->s_err_event_sent, 1)) + if (!kobject_get_unless_zero(kobj)) return; + if (action == FS_UA_ERROR && xchg(&sb->s_err_event_sent, 1)) + goto out_put; if (action == FS_UA_ABORT && xchg(&sb->s_abrt_event_sent, 1)) - return; + goto out_put; e = kzalloc(sizeof(*e), GFP_NOIO); if (!e) - return; + goto out_put; - /* Do not forget to flush fs_events_wq before you kill sb */ e->sb = sb; e->action = action; e->kobject = kobj; INIT_WORK(&e->work, fs_send_uevent_work); queue_work(fs_events_wq, &e->work); + return; +out_put: + kobject_put(kobj); } EXPORT_SYMBOL(fs_send_uevent); -- 2.55.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel