All of lore.kernel.org
 help / color / mirror / Atom feed
From: "majianpeng" <majianpeng@gmail.com>
To: Neil Brown <neilb@suse.de>
Cc: linux-raid <linux-raid@vger.kernel.org>
Subject: [PATCH] md:Fix mem leak about rdev->badblocks.page.
Date: Wed, 11 Apr 2012 15:58:27 +0800	[thread overview]
Message-ID: <201204111558200780185@gmail.com> (raw)

From 7cc5b99748a5505d94d6e67ba4e639e341f0a00a Mon Sep 17 00:00:00 2001
From: majianpeng <majianpeng@gmail.com>
Date: Wed, 11 Apr 2012 15:44:55 +0800
Subject: [PATCH] md:Fix mem leak about rdev->badblocks.page. When exec
 md_import_device(),alloc badblocks.page.But met error when
 exec bind_rdev_to_array().So exec export_rdev().But
 export_rdev() did not free badblocks.page.

This may occur in those functions:
1:add_new_disk()
2:new_dev_store()

Reported by kmemleak:
unreferenced object 0xffff88008223d668 (size 4096):
  comm "mdadm", pid 9497, jiffies 4295848888 (age 21898.212s)
  hex dump (first 32 bytes):
    6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
    6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b  kkkkkkkkkkkkkkkk
  backtrace:
    [<ffffffff81695ec1>] kmemleak_alloc+0x21/0x50
    [<ffffffff811180fd>] kmem_cache_alloc_trace+0xad/0x1b0
    [<ffffffffa0003b78>] md_rdev_init+0xd8/0x130 [md_mod]
    [<ffffffffa0007e28>] md_import_device+0x58/0x2a0 [md_mod]
    [<ffffffffa001199e>] add_new_disk+0x178/0x49d [md_mod]
    [<ffffffffa000d78e>] md_ioctl+0xb8e/0x11f0 [md_mod]
    [<ffffffff8127aa18>] blkdev_ioctl+0xd8/0x790
    [<ffffffff8115416b>] block_ioctl+0x3b/0x40
    [<ffffffff81131cc6>] do_vfs_ioctl+0x96/0x550
    [<ffffffff81132211>] sys_ioctl+0x91/0xa0
    [<ffffffff816bc9a2>] system_call_fastpath+0x16/0x1b
    [<ffffffffffffffff>] 0xffffffffffffffff

Signed-off-by: majianpeng <majianpeng@gmail.com>
---
 drivers/md/md.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index b572e1e..e07c60c 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -813,6 +813,7 @@ static void free_disk_sb(struct md_rdev * rdev)
 		put_page(rdev->bb_page);
 		rdev->bb_page = NULL;
 	}
+
 }
 
 
@@ -2161,6 +2162,10 @@ static void export_rdev(struct md_rdev * rdev)
 	if (test_bit(AutoDetected, &rdev->flags))
 		md_autodetect_dev(rdev->bdev->bd_dev);
 #endif
+	if (rdev->badblocks.page) {
+		kfree(rdev->badblocks.page);
+		rdev->badblocks.page = NULL;
+	}
 	unlock_rdev(rdev);
 	kobject_put(&rdev->kobj);
 }
-- 
1.7.5.4

 				
--------------
majianpeng
2012-04-11


             reply	other threads:[~2012-04-11  7:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-11  7:58 majianpeng [this message]
2012-04-17  1:54 ` [PATCH] md:Fix mem leak about rdev->badblocks.page NeilBrown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201204111558200780185@gmail.com \
    --to=majianpeng@gmail.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=neilb@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.