From patchwork Mon Jul 29 02:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744223 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 25B77C3DA49 for ; Mon, 29 Jul 2024 02:39:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B906C6B0085; Sun, 28 Jul 2024 22:39:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B40936B00A1; Sun, 28 Jul 2024 22:39:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A08CF6B0098; Sun, 28 Jul 2024 22:39:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8048E6B00A1 for ; Sun, 28 Jul 2024 22:39:45 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2B617801CD for ; Mon, 29 Jul 2024 02:39:45 +0000 (UTC) X-FDA: 82391234730.14.944A8C8 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf09.hostedemail.com (Postfix) with ESMTP id 570DA140008 for ; Mon, 29 Jul 2024 02:39:43 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KaejUm5U; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.179 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=1722220757; 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=QQdkC9XISn7BWPlTE5/iE7aUj/L2jeLonKoaBsbNpS0=; b=ahQnyn9e2wh4pJtbwCkB43R/mPG1n0GHq/bSV2KrVZJO1FVOHmUUxT4TV5GA7h0s5Kr5yR mKQTrFyj6N1P+mWIYg3YXszPEx5pNXuvWtOG+xj8UEmxd58Ep8/MWpzpKreFUMaZ0gApDb NQIerBaTrOKVqHNO0fuFcfMmWCUbPCk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KaejUm5U; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.179 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=1722220757; a=rsa-sha256; cv=none; b=vWOa436xj55xzNQr90HhrN+/1ygjWo7NuNwEoMArCXKOx6eH8xZyakum4Yte1jMOQ91CHm TMruVTb5lSEv/zFHbgydh/cW6iM6x3RUITrn30zrf8+V+UGGbGQFIRlm4tjhhMusApC1X7 /WFN06Sd51r5Cb/TXl3hnN0lRvlxgV8= Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7ab09739287so1461491a12.3 for ; Sun, 28 Jul 2024 19:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220782; x=1722825582; 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=QQdkC9XISn7BWPlTE5/iE7aUj/L2jeLonKoaBsbNpS0=; b=KaejUm5UPUsRElSnjdqwxWpYQMp6H96GPNEHpF+yRNwuhdPCKHSTtKJ+gnSMHzjtxf n8iPKcl9JzpIvjzdjJpxX0dDyZq9rJyuNOtdo3n6ak+pyYU/eB8YIy/UkwHrIZgS2T8x oVPaCFMYgsqKD/vqY7rlsB09X7zDTt9I+inJ6irabDvfosSsOkd4x5yWM5Ru1kXzmNoF 84RuC/vsaJ6FB2EVbTNTADyiJPWURLhcbL1OO7fM40g5m8AT0tg3x2fOjtIWO7+A8vXR 96Yi1ufsk23eaexhI9bRfFYdGd0I5ZSXJSEzTOHZonl/psixsBj6HojclRoNeQA3MiPa CwDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220782; x=1722825582; 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=QQdkC9XISn7BWPlTE5/iE7aUj/L2jeLonKoaBsbNpS0=; b=bQzvcQvztQ01m2N2XcBSOE2eJKf27lZQrXvovyMZf8dK+SkgBsP0e2b+Bc3EKyxJJ6 jbh4EeEYP937v8qvlOOt8EaiqJJPh17CW8/oK9NF+CqkIN+g6VvVBtKQAVinbyCilzFz GiCDOgKXYTsWSFAuYVBhRAMSNPKYIvUT3HB3tlx+VePKCWo1V7XCDqN7C6isMQmASV61 3YtZrGLz6IV6tvF7dlLvMnzkmY3AW7FilpOuFUNm8FcslaTOnTSpqXOmmYe8nCh2k2/J 3jVWHpeZnTIGIcj7PBA0Z0OK6uV6wrtTuBkFcJuMz4+3YEMm57sla7GYWJpHuDDmPZml A04w== X-Forwarded-Encrypted: i=1; AJvYcCUrQTG0H/c7F/v4rS4D5oQOPf/xGM5l/Nsk2pKleFrKCaMs8eVLDKtIGOVIHFn/y5ydjouaYtQXFVnp7GobEP3lCh8= X-Gm-Message-State: AOJu0Yzq/LHuRjd+2dAhaLhHLdGYZNuNk/JUOvzh4uiuuJjKgDRlmIRz pOoyO9R+gvRKLXYxYHMGLVP5WqsiLku6YjKviJ21ZDqDQGA5Na8S X-Google-Smtp-Source: AGHT+IEB8l3Gwpw2EoLQWPXs9e5ig3IiPuxqtfGfuMuw62eXKcBpM2d5t6Uy/en6iDAcfcY1gaCpLA== X-Received: by 2002:a17:90a:6581:b0:2ca:8684:401a with SMTP id 98e67ed59e1d1-2cf7e5f27a9mr4176294a91.32.1722220782084; Sun, 28 Jul 2024 19:39:42 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.39.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:39:41 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, 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 v4 04/11] bpftool: Ensure task comm is always NUL-terminated Date: Mon, 29 Jul 2024 10:37:12 +0800 Message-Id: <20240729023719.1933-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 570DA140008 X-Stat-Signature: 86f7tbrhpp54h9i4ttfnarezy16n87ok X-HE-Tag: 1722220783-413538 X-HE-Meta: U2FsdGVkX19zL4ifaZcBTF6YokEwCLzVWNlD/26aN4fsVRhQpyGEZYGvSMNSBPk8DJq8uWZzKjZqfANtWS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CkVKfw0fMrmN3VhtClq49m7C4H7fJXFga+lb5pmpaPtzXvu/Fu3z+D0x9SQyQqIZugAidAP7UqBkwb1d95fsQ4vULWI6xUthnRQBkJu9A168TJYGmdwbYeKwZ2pwZSFQzh+Aj+U/1Wo3WVgB56sjfbCXTcHB1JV2wTdJjkJ261c/LQNSpib4/fUJ0QRCeHV1tRx89QXeQvJh8EETVbmyHOUIK1ea7FxnM4CztRmkIm23rSDYjx73yEvd0aAfvu3tA7IwOw6yWUB/yroRzTm2xFPgdux+mprz8z14I0Yju/lzrwsfvd/4tXlbdIrEVlQ8EP9LPpJQc4acKNL44o6zs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000027, 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;