Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp752776yba; Wed, 15 May 2019 09:19:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqygI6gKn3qNMVi95s0T0lSiZdX3+X9y+pZ3ynxCDMcXH/Duj88zWZd5NLgEaLorTeYf8HmX X-Received: by 2002:a65:4544:: with SMTP id x4mr21567601pgr.323.1557937183667; Wed, 15 May 2019 09:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557937183; cv=none; d=google.com; s=arc-20160816; b=PHrqS+Kew1KqNp5FdcrAMeW98c5znf4tn6ZM1JszYr0nhHnwMqyxZGTcJGQZBgLzOI 4uukHGljVHLnsBQ7bC0wuPN1evSRYe4Z3Z6w07xNI7ppIMzqoqGIVU7UsskJ7HLHjxtc aXhnq7SrJ7nsY3vgrlwGA85C3tQNbjyWJUB0PW2tTm8fjTXeF0CffAbcT76nMUfpZakH n6fjdCKVMP2ifrLscHuxTlPjmxDtDD2SdCy6utWyurO/8HhYtAtdkEOzDg5xrRvrZ55d pYHrRsybaHpDxjNuBGIRvq/6mqg9snmn/8n1UnfrFlHr9Nvk/ohgpZj6A5+wE5M62tYr FppA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=6/jZxe/KGe9D7V62cxDaa2sx7LSajvlIfD4Fn+RmXEo=; b=HacelOTTDuIE663OhlrgCX9JJovx8RjOfYWA23rPOrZKY8oPZdr2A34QhViCXWwsvA yjLPE9ioQMgXTu5lkKcDfGRoAm3G1XECOVqQ7P6zSDsXH+qZBF1nTNjDUa8aTFK5cRon nM8No9jcBnAdBznea7ooPaa5Sk72+uAidxaf8/aPp8+qj3ypSLcrBpnP+9+qx6ZnbHhQ Hg+VLGLmPY2IpTxDVfnPiOvPwsqRnhRnu5UcXW1fbfyjWfQEazZrzcczXZ6k2WlvJLUD d7GsQofjPwNQXEHAiqfSTshrNlFlCJdKbhjHOtsMJrzPt4ZMsouYc/VNf888mM0b1PCa cBIQ== 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 u12si2179082pgj.145.2019.05.15.09.19.28; Wed, 15 May 2019 09:19:43 -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 S1726881AbfEOQSB (ORCPT + 99 others); Wed, 15 May 2019 12:18:01 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:56312 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725953AbfEOQSB (ORCPT ); Wed, 15 May 2019 12:18:01 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id E38CC4ACC87273627881; Thu, 16 May 2019 00:17:57 +0800 (CST) Received: from localhost (10.177.31.96) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Thu, 16 May 2019 00:17:49 +0800 From: YueHaibing To: , CC: , , YueHaibing Subject: [PATCH] kernel/module: Fix mem leak in module_add_modinfo_attrs Date: Thu, 16 May 2019 00:12:12 +0800 Message-ID: <20190515161212.28040-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.31.96] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 1.8.3.1