From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (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 2AD4628468E for ; Fri, 20 Mar 2026 06:23:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773987793; cv=none; b=ePt2Oj2zr5vr9smS1jpK0cBDiHjFO34YvKupLOw01spJqnfS8N3GFzJYUAfH+xjvOYlP8f9wFgcwEbT5d31HQ1DS6xOeK2LX90oVzqEBN500bQ/VBLuAmzWYepVP/+/fnbKkfMed3MKhjLpyPjwKR6CxjNAOsfrWOMzrLacNtGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773987793; c=relaxed/simple; bh=PVQ77e0jbKpBY2tJZGoqQGz8ou5TJuzgxx42AvozcOc=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=nEcCnZPPudPH9HpOQrg2isvJFG1+bAAlUSSii8bdJNktC4xjazyq9mraZSvXCFtvVdjRYQlkVoMAhg9f2zjcntNsgknUkWk46mDTsasoSDC19d8u6ezkpqODAAuOJ/QbNQL1Yf2xBYOSsJ0gE80AUu3TewikfKnG6GHMUK6OE2g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.210.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-7d7510702e6so14747911a34.3 for ; Thu, 19 Mar 2026 23:23:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773987791; x=1774592591; h=to:from:subject:message-id:in-reply-to:date:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ql18l176PvKtgikXfHvk7yFlowN+Q1SiUc2MMTj6OmY=; b=R57Xfcy1v+1sGHLeMjrt4SDCHSwqgEI5eNkhpburu5gF5RmPjxHv7LBHQnWhniX/Cb W94Ry/mYriLdTXUQODcXeYOwd1JdKB+F8FNNpaYHMzNeCrmVmf8HkLLf5cP2qlqPClEu Qsi1z0c2cK/Qm5hQ3knQWq6GC7mYCf8wBDPHSmTsIGPt0psQoaAgsBGw7bQ8L5lGJz2u Di00MVa7vze4hP/is6fQcOGv3ijOsdOoN7ZAaa7Kt2X2/KIDUlFBuwWR2x91LaZN4xia N1MVNfIrS2WAyRDK7XEpBNl0DUkhsqzdxpJe0pBL5oagwd3subxbt/y2dBghs0taNvLg AMIQ== X-Gm-Message-State: AOJu0YwXmRA4Xuxx68oYxr3DySrFAM7fR4iO9EfPJYrpNRApBtfBb/SX /CjP3IYzYsRQwoEwvLy/XJx73OsSKIKgUNRkR/LHaDBGNuxRQt3H0TIU/FeIBhxYF8AMR0XTsch FCq+W46XOYQ3z09avidfdfQ5i61YEQ+Q6AIFCuSsz1E3ZTTZvAwRrqkvUn/g= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6820:2003:b0:679:946d:351f with SMTP id 006d021491bc7-67c22bd076cmr1648055eaf.13.1773987791229; Thu, 19 Mar 2026 23:23:11 -0700 (PDT) Date: Thu, 19 Mar 2026 23:23:11 -0700 In-Reply-To: <69bba3fe.050a0220.227207.0030.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <69bce7cf.050a0220.3bf4de.000e.GAE@google.com> Subject: Forwarded: [PATCH] media: em28xx: fix use-after-free in v4l2_open() during init error path From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" For archival purposes, forwarding an incoming command email to linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com. *** Subject: [PATCH] media: em28xx: fix use-after-free in v4l2_open() during init error path Author: kartikey406@gmail.com #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master em28xx_v4l2_init() calls video_register_device() which makes the video device immediately visible to userspace. At this point, v4l2_open() can be called concurrently and access vdev->dev_debug which is embedded inside the em28xx_v4l2 structure. If a subsequent initialization step fails after video_register_device() succeeds, the error cleanup path calls kref_put(&v4l2->ref) which drops the reference count to zero and frees the em28xx_v4l2 structure via em28xx_free_v4l2(). This results in a use-after-free when v4l2_open() reads vdev->dev_debug from the already freed structure. Fix this by adding kref_get(&v4l2->ref) at the end of successful initialization, matching the kref_put() already present in em28xx_v4l2_fini(). This ensures the v4l2 structure is not freed while it is still accessible through the registered video device. The following race triggers the bug: em28xx_v4l2_init() video_register_device() <- device visible to userspace later step fails goto unregister_dev kref_put(&v4l2->ref) <- ref hits 0, struct freed! v4l2_open() <- runs concurrently reads vdev->dev_debug <- use-after-free! Fixes: 47677e51e2a4 ("[media] em28xx: Only deallocate struct em28xx after finishing all extensions") Reported-by: syzbot+1a7507a194fff09e5c44@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=1a7507a194fff09e5c44 Signed-off-by: Deepanshu Kartikey --- drivers/media/usb/em28xx/em28xx-video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c index 5f13f63fbdee..fe2a7771275d 100644 --- a/drivers/media/usb/em28xx/em28xx-video.c +++ b/drivers/media/usb/em28xx/em28xx-video.c @@ -2876,7 +2876,7 @@ static int em28xx_v4l2_init(struct em28xx *dev) "V4L2 extension successfully initialized\n"); kref_get(&dev->ref); - + kref_get(&v4l2->ref); mutex_unlock(&dev->lock); return 0; -- 2.43.0