Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01B96C433FE for ; Fri, 11 Nov 2022 13:23:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233183AbiKKNXh (ORCPT ); Fri, 11 Nov 2022 08:23:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231625AbiKKNXg (ORCPT ); Fri, 11 Nov 2022 08:23:36 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7595DFD9 for ; Fri, 11 Nov 2022 05:23:32 -0800 (PST) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N7zsh2p43zHvhm; Fri, 11 Nov 2022 21:23:04 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 11 Nov 2022 21:23:30 +0800 Received: from [10.174.178.174] (10.174.178.174) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 11 Nov 2022 21:23:30 +0800 Subject: Re: [PATCH] media: v4l2-dev: fix possible name leak in __video_register_device() To: Laurent Pinchart CC: , , , , References: <20221111085809.1676804-1-yangyingliang@huawei.com> From: Yang Yingliang Message-ID: Date: Fri, 11 Nov 2022 21:23:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.178.174] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On 2022/11/11 17:19, Laurent Pinchart wrote: > On Fri, Nov 11, 2022 at 04:58:09PM +0800, Yang Yingliang wrote: >> Afer commit 1fa5ae857bb1 ("driver core: get rid of struct device's >> bus_id string array"), the name of device is allocated dynamically, >> so call kfree_const() to freed it in error case. >> >> Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array") >> Signed-off-by: Yang Yingliang >> --- >> drivers/media/v4l2-core/v4l2-dev.c | 3 +++ >> 1 file changed, 3 insertions(+) >> >> diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c >> index 397d553177fa..1fce1c29c60f 100644 >> --- a/drivers/media/v4l2-core/v4l2-dev.c >> +++ b/drivers/media/v4l2-core/v4l2-dev.c >> @@ -1036,6 +1036,9 @@ int __video_register_device(struct video_device *vdev, >> ret = device_register(&vdev->dev); >> if (ret < 0) { >> pr_err("%s: device_register failed\n", __func__); >> + kfree_const(vdev->dev.kobj.name); >> + /* set it to null to avoid callers using a bad pointer */ >> + vdev->dev.kobj.name = NULL; > This doesn't seem right to me. We shouldn't be poking into the kobj. > This should be handled in the driver core, or if that can't be done for > a reason specific to how the device is used in the V4L2 core, we need a > helper function from the driver core to perform the cleanup. In technical, we should call put_device() here, but the release() function has not been set in this case, and v4l2_device_release() will release something that not need be, so we can not handle it in the driver core well, I think free the name here directly is the best way to fix it. Thanks, Yang > >> goto cleanup; >> } >> /* Register the release callback that will be called when the last