From patchwork Mon Aug 12 02:29:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13760008 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 A65FEC3DA4A for ; Mon, 12 Aug 2024 02:31:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36F8F6B00A1; Sun, 11 Aug 2024 22:31:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F73B6B00A2; Sun, 11 Aug 2024 22:31:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BF336B00A3; Sun, 11 Aug 2024 22:31:02 -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 EFD5B6B00A1 for ; Sun, 11 Aug 2024 22:31:01 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B1C5080635 for ; Mon, 12 Aug 2024 02:31:01 +0000 (UTC) X-FDA: 82442015922.03.1EA20C7 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf05.hostedemail.com (Postfix) with ESMTP id D739F100004 for ; Mon, 12 Aug 2024 02:30:59 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ds2BGLJb; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.182 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=1723429825; 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=QxZg9dPaWsziTaIkrilUlseK0Vur9RcZhP7emHPG49t6jsWvKQNzXW8VUFaqF13tZnjqkF hZXVfajRh69rCMdLQ+gFRCgJkmt3jDidhUXtVWIgzs45HhIp0qQMpAh8Hejcu2BFCPd/nO 1zo1D5rITVoBACVulAmoJjPTuBzuHuw= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ds2BGLJb; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.182 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=1723429825; a=rsa-sha256; cv=none; b=RUbuXDYnR3/nCUXYluv1hCcWjbZZbSY3nK9qK7q5VM2zLy3C0hHxc65YBNw91HEcuqsPbT vZ+tCVf9Am2nQOlH0KlTy4NbDJP8tXzxdzlBGJ5znX+FEujwT3vCsdw3p6+JpUd7ChZqrp 5zFcs8K3PM+Lw6lmsd8nXciFhja2lD0= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1fc5296e214so37046555ad.0 for ; Sun, 11 Aug 2024 19:30:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723429858; x=1724034658; 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=Ds2BGLJb0IpS4+BJL2Nto+KoCDhAyST05SDG6iVZGZcflcQom9LgXxm6A89XM+W82v iYxdq2gSe4qkqKB+hNMPNfFSxtsYbpmYXrVr4BwZ8JvWSHZX+2I8/vNrqG8scO2/EIsv VynbcKuhEAf3peMMNjNHQ5sMA4JgzhfzYYrfJinUhAbvTdKZqXmiqEvwOqhZ4DNQLQPc WfQm9TMvW4lHEHGoPjWU6tJLjSlKCeTRHnAfVA7u0hChHeWCYaPg2xn/pnFIgbl7ygUI 8AwE3nJRJDi8TzSBua8gUj3GfWcg+K7zUiDWlDvyOpOQoG9zU8k+4bseU5NKxiJYYG1+ dc1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723429858; x=1724034658; 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=QEFrIuUXtlWgHCNvQFF8vnLdaARfo28T536nb+VqCgC+SYj9xp8MsbkYviSbckd0fa 7a5Zs0Ee4txgZ+qi7pWIb358lVR2ARf7v9XpfwdUpuWHDwNvM+EvosrzOsRkFl7i9XpY tFqNDZkpUzEhq+U2yPyFKDWYpTEA2hlvah5hbzE6pZWaX4QvnCMAcZmiSYCkwHlyb5QY ZmozaHWSyJvHAi4E2RxvWENWsIBi8wNvI6L4yYhzY1KlK3CBA5+qYe6S20Z+WOHugF2F H/Q+J1f08XpzqtA1lPLqXwouSXPhzRUtG5xD+Q8D9ypZXvI9e3s1w137G2uO9SbI8Itx +8mQ== X-Forwarded-Encrypted: i=1; AJvYcCXgQNUzMY+aEMqSIanASo6Oo31MauEUHQpRIOgmoOrBsFhQp/0R8ZGjQVyQLV3otDSOdrz7/DSdclpnpu9qmMd+QkA= X-Gm-Message-State: AOJu0YwD94C6lXeHwT3xLQB/2SCLIX0AiRQpwkEe2asDgFDKRXlW9x+k ThIwHVJRLpORDTNe3dyVbqwu2N8UBgoikzfbX7IvURHROwLU2z0+1r44KMbwkJuE9Q== X-Google-Smtp-Source: AGHT+IEa9lv8MoV6zk/9zF8wCzjKsRZm15PR0yRidIjcflgd8FgwO2+8+6fP26BlJQqb1WyA3rzQJQ== X-Received: by 2002:a17:902:f54b:b0:1fd:d7cd:ee53 with SMTP id d9443c01a7336-200ae540e2fmr93875475ad.28.1723429858561; Sun, 11 Aug 2024 19:30:58 -0700 (PDT) Received: from localhost.localdomain ([39.144.39.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-200bb9fed69sm27884765ad.188.2024.08.11.19.30.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Aug 2024 19:30:58 -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 v6 4/9] bpftool: Ensure task comm is always NUL-terminated Date: Mon, 12 Aug 2024 10:29:28 +0800 Message-Id: <20240812022933.69850-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240812022933.69850-1-laoar.shao@gmail.com> References: <20240812022933.69850-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: D739F100004 X-Stat-Signature: mw6zrfigpj1mp9f5fp7mztu8yok4y19t X-HE-Tag: 1723429859-986138 X-HE-Meta: U2FsdGVkX18v2rawAogJ0CSHbaITeA/niv/xQ8XQSuDepLxkKiRWWNzQPRDUVwfdklM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So6py8o4ilRYF2gbU7OuCsEGCI0+9jlLN838HZxOcGBm/2CLppuFJLoSeFwV5SIeBULbYHEm5rj4JIBP9IMvm4s/imsj6NC/ghzxYka5Xmwg3F7pL5E04Hxmf6Zw3XhqXFWYJkxUKjzK2vSUfH5OXyr6IOJiE1Go0Vo26TdcGfVQZieqNh5LrTBBL5OOE0ag7k/0taINtNpHhrBrc4XuhRxLJ2ClRQGs1Ii+9LgFzU/sE8bDMLHCTVjogs9ZJVVJKZ412MRxXgf7HS0drirE/7R3QjRUYX1i63aah3ETzqpAWqMk5+eXEgvIjCwsJKiTlwul2FLoCrTQfq1X99C571RETDt1Gd45Lht+uAhE6vmKULP1RY8beRJypIbKiXBzbnbKMDbabQBb4uz9V7PMMa7/upscdhNdZth7WP8n0RfnAI4YUALCLdEIUcQGPA== 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;