From patchwork Thu Nov 10 21:06:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 81757 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp958277qge; Thu, 10 Nov 2016 13:41:42 -0800 (PST) X-Received: by 10.99.117.71 with SMTP id f7mr38946283pgn.61.1478814102865; Thu, 10 Nov 2016 13:41:42 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si6812372pgj.255.2016.11.10.13.41.42; Thu, 10 Nov 2016 13:41:42 -0800 (PST) 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; dkim=pass header.i=@linaro.org; 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; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965040AbcKJVlj (ORCPT + 27 others); Thu, 10 Nov 2016 16:41:39 -0500 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35458 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934164AbcKJVlh (ORCPT ); Thu, 10 Nov 2016 16:41:37 -0500 Received: by mail-pf0-f172.google.com with SMTP id i88so151833536pfk.2 for ; Thu, 10 Nov 2016 13:41:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=mlbW6AwM0OZ4/UkWpf4kXuq170mYAg68k0NJh+zYmjE=; b=SkPdSOveQB3ZqpQfjTCQd/EMhoKTAt7qJdDGHGpWm1zJLyHsMWQRtZv99N3W69RXBE k0meqNXOCaWKpEueCVDXxpWoZNQGMW3CkmkAjIcVRuydM8u+neB/uFMTUFmDfHQdbLmS M/vGTV9QZcdqiE6oMummaDx8qNH0r4rK1Qpk0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mlbW6AwM0OZ4/UkWpf4kXuq170mYAg68k0NJh+zYmjE=; b=H2Rs7naYqSDIu3f2Bw+3rxJDOLiSeZj+nPR2h8r38vPTX//iq12HUUL5F8TTMgTpRN MWGIICzvD1sw5+IrVS6xUhnTDFYE5TF8j8lvhrhhOhkgVIQxzyS42sk2v7zia0BK+80q 4Q9I1zmvwILjLHIMHKZmnZv4cWgalNVDPiqJZxI+8znHDrPONC8Q1rLWaQza+8+XURQi +jwh5/X0goIA5fGgp7uHyCbOIudWH1CQTINLga9irWpjhuCPLNZpwVKSFVv1WVm3POcD gICd4R4yYWjP3Ukz/TXYd8WEEio8wqh5gEUGZdgB3Bxc6EyNW67fVBLeX4W9HjxrEtxg Dnpg== X-Gm-Message-State: ABUngvfu/+IBgsVKZlhl8oT0H0g+38FnRJmh7ZlaHqAUQqbjm72nMGgwz4GD142x7t+fvXKb X-Received: by 10.99.241.21 with SMTP id f21mr26998154pgi.110.1478814096689; Thu, 10 Nov 2016 13:41:36 -0800 (PST) Received: from yshi-Precision-T5600.corp.ad.wrs.com (unknown-216-82.windriver.com. [147.11.216.82]) by smtp.gmail.com with ESMTPSA id p6sm9516164pae.16.2016.11.10.13.41.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Nov 2016 13:41:36 -0800 (PST) From: Yang Shi To: paulmck@linux.vnet.ibm.com, josh@joshtriplett.org Cc: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, yang.shi@linaro.org Subject: [PATCH] locktorture: Fix potential memory leak with rw lock test Date: Thu, 10 Nov 2016 13:06:39 -0800 Message-Id: <1478811999-12696-1-git-send-email-yang.shi@linaro.org> X-Mailer: git-send-email 2.0.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When running locktorture module with the below commands with kmemleak enabled: $ modprobe locktorture torture_type=rw_lock_irq $ rmmod locktorture The below kmemleak got caught: root@10:~# echo scan > /sys/kernel/debug/kmemleak [ 323.197029] kmemleak: 2 new suspected memory leaks (see /sys/kernel/debug/kmemleak) root@10:~# cat /sys/kernel/debug/kmemleak unreferenced object 0xffffffc07592d500 (size 128): comm "modprobe", pid 368, jiffies 4294924118 (age 205.824s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 c3 7b 02 00 00 00 00 00 .........{...... 00 00 00 00 00 00 00 00 d7 9b 02 00 00 00 00 00 ................ backtrace: [] create_object+0x110/0x288 [] kmemleak_alloc+0x58/0xa0 [] __kmalloc+0x234/0x318 [] 0xffffff80006fa130 [] do_one_initcall+0x44/0x138 [] do_init_module+0x68/0x1cc [] load_module+0x1a68/0x22e0 [] SyS_finit_module+0xe0/0xf0 [] el0_svc_naked+0x24/0x28 [] 0xffffffffffffffff unreferenced object 0xffffffc07592d480 (size 128): comm "modprobe", pid 368, jiffies 4294924118 (age 205.824s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 3b 6f 01 00 00 00 00 00 ........;o...... 00 00 00 00 00 00 00 00 23 6a 01 00 00 00 00 00 ........#j...... backtrace: [] create_object+0x110/0x288 [] kmemleak_alloc+0x58/0xa0 [] __kmalloc+0x234/0x318 [] 0xffffff80006fa22c [] do_one_initcall+0x44/0x138 [] do_init_module+0x68/0x1cc [] load_module+0x1a68/0x22e0 [] SyS_finit_module+0xe0/0xf0 [] el0_svc_naked+0x24/0x28 [] 0xffffffffffffffff It is because cxt.lwsa and cxt.lrsa don't get freed in module_exit, so free them in lock_torture_cleanup() and free writer_tasks if reader_tasks is failed at memory allocation. Signed-off-by: Yang Shi --- kernel/locking/locktorture.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.0.2 diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index f8c5af5..d3de04b 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -780,6 +780,10 @@ static void lock_torture_cleanup(void) else lock_torture_print_module_parms(cxt.cur_ops, "End of test: SUCCESS"); + + kfree(cxt.lwsa); + kfree(cxt.lrsa); + end: torture_cleanup_end(); } @@ -924,6 +928,8 @@ static int __init lock_torture_init(void) GFP_KERNEL); if (reader_tasks == NULL) { VERBOSE_TOROUT_ERRSTRING("reader_tasks: Out of memory"); + kfree(writer_tasks); + writer_tasks = NULL; firsterr = -ENOMEM; goto unwind; }