linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Miaohe Lin <linmiaohe@huawei.com>
To: <akpm@linux-foundation.org>, <cl@linux.com>, <penberg@kernel.org>,
	<rientjes@google.com>, <iamjoonsoo.kim@lge.com>, <vbabka@suse.cz>
Cc: <gregkh@linuxfoundation.org>, <faiyazm@codeaurora.org>,
	<andreyknvl@gmail.com>, <ryabinin.a.a@gmail.com>,
	<thgarnie@google.com>, <keescook@chromium.org>,
	<bharata@linux.ibm.com>, <guro@fb.com>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <linmiaohe@huawei.com>
Subject: [PATCH 1/5] mm, slub: fix two bugs in slab_debug_trace_open()
Date: Thu, 16 Sep 2021 20:39:16 +0800	[thread overview]
Message-ID: <20210916123920.48704-2-linmiaohe@huawei.com> (raw)
In-Reply-To: <20210916123920.48704-1-linmiaohe@huawei.com>

It's possible that __seq_open_private() will return NULL. So we should
check t before using lest dereferencing NULL pointer. And in error paths,
we forgot to release private buffer via seq_release_private(). Memory
will leak in these paths.

Fixes: 64dd68497be7 ("mm: slub: move sysfs slab alloc/free interfaces to debugfs")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/slub.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/slub.c b/mm/slub.c
index 3d2025f7163b..ed160b6c54f8 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -6108,9 +6108,14 @@ static int slab_debug_trace_open(struct inode *inode, struct file *filep)
 	struct kmem_cache *s = file_inode(filep)->i_private;
 	unsigned long *obj_map;
 
+	if (!t)
+		return -ENOMEM;
+
 	obj_map = bitmap_alloc(oo_objects(s->oo), GFP_KERNEL);
-	if (!obj_map)
+	if (!obj_map) {
+		seq_release_private(inode, filep);
 		return -ENOMEM;
+	}
 
 	if (strcmp(filep->f_path.dentry->d_name.name, "alloc_traces") == 0)
 		alloc = TRACK_ALLOC;
@@ -6119,6 +6124,7 @@ static int slab_debug_trace_open(struct inode *inode, struct file *filep)
 
 	if (!alloc_loc_track(t, PAGE_SIZE / sizeof(struct location), GFP_KERNEL)) {
 		bitmap_free(obj_map);
+		seq_release_private(inode, filep);
 		return -ENOMEM;
 	}
 
-- 
2.23.0



  reply	other threads:[~2021-09-16 12:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-16 12:39 [PATCH 0/5] Fixups for slub Miaohe Lin
2021-09-16 12:39 ` Miaohe Lin [this message]
2021-10-05  9:46   ` [PATCH 1/5] mm, slub: fix two bugs in slab_debug_trace_open() Vlastimil Babka
2021-09-16 12:39 ` [PATCH 2/5] mm, slub: fix mismatch between reconstructed freelist depth and cnt Miaohe Lin
2021-10-05  9:57   ` Vlastimil Babka
2021-10-08  2:01     ` Miaohe Lin
2021-09-16 12:39 ` [PATCH 3/5] mm, slub: fix potential memoryleak in kmem_cache_open() Miaohe Lin
2021-10-05 10:02   ` Vlastimil Babka
2021-09-16 12:39 ` [PATCH 4/5] mm, slub: fix potential use-after-free in slab_debugfs_fops Miaohe Lin
2021-10-05 10:36   ` Vlastimil Babka
2021-09-16 12:39 ` [PATCH 5/5] mm, slub: fix incorrect memcg slab count for bulk free Miaohe Lin
2021-10-05 10:50   ` Vlastimil Babka
2021-10-05 21:43     ` Andrew Morton

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=20210916123920.48704-2-linmiaohe@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=bharata@linux.ibm.com \
    --cc=cl@linux.com \
    --cc=faiyazm@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=guro@fb.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=ryabinin.a.a@gmail.com \
    --cc=thgarnie@google.com \
    --cc=vbabka@suse.cz \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox