Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7217519rwb; Wed, 23 Nov 2022 03:56:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf4z8JhVu5GzyXD1h0Jv1u2gpOBZZJMT5Ci0wgIWA8qJBjAuv5vhICYJgLn7xpew657tf7js X-Received: by 2002:a65:67c3:0:b0:477:96e2:beb8 with SMTP id b3-20020a6567c3000000b0047796e2beb8mr8130940pgs.151.1669204563018; Wed, 23 Nov 2022 03:56:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669204563; cv=none; d=google.com; s=arc-20160816; b=sqcsMf1/Mkf1vFD6FzKb3+rp4XAPBLPkjpZ5yX/ZgIDI3/T72GdYPLhWQXOZTgkMp+ Jp9DdAoKFTYweME0reGBoiPPzN1MW/7X+Onds8o1xuhondM6kT7W0TkVRb5wvd/f7Mbd vXJZmqUTNaJvYa0f3M+c98WnedzhjmTnRr6kRw7XnBp6zuwg4p5PPMfRMPLvNZeC5fH6 h9cXkbxbXDHFAxJgjoQ970FuVCicET2L4xVy+mbT6qMx/wzLpa+VTx5rXcQV/Mt7yW+M RISsFIVmzZOQ+mIe24j2IxvLAcLsMhVZCqBTceX7+Ds7N5bTdz3+i/gXJwKHnpCB+hPR UazA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=fjDRqrrADbimvtZcHCSsIH/0QACVnwkeXfJBnhvhafc=; b=VhJHQS5GQBhHBr5wGlpfEhok9EmWUyeC8/Mh34TiNJb1UhzEJ1jLEPSo8mDPqB8BDs dE0AAv455Nk/cXjvka1NiAvP2JARSik3lTb5nKgbra2LP7E6KTGESfRX8jY+X/NUzt2e n4Wuhuy4CtODjgCRCIjyBFtie9k6J5LKZjR+xp5Oz9Vv7RjDMt2mutPgFaABoEUADx1g POKPkn5N5TfprtXas3uP5K1Aeb9GGB7HrgwmILFGB5nb988Qn2bJ050GpA+Ilmt6tT6U sA5kq4wodd29CAzrbRArTRM8+X0MJqbwxrUToThf0SWkhVF+g/AczrQtSHM5xkjtIHGd zIKQ== ARC-Authentication-Results: i=1; mx.google.com; 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 w7-20020a639347000000b0046ec0715bd9si4521569pgm.818.2022.11.23.03.55.50; Wed, 23 Nov 2022 03:56:03 -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; 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 S237023AbiKWLOG (ORCPT + 89 others); Wed, 23 Nov 2022 06:14:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236447AbiKWLNn (ORCPT ); Wed, 23 Nov 2022 06:13:43 -0500 Received: from cstnet.cn (smtp21.cstnet.cn [159.226.251.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 27904116AB8 for ; Wed, 23 Nov 2022 03:10:28 -0800 (PST) Received: from localhost.localdomain (unknown [124.16.138.125]) by APP-01 (Coremail) with SMTP id qwCowAA3PjaL_31j3FZDAQ--.40765S2; Wed, 23 Nov 2022 19:10:04 +0800 (CST) From: Jiasheng Jiang To: rostedt@goodmis.org, mhiramat@kernel.org, vbabka@suse.cz, 42.hyeyoo@gmail.com, vasily.averin@linux.dev, akpm@linux-foundation.org, shakeelb@google.com, vvghjk1234@gmail.com Cc: linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH] mm/tracing: Add check for kmem_cache Date: Wed, 23 Nov 2022 19:10:01 +0800 Message-Id: <20221123111001.34855-1-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: qwCowAA3PjaL_31j3FZDAQ--.40765S2 X-Coremail-Antispam: 1UD129KBjvdXoWrtw13AFy7Gw1fGrW8tFWDArb_yoWkurc_uF 47Xan5C3yrKrnakr42yw1Uur1S93yfJw1S9rn5tryaq3yrGr45Gw1v9w1Svw4xWrnFvF12 ya9FvrWSyrnxujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb4kFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s 1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0 cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8Jw ACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka 0xkIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67 AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIY rxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14 v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfU5sjjDU UUU X-Originating-IP: [124.16.138.125] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,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 In __kmem_cache_alloc_lru() of mm/slab.c, cachep may be NULL when error occurs in slab_alloc(). 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) ? -- 2.25.1