From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5458CC433EF for ; Tue, 5 Oct 2021 09:46:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E52156137D for ; Tue, 5 Oct 2021 09:46:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E52156137D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 732436B006C; Tue, 5 Oct 2021 05:46:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E1326B0071; Tue, 5 Oct 2021 05:46:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D0676B0072; Tue, 5 Oct 2021 05:46:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 4F54E6B006C for ; Tue, 5 Oct 2021 05:46:05 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EDE021803F79E for ; Tue, 5 Oct 2021 09:46:04 +0000 (UTC) X-FDA: 78661902648.30.2101C22 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf05.hostedemail.com (Postfix) with ESMTP id 592855072AF0 for ; Tue, 5 Oct 2021 09:46:04 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2704E223BB; Tue, 5 Oct 2021 09:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1633427163; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3PzVyIIrgEezjranyNc5nPmS1dlxJBdJtBNQsCuW5RU=; b=bwVtP45s1aw1w7lYMwZzDGuMqKc4Kw1H38gSVSuv6Xidq7xUpgpboihxtSMA+5QxoAf5gY zxnFmv/Sy0bkMbAtiMbF4HD5HOJeVHX3jmNgo4NPHEWais+H7WEaW0IU9McBAUTGpDTIh8 B42hByekkRwDl/sddgD1HFPLi/KRtpY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1633427163; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3PzVyIIrgEezjranyNc5nPmS1dlxJBdJtBNQsCuW5RU=; b=rhQJ35PXZH2zrvT+kkl6rIp+Z8ddfhUv/IeM7QgyDQkDFnQ2PI1wxp+5Nj/poaIc8vPj3n wup6mWcN9RBl+1Ag== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D9FDE13C23; Tue, 5 Oct 2021 09:46:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Id9qNNoeXGGKCwAAMHmgww (envelope-from ); Tue, 05 Oct 2021 09:46:02 +0000 Message-ID: <1818ff73-3f14-a029-8c7f-370cd371abaa@suse.cz> Date: Tue, 5 Oct 2021 11:46:02 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH 1/5] mm, slub: fix two bugs in slab_debug_trace_open() Content-Language: en-US To: Miaohe Lin , akpm@linux-foundation.org, cl@linux.com, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com 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 References: <20210916123920.48704-1-linmiaohe@huawei.com> <20210916123920.48704-2-linmiaohe@huawei.com> From: Vlastimil Babka In-Reply-To: <20210916123920.48704-2-linmiaohe@huawei.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=bwVtP45s; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=rhQJ35PX; spf=pass (imf05.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 592855072AF0 X-Stat-Signature: c1a39yrp3rqez6xqnec76idu5p1y5frh X-HE-Tag: 1633427164-953831 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 9/16/21 14:39, Miaohe Lin wrote: > 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 Reviewed-by: Vlastimil Babka > --- > 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; > } > >