From patchwork Sun Jun 2 02:37:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13682618 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 EA1FAC25B76 for ; Sun, 2 Jun 2024 02:38:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 807986B00A6; Sat, 1 Jun 2024 22:38:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B7DE6B00A8; Sat, 1 Jun 2024 22:38:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 659896B00A9; Sat, 1 Jun 2024 22:38:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 43EE36B00A6 for ; Sat, 1 Jun 2024 22:38:58 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BB3481C19E1 for ; Sun, 2 Jun 2024 02:38:57 +0000 (UTC) X-FDA: 82184391114.11.1B76507 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf19.hostedemail.com (Postfix) with ESMTP id 064BD1A0005 for ; Sun, 2 Jun 2024 02:38:55 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PQl1so0H; spf=pass (imf19.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.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=1717295936; a=rsa-sha256; cv=none; b=23nuL/aYY2dQJDaolapGNMRvXwzuDzAbwmTdDcP0sL05GH+Mj2zjn+Aq58LZv2j+E84WPp QXSQmCcURSbHRJjuyGqzkhhPq6arEGvhPwNXSqk8GSK46hMMo3PoRoaUnYZCvlazn+2djy uj41xkQ/FlixHkniwCXdmXd5P8U0Hpg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PQl1so0H; spf=pass (imf19.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.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=1717295936; 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=3TpGu6Oq1vjxccb8W6xWjhiTwznYEKWGAfAIwahkDiA=; b=rXVQ56Hbi8Wr/WctzO0ZqGB3IfbaBzQFU2YRhpCHR26eaFqMHr4JagMwaInvbnYjM6WFdb Z8YbdxRSoU1QerEUT4dmSFwINkAbhWYAWNnBRmue5OeQqqfka1bDzPcX0qvAodwSEtnKH+ K+KqANR60o5tpm+WgfpTNBnBihjY/fI= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f4a0050b9aso18410685ad.2 for ; Sat, 01 Jun 2024 19:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717295935; x=1717900735; 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=3TpGu6Oq1vjxccb8W6xWjhiTwznYEKWGAfAIwahkDiA=; b=PQl1so0HvQ3sIPklSNvs/I+e91GgYimbA9KM3u9rD1kKNQvSvSgSDsd61UW8avxuaz cB8as9J0x7t0WlQ+1PquNgY3toXKSIAUy+6Vmr9uEc6YVcPOTK9VgKtbEmCJ2cTCGdJg R6RobZ0BDS+TqeHH+j7TYaN9V6o05PtFoA31tzuKWgvLM8WpCJDpOJ7uviOUvkCNM366 DihpXZ4Q/H85/ByBGorPVCfMmIA9IkqF+9NRskP7Z1VuKNTeKGTaCzRRQ1MtG6NUFEUR EAiBAkVZevnqiaNGRyaEJ0TVzHB9TjyB2OXiyKwgkQzPgOOzjatSbV5gQh5kcRlmZTmx jJwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717295935; x=1717900735; 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=3TpGu6Oq1vjxccb8W6xWjhiTwznYEKWGAfAIwahkDiA=; b=emqBKrBiX776DVBKfGZOp20/Pw6ik3n4Z64BfN3mA4RLUatPve8TkBYnRSsoJIOQsp K+85Qkv85BIixOrKdYFCWApt97i+vJasdrxHsIgOn8zi6hTkcOBFQh8Y9Id6PujK9wtJ 8U+r0QBNiQwz9BAsMcHNowwYtfoe53jDTt6OEcyY1NMrI0+DwykEdwawE0iRTYHUsQRe f5hMU+RssxMQoLZNQYsmbsiGPsSMWxsQx8LSKN1cy1yxWqPgtyxEblcLchqUcAqyBiMu ZzvrqW8QGWDd3n9aQcw9HnI4Le7+xMFKAUOJgD0BTfHcOcK2KdaxcYfvZm7OjKOsr/8t CKaA== X-Gm-Message-State: AOJu0YzF5GmtsMnfIlMTmMz2caRmsJNGAddXLIWN4d0Rt36xI+sC9l6/ dA58bQSlx9Y/5d8ob7FHl9qzJ+jclcu+itaamuxGUZQLrch0cN2R X-Google-Smtp-Source: AGHT+IGxvOn5+cLL6IQR7JJZSFxqN/pAIswbvkNRxUdWw/EDTeYezEeBw1uxYC432gXEUnzhdS2+uQ== X-Received: by 2002:a17:902:a38d:b0:1f3:903:5c9a with SMTP id d9443c01a7336-1f6370aa056mr64384745ad.58.1717295934923; Sat, 01 Jun 2024 19:38:54 -0700 (PDT) Received: from localhost.localdomain ([39.144.45.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323ea21csm39379575ad.202.2024.06.01.19.38.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 19:38:54 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: 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, Yafang Shao , Quentin Monnet Subject: [PATCH 5/6] bpftool: Make task comm always be NUL-terminated Date: Sun, 2 Jun 2024 10:37:53 +0800 Message-Id: <20240602023754.25443-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240602023754.25443-1-laoar.shao@gmail.com> References: <20240602023754.25443-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 064BD1A0005 X-Stat-Signature: q9r3jju79qjj499ouxsixg8mdgsscgp8 X-HE-Tag: 1717295935-651036 X-HE-Meta: U2FsdGVkX19kRocgkZBuFubL0rUo8/B6qFQ7JNhfE4ReAUyaQ35s/6NRufRhh0vXdV5VVKhH8W9pAirPqKrGnd0ocjgGn8LNj4cmxajcj1LGiTV9Xgh9gpAK9XWVyuRJHseXvPUGOIONyZF5c8kq7jBVVifsbZ285IKQLNRj4GCLEjmfREJiWf7EZLEkFj4GUCOYYHXiLLjSljjnwI8Xv3IH/Vbg+2KoSCVZsvBfqbSFMjn28Sjg5rcrD4gW2pyxY+KxKjezaA1lCgeTZ2+D5CJFCzIseAzAhHUwI+B8+bAePO3fEaBKL2ztK6BFK/GGnG6RhiVObLw6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iI1X99aQEvk+KKXqb+8UDynFMQb9OaLk6XXzejlpoz+kzztOJ7kVWYH8hjgD20lp0UJ1zdvAO9+6GD0yc6dybrC2+/DnYqIB99FeaZrm/DNtaX3GDZ57RROKgr7oB3vXgFpL3VcBMlYvDRNRgSgPQE6MSV0XpEA0Nj872LXkf2JQfq4SuKomVwoKD7bE4NXIEi4h X-Bogosity: Ham, tests=bogofilter, spamicity=0.000012, 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 Cc: Quentin Monnet 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;