Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp524506ybi; Thu, 30 May 2019 02:26:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQ29XRXSuBISoijyglzT/jAlaXBybX3JRbubjd71oL94wf65NKEqvH8CmUPgfxuTyCiAbS X-Received: by 2002:a63:e408:: with SMTP id a8mr2911715pgi.146.1559208415596; Thu, 30 May 2019 02:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559208415; cv=none; d=google.com; s=arc-20160816; b=0Gp8Reic6pv3kOmjRmhuCOWR/OTT/+OekroV/R0esMjTS4sp6DAphJ564GIbWK2hjY WsZXrAW32pOzBi5viY0yPsRq45I3kYhVieFlbzNr9Ev9zAsuqcUCKSXuM56p1qUTFCId AbCNrAm4Lf4HL0Yzd2mCC6xQPTSjq845dXIR7YUFZa/6dT9ygnNoBs2BNvaWqKcsl/AZ zC81vmv6b62mRQZtUVI5SIL9GkaQyo66dNTT36reySdFVtB67BETnuNe6UyEBOp09m1P CJ4oKns0xhm2dpZ1zSRXk23h97l7HP5R6pP4QOzhY/TnxWE8RBlKIh75tf3Y7U6lGwrN vhrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject; bh=8gVM/YxpS0/+IPVI3uvRsE85dhPwPixzapxc6BRHq7U=; b=Py3AJRSZ6KQ/BjcDAq+dQuDWqcQLrRomBaFuVT6ZnqU30k9ddi9XqR/9P/LYjCo7OV uC9VrCYV9iSrQ2rj9VuVys4hLfuHuD5vbOsbEaudd0ultixZ5j1FWB1Nd/59MSaI9tmk XHC/Pwvp78jvBZGHWzYcPwxkx+k9ZFYaqvOmf0f78mKEpFT9MhhUZMTfyUWRhVtjBrOg etlU4aQqtkTc6nBlBXH/wkkxaaaa6nDCIX2PUsA7qG+huhR5OQYVewrFwDLuWQkx4vig x71Sx3wuJD5GTtb2gkVJq7ek+BAs+MNu8LZ7/7Cn1qsqVDo/NqSQsCyzho9I0H6gCfpS z2GQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9si2377635pjo.95.2019.05.30.02.26.39; Thu, 30 May 2019 02:26:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727228AbfE3JYa (ORCPT + 99 others); Thu, 30 May 2019 05:24:30 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:17627 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726382AbfE3JYa (ORCPT ); Thu, 30 May 2019 05:24:30 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 9FE9EAEEAA03EE4475B0; Thu, 30 May 2019 17:24:27 +0800 (CST) Received: from [127.0.0.1] (10.133.213.239) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Thu, 30 May 2019 17:24:23 +0800 Subject: Re: [PATCH] kernel/module: Fix mem leak in module_add_modinfo_attrs To: , References: <20190515161212.28040-1-yuehaibing@huawei.com> CC: , From: Yuehaibing Message-ID: <60ececa2-2741-c4e5-c028-35d95cbeb731@huawei.com> Date: Thu, 30 May 2019 17:24:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20190515161212.28040-1-yuehaibing@huawei.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.133.213.239] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Friendly ping... On 2019/5/16 0:12, YueHaibing wrote: > In module_add_modinfo_attrs if sysfs_create_file > fails, we forget to free allocated modinfo_attrs > and roll back the sysfs files. > > Fixes: 03e88ae1b13d ("[PATCH] fix module sysfs files reference counting") > Signed-off-by: YueHaibing > --- > kernel/module.c | 16 +++++++++++++++- > 1 file changed, 15 insertions(+), 1 deletion(-) > > diff --git a/kernel/module.c b/kernel/module.c > index 0b9aa8a..7da73c4 100644 > --- a/kernel/module.c > +++ b/kernel/module.c > @@ -1714,15 +1714,29 @@ static int module_add_modinfo_attrs(struct module *mod) > return -ENOMEM; > > temp_attr = mod->modinfo_attrs; > - for (i = 0; (attr = modinfo_attrs[i]) && !error; i++) { > + for (i = 0; (attr = modinfo_attrs[i]); i++) { > if (!attr->test || attr->test(mod)) { > memcpy(temp_attr, attr, sizeof(*temp_attr)); > sysfs_attr_init(&temp_attr->attr); > error = sysfs_create_file(&mod->mkobj.kobj, > &temp_attr->attr); > + if (error) > + goto error_out; > ++temp_attr; > } > } > + > + return 0; > + > +error_out: > + for (; (attr = &mod->modinfo_attrs[i]) && i >= 0; i--) { > + if (!attr->attr.name) > + break; > + sysfs_remove_file(&mod->mkobj.kobj, &attr->attr); > + if (attr->free) > + attr->free(mod); > + } > + kfree(mod->modinfo_attrs); > return error; > } > >