Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7410178rwb; Wed, 23 Nov 2022 06:15:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4h7oIehKe3e6tGBhmSi9HMbiVAqCGIDg03t8sey/guI9R0euGuND1TpHeFh4Fz8ux5ld6x X-Received: by 2002:a17:906:34d0:b0:78d:c16e:dfc9 with SMTP id h16-20020a17090634d000b0078dc16edfc9mr24294507ejb.327.1669212959665; Wed, 23 Nov 2022 06:15:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669212959; cv=none; d=google.com; s=arc-20160816; b=XNUT6x0wqv3lz61e64h0dtZtPBrjT+LTJ28mrLPqW637BjP0E6IraYCuNJAhXPeuyM Y8LH0me0KOg9jQeL8s3yR6wMp8D6hSsLOoUTmImaiSDi296xuJRu/LUKr7srLx+Xozc1 yvAY44avJh/n7qXQwheIoLQcxAdLkfwSPJjWGHXjGQbbUbLEGaM097ego1qKFyJ82Svs GMp+A3iA2C7ZnJ1rZsRDoU4f67lmirij6nezwjSGKC7M8mgowrDI3fdhuWUS2qqVIKjE 0M4gSU7gSLxorVLqHHqvkDz2dWxvLnFFEu4P61vJpzRlMhmAia8Q+bBrBrvbCvk6va+Y ygzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature:dkim-signature; bh=BwHThTpYm4ogWgiikA57PW4WR5H2lDWMkGSpVJhBdAQ=; b=pOsVyzjM1ZiW6E4EV3KHZp0ziNY2hQfGQOeKWElHoRUWn67HGCr/OjKyOr8324/fRf DJRmWv2Yi+Yn27YmgVnLKeodvhw3iAIdK6xiFCEx9mbBXxe5Lfn5oT1mHmtOC+5fSjRg 0M3vCUt+27PGT9cSnJayRW9I6wCPbalNPaH9TMhkyIbiti4yAZx4giLCIeXCvuDKh5HF R7IbtEzyMbdZmVvAVM2WJVFFtYGVFG29JyaIHBh8VqidBQLRyHGtVFZvnPdahdUBG/0f Ht7EYkBz7FWqWwOxwNyAMACKWlRoXddqvnq5x4yo06i700cc3viE9mu1cUWPyMHRvOMp AExg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=1LaCHmhM; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs17-20020a170906dc9100b00791994dfb9esi15202453ejc.491.2022.11.23.06.15.34; Wed, 23 Nov 2022 06:15:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=1LaCHmhM; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238827AbiKWNdW (ORCPT + 89 others); Wed, 23 Nov 2022 08:33:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238848AbiKWNcO (ORCPT ); Wed, 23 Nov 2022 08:32:14 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5037D6F358 for ; Wed, 23 Nov 2022 05:17:26 -0800 (PST) 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-out2.suse.de (Postfix) with ESMTPS id C75281F85D; Wed, 23 Nov 2022 13:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1669209444; 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=BwHThTpYm4ogWgiikA57PW4WR5H2lDWMkGSpVJhBdAQ=; b=1LaCHmhMTUOmzes6tF4T0u/nAJDQ3PberecBaI531n5rvnFq+GRgMF/6AMADSLomJyoEMy 7iO5E7WdKjNSsRVF1c+Me9oip+Rmo2KNxQdXUoFJg4HGbfZXoxOA34IvgWHnSU0exHXyKv 928cVDirLHkxUKJ+fQV9QalNPQhrJ4g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1669209444; 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=BwHThTpYm4ogWgiikA57PW4WR5H2lDWMkGSpVJhBdAQ=; b=5od+xeF3ejKfwKoFoxF772QplZmHVfCAoyGAoSgICdLOgXmQ35QvUURDhMedCKNpsVbKCA ECsMxpYGhEoBRGCQ== 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 A0C9013A37; Wed, 23 Nov 2022 13:17:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /Nt7JmQdfmPgfQAAMHmgww (envelope-from ); Wed, 23 Nov 2022 13:17:24 +0000 Message-ID: <0afc97c8-2b43-8a0b-8884-20347438a347@suse.cz> Date: Wed, 23 Nov 2022 14:17:24 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] mm/tracing: Add check for kmem_cache Content-Language: en-US To: Jiasheng Jiang , rostedt@goodmis.org, mhiramat@kernel.org, 42.hyeyoo@gmail.com, vasily.averin@linux.dev, akpm@linux-foundation.org, shakeelb@google.com, vvghjk1234@gmail.com Cc: linux-kernel@vger.kernel.org References: <20221123111001.34855-1-jiasheng@iscas.ac.cn> From: Vlastimil Babka In-Reply-To: <20221123111001.34855-1-jiasheng@iscas.ac.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/23/22 12:10, Jiasheng Jiang wrote: > In __kmem_cache_alloc_lru() of mm/slab.c, cachep may be NULL when error > occurs in slab_alloc(). Are you sure? AFAICS internally in slab_alloc_node(), slab_pre_alloc_hook() can return NULL which is assigned to cachep local variable, but only NULL propagated back to __kmem_cache_alloc_lru() is the object, not cachep. So trace_kmem_cache_alloc() should only see NULL s, if it was already NULL when passed to kmem_cache_alloc(), at which point the NULL is dereferenced and crashing (as expected) earlier than reaching the tracepoint. > However, trace_kmem_cache_alloc() will still use it as the parameter, > which may cause NULL poineter dereference. > Therefore, it should be better to add the check and handle the error > in the trace_kmem_cache_alloc(). > > Fixes: 36555751c675 ("kmemtrace: SLAB hooks.") > Signed-off-by: Jiasheng Jiang > --- > include/trace/events/kmem.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h > index 243073cfc29d..d99507d32ef5 100644 > --- a/include/trace/events/kmem.h > +++ b/include/trace/events/kmem.h > @@ -32,8 +32,8 @@ TRACE_EVENT(kmem_cache_alloc, > TP_fast_assign( > __entry->call_site = call_site; > __entry->ptr = ptr; > - __entry->bytes_req = s->object_size; > - __entry->bytes_alloc = s->size; > + __entry->bytes_req = s ? s->object_size : 0; > + __entry->bytes_alloc = s ? s->size : 0; > __entry->gfp_flags = (__force unsigned long)gfp_flags; > __entry->node = node; > __entry->accounted = IS_ENABLED(CONFIG_MEMCG_KMEM) ?