From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796156674; b=dDqFEDLPbm/FDtj/ReAnK6MPSVqKROSNsqNRCeZVrBPq9wqA0oUu8hitExzguaOkdPzs na9EfI5viSp97rtYcVPfTjpeWMKaRmrTx0bHMy/qdgmo7YhClP5I7ILeudMdoRApAfl1k KCoNObLuV7Ym8c34i80cFtP/iUUBwjp1jeB5w5V9VanSrr3RPLrNeEVL+BTmO2XMCfNLq W7nj01L39Vmw6Vjn/y75UqsIwgjksPc5XHVLwUfVfmY2jNAIKKrvqB04v7pIBr9j/MY4s tk2ZWrsNMMCoyc6HWkWusZ3+Ivx8Hfj1SU1m6/iNG3lJv3dwWId9sddyKBKLmIueXLQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796156674; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding; bh=IndbUCyBVqikx9szdspG+uRwZ63WqtRcff/R61B4+rI=; b=vDO9uBo3syb3KylOL3p10ED24uLZgfdtT8jMao0mn0xOXxUzjlAEL3NvoUtCAw0PMUru wteQHUno+GcY4XdT6YoxkNvjQQxzrEllqi6vSpm6KUeUCWWugP7WL6LGEl92dbtISHjQs RJzEz1tvZSRtimi795jLiXDjjObzlY5hSCBup2IDipcCywr6mNLKz+J0ye4kKj8w7x2rL Fxuq8kZuFazb9AO24VX5GBV3KYzLdzQySpV7gJ24Bd/STu+8WwZS96sBoIccthQzfh9Ox y/DcAFJUmNF7Zn+w8rHVd5wl4x2ihAPr4EL/VDF1c58FvSOfx2EMGv/Tj2sHMGEv89g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass header.d=trailofbits.com header.i=@trailofbits.com header.a=rsa-sha256 header.s=google header.b=Us3btzgs; arc=none smtp.remote-ip=74.125.82.47 Received: from mail-dl1-f47.google.com (mail-dl1-f47.google.com [74.125.82.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2AEB606A322 for ; Tue, 1 Dec 2026 20:24:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A2AEB606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.a=rsa-sha256 header.s=google header.b=Us3btzgs Received: by mail-dl1-f47.google.com with SMTP id a92af1059eb24-1a3c08d6928so18761311c88.0 for ; Tue, 01 Dec 2026 12:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1796156673; x=1796761473; darn=vger.kernel.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=IndbUCyBVqikx9szdspG+uRwZ63WqtRcff/R61B4+rI=; b=Us3btzgsjAnnbYCI4c0gQEqAhuSYXWldt1lVt3GlSeOBJyN6TAWXgb6VgAplkBtcP7 EYrvp4DvK0tCoC3Wcjw1K9H5aCnPqVYjUcVE6UCU34o5Ui7XMQXE7mXHhqGszDKbzGKk FOlQHXZN1uMZoznq9QKiJFQy8vjHLm3MW1N//NdE5GFGbdDR1RDwzmIXooIDRuegC9Rj DHiBKs00KMl+b+HkNtzs2vkohNNnbEyR5vfCe9Zlb/1fIbNcPKZFiuIRV72lBLF+Bgsy j+RloqF2l2h8uszKZl23wzewOENXRMEfAT//OS1pipWz2Y5bEZ0Uf5c/4MVESOiyaeQ9 AMvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796156673; x=1796761473; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=IndbUCyBVqikx9szdspG+uRwZ63WqtRcff/R61B4+rI=; b=NMHgZILTKViAZdQxaTnHMwBSqXbZ5gbLYBF4C0OzhNHDOLtVTsKk32sr4OTuxNM/wM WqptxifblQkNvSpzcp+hqecsscWFi8Hh0A5/O6LyK0Lwg4ty3Z4mRXnS7u+RzIJ8bfy8 kxxQ3NUcUevGdXNSbM9oqZS/t/ww1Tu/d9JP4r5heijY3y1SPUZet0w+Jy2J1UnlszJ3 1ENR/yuBE0ucsS6RkQWFpGJtA5Q7t763CXg86xbc9Sq7KDMSiWVwTwllmMobe9bbBDxv S8oFF1OtB+7Wrzwl6gk35yrRVu9s7nXZD36HTKo7xPmD3u2M8hHfDXORXcAhRwp0lQV4 5JAQ== X-Forwarded-Encrypted: i=1; AL+hErGQDe6QQoLnqVGDLCSjoubRMsXlMVQeGlXp9UfQz587w2e2IYT0lY0e6FbIrlc9Cgw0DEwAy40gyZuv8js=@vger.kernel.org X-Gm-Message-State: APuU4Z+4tHU7MxO3+OBC9QGtyTiIPmnE98sKoYJTEaWEWXVbRiYV9M79 oXgCcvH7jsiAK2d4M8Mh/z7cXzMa3aaTN488KKR2QsLDP61I2MGqOkrm99xkpGmLmcs= X-Gm-Gg: AZFdTZfiNqmAvYwP58ekl2EbgW9SKihuGsbEzdjoMdp2M05a8l0tsHUPtNItR5G6Lqx jPS303GAj8TuGNgKSFnBZ7ty78QtuUwmwndj71wPu6ZVNMglek4tcc+ZNal3UWq90pBuSzU+TOJ ZfHxcNwm3IOuKXxFXfQGo6+cPNw43IwCJmafU6Y9LGKXVHpOMSWaB+PNbuU7oY+qna3yh1cbGfS maYurijh5rJmvIGdYAb60XVI294KGqf5cuQuTM/lV3TtY/xqP4EPdabf7yCQ6XU3FNfLHhWGqSD cRbRcG0P1NrMA4j3SEy1MbpcsW00uXcmeQtOL5GDAA+bDIlCc4cJEvwJjkTbUgmDxXuGdXNC2ib CoaC7zjvp/I6V0SfO1EPYohSsMAUpHEIc/8sPXpeN0whJze9tOiKt+9Dcqqw/e5zN+RssTApS0C jcN1skHgfgR8QOeQ+TDpLO+fenTZ1SDpp56st4ZCVJxWkyQdr1Fy1OAOD83i0meDfx/YVujdEn2 7njf0Pu1tTG7DGIYNyAOYXMsOy0epRni67j659imqUFQX3WUW7FVyZsgZLTw/ENxO4aEa0FoTkZ XCuGOuXfd4VWcBL9MVHMMRN7wUSPwCK4g7SX+b/EszJpjKCRC+KMuLoNp+8f8+A0FwS5ZODo7Uh 5B2ATXzFzs4CAPAkz3WQf5rQveFYHlgSu0KiZPC459jZ/pg== X-Received: by 2002:a05:7022:299:10b0:1b5:7329:90a8 with SMTP id a92af1059eb24-1b57329918fmr27813653c88.38.1796156672285; Tue, 01 Dec 2026 12:24:32 -0800 (PST) Received: from localhost.localdomain ([2603:8003:6d40:6669:64d9:8f5c:3d5:8f62]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b55ff0e4e6sm79620377c88.11.2026.12.01.12.24.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 12:24:31 -0800 (PST) From: Artem Dinaburg To: isely@pobox.com Cc: mchehab@kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] media: pvrusb2: release DVB frontends before I2C adapter Date: Tue, 1 Dec 2026 15:24:30 -0500 Message-ID: <20261201202428.32470.380.02-pvrusb2-dvb-i2c-teardown-patch@trailofbits.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The USB disconnect path unregisters the I2C adapter before the context thread releases DVB frontends. An I2C-backed frontend can then be freed while dvb_unregister_frontend() still accesses it. Defer I2C adapter removal until after the context thread has checked and released its channels. Keep the final removal before v4l2_device_unregister() so I2C subdevices are gone before their parent is unregistered. Found with an AI-assisted code audit; the fix was drafted with AI assistance and tested with a KASAN USB replay. Fixes: f8194e5e63fd ("media: pvrusb2: fix warning in pvr2_i2c_core_done") Cc: stable@vger.kernel.org Signed-off-by: Artem Dinaburg --- KASAN report from a USB emulation replay of a disconnect: BUG: KASAN: slab-use-after-free in dvb_unregister_frontend+0x84/0x90 Read of size 8 by task pvrusb2-context/443 Allocated by lgdt330x_probe [lgdt330x] Freed by i2c_del_adapter -> pvr2_i2c_core_done [pvrusb2] A reproducer is available privately on request. drivers/media/usb/pvrusb2/pvrusb2-context.c | 3 +++ drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 9 ++++++++- drivers/media/usb/pvrusb2/pvrusb2-hdw.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/media/usb/pvrusb2/pvrusb2-context.c b/drivers/media/usb/pvrusb2/pvrusb2-context.c index 93f5da65ead9c34620e61d3cbd50ebffd348a576..42a7c2d1692f5667b8dc797f19abff11ba02dffc 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-context.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-context.c @@ -132,6 +132,9 @@ static void pvr2_context_check(struct pvr2_context *mp) if (ch1->check_func) ch1->check_func(ch1); } + if (mp->disconnect_flag) + pvr2_hdw_i2c_done(mp->hdw); + if (mp->disconnect_flag && !mp->mc_first) { /* Go away... */ pvr2_context_destroy(mp); diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c index c749ef7e490a87f510dcee3b743cf8c9cf1933f1..88a0dd61caae524325dc8d0bea398df89772a3e7 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c @@ -2678,6 +2678,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw) pvr2_stream_destroy(hdw->vid_stream); hdw->vid_stream = NULL; } + pvr2_hdw_i2c_done(hdw); v4l2_device_unregister(&hdw->v4l2_dev); pvr2_hdw_disconnect(hdw); mutex_lock(&pvr2_unit_mtx); @@ -2706,7 +2707,6 @@ void pvr2_hdw_disconnect(struct pvr2_hdw *hdw) { pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_disconnect(hdw=%p)",hdw); LOCK_TAKE(hdw->big_lock); - pvr2_i2c_core_done(hdw); LOCK_TAKE(hdw->ctl_lock); pvr2_hdw_remove_usb_stuff(hdw); LOCK_GIVE(hdw->ctl_lock); @@ -2714,6 +2714,13 @@ void pvr2_hdw_disconnect(struct pvr2_hdw *hdw) } +void pvr2_hdw_i2c_done(struct pvr2_hdw *hdw) +{ + LOCK_TAKE(hdw->big_lock); + pvr2_i2c_core_done(hdw); + LOCK_GIVE(hdw->big_lock); +} + /* Get the number of defined controls */ unsigned int pvr2_hdw_get_ctrl_count(struct pvr2_hdw *hdw) { diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h index 860f0a6b099c1f5b752752e3538ad67abb34b936..2f07ba4634766ca86502634693409210ce431e9b 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h +++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h @@ -103,6 +103,7 @@ int pvr2_hdw_initialize(struct pvr2_hdw *, /* Destroy hardware interaction structure */ void pvr2_hdw_destroy(struct pvr2_hdw *); +void pvr2_hdw_i2c_done(struct pvr2_hdw *hdw); /* Return true if in the ready (normal) state */ int pvr2_hdw_dev_ok(struct pvr2_hdw *); -- 2.39.5