From patchwork Fri Jun 28 09:05:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13715779 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 8EB12C2BBCA for ; Fri, 28 Jun 2024 09:05:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24DA06B009F; Fri, 28 Jun 2024 05:05:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FE1D6B00A0; Fri, 28 Jun 2024 05:05:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09F206B00A1; Fri, 28 Jun 2024 05:05:52 -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 DF1C16B009F for ; Fri, 28 Jun 2024 05:05:51 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 68F01A0B89 for ; Fri, 28 Jun 2024 09:05:51 +0000 (UTC) X-FDA: 82279714902.20.597711A Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf30.hostedemail.com (Postfix) with ESMTP id 8C9EA80016 for ; Fri, 28 Jun 2024 09:05:49 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=I5FKL06+; spf=pass (imf30.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.174 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=1719565540; a=rsa-sha256; cv=none; b=dof0ygintnWQ25HhXfKAKGaH+xx36epUR2NN3XjTdBr3hQakCGNc6jJmzhSEhMCXpsgVHE maaibxXX1n0K9xUmwyGeAFjCtbO8GI+fMRdZMKE62jq2rc1EiMmwXj7DdJKWBLRq1Aa8HV IrNJPwQivXmMIrE6HpO02fsUMYmQu9k= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=I5FKL06+; spf=pass (imf30.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.174 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=1719565540; 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=PHZ91jLNLd3RRWdCERm+RtkP7fZ6OJhSoGlxT0WZL4LGHJ0+hp4JOBUXLib6G126r+T5eA x29ytu7a6m0NAm6vn6KbPGwwrvXnegUjrU50OFg+th/rThcA0MYQtp+QVR4Bg2DXwvRS8F E6AxIO/VJgT2RVIV6buZD+cO53F0C3w= Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-71910dfb8c0so214679a12.3 for ; Fri, 28 Jun 2024 02:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719565548; x=1720170348; 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=I5FKL06+9sfKMWFh107wZZr3lRPzG9/ziMDvvJRLjcvfiSRZ/IJIgwswfNpkUbtFiB UMAEvUeyLD/+OBydzuYVk25x/dcthflPhvWh4iXYBo5GDADLXkIuUtdWMods4GU1Sa4L AtYO1r7L3lMKtkRnaGl6YzI99H8JI3xp1xANARb8jc+JZDDHhT5MGIT1eh+f/eHApqTc 0rX/XGxtckyFxxK31tg0+h+7+d4gUUAE0Vfyjss0+TaU+San7qSTfLRAwMKbFileYn4Z +rd8zzxPzScZmqIUsCnJxPW6DHPZ4QWZ7XCI8rvE1qDT8ayEKNOXA8F4QzuT2uWy40O0 qH5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719565548; x=1720170348; 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=lZG3oBLN7E3uRtbMj5MS8l0exg41YjbwrU09AiHniMv7YQWzms7lQmSyI9tWl6MEXN POWYvhFlhii9mY1SOcOi2qcMcvDXbLI+KXOJsjIjnzr7poom+xSs4/2njca8ZN8ZmgcP MXW34KnDS0nzYykiltQqIW/mXgYbov5UAAzDEc2EoQZyU/1MT+rz8FQ8nnRnl1I6QQkH e/z/cU9akmVySeXPPa9IAe454HmN6EyLLLqgD7VzRjHmEG/pyg806V1uNHRZqQ4KzKBS 7sHR5M0PBkmDVVn4VSHgm5kjxbieFJLUdCVxiA2dTIlshW03uQwSsIXSE/C+w/AXIPrq Ap8A== X-Forwarded-Encrypted: i=1; AJvYcCUo0FEZbPJM+64irRFljp72F5sId9MgssK9tvci3NTYS81H/cohWYIb0vly3SWAfTZ4gTuD6BsUBna3tIcLHy74VuU= X-Gm-Message-State: AOJu0YyahhoAdHqzuGF93CJy1MGPnybtJQOt6Ribs+YOPhJxAKSrNlY/ 1kEmYaNo8xnMpIBiLZYrAjDqNdsH9BXaNn4NYo9s3ZCKRMp7ikv7NypPtIWKMLk= X-Google-Smtp-Source: AGHT+IFMoCwH/epxCGvG8TCVrNgBjmP2Ft1l1xXAwKN56cpOIayJsWQPU41hiw8mZOfUPZaXevc3Mg== X-Received: by 2002:a05:6a20:6a04:b0:1be:d9fc:7f03 with SMTP id adf61e73a8af0-1bed9fc824fmr4655522637.23.1719565548310; Fri, 28 Jun 2024 02:05:48 -0700 (PDT) Received: from localhost.localdomain ([39.144.106.153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fac10e3a1dsm10473085ad.68.2024.06.28.02.05.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jun 2024 02:05:47 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org, laoar.shao@gmail.com Cc: akpm@linux-foundation.org, alexei.starovoitov@gmail.com, audit@vger.kernel.org, bpf@vger.kernel.org, catalin.marinas@arm.com, dri-devel@lists.freedesktop.org, ebiederm@xmission.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org, penguin-kernel@i-love.sakura.ne.jp, rostedt@goodmis.org, selinux@vger.kernel.org, Quentin Monnet Subject: [PATCH v4 04/11] bpftool: Ensure task comm is always NUL-terminated Date: Fri, 28 Jun 2024 17:05:10 +0800 Message-Id: <20240628090517.17994-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240628090517.17994-1-laoar.shao@gmail.com> References: <20240628085750.17367-1-laoar.shao@gmail.com> <20240628090517.17994-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: m8mcwwwej8bcgubhnqsfaroc68q4jif1 X-Rspamd-Queue-Id: 8C9EA80016 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1719565549-183426 X-HE-Meta: U2FsdGVkX19yWDtlAhW5VuKKuhsN2gNfkrd6vmAy9IeZKHP2cvLg/6SYy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nJH8WzZJtCKlnvnKnC2BJHQ5n0Zl+j1/KW7QASjJG2ZF+PdO/f297mp6DKK/sfKiQ6qp1LGb46iQRKPnfTrmv8nSt8vJoobyePEZ+YpOLUlTC8ZIuwEe/h9B69J4FR17bKuNzKbjUF9uMc2E+sGti42ObkD4lJxDl/UAjvDN4aA5j8oZE0cuVVUv43Wq8VppepDTgd/zYHtmgekwVfxJsiVLcyD/qB/ZeqP/BBjvIJaHyQQvxCnjgGMzwIcMxSftSsvfdTPpBLp/p/nDxCum98oxc3AcGIfCYH6o7mxnN7XpP/ChL33cQSTQKY5viCjvn4x6lkxK3WN4livWTRA4W4acuyJnHY8eWjsHYYrnwvtiIJ+bFKhEymnc+0kLIw= 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;