From patchwork Sun Aug 4 07:56:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13752527 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 CC613C3DA7F for ; Sun, 4 Aug 2024 07:57:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A4AD6B0093; Sun, 4 Aug 2024 03:57:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 553776B0095; Sun, 4 Aug 2024 03:57:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F4656B0096; Sun, 4 Aug 2024 03:57:53 -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 1E95E6B0093 for ; Sun, 4 Aug 2024 03:57:53 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CA2AC1409AB for ; Sun, 4 Aug 2024 07:57:52 +0000 (UTC) X-FDA: 82413809184.09.69691B3 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) by imf13.hostedemail.com (Postfix) with ESMTP id 01CAA2000B for ; Sun, 4 Aug 2024 07:57:50 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="e/r2oSEx"; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.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=1722758223; 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=eQQ3mmtZRuc+UzgaTIbXRCgMjfWu2etwx8M84uu2mcE=; b=QrVrSLEZwMV9IaTO396EWonU4GLbKNXR8p/EfIAVUF08EE98DAweJsX2ngmjYgFMPAhNIk gKADYoQCcXzPeeAH0/hCZ6RHqW5DZechHpcsqH9BWjcmclIlipoBVQMxgJkZ0JnGGweFJW yFSasZlk1LRFauHRzVZG8JbHI8DxwrA= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="e/r2oSEx"; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.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=1722758223; a=rsa-sha256; cv=none; b=RMQetB5xmBdwPGTIIYEOVo1q2p+DH0DVjS+ol2TvunSvkg5smHA6E2VO+3kH+0iYl1vl8D BacU+E4kKI0eUDeYOlFADkJKk+pB5OWoRsiktjSF7f3VuCVOAE4xK4XGyEAIW9Vph35Uhy G2Sy/RPY9kBAo2i8EcylUIkLVQHzfxU= Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3db16a98d16so6095528b6e.0 for ; Sun, 04 Aug 2024 00:57:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722758270; x=1723363070; 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=eQQ3mmtZRuc+UzgaTIbXRCgMjfWu2etwx8M84uu2mcE=; b=e/r2oSExR5s8l8M5qc8Y9+aFEzZ6mKz3n1LKtgPjNemgqqaF7WCDnNccbdaF4mj5v0 9hUiENNCh9w9SZaF3ApAKsz+Avrje0lFTl5zjtZDPpBdAXDCYTni6C47JCOyhuQIsF2o QQZA16OOab1J2/41vxcNdn+nss/YYiF70bLKk5MM/pbdv/LqjtSxHpLVailqJQbN5rCQ 1fF2ruHNBeTpJFgMhbvMAsNS76JsHKPXwkRddwArGIUcvQju6xum2yNjHQmb5pQZjbvb ifZ8gRzzew68tNKo9Yq8yje2Z4mD1ucQn8VIxUcMXRq7jPNLf/WKny81NEW64yZwBExq a+Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722758270; x=1723363070; 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=eQQ3mmtZRuc+UzgaTIbXRCgMjfWu2etwx8M84uu2mcE=; b=XQhX5QVwjfcmoCfPFfj+jp2ga9PvCg0gYpYsDUVVKcPCP4TnINHLPlpm0OycKcjjbb 8n2MpamBLPVuFuUTaLEuu93DCCt3Qq0WCPm1Na6cPsTy0kbEQYYZ6oNH7Hk6bjBuPbxf QULsvcJpltKOO2im/U/ysYpeJcC4jgl+Nxj3lOKVxyjzb2AFIrEtKdeMLhCi8WCjm4wq WkdO2lDJxkZbrUleepmDKFj/oVr1yfeitnaxHkUyly4qZ0No5LSAnCuKnslu9IzY75uB PIcn22i4J20bKEo6YLCCVl+ATp6J2XYVVNFUt0xVAbABZfRH9SnzC+vZ9XTZ8LtuSMWo pkdA== X-Forwarded-Encrypted: i=1; AJvYcCXJNWf8Wo4NtmJy6B/Iscz9D6Kxio7ETUdH+qvEnzq1ccGt2Cf6w1bKwk5blwDuqLz9kprr1iFtsi7iuvZgKKmQZnw= X-Gm-Message-State: AOJu0YwHkg/w7dsqOL+K9QPCdEd6iwsaBffU7DU6RO1Sb9J+c1PmFwto IZjiiBuoqFEyJEvJG/z9yHEGO1Mbxq2iCP1PRB9Te0xrOMSPB+m/ X-Google-Smtp-Source: AGHT+IEnK16jBONqPu6EI1AggsrrDpNbP1fkcELTlG1wIUqkHXvdRtx4NsDiXlOwAOqcDTPz63EQbg== X-Received: by 2002:a05:6808:159d:b0:3da:ac85:3bd5 with SMTP id 5614622812f47-3db557ef9bemr11482423b6e.8.1722758269943; Sun, 04 Aug 2024 00:57:49 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.172]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff59178248sm46387605ad.202.2024.08.04.00.57.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Aug 2024 00:57:49 -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 v5 4/9] bpftool: Ensure task comm is always NUL-terminated Date: Sun, 4 Aug 2024 15:56:14 +0800 Message-Id: <20240804075619.20804-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240804075619.20804-1-laoar.shao@gmail.com> References: <20240804075619.20804-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: 4p4xfayueu3pof8t55csdbxh5dui6dmz X-Rspam-User: X-Rspamd-Queue-Id: 01CAA2000B X-Rspamd-Server: rspam02 X-HE-Tag: 1722758270-620888 X-HE-Meta: U2FsdGVkX1+2sOXgl++ar7tLe4whIMD1Ca4WqKaEcaiGfp8TTLANpiS477sGtKUIogcIg4Y3nqf9WbJnuXiTbJbG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fRhlrCNAShdixt8gab0fNiJn9w/Zt0OK3WT44EacxOJ37YV4NH8VLqDZLhmUxDOTKwQuEPCQcDJkoQj/zQVO67CAXowjLWUMBLzb8bYrOC89l+zsGF79aOfJt7FqQcDzOMNnt2colxPmpEoHFAEDiSptwW1zVYL8Ld2RHYe4aQALwZvBBSlH6dUFzB75tloTVM3noks+PnVsEpe3RbTeS6ONag69fKljjgcdyH3Tcg5TgHMuoja3FFg7CEMin6sM42y+Z3zs/b/5kYh6qhR/P/XHrzdvpTDYuknXGDSOJ/4EkFUDJtFK6YZZIEqYRtWLKLSv/q3EsFhZZDRE+9wJlAyn8= 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;