From patchwork Fri Jun 21 02:29:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706695 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6093FC2BD05 for ; Fri, 21 Jun 2024 02:31:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AACDB8D0121; Thu, 20 Jun 2024 22:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5C2F8D0111; Thu, 20 Jun 2024 22:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D7898D0121; Thu, 20 Jun 2024 22:31:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6B0338D0111 for ; Thu, 20 Jun 2024 22:31:22 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 265831C1581 for ; Fri, 21 Jun 2024 02:31:22 +0000 (UTC) X-FDA: 82253319204.22.8573D6E Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf15.hostedemail.com (Postfix) with ESMTP id 57262A0008 for ; Fri, 21 Jun 2024 02:31:20 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A4lussnk; spf=pass (imf15.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718937067; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=c7QH8g7nY2INvVrL4NU75ftNhN6FL7HL04IiCAjwJmE=; b=osoC4U7Y0C9ACOKAIUjSNeibUsmpVBMpEI4tZ2I8Hp9bU5whttQ9BPvmaOBEoxdOj7FsAN EfuQld+7aY/SNlo3UJ3hMmZrtpQIr4srEHdP83yu7I0iy6zcii4NjQA+nrGD2+hYz9pHA4 iKzdaQ7oaSywMoGd7VWK73omQRPGUMA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A4lussnk; spf=pass (imf15.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718937067; a=rsa-sha256; cv=none; b=ddJ9uCkWk1emAMzmC9N6wuiLYGWUGp/pULrR+OxfU98xQQvDqIN/Zps3JsqBBQ6NZ+nnfQ VozwaZBDvG1rxyOwpLsVmMlSx+mu8eIFyFeSJWGpfPobI7z6qWgJZuTcSU4DoSirOx3Ax8 G8fz+3gwwAlUyiuaGUBbyi5PfiTy+RY= Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3c9c36db8eeso781772b6e.0 for ; Thu, 20 Jun 2024 19:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937079; x=1719541879; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=c7QH8g7nY2INvVrL4NU75ftNhN6FL7HL04IiCAjwJmE=; b=A4lussnkyrXSPjAKckzIo5jKQtdPUFA7L/QEVxBR53A+anHzJbDFWU6HCw/W/RUPVG SPaO0imYnYXNfAsF9PHhb7nURCY7ZNhsqGv8NVnDzLKD1UyIyi6Z6CXhpRGuRaXTdfh8 wx671b42OZF9Y/43nxuE4Zk9tG9fBaPV/S5cxbWbs93GAwNnuvuOs5NQuOTqIoBUoBO+ G7Ju7NmdaS7/lY1+qChOiGtlt0c7VEFhBml+jsjMRkRQcovnpu0+qkh/kbw2Nd9OBffp 8y9vEQFaUvdf3pYfKvIVqQilUAY75fhWgW1i3s+mqi7TWExBXkOBP0BxYTt5rOh4Csbb /B/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937079; x=1719541879; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c7QH8g7nY2INvVrL4NU75ftNhN6FL7HL04IiCAjwJmE=; b=hEjAtNnaptyDzIDHYZK8xP9c0vQqoQFhZZmDJs/DVrD2vklBWhucDngF02xQ/DJv32 337bqRDcccHDBn6N15wD9V2Il495hAtwAkP/U08ziF8ffZCtTyhtpPObEniDz+Tg0W+2 cgm/8GlvNaZZgaQiGRELfwB9fHb35fz23tp++4prGtOR47bBOuapqpS3reaoXUmtvIi9 /DpTYrU5ejbGZdMh37GOt7HxQ1Be8uxVH/EMcdwmWg6gREipQdv4ro4kbA+un4+6UuTI aDUlRlFacDCfRZRSKBXALsTRXYwkj8SnNiwE63xgGi6tKF4qYPLUok9D+nOfeHGa4CNX cpGw== X-Forwarded-Encrypted: i=1; AJvYcCU33nVAAqe2IJqoVvl4wbjBa+saMt/gKTY5cXDhsHFnQcDatr1crVqehZVwKLJkhFJVEZzyKlEMMhAAuTfaL9a4wm8= X-Gm-Message-State: AOJu0Yxl3/YqNFiT/ILPrUZCOC7dsA2BMJ4fiEUjBZbHg1p3mN9R2vbE r26Hd3mwiqyV5VP8fvFpeQJngwSgwDKZevpoKsDsm2aF/78kABmb X-Google-Smtp-Source: AGHT+IED/biJ/4HZ3XKtIPvcAUdQBx9cm4PcU9a703LBYQtgmllriwsa8W5+N5BARKh/qYuDuJagiw== X-Received: by 2002:a05:6808:f07:b0:3d2:21a7:8629 with SMTP id 5614622812f47-3d51bac4b56mr7794777b6e.41.1718937079354; Thu, 20 Jun 2024 19:31:19 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.31.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:31:18 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, penguin-kernel@i-love.sakura.ne.jp, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, audit@vger.kernel.org, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, Yafang Shao , Quentin Monnet Subject: [PATCH v3 04/11] bpftool: Ensure task comm is always NUL-terminated Date: Fri, 21 Jun 2024 10:29:52 +0800 Message-Id: <20240621022959.9124-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 57262A0008 X-Stat-Signature: q7rywh35dhb5xnhjfkzx3bi9rpcyw83a X-Rspam-User: X-HE-Tag: 1718937080-842974 X-HE-Meta: U2FsdGVkX195WQ2P29m2Xw1tu8onLQMUkgUtg6Hpyc8J7tPSR9MjgtjlmjXjCaZU0H5gArYRrWQYgXfPM87KKicGbA3auSrblGsCb7MC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MXrLgn2lqSvGBU+FpTEupvPpNn2tp7jmXpXjILUM9PaG3X1do4Nbu1CmW6e2FAVjqmqOYTEAadmdNuBCGgUt5W02ohYkyI61hFNSwrS2WDPNEtLLzewO9iTizUpVBkBGqVBy6XlKr4pg7p3vOr535maFv7qWPrfQwBty9wcTZkYZbl0UzUB5NdK+VruAKVnaedHzG7SYp997T1PuQPg1MxoDygbnFwgfWQqMBtQpuHRISWKIvk0Vj+M4nfr1jN8lwjcpCPTsGneq3N39baoGGUD6+rRBMm2SIsDZLUnqW1Ewk68AucHTop3wekZpqJEz1hr3M= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c index 9b898571b49e..23f488cf1740 100644 --- a/tools/bpf/bpftool/pids.c +++ b/tools/bpf/bpftool/pids.c @@ -54,6 +54,7 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e) ref = &refs->refs[refs->ref_cnt]; ref->pid = e->pid; memcpy(ref->comm, e->comm, sizeof(ref->comm)); + ref->comm[sizeof(ref->comm) - 1] = '\0'; refs->ref_cnt++; return; @@ -77,6 +78,7 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e) ref = &refs->refs[0]; ref->pid = e->pid; memcpy(ref->comm, e->comm, sizeof(ref->comm)); + ref->comm[sizeof(ref->comm) - 1] = '\0'; refs->ref_cnt = 1; refs->has_bpf_cookie = e->has_bpf_cookie; refs->bpf_cookie = e->bpf_cookie;