Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp332502rwb; Thu, 10 Nov 2022 01:14:52 -0800 (PST) X-Google-Smtp-Source: AMsMyM7gklYu01ooQZPFXkIU1up6JQMBsJY+Ld/UvFOdvebuZscvrWlWNRDGUwD2NH7yuS6LcGlP X-Received: by 2002:a05:6402:2d8:b0:462:750b:bced with SMTP id b24-20020a05640202d800b00462750bbcedmr1847447edx.313.1668071692035; Thu, 10 Nov 2022 01:14:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668071692; cv=none; d=google.com; s=arc-20160816; b=STVanvnSkT71eGm4/TzueBEtNgNr6EFWRK6NlvQ6dDlGaPRJ2Lq4bGIIJPpvo3hP+2 kh/6Tyh2vvogVGRhTFauNHch8w5scOWo8M5VsIIqjRrE7gNQZZqth0P4ny7O9QSjpFYe My8nhvMZu4t0qEX+SgxVez+ESCtGX7RQgB6ZcWmsMqxdZApbf0UHTwoYcXyMt/IsFcPN EO4U+Iym50fnagxpGFgF/xYJxdAaBCkrj0TQ9R+a7VC+tGulqQCs/qA2eHuO0fWG9Uan JUVsgkWFkCkRGhnIx7+HwPmN2o7DmavY6HUAehEfLSibtUn7JFBMd2uYG/9uth5OXg9Y pNCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=xVupVkAepRVtqYo5RQLiU+yPNLHBbQaVru0w6YNlwbI=; b=aTIXC2HrZPzMolI0gOC8bS+kF+L1El09MkFr70gHTE4RISvYgsSLIrWSifM0s4eeiK uwbZN/qImVlKno1TLOm4eavS/GkUWvVQM3h7YjCr+D5VhNip0Kct+wi2UiUwi1PPOqaA lcse2/9ewL3ZMi+5ztjPLh2ZLdP10oT87UYMytpKRtfMaPkOMnP/mtq3K7cw+iVqd7aZ /fa+h/RFGx5dzBVUFuobtXZAV1FyqjymAZZ6Y1rLimAOBcORpEngzQYoNcezaErr+f9S 3VRhm8D5+xxm/PUJY6olpiwRjjmN/QqJykzPRPS2AaAvXnPp09VgNEDqk8RmtwbnGBql hykQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd1-20020a056402206100b0045c2e7e5532si13948175edb.585.2022.11.10.01.14.28; Thu, 10 Nov 2022 01:14:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229573AbiKJJAE (ORCPT + 93 others); Thu, 10 Nov 2022 04:00:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbiKJI77 (ORCPT ); Thu, 10 Nov 2022 03:59:59 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAB27EB6 for ; Thu, 10 Nov 2022 00:59:57 -0800 (PST) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N7G4K1RXkzRpF9; Thu, 10 Nov 2022 16:59:45 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 10 Nov 2022 16:59:55 +0800 Message-ID: <8796ba38-8aa4-42d5-d8b2-ee0d539a191a@huawei.com> Date: Thu, 10 Nov 2022 16:59:54 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH v2] vdpa_sim: fix possible memory leak in vdpasim_net_init() and vdpasim_blk_init() Content-Language: en-US To: Stefano Garzarella CC: , , , , , , References: <20221110050446.3932031-1-ruanjinjie@huawei.com> <20221110080147.bpfumiab2yt7nehf@sgarzare-redhat> From: Ruan Jinjie In-Reply-To: <20221110080147.bpfumiab2yt7nehf@sgarzare-redhat> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.109.254] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thank you very much! On 2022/11/10 16:01, Stefano Garzarella wrote: > Hi, > > On Thu, Nov 10, 2022 at 01:04:46PM +0800, ruanjinjie wrote: >> Inject fault while probing module, if device_register() fails in >> vdpasim_net_init() or vdpasim_blk_init(), but the refcount of kobject is >> not decreased to 0, the name allocated in dev_set_name() is leaked. >> Fix this by calling put_device(), so that name can be freed in >> callback function kobject_cleanup(). >> >> (vdpa_sim_net) >> unreferenced object 0xffff88807eebc370 (size 16): >>  comm "modprobe", pid 3848, jiffies 4362982860 (age 18.153s) >>  hex dump (first 16 bytes): >>    76 64 70 61 73 69 6d 5f 6e 65 74 00 6b 6b 6b a5  vdpasim_net.kkk. >>  backtrace: >>    [] __kmalloc_node_track_caller+0x4e/0x150 >>    [] kstrdup+0x33/0x60 >>    [] kobject_set_name_vargs+0x41/0x110 >>    [] dev_set_name+0xab/0xe0 >>    [] device_add+0xe3/0x1a80 >>    [] 0xffffffffa0270013 >>    [] do_one_initcall+0x87/0x2e0 >>    [] do_init_module+0x1ab/0x640 >>    [] load_module+0x5d00/0x77f0 >>    [] __do_sys_finit_module+0x110/0x1b0 >>    [] do_syscall_64+0x35/0x80 >>    [] entry_SYSCALL_64_after_hwframe+0x46/0xb0 >> >> (vdpa_sim_blk) >> unreferenced object 0xffff8881070c1250 (size 16): >>  comm "modprobe", pid 6844, jiffies 4364069319 (age 17.572s) >>  hex dump (first 16 bytes): >>    76 64 70 61 73 69 6d 5f 62 6c 6b 00 6b 6b 6b a5  vdpasim_blk.kkk. >>  backtrace: >>    [] __kmalloc_node_track_caller+0x4e/0x150 >>    [] kstrdup+0x33/0x60 >>    [] kobject_set_name_vargs+0x41/0x110 >>    [] dev_set_name+0xab/0xe0 >>    [] device_add+0xe3/0x1a80 >>    [] 0xffffffffa0220013 >>    [] do_one_initcall+0x87/0x2e0 >>    [] do_init_module+0x1ab/0x640 >>    [] load_module+0x5d00/0x77f0 >>    [] __do_sys_finit_module+0x110/0x1b0 >>    [] do_syscall_64+0x35/0x80 >>    [] entry_SYSCALL_64_after_hwframe+0x46/0xb0 >> >> Signed-off-by: ruanjinjie >> --- >> v2: >> - add fault inject message >> --- >> drivers/vdpa/vdpa_sim/vdpa_sim_blk.c | 4 +++- >> drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 4 +++- >> 2 files changed, 6 insertions(+), 2 deletions(-) > > Thanks for the v2 of this patch! > It LGTM, just a couple of comments about the submit process. > > Usually when you get A-b R-b's and the patch doesn't change, it's better > to bring them in later versions. > > Also, we had suggested reporting the Fixes tag, because usually when we > fix a bug it's good to identify which patch introduced the problem, so > it's easier to backport this fix into stable versions of the kernel. > https://www.kernel.org/doc/html/v4.17/process/submitting-patches.html#describe-your-changes > > In this case we should use the following tags: > > Fixes: 899c4d187f6a ("vdpa_sim_blk: add support for vdpa management tool") > Fixes: a3c06ae158dd ("vdpa_sim_net: Add support for user supported > devices") > > With them: > > Reviewed-by: Stefano Garzarella > > Thanks, > Stefano >