Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp774784pxb; Mon, 25 Oct 2021 18:41:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe9IgGUf7n2cKSgUVByML9w4VeooU34nHAGT1HwBZHjzxRxDFDPLQa82LVVDhnGkloDpz8 X-Received: by 2002:a05:6402:2811:: with SMTP id h17mr24375896ede.389.1635212502007; Mon, 25 Oct 2021 18:41:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635212502; cv=none; d=google.com; s=arc-20160816; b=LCO59CFknlDiHCc0Wf/vlJyBbdGHSQHjcvChzEx14Mw9xCbiUCxHP8N5FirUsj8/W1 hL79sUnpsGPQbZnMlCTFm3MlMUIlpHlqE7pi8QMSPTpnkRPoDLuhHeRrlRKdt5ILZGd8 OsmELduaMKvUkeWJl7VLBCzsDg/kafGgitb/45DHLrpcOJYYybNYDrQN0Hu0k63Gwg1c RmFeisGuT1VnHQip4NAHQwBt+K7Xc82hnEesu1zWgDwRmCi/yT5oI3yCzQRQplZ48rvN o1umtCNoiXKo7i+Q6sWZ60Sn5GC09uOi2gc1Vp++4gruZlMiYFJzHKJen7i15qGBKnmN s9mA== 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=cVVSf4gV+VHKaMcPkqXKR+j1Pi643cPAlkbYEqi72eA=; b=Bx243WOfp+dF4t3COWnWK4DvSX6oQDekeenK44Q/XHoK6pSL6gcDu24V2GL4CiFgDw LMGLEt03AB3U4kkEPxy5ZsqhSoW/0vHqJRK6DRBDN9+BJu0LFEoOvuLdYsjfeM7B8aYQ 0kUxPRcI35QdjyQFtiAmXEaycZ8qkuObP4IX04FV1LkvEMLs1zIh5OttdhzeM5j5LEj+ i/goZ3ZGt6y9EmAFwQ6PMxyFfcL+kqyfv/pezptVIQfkjwkhflqrT4XNESKvsjd5qkAc RFZHfPopt5lue4MssBqxIKVEvMzZaBR9rvBk+g5qzMKf+0iQCQdtHoqusGA0P3WTytF3 j6KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KaZ4GqG+; 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 ft6si7062216ejc.347.2021.10.25.18.41.18; Mon, 25 Oct 2021 18:41:41 -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=KaZ4GqG+; 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 S232670AbhJYV07 (ORCPT + 99 others); Mon, 25 Oct 2021 17:26:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbhJYV05 (ORCPT ); Mon, 25 Oct 2021 17:26:57 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 687A6C061745 for ; Mon, 25 Oct 2021 14:24:35 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id oa12-20020a17090b1bcc00b0019f715462a8so1049730pjb.3 for ; Mon, 25 Oct 2021 14:24:35 -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=cVVSf4gV+VHKaMcPkqXKR+j1Pi643cPAlkbYEqi72eA=; b=KaZ4GqG+L5BbOZwNRz+ZFzGoL6DWdRGwHmkuHMpBhtnIoIFP7poSXqXdiC9eBIyduE 6sSiiJ6O5yk+WTD2QWicyc0FTSHsKOmopPGxh0MCwFc1j6PJnh91QVp8PhupQgoFO3oT Q3TjaKiDTb/FYgwk7I8NiHqVtaa3U7K42dudE= 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=cVVSf4gV+VHKaMcPkqXKR+j1Pi643cPAlkbYEqi72eA=; b=e/EbudlFpFwA7xOqqItiNrxLsflVoqPI58Y5vEtXkgJiF89VLFeyA71h1MFNGYyIj7 AbixooKGRruFz9YgdwPfBVNyUKUPV0MLDZgMu0N66htP9Ss7htAN5CgWKQaBcCLrwvLw butD5pm0zUQbDrvl0aBNj9fuR/xfkeB9hUT9s0lSD8JN1/KKyKD4RUrHbUHIB+viKMw9 +PklVCdMlGHRNT0GPEkVxJjg9TwdkhE1AWDwsev95yHRjvsAeceLAUUGSQxrXl3VmZFW RSUv3Z89M3KkTmFufjI8XcXOzW4pGxun+vuzEwF6Emu0xVSFWaC3Wx122jfMXcJnlxeu YywQ== X-Gm-Message-State: AOAM533dOpy1C4g3Al3Kf6Vbqp9cWPwhaDGwSW1VYF6N+HeoE29hUfu0 Y52RHeMTBAw1cfUVxR/hYL2LlQ== X-Received: by 2002:a17:90a:514f:: with SMTP id k15mr15033244pjm.71.1635197075028; Mon, 25 Oct 2021 14:24:35 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t11sm21841162pfj.173.2021.10.25.14.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 14:24:34 -0700 (PDT) Date: Mon, 25 Oct 2021 14:24:34 -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 08/12] tools/bpf/bpftool/skeleton: make it adopt to task comm size change Message-ID: <202110251421.7056ACF84@keescook> References: <20211025083315.4752-1-laoar.shao@gmail.com> <20211025083315.4752-9-laoar.shao@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211025083315.4752-9-laoar.shao@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 25, 2021 at 08:33:11AM +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. > > 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 So, if we're ever going to copying these buffers out of the kernel (I don't know what the object lifetime here in bpf is for "e", etc), we should be zero-padding (as get_task_comm() does). Should this, instead, be using a bounce buffer? get_task_comm(comm, task->group_leader); bpf_probe_read_kernel_str(&e.comm, sizeof(e.comm), comm); -Kees > --- > tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c > index d9b420972934..f70702fcb224 100644 > --- a/tools/bpf/bpftool/skeleton/pid_iter.bpf.c > +++ b/tools/bpf/bpftool/skeleton/pid_iter.bpf.c > @@ -71,8 +71,8 @@ int iter(struct bpf_iter__task_file *ctx) > > e.pid = task->tgid; > e.id = get_obj_id(file->private_data, obj_type); > - bpf_probe_read_kernel(&e.comm, sizeof(e.comm), > - task->group_leader->comm); > + bpf_probe_read_kernel_str(&e.comm, sizeof(e.comm), > + task->group_leader->comm); > bpf_seq_write(ctx->meta->seq, &e, sizeof(e)); > > return 0; > -- > 2.17.1 > -- Kees Cook