Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp770412pxb; Mon, 25 Oct 2021 18:35:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyd5Qmo45hLtopHOpXtiOygOv2DoiLseHNpwgY784QMAOitlnYWyftVTRnz84DzhqqP3GFU X-Received: by 2002:a17:906:7ac9:: with SMTP id k9mr27199696ejo.411.1635212126695; Mon, 25 Oct 2021 18:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635212126; cv=none; d=google.com; s=arc-20160816; b=fpBhaqNyDQW9P9cnr/J/8zT2VWexbijE325Wl3GhprNEfsPWv8HfB+U5hpxLlQK2op PJVXWWC4i/S08+5nhXjCwL7foh3ElyszVqT8tvqLoTbMBn3+AtH146B5Fuz2xpostSZb oQm5Ee2rd8KI1dbAwDrDVFLfBzK9yGISafMedjREeguK+ECYg9K3IMzCXW09wcl/zXqg BJeFfQhB58OpC9NvpFgOLWlRtbuj3LMCZJ3z1oesTOE9f1kzf8iAtAK5Bqk1ZUZ/2NcZ kg4tCcw1+tcwb2grtxhwSWYwZgePu9tXWG4IKDWrKh8iUO+1KeApn8TloQQ8KJGpYQ4K vXxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NfrrVRCciJICOev8gMVBuAQquLy9VSfP1uEbEqVM24w=; b=kGVAtiwqKGzmAzudePj6Rycj/Iip/W0yW+nRDepffOk0nwJPVvPfpYNiY1rtVJbwO7 Y2XFDG1EDON9JZariXFTlwXxFuwKgXwJI7bkwEzMbcROjZ0rK25KUOtWCuTzkTp7JFeh Wrju0THUA6vzy+Kj6eHhBZA91lrqCdP8ptO7r1tNj1XFCHK7yrK4TWHoxj63ZN6+M2YL nhEswXTG/ZeK435R43KTMmDe30AK2oUAbhm+dqMfDRviPay0eEf5gGOWO0GMCSgDSAcn xwtmwZpVXOeOTan45r6C9zoCrU0s+hZF1e4NRc8Avyrqod6hICkkYgnGUwxzZEO3hT0S uUTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=H2EpbH8C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dz9si2090652edb.318.2021.10.25.18.35.02; Mon, 25 Oct 2021 18:35:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=H2EpbH8C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235171AbhJYVXK (ORCPT + 99 others); Mon, 25 Oct 2021 17:23:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235148AbhJYVXJ (ORCPT ); Mon, 25 Oct 2021 17:23:09 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CD18C061348 for ; Mon, 25 Oct 2021 14:20:46 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id 187so12143388pfc.10 for ; Mon, 25 Oct 2021 14:20:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NfrrVRCciJICOev8gMVBuAQquLy9VSfP1uEbEqVM24w=; b=H2EpbH8CK+eyq1Svymbl0Dbfo2kpVmHsKpcpd8aOlyPgS9egcampbijVN2rYBa4Rgn p7a+kyLwjWzm6IJXev9oy30YE4CPP1J9p6CFzIEnGFOIGhjk7GBbSz5REtZqbByQpuoA zURwII3gv6rc2pNshcM6TV+ht6kflPX4D3tGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NfrrVRCciJICOev8gMVBuAQquLy9VSfP1uEbEqVM24w=; b=Fa4fg47d1NRR6aQtIF+7KfeodD9BDEpJ85vRsj1JiiNuh2KwPZ+ux6408kd/1Mz8ta wSb35Nyotj5P0ittZVVDAY9loVTLso68QZmFW94l9aE9gzSJPIf9eH0rBcW8AyNSH/oj dGGkD0Qmv7t25ysue2vlaQTGiXSwVTVIv0zm5CtuxqWP2y7lisA1CJkXQRaSIFLNz0o2 NA+VnlVNswuYVqrvt8Sk3wDn7J3jheMRPkqa/VQyKnFaJlNTwW4xRk/J6oYXGJYL2S8a 3rwo4tnG3LqO193UOUivvtCFrjxq4gRrtAjGG6nw7U9tU5Tq7AceA5d+8ZDz+FqvxoQS O0UA== X-Gm-Message-State: AOAM531iS+/+yVO1odZ+SEK0CL6FltXwzjdlKGt9pt1cGvgxk4Sf2NGE c0BYOutrO7IiXvGN1oFeKJPaZw== X-Received: by 2002:aa7:8d88:0:b0:47b:d965:fbb2 with SMTP id i8-20020aa78d88000000b0047bd965fbb2mr17526856pfr.16.1635196846138; Mon, 25 Oct 2021 14:20:46 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u4sm20477372pfh.147.2021.10.25.14.20.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 14:20:45 -0700 (PDT) Date: Mon, 25 Oct 2021 14:20:45 -0700 From: Kees Cook To: Yafang Shao Cc: akpm@linux-foundation.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Andrii Nakryiko Subject: Re: [PATCH v6 06/12] samples/bpf/test_overhead_kprobe_kern: make it adopt to task comm size change Message-ID: <202110251420.9D2C7731@keescook> References: <20211025083315.4752-1-laoar.shao@gmail.com> <20211025083315.4752-7-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211025083315.4752-7-laoar.shao@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 25, 2021 at 08:33:09AM +0000, Yafang Shao wrote: > bpf_probe_read_kernel_str() will add a nul terminator to the dst, then > we don't care about if the dst size is big enough. This patch also > replaces the hard-coded 16 with TASK_COMM_LEN to make it adopt to task > comm size change. > > Signed-off-by: Yafang Shao > Cc: Mathieu Desnoyers > Cc: Arnaldo Carvalho de Melo > Cc: Andrii Nakryiko > Cc: Peter Zijlstra > Cc: Steven Rostedt > Cc: Al Viro > Cc: Kees Cook > Cc: Petr Mladek As these are samples, I guess it's fine to change their sizes. Reviewed-by: Kees Cook > --- > samples/bpf/test_overhead_kprobe_kern.c | 11 ++++++----- > samples/bpf/test_overhead_tp_kern.c | 5 +++-- > 2 files changed, 9 insertions(+), 7 deletions(-) > > diff --git a/samples/bpf/test_overhead_kprobe_kern.c b/samples/bpf/test_overhead_kprobe_kern.c > index f6d593e47037..8fdd2c9c56b2 100644 > --- a/samples/bpf/test_overhead_kprobe_kern.c > +++ b/samples/bpf/test_overhead_kprobe_kern.c > @@ -6,6 +6,7 @@ > */ > #include > #include > +#include > #include > #include > #include > @@ -22,17 +23,17 @@ int prog(struct pt_regs *ctx) > { > struct signal_struct *signal; > struct task_struct *tsk; > - char oldcomm[16] = {}; > - char newcomm[16] = {}; > + char oldcomm[TASK_COMM_LEN] = {}; > + char newcomm[TASK_COMM_LEN] = {}; > u16 oom_score_adj; > u32 pid; > > tsk = (void *)PT_REGS_PARM1(ctx); > > pid = _(tsk->pid); > - bpf_probe_read_kernel(oldcomm, sizeof(oldcomm), &tsk->comm); > - bpf_probe_read_kernel(newcomm, sizeof(newcomm), > - (void *)PT_REGS_PARM2(ctx)); > + bpf_probe_read_kernel_str(oldcomm, sizeof(oldcomm), &tsk->comm); > + bpf_probe_read_kernel_str(newcomm, sizeof(newcomm), > + (void *)PT_REGS_PARM2(ctx)); > signal = _(tsk->signal); > oom_score_adj = _(signal->oom_score_adj); > return 0; > diff --git a/samples/bpf/test_overhead_tp_kern.c b/samples/bpf/test_overhead_tp_kern.c > index eaa32693f8fc..80edadacb692 100644 > --- a/samples/bpf/test_overhead_tp_kern.c > +++ b/samples/bpf/test_overhead_tp_kern.c > @@ -4,6 +4,7 @@ > * modify it under the terms of version 2 of the GNU General Public > * License as published by the Free Software Foundation. > */ > +#include > #include > #include > > @@ -11,8 +12,8 @@ > struct task_rename { > __u64 pad; > __u32 pid; > - char oldcomm[16]; > - char newcomm[16]; > + char oldcomm[TASK_COMM_LEN]; > + char newcomm[TASK_COMM_LEN]; > __u16 oom_score_adj; > }; > SEC("tracepoint/task/task_rename") > -- > 2.17.1 > -- Kees Cook