From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 087A8577E4F; Wed, 9 Sep 2026 14:27:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788964058; cv=none; b=YzoqxgzE8J5kQr/9L1lpHGh3z9YMkEqU8Ho92kEfnEWgqjNAUWzhYP4wAPHl1tZvMeIjPBsaUu6ThQs9UjdK1ixJfdRtQYtLGsBL0M7DTUuuqs5BEEHnE5Jhf7wvfVL1p2BasLPCwpJzrk4sS966Un1yi/gMHQFv7gij9KdlCmQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788964058; c=relaxed/simple; bh=5yLTbDM3hFBa1kpWBNA3qiyYqwLmNzLs9DefjBiQPdw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDotHgSeE/78CssDMGTlMqMQnRRNS0sEpzUZwi09Ak/Fv/903B1Ae8eZaLvyqJv7oL395MxQ3cwbbNKprkI0AFPfozvdXGSyuVxAXTPSWzTS64XU+GA/pzpelbHeygOZqHRnrEM5FoDYRpDaGZu0kG+rBtTx+/fMGQMtr6tm02U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cdzdX9KF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="cdzdX9KF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42D7B1F00A3D; Wed, 9 Sep 2026 14:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1788964056; bh=EMbGdT1JZYgDgLr+crRCgLmgmpb5Wg+kTIWziGTJSaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cdzdX9KFuYOU5lDm1jPyJaM/2sj554CnTVs0LMmnF1qtbW+2Q4vQDs6vd6Sm4PX86 TVmkr7uk7mQnAnD6bi7ScbGjWHFB78i1BBvhupYkNm3dPdjYInKvCK5uTST5aWlIjK heL9uoho+3ixLsSoVUSNLUqxVqOJRLWmI8RSp/ME= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Biren Pandya , Sakari Ailus Subject: [PATCH 6.18 292/583] media: i2c: ov7740: fix use-after-destroy in remove Date: Wed, 9 Sep 2026 15:39:37 +0200 Message-ID: <20260909134248.156836828@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260909134237.773280130@linuxfoundation.org> References: <20260909134237.773280130@linuxfoundation.org> User-Agent: quilt/0.69 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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Biren Pandya commit 5d1b3dea5a44124bab6c14a2d71b977dabed54e7 upstream. The ov7740_remove() function had a severe teardown order bug where it destroyed the driver's mutex before freeing the V4L2 control handler which relies on that mutex, leading to a use-after-destroy kernel panic. Furthermore, the driver explicitly called v4l2_ctrl_handler_free() and mutex_destroy() sequentially, but then called ov7740_free_controls() which invokes both of them a second time, resulting in a double-free. This patch fixes the issue by unregistering the subdevice first, and relying exclusively on ov7740_free_controls() to safely tear down the mutex and control handler in the correct order. Fixes: 39c5c4471b8d ("media: i2c: Add the ov7740 image sensor driver") Cc: stable@vger.kernel.org Signed-off-by: Biren Pandya Signed-off-by: Sakari Ailus Signed-off-by: Greg Kroah-Hartman --- drivers/media/i2c/ov7740.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) --- a/drivers/media/i2c/ov7740.c +++ b/drivers/media/i2c/ov7740.c @@ -1116,10 +1116,8 @@ static void ov7740_remove(struct i2c_cli struct v4l2_subdev *sd = i2c_get_clientdata(client); struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev); - mutex_destroy(&ov7740->mutex); - v4l2_ctrl_handler_free(ov7740->subdev.ctrl_handler); - media_entity_cleanup(&ov7740->subdev.entity); v4l2_async_unregister_subdev(sd); + media_entity_cleanup(&ov7740->subdev.entity); ov7740_free_controls(ov7740); pm_runtime_get_sync(&client->dev);