Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1145585rwb; Fri, 23 Sep 2022 08:44:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5foVicXN+GnIaOOpJYbmOTapWtxS9kq+NWWT6DjPBuDAmDYA2ards+V14VTMROTCZsB3B4 X-Received: by 2002:a17:906:58c6:b0:782:bfb1:eae8 with SMTP id e6-20020a17090658c600b00782bfb1eae8mr1981390ejs.546.1663947895051; Fri, 23 Sep 2022 08:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663947895; cv=none; d=google.com; s=arc-20160816; b=jDVWRc02F74SBgKLkC6JkxIF+8bLUIPGYuaHZ3HGh5FgvkYErL2G7jtTcQ9opdJyoo +Ti6jkx1S3sIpRalsnBVYHDDyjzdF5CdXcAxJPAzrssGJGjCMJmtbEKkRh3uErPOvTJv /Jmd2I+t0Uu9splqVWmYY9vwp8WzQHdGnhX4I0tQiniHet/9wVjp/TABWTMpNEjyHCWB I+xM3tYw0G+QmojIK+KKqgofm5zy8ciWcbMbdbbJqjF1u1tWxDRWX3Zq3stLIRipiFZM Yb5cfNORVgJgP7IU2P/FEuzd2lVghjgTO1YlcVjUIbU8zMEv+rB+a+X9QbGky+yld0oV 73mg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=tpknfFKN/5RjMPdB7AtubK8EwfZ0Vsagvm6yC5YwG24=; b=Tb04Iz7kU2jZVxqZsFrqOtwv1T+DdPodaLhvp7bRRj+omdmSzICZquqWSVJWaOw+E0 of5qRrlsBT6mVoxbpmZtdkqHiApdCGVOgpozfCbMRP0IQmIlpTxDzjbQY8wGOIuMNX6/ 18TGcTKrdE44PNba5TE0yKJleOtrIkHCjbhcW31UAN81B4EoHRLvVdTuMqzrHXRuUODC f83PEj/FVYr2K1oY7py1rAIMZJ5ZmLbhF1fyD8mYlk964deVt4LtzIAe09ijDNCoJkxt BNKu1FxkeeqIJapvW95+8y5tfauf26iwcGZoNQHQzyl0khDp+a4hveBctacHHE4uhhqO yBuQ== 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 e4-20020a50ec84000000b00456d901922bsi869178edr.510.2022.09.23.08.44.29; Fri, 23 Sep 2022 08:44:55 -0700 (PDT) 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 S232125AbiIWO75 (ORCPT + 99 others); Fri, 23 Sep 2022 10:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231994AbiIWO7s (ORCPT ); Fri, 23 Sep 2022 10:59:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C350319002 for ; Fri, 23 Sep 2022 07:59:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4F56361219 for ; Fri, 23 Sep 2022 14:59:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DEF1C433D6; Fri, 23 Sep 2022 14:59:40 +0000 (UTC) Date: Fri, 23 Sep 2022 11:00:44 -0400 From: Steven Rostedt To: Kassey Li Cc: mingo@redhat.com, tj@kernel.org, william.kucharski@oracle.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] cgroup: align the comm length with TASK_COMM_LEN Message-ID: <20220923110044.7261afa0@gandalf.local.home> In-Reply-To: <20220923075105.28251-1-quic_yingangl@quicinc.com> References: <20220923075105.28251-1-quic_yingangl@quicinc.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,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 Fri, 23 Sep 2022 15:51:05 +0800 Kassey Li wrote: > __string could get a dst string with length less than > TASK_COMM_LEN. > > A task->comm may change that can cause out of bounds access > for the dst string buffer, e.g in the call trace of below: > > Call trace: > > dump_backtrace.cfi_jt+0x0/0x4 > show_stack+0x14/0x1c > dump_stack+0xa0/0xd8 > die_callback+0x248/0x24c > notify_die+0x7c/0xf8 > die+0xac/0x290 > die_kernel_fault+0x88/0x98 > die_kernel_fault+0x0/0x98 > do_page_fault+0xa0/0x544 > do_mem_abort+0x60/0x10c > el1_da+0x1c/0xc4 > trace_event_raw_event_cgroup_migrate+0x124/0x170 > cgroup_attach_task+0x2e8/0x41c > __cgroup1_procs_write+0x114/0x1ec > cgroup1_tasks_write+0x10/0x18 > cgroup_file_write+0xa4/0x208 > kernfs_fop_write+0x1f0/0x2f4 > __vfs_write+0x5c/0x200 > vfs_write+0xe0/0x1a0 > ksys_write+0x74/0xdc > __arm64_sys_write+0x18/0x20 > el0_svc_common+0xc0/0x1a4 > el0_svc_compat_handler+0x18/0x20 > el0_svc_compat+0x8/0x2c > > Change it as arrary with same length TASK_COMM_LEN, > This idea is from commit d1eb650ff413 ("tracepoint: Move signal sending > tracepoint to events/signal.h"). This does not make sense. What exactly is the bug here? __string() will do a strlen(task->comm) + 1 to allocate on the ring buffer. It should not be less that task->comm. The above stack dump does not show what happened. This looks like another bug and I do not see how this patch addresses the issue. -- Steve > > Signed-off-by: Kassey Li > --- > include/trace/events/cgroup.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/include/trace/events/cgroup.h b/include/trace/events/cgroup.h > index dd7d7c9efecd..b4ef0ffa38a4 100644 > --- a/include/trace/events/cgroup.h > +++ b/include/trace/events/cgroup.h > @@ -130,7 +130,7 @@ DECLARE_EVENT_CLASS(cgroup_migrate, > __field( u64, dst_id ) > __field( int, pid ) > __string( dst_path, path ) > - __string( comm, task->comm ) > + __array(char, comm, TASK_COMM_LEN) > ), > > TP_fast_assign( > @@ -139,12 +139,12 @@ DECLARE_EVENT_CLASS(cgroup_migrate, > __entry->dst_level = dst_cgrp->level; > __assign_str(dst_path, path); > __entry->pid = task->pid; > - __assign_str(comm, task->comm); > + memcpy(__entry->comm, task->comm, TASK_COMM_LEN); > ), > > TP_printk("dst_root=%d dst_id=%llu dst_level=%d dst_path=%s pid=%d comm=%s", > __entry->dst_root, __entry->dst_id, __entry->dst_level, > - __get_str(dst_path), __entry->pid, __get_str(comm)) > + __get_str(dst_path), __entry->pid, __entry->comm) > ); > > DEFINE_EVENT(cgroup_migrate, cgroup_attach_task,