From patchwork Sat Aug 17 02:56:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13766926 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 82689C531DC for ; Sat, 17 Aug 2024 02:57:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19DA76B03F4; Fri, 16 Aug 2024 22:57:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14D736B03F5; Fri, 16 Aug 2024 22:57:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 014766B03F6; Fri, 16 Aug 2024 22:57:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D0AB26B03F4 for ; Fri, 16 Aug 2024 22:57:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8CD6DA6639 for ; Sat, 17 Aug 2024 02:57:27 +0000 (UTC) X-FDA: 82460226534.24.33CADF1 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf06.hostedemail.com (Postfix) with ESMTP id BBC49180003 for ; Sat, 17 Aug 2024 02:57:25 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mGzVKWrh; spf=pass (imf06.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=1723863372; 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=yafMfwb+HSoYZwq9yXC5wS/U2NNWLBgbopuYYITBNcRZPiC/6/ZgCn76IeBSKXXo9TnT8+ 2ka1CormdYooGxJ1QDTKVMSbQHUbBhdozOJgCHk+09ZATacfJIoD66bBOd9JY1XfDQ3Urx mfhNbpA16T8+zyLPeSnnmnfGYXWmimk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723863372; a=rsa-sha256; cv=none; b=ovxJj9O/uqu/OYfkIuU/fvPoHnll4cLKelz1bN2hcGwCAIuhVv+AuBwkTIQxI3IdayWfOm S6LXJ8BjfIkn5msWjvdKzPQyEra7iGcAiCplKlnB+l3YB60S7uR+j/XgaiyOOd+chWuRTF U9Q/SJvKk5oZ2eWj8N9qEdrCUKr9RfQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mGzVKWrh; spf=pass (imf06.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 Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-20219a0fe4dso3462085ad.2 for ; Fri, 16 Aug 2024 19:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723863444; x=1724468244; 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=mGzVKWrhOgAMM/2qNLfm3X29yzh82kTQOGmQBjpS7U287pGqeBggOdCDp+AeXhdKRN e8eieaK4ICbK8auSskBlkV3aqouG9C26WjLRTiU0fL8Rd++hUgu360SLeHFGLv/wJyDJ o0iM6RS9CI/BaMMpRkRU+g6+lfDG2fwqMc4XfYByUXy4o92iTtMn6UcVR3kDTMEUYiDK ynBvGon7pFzq9ekhlsbMrfVFPuCBt7hCw07gFygqXuNBfsNY4lYH4SJVjPqn1jGFBBd1 2B+P3OJAzfC1aOv/HsdLcxpQb78uA0lNUlJO5v8oL/7Vk9XtMPc0ePc/4HrqNQqxutY3 rElA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723863444; x=1724468244; 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=RMR7fpFsbNRmE3IsXYyP8gAlZyiUK/aQ2cxajxUeHs/WD9xJHaNs49EPB9vMC4hjpv G/DEAcCYVRl1hdzDB0HQrWtneZRi/ckNZANAKR2QZp4oVGOMfsQwWABCln9tB6a1LO1m g8rzQxr0vUe3CJ3HV9x+VrCvXUIhwsUnwei5ulAenR9XbNOc35B1vWTMnYZPi9BJrkQo 6BM6jKSwt/WiksoWaMKo4ruQTTg8LLyHYnpj9AP4Jc8KRmuT9QaGSCc7btjJAz50wG3f AEHrA8V0bL8Q+kXMlfy2nEwMz30oKN/hsblTWnC0Brq2An2dl7S+nefUlliV1iDMUvuE 1dlQ== X-Forwarded-Encrypted: i=1; AJvYcCUlvjcmuGptqgAyTmKs03PDXPws4IyIse5A2HCTguEnad5oc3t+pdY8+NzlHjfJ6pKJf9af00Dhng==@kvack.org X-Gm-Message-State: AOJu0YzLAmwCB6qvLJ+fnWSdAEDTtGBh/IBx4uwshOWesMdYwSfIAPc5 +jBrnG7Kxth3hmLz9U83UtoSr9Hus0zbGg5RUED9zFjIAo6chH/D X-Google-Smtp-Source: AGHT+IGimEn6HMsvkqgHYM+kruqPW+JJG9kJGgyigEFWYmxee2uabObu84uvkyN6MQRp9Qx9ywJBnQ== X-Received: by 2002:a17:903:2281:b0:201:febc:4366 with SMTP id d9443c01a7336-2021969a77dmr17762915ad.55.1723863444544; Fri, 16 Aug 2024 19:57:24 -0700 (PDT) Received: from localhost.localdomain ([183.193.177.10]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201f031c5e1sm31801785ad.94.2024.08.16.19.57.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Aug 2024 19:57:24 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, alx@kernel.org, justinstitt@google.com, 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 v7 4/8] bpftool: Ensure task comm is always NUL-terminated Date: Sat, 17 Aug 2024 10:56:20 +0800 Message-Id: <20240817025624.13157-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240817025624.13157-1-laoar.shao@gmail.com> References: <20240817025624.13157-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BBC49180003 X-Stat-Signature: cae6uu9z1oc3gzxnesexnzeanmqp6196 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1723863445-756896 X-HE-Meta: U2FsdGVkX19We/oru6K0i7s5+TkVO602O4noBlgDC4Tbvtwr2yhXr4Msasaxl8YackcsFNmDC8JVsoDSq0t/ojMEItFo2u/yf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Np2mvalayoOf6bmt07CPGoITFpWOxHnigjuOkshZcwJGBFfG5yTsD/nQ9dp8oGSKc3jvuyQXcGCWmXDbfqOo77xGC6Wq0ft5kCR612YJ+eqgsUl5T2c/H/hr3Li5AIJDK+JmW+HQUvLjl4sYYYmEsgD9Z7d3LltUTZr4qUbE9rc8D6KzJjhQI53XGFjjPrfd8+04nt5Be0DTVpEMNoN1A3qMEzORGkoNkyBjnI267NIs8II8XCH1c3PuL/s2lGUZAPau8v66vj671Oa2WAREjEylhqdsTez/FxtQYe3Y+OLA8dJgMDCB0zIxnLPoSF5DwNrd+a/mEVMh7bhIC/x0CG5N2DYlDSXK6rkBZJ1CEicb0SZ0LBQgjic4vguEA3jem+4MJxSr4Pmu45mwO5IJ6tc4e78o3Gqfu9/K4EVOQ== 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;