From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 391693803D7 for ; Mon, 10 Aug 2026 06:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786343145; cv=none; b=NgWN9wm1j3A0v+bASdN1ZLLCxKF2IHHE4B++UJLT7JNbAqU6+on74BPEU5DAFTho4/9zbOa316LQoFwRqdOpaLisY8y2it73/Rfiv8sDshegVYGcHVPKkKKbYWvt+b+LRLmSSwua/pB4NhtTfG8w4a/WEGa4qPOwfTttoBtywas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786343145; c=relaxed/simple; bh=VxI4YwnIEvRBHYTD62MGgVzbo0v1YE11LFlnHHYsuyA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V2FNeK8LvHAiUQSZHG3U5DtjBWucEf6FXx/vpQrrQpkJopRPdd3U+I27vKU937OBNxZLxzu0KUYnDjUIeYEBtPVGioKsWYaIPB0aQ3pzLVtGIf2t4Pm0kf6glOsmzqzeg1JdhoExJknH8HsWAwfcrowkPTkBQ7WsP8mo8+3mZU0= 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=ZCkdkxz/; arc=none smtp.client-ip=209.85.215.179 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="ZCkdkxz/" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-ca97d139d8dso773430a12.2 for ; Sun, 09 Aug 2026 23:25:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786343142; x=1786947942; 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:content-type; bh=l6svQF5GPAZfouFfjRsxMRw5S+3HKyD/RZ/OlzpdStc=; b=ZCkdkxz/lM4xfFn+JhoYl461EWV7hkqcFdEwbT5IJA8Y5H/Kue5XXn0gyMY0jb+UUF +XihhGHP8pe2kPPK5ghLGWMai/Kz0wIFTU0sKfWCOppzr2GiiyCBFy8Of2XRzyH7zi7/ e7dnd29f7kSfnaNesmdqyAYOpE3rJ+RSQfNzf33Q4ggpMX9GRMjErZWb6xrXDjTmkqiX 0IPJ4zMSQ+o/DAUrjKz3nz3UC2wDx7UEtNDG5CUkK4VEUedyGmXQVfTsBNrImccgTj4m 4L7KWh6yz2NYsJxj/xBQSBbYqlf1aVOSA+ZpMVAOzZu3/PyYTagyI4G7RDBLL5en5fJs jO2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786343142; x=1786947942; 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:content-type; bh=l6svQF5GPAZfouFfjRsxMRw5S+3HKyD/RZ/OlzpdStc=; b=fOr4hu5FApgbNzQ/mlKxw3MjbhUwI3x685JenDMCy5RlqwJdD4jWJhoJxQebejgSTY parEXWYBMpekR2jm72kat7SdvPF8JYdP0Zbf+uerfm6Zp/DsPBJuV7/E51G9jNELXPqC 9s7PqAGiaGW+QQOzrdp/vbKq6HgvlN8sLKb8pGhUHpeQc13TwdAptrvgobsJZ2kBVL/m LpjfWM5jjX/3dC426Oc1mO6rIY8gLRxt0KQteKjPjKN4KN9EhRprbXvFqFxABopxE8S2 8yeDlVpjimV8XI7M1WMZigN9HCkf7wmVSDES43t89sneqGxUKP/tuKUmGfyOxCwg4aTE M6kw== X-Forwarded-Encrypted: i=1; AHgh+RoW4ax3v3kbTbAespF7D28SUuKRFwilZNbWg4opJxOGhZejdQ87iqi0P6lvditt1JJDLwyS8Ibe1HwAQ7Q=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8CvAqJM4Vx/M0sEYFqrb0mLbA3D8ZPuxsMxvofbz1nGrgfyTH mTKvB5Vyfz2WGl2S5MN5J4Fklkz5WGCxvsEEdYt2tXHpoGbCab6qz9z6 X-Gm-Gg: AR+sD115tQtP7IOLEcA9EDTSXzUSfskYK2IkWuYrFrw5VQW+C5sH6iYDR2lBB/64qUk MPBlNXrjPxN01esK4TSGjCYBn25woOA4WmkcDFdHXi4dbRLSyIARjqE5L6oIT++sQK5VaGgPeCR N6B4dgdxaBEJgfEW5bPA9/9Fa59HRu5DEV8r08eeWYwykb93jbrWWMO9mSMQA+mce4zLW8s6tma iqmFdoltUg2GWK5xY+LFWY/8lOdCVUJnj4OjGQzMk4AfNrQcYopjIAiYRIGcpaCtS2Hbzh08Lv6 g5FdwOmAVNR+1PwqWNC4Ff68UAZvWawP8iniMauEb6EtP3+YOC7OkuCzhvIdww8yCaik7VIGthN a9d47B9nP5cHLa+Z6Kp/P0yWws01cm9OcOjGUKqxl4l/ggtQ7U/QOMsNz4oH+zcM6nfhc1U83HT ireDBwp4gWlYd0O4x2pXT6FEC2MQuFSlPNXCpWzd34ooPnpbJyh04QU6667zVPltxJ+HBHowrDi jC1Jw== X-Received: by 2002:a05:6a20:d43:b0:3c3:b5db:cd93 with SMTP id adf61e73a8af0-3cbce7999e3mr19834403637.13.1786343142488; Sun, 09 Aug 2026 23:25:42 -0700 (PDT) Received: from SGN-LDSENG.tasernet.com ([2405:4800:5cc3:11a:1ac0:4dff:fe8b:4a69]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-315beb8844fsm40642912eec.16.2026.08.09.23.25.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Aug 2026 23:25:42 -0700 (PDT) From: Cong Nguyen To: Maxime Ripard , Mauro Carvalho Chehab Cc: Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Sakari Ailus , linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/3] media: sun4i-csi: add notifier unbind callback to drop the source subdev Date: Mon, 10 Aug 2026 13:25:21 +0700 Message-Id: <20260810062521.1709379-4-congnt264@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260810062521.1709379-1-congnt264@gmail.com> References: <20260810062521.1709379-1-congnt264@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit sun4i_csi_notify_ops only implements .bound and .complete. The .bound callback caches the remote sensor's subdevice in csi->src_subdev. When that subdevice goes away (e.g. its module is unloaded), the V4L2 async core frees it, but without an .unbind callback the driver keeps the stale pointer. A subsequent VIDIOC_STREAMON reaches sun4i_csi_start_streaming(), which calls v4l2_subdev_call(csi->src_subdev, video, s_stream, 1) on the freed subdev, resulting in a use-after-free. Add an .unbind callback that clears csi->src_subdev. The pointer is only dereferenced by v4l2_subdev_call() (NULL-guarded, returns -ENODEV, so streaming fails cleanly) and by sun4i_csi_notify_complete() (which only runs while a subdev is bound), so clearing it is sufficient to prevent the use-after-free. Fixes: 577bbf23b758 ("media: sunxi: Add A10 CSI driver") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4 Signed-off-by: Cong Nguyen --- .../media/platform/sunxi/sun4i-csi/sun4i_csi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c index a8711336a754..f19508f2c7ed 100644 --- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c +++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c @@ -122,8 +122,25 @@ static int sun4i_csi_notify_complete(struct v4l2_async_notifier *notifier) return ret; } +static void sun4i_csi_notify_unbind(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *subdev, + struct v4l2_async_connection *asd) +{ + struct sun4i_csi *csi = container_of(notifier, struct sun4i_csi, + notifier); + + /* + * The remote subdev is being freed. Drop our cached pointer so that a + * subsequent sun4i_csi_start_streaming() does not issue a + * v4l2_subdev_call() on the now dangling source subdev. The call is + * NULL-guarded and returns -ENODEV, so streaming fails cleanly. + */ + csi->src_subdev = NULL; +} + static const struct v4l2_async_notifier_operations sun4i_csi_notify_ops = { .bound = sun4i_csi_notify_bound, + .unbind = sun4i_csi_notify_unbind, .complete = sun4i_csi_notify_complete, }; -- 2.25.1