From patchwork Sun Jun 2 02:37:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13682614 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 CD039C25B7E for ; Sun, 2 Jun 2024 02:38:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 659666B009A; Sat, 1 Jun 2024 22:38:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60A4C6B009E; Sat, 1 Jun 2024 22:38:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AA726B00A0; Sat, 1 Jun 2024 22:38:24 -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 290456B009A for ; Sat, 1 Jun 2024 22:38:24 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 79F6A12127F for ; Sun, 2 Jun 2024 02:38:23 +0000 (UTC) X-FDA: 82184389686.26.B622BFB Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf09.hostedemail.com (Postfix) with ESMTP id A0349140005 for ; Sun, 2 Jun 2024 02:38:21 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=asJ0zeyN; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.171 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=1717295901; 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=eDSXYBnkhoFlTFb/2ZctlhGfFi3vGVZVEbq0hz4eBkQ=; b=1sU6l8ojaaxqWoe/l79mGJsCGiSfc64MKRc0eqoipr8GZ1oLtiPTUPlb7zYlY9ZoQObb8f NspqhplLJIA5wUBL4pwhAp52EldaZW++0Gyrb9jAbQymYpuAfo2cAr3XLKW+gocL0dbqJU ZKgeTKK+g3dqJLuRwpvb7vU66Wm8baY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717295901; a=rsa-sha256; cv=none; b=AO5hKTONmt84dRBYjPYtGpyi3IEzRCY4uWD7GSS9iTPkVr2fK34ZPgowe7o0NznpTsUGHC ZcTtERRXiLnqeQmgTeFS0WMKifOAoH8woMEdJDDTK24bRjG8cbRsWQujiYN1anYSBMQUyS b0ElONqV2QsZ9QnJkd/uC7dHh/+bCeU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=asJ0zeyN; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.171 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-652fd0bb5e6so2617741a12.0 for ; Sat, 01 Jun 2024 19:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717295900; x=1717900700; 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=eDSXYBnkhoFlTFb/2ZctlhGfFi3vGVZVEbq0hz4eBkQ=; b=asJ0zeyN+StzyqN9FUXt8zXs6CHUIJPOvep28XcM5LMEVmFP4zM5znmqycIofmcE+d PhxKUlLU3iy66fNvW6ZmnHHFjEUPDxdgSpVsI/2eAQjfyS8OZ6LKjhuXd4i0CCvnbo8D 5ah2DIahH7H+aGJo2/Ir3f2aSSIzBUa0U3/MAbm0k3JfvQ7Q2qZPWvVuHdSmIq7B3628 hSoxX7Hdk19+HUR3foH5uf+hHKMxIe51uhbSkwgwlj/0KKQtNt2UE67DKb4J4qWzMmtW cVfTCpPEid0pbZjrxitahUOWTZTAElE29ceZeHC/DOgP/zEvDkpSwiFWcab8UoCg8NBP s9cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717295900; x=1717900700; 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=eDSXYBnkhoFlTFb/2ZctlhGfFi3vGVZVEbq0hz4eBkQ=; b=ocV4Fwz0Q8U7haRyJI01Yry5r2r0YJQExt4SYESKDLBhVzGecJl+unVRht1ls+/NMy x4OGupAOXKcIWjiubymJw6rRMrjDQGbyL5nRhc5VfHqExqTtDhGrCx+tEmtzScPvfjw6 ypHOE6TCAK6VjTdXt5lUxbOrTaXr2QB6lKo+H/QkNdiWBzomGpurcDSOxiF5mNqeWF+o EEceZ7ikh5KN7EMNTZMESLTHK8dCvMBM+mBI8l2vh/bg+hMi9jgySOL11X9Fi1Qx/tBu vQ4/zLa4QwobQgaM4h4jY9u1LzJZa7Xeze9cMwpgsokLMH6FuoPJNGjwQKdn9VBG45RD dX6A== X-Gm-Message-State: AOJu0YzwpKculPR577iZqEcCCPCgpk7yKWos3wS4O653fG4tSVArHetM Ak0MD/yuDNPnS8q7tEPrLjPHSvn78FLOIJe3/nOaRYj7gpJLoEXU X-Google-Smtp-Source: AGHT+IGSkiCT1T8H8uAL0usG+RhmGH5uSZT9xuU+RtiT09NgmrJQRFy+Yk6pxuNFE1Yrq524r9yvYw== X-Received: by 2002:a17:903:30cd:b0:1f4:7d47:b889 with SMTP id d9443c01a7336-1f6370209femr47779675ad.30.1717295900374; Sat, 01 Jun 2024 19:38:20 -0700 (PDT) Received: from localhost.localdomain ([39.144.45.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323ea21csm39379575ad.202.2024.06.01.19.38.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 19:38:19 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: 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, Yafang Shao , Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Kees Cook Subject: [PATCH 1/6] fs/exec: Drop task_lock() inside __get_task_comm() Date: Sun, 2 Jun 2024 10:37:49 +0800 Message-Id: <20240602023754.25443-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240602023754.25443-1-laoar.shao@gmail.com> References: <20240602023754.25443-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 9kp8u3zw58o73wodmd9zuysprqii7eko X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A0349140005 X-HE-Tag: 1717295901-888413 X-HE-Meta: U2FsdGVkX182rSaUabumdh4rDIj0fiapUpso+xEgmK/BQiUMo813At8ZMWtoydNsuSURKOufaiWfq5L7uiRoxoVNdZehQjE4C8Ol5Hy+F/AFYlzQ7QB7FkL5qPDo9WgDJWezOwNf6FxoHIbTNFkq56DrsQr3D5u8EvMUmLmHlIKcP5I1KerBWukcaX77NwqAz9So6iOhw27A9JIemSlGnc2nA7udileH+0RcLM8XxlYI1/4oTxracGboEuQEGd41U8MmraCsS6Um2jxLcD8AGF/2wJlz6rKkPr34nLB0sixhpGUNorsuSFVNBku1XaV73Lsqrfr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bFh5Y8xPmLby0B54N5NxeWLH+UBbJcLp9eGjI3CHlfUP/Gk1SbkNNTicmyeV6B69BwlUnHtJm5HkQPVnPohRaGWQg2WfHF2hFoqFYwNkCB9KYHKZJisgxI94WEoY5biymlEUSiqq28pKxTU0bWfjIKazTUuUUsiF31+7HOguXhhPJytOTgi5WbG21ID3XitE/CkoPqoGTt8k6sI8aMapxrybaqF06wwke6S/9pCo+Vj1nibh4B+jlkHltWVQolZrAMio7ByIvX5Fz5JdiDTPZ5Lujg1QVWhJvmseGoweIMPVymwsR26YEI8l0S6ns36sjM8BMzLzjJD18s3zKhFTi3OJjjMwwOfgnfNhEN/5lXwbbeaOAk2jj0oFm+UsX4UuHxZ3yy9w+2IIDqvJkYlx9Ee/1YJImHc+i6s+A1YeyWx5JheKaUmv6YriMY4oXCGCjWHeYLLpFvoKm0xCaKQuxKmfwfoYzqA= 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: Quoted from Linus [0]: Since user space can randomly change their names anyway, using locking was always wrong for readers (for writers it probably does make sense to have some lock - although practically speaking nobody cares there either, but at least for a writer some kind of race could have long-term mixed results Suggested-by: Linus Torvalds Link: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npJooP8chLPEfaFV0oNYTTBA@mail.gmail.com [0] Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook --- fs/exec.c | 7 +++++-- include/linux/sched.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index b3c40fbb325f..b43992d35a8a 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1227,12 +1227,15 @@ static int unshare_sighand(struct task_struct *me) return 0; } +/* + * User space can randomly change their names anyway, so locking for readers + * doesn't make sense. For writers, locking is probably necessary, as a race + * condition could lead to long-term mixed results. + */ char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk) { - task_lock(tsk); /* Always NUL terminated and zero-padded */ strscpy_pad(buf, tsk->comm, buf_size); - task_unlock(tsk); return buf; } EXPORT_SYMBOL_GPL(__get_task_comm); diff --git a/include/linux/sched.h b/include/linux/sched.h index c75fd46506df..56a927393a38 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1083,7 +1083,7 @@ struct task_struct { * * - normally initialized setup_new_exec() * - access it with [gs]et_task_comm() - * - lock it with task_lock() + * - lock it with task_lock() for writing */ char comm[TASK_COMM_LEN]; From patchwork Sun Jun 2 02:37:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13682615 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 DB519C25B76 for ; Sun, 2 Jun 2024 02:38:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 570596B00A0; Sat, 1 Jun 2024 22:38:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51ED26B00A1; Sat, 1 Jun 2024 22:38:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 398C36B00A2; Sat, 1 Jun 2024 22:38:31 -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 1B4056B00A0 for ; Sat, 1 Jun 2024 22:38:31 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BE31DC013F for ; Sun, 2 Jun 2024 02:38:30 +0000 (UTC) X-FDA: 82184389980.12.CADD829 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf06.hostedemail.com (Postfix) with ESMTP id 01C86180009 for ; Sun, 2 Jun 2024 02:38:28 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nUTG4UNe; spf=pass (imf06.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.181 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=1717295909; 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=Y4yHgpWtrekLlyiVlHlJ07YnG43AZ2I7wcs9NGubtp0=; b=FQv9RZdZCM+wA4Sip+LECY3fUO8LV8jzp0O9v6ImTpS75An8oZvmzHo/RgsbJtE+NunJl6 S9/Ap8HlGtMjjpPCL6R+vVboqjnSrcpQ7qyh1NNdSUpU7gcyd3E8ONKYegoH5G6ZU5r4c0 cEJQcnvaZ2O6w/YLgL9ml06dSYtfHFg= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nUTG4UNe; spf=pass (imf06.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.181 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=1717295909; a=rsa-sha256; cv=none; b=U+WoUpg/mwKmpZFHxNWUgAJBvgyhhuXKOh1PyWPgn+8ogOqUHlbYkLNO3P4C22lTM0/P/B yxCFBel2pZm9aNTOeWLqpE5kCuodAKBQYIJRtaKUUlQCCLz/5/oJQYPG2QUyZ1viBmwwYR eQVIHvD0pQvGX4mKaATzEhMiBn8QmuA= Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-6c5bcb8e8edso1367937a12.2 for ; Sat, 01 Jun 2024 19:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717295908; x=1717900708; 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=Y4yHgpWtrekLlyiVlHlJ07YnG43AZ2I7wcs9NGubtp0=; b=nUTG4UNe/XHVK7m72zSLwoy4S1mM6h3MjdrkAc6VbONYPBVV/bit3R5iyYZQy4qKgF 6eWIVbZbKlFjjbtrV6dK12g6WGFWY0Xuvpn78tiFs087pthx1zo3a5ArNAX/SnVFZ0CU 0wllABcmk+rHF8StXgqkz49USYatqGzIIBz6YDdjPuc3clHGDEeSohuEmFEW7LW6pWhl PbWQki0m7xp8Yq0w5uIkMrKo9DoCWVtiynsIisnG0D6BRhlanqQ34kHtBgoavrCb7/o4 k4gIeCtrjD+VfWfAsrSR6ZdRUlFsT2TvjRWTzvHN1vwFsvYs0XL0pbCYV5C5BN+5XYPT yaUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717295908; x=1717900708; 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=Y4yHgpWtrekLlyiVlHlJ07YnG43AZ2I7wcs9NGubtp0=; b=JO/m4PUKLO2FuOoyipxkIDbWGQoglR1Lj6n9Wuc9/nbJRcqiy7cFtA3dnEIGG9RC4t 4gfQbb5tluKrNFtP1B0AsdexZaS5OOaDz+qoiieKfxgwM6ySzITyO91bzJcVpGxSK5VQ eFjy5SVItEKsney2KEIg7LixeREqsefXQb2ErnzOcB+IkVflj1UVJUWGa4Pr+T6yCCDY jflXIfs1iEiUJagF7o9j7pxumSVG1ew6oXNjswMBnV0pYVegZq0bYkiB1CIBs8pIPFco xoMb4b3SZSiChX5GVHqydYiqaHIxp3eyIn076camKgoxbLPIbKIoG1ncc6t4WXUP5ZRb wHgg== X-Gm-Message-State: AOJu0Yz8i0Nyf8juUZgnnoir7LON4hqsmpl84PMymqCp9cU/9gnTVWmg TsagV26RT1oFS2ykIXwNrSV5HicO6MWgbFYmVdRBqecS4KNb1trLjUAztPfw X-Google-Smtp-Source: AGHT+IE+a6Agoj8+Gjr8xAx8NUyto1//finy+7nb6g1z3TiLFFz5Bgij41khKDrpJ1UuLaT9z0xZDA== X-Received: by 2002:a17:902:d4cc:b0:1f2:f1bf:cf44 with SMTP id d9443c01a7336-1f636fdebcamr71682625ad.6.1717295907785; Sat, 01 Jun 2024 19:38:27 -0700 (PDT) Received: from localhost.localdomain ([39.144.45.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323ea21csm39379575ad.202.2024.06.01.19.38.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 19:38:27 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: 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, Yafang Shao , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers Subject: [PATCH 2/6] tracing: Replace memcpy() with __get_task_comm() Date: Sun, 2 Jun 2024 10:37:50 +0800 Message-Id: <20240602023754.25443-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240602023754.25443-1-laoar.shao@gmail.com> References: <20240602023754.25443-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 01C86180009 X-Stat-Signature: czxo3dyys7kcyrkde5t534wx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hMyotrcF7w0x85ky6pocgwnmy/UrvkOvDPas+/ndQbjihsoVRJCDbpuVW7larsqtWRNqqmc32pgBwHZv06qzOsOf2ocXNyEq6Wi87x/ImarZWE7IeJSsJVgTwfrXhMlyQAD81oqfDEy+4LZRApfLwgMr3h4UPb0wjNppugCOUyi7ei1/SmH4qn9znNQrwh/rOGoLvAD04xqop8nVaTD3J6ytThDG8n5mb4ZSC6sEZfF+NOFCAOSx5MkC9fJ9BqZP8aoXxHDUo0Ae+PoW+qYWtq1y4L5RumSidVPx3VaWji5uAGN0E9rkiTvbsk4oE4ompCzllGXOSkjszoPSLE86iZMab7i5VPUCuoOAFVft5YHw892O6suKRwOz4OAhkrapKvTdyXpaoK2ET87HLxE96u2HUQdU+rJHM4e2GY9L8MIU/DgWXQ0blncZt59+q58RWvqOQ27PGkx8c03pea45UcNco3F8xJl9HpR9czH8ONw98jrnp3JTEEftEdNFf6q5GxOOPLyr1HKeJ1rhWoYUOYbsReMD9iFoQy+YksrTeEu7Vc6GTD6ckfzVmaQoKfRlIz2jgcafs7LkcL8YhnYQ8Fo2xoqUtGqIBHCWNtRtKBrkf/jhY5Xyjm2lkDZZOkaj5ozUmxzeskcGiLOA8SHYbz70605MV1D3FRA5/GtHFgJNZ/mXiwJzc1K0M/TzaWlKLJJ2nNtQ3y08YNMrkLPt49wnfYzQ= 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: Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Mathieu Desnoyers --- include/linux/tracepoint.h | 4 ++-- include/trace/events/block.h | 10 +++++----- include/trace/events/oom.h | 2 +- include/trace/events/osnoise.h | 2 +- include/trace/events/sched.h | 27 ++++++++++++++------------- include/trace/events/signal.h | 2 +- include/trace/events/task.h | 4 ++-- 7 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 689b6d71590e..6381824d8107 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -519,10 +519,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p) * * * * TP_fast_assign( - * memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); + * __get_task_comm(__entry->next_comm, TASK_COMM_LEN, next); * __entry->prev_pid = prev->pid; * __entry->prev_prio = prev->prio; - * memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); + * __get_task_comm(__entry->prev_comm, TASK_COMM_LEN, prev); * __entry->next_pid = next->pid; * __entry->next_prio = next->prio; * ), diff --git a/include/trace/events/block.h b/include/trace/events/block.h index 0e128ad51460..6f8c5d0014e6 100644 --- a/include/trace/events/block.h +++ b/include/trace/events/block.h @@ -193,7 +193,7 @@ DECLARE_EVENT_CLASS(block_rq, blk_fill_rwbs(__entry->rwbs, rq->cmd_flags); __get_str(cmd)[0] = '\0'; - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, current); ), TP_printk("%d,%d %s %u (%s) %llu + %u [%s]", @@ -328,7 +328,7 @@ DECLARE_EVENT_CLASS(block_bio, __entry->sector = bio->bi_iter.bi_sector; __entry->nr_sector = bio_sectors(bio); blk_fill_rwbs(__entry->rwbs, bio->bi_opf); - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, current); ), TP_printk("%d,%d %s %llu + %u [%s]", @@ -415,7 +415,7 @@ TRACE_EVENT(block_plug, ), TP_fast_assign( - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, current); ), TP_printk("[%s]", __entry->comm) @@ -434,7 +434,7 @@ DECLARE_EVENT_CLASS(block_unplug, TP_fast_assign( __entry->nr_rq = depth; - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, current); ), TP_printk("[%s] %d", __entry->comm, __entry->nr_rq) @@ -485,7 +485,7 @@ TRACE_EVENT(block_split, __entry->sector = bio->bi_iter.bi_sector; __entry->new_sector = new_sector; blk_fill_rwbs(__entry->rwbs, bio->bi_opf); - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, current); ), TP_printk("%d,%d %s %llu / %llu [%s]", diff --git a/include/trace/events/oom.h b/include/trace/events/oom.h index b799f3bcba82..f29be9ebcd4d 100644 --- a/include/trace/events/oom.h +++ b/include/trace/events/oom.h @@ -23,7 +23,7 @@ TRACE_EVENT(oom_score_adj_update, TP_fast_assign( __entry->pid = task->pid; - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, task); __entry->oom_score_adj = task->signal->oom_score_adj; ), diff --git a/include/trace/events/osnoise.h b/include/trace/events/osnoise.h index 82f741ec0f57..50f480655722 100644 --- a/include/trace/events/osnoise.h +++ b/include/trace/events/osnoise.h @@ -20,7 +20,7 @@ TRACE_EVENT(thread_noise, ), TP_fast_assign( - memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, t); __entry->pid = t->pid; __entry->start = start; __entry->duration = duration; diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index 68973f650c26..2a9d7c62c58a 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -9,6 +9,7 @@ #include #include #include +#include /* * Tracepoint for calling kthread_stop, performed to end a kthread: @@ -25,7 +26,7 @@ TRACE_EVENT(sched_kthread_stop, ), TP_fast_assign( - memcpy(__entry->comm, t->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, t); __entry->pid = t->pid; ), @@ -152,7 +153,7 @@ DECLARE_EVENT_CLASS(sched_wakeup_template, ), TP_fast_assign( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, p); __entry->pid = p->pid; __entry->prio = p->prio; /* XXX SCHED_DEADLINE */ __entry->target_cpu = task_cpu(p); @@ -239,11 +240,11 @@ TRACE_EVENT(sched_switch, ), TP_fast_assign( - memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN); + __get_task_comm(__entry->next_comm, TASK_COMM_LEN, next); __entry->prev_pid = prev->pid; __entry->prev_prio = prev->prio; __entry->prev_state = __trace_sched_switch_state(preempt, prev_state, prev); - memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); + __get_task_comm(__entry->prev_comm, TASK_COMM_LEN, prev); __entry->next_pid = next->pid; __entry->next_prio = next->prio; /* XXX SCHED_DEADLINE */ @@ -286,7 +287,7 @@ TRACE_EVENT(sched_migrate_task, ), TP_fast_assign( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, p); __entry->pid = p->pid; __entry->prio = p->prio; /* XXX SCHED_DEADLINE */ __entry->orig_cpu = task_cpu(p); @@ -311,7 +312,7 @@ DECLARE_EVENT_CLASS(sched_process_template, ), TP_fast_assign( - memcpy(__entry->comm, p->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, p); __entry->pid = p->pid; __entry->prio = p->prio; /* XXX SCHED_DEADLINE */ ), @@ -357,7 +358,7 @@ TRACE_EVENT(sched_process_wait, ), TP_fast_assign( - memcpy(__entry->comm, current->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, current); __entry->pid = pid_nr(pid); __entry->prio = current->prio; /* XXX SCHED_DEADLINE */ ), @@ -383,9 +384,9 @@ TRACE_EVENT(sched_process_fork, ), TP_fast_assign( - memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN); + __get_task_comm(__entry->parent_comm, TASK_COMM_LEN, parent); __entry->parent_pid = parent->pid; - memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN); + __get_task_comm(__entry->child_comm, TASK_COMM_LEN, child); __entry->child_pid = child->pid; ), @@ -481,7 +482,7 @@ DECLARE_EVENT_CLASS_SCHEDSTAT(sched_stat_template, ), TP_fast_assign( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, tsk); __entry->pid = tsk->pid; __entry->delay = delay; ), @@ -539,7 +540,7 @@ DECLARE_EVENT_CLASS(sched_stat_runtime, ), TP_fast_assign( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, tsk); __entry->pid = tsk->pid; __entry->runtime = runtime; ), @@ -571,7 +572,7 @@ TRACE_EVENT(sched_pi_setprio, ), TP_fast_assign( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, tsk); __entry->pid = tsk->pid; __entry->oldprio = tsk->prio; __entry->newprio = pi_task ? @@ -596,7 +597,7 @@ TRACE_EVENT(sched_process_hang, ), TP_fast_assign( - memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, tsk); __entry->pid = tsk->pid; ), diff --git a/include/trace/events/signal.h b/include/trace/events/signal.h index 1db7e4b07c01..8f317a265392 100644 --- a/include/trace/events/signal.h +++ b/include/trace/events/signal.h @@ -67,7 +67,7 @@ TRACE_EVENT(signal_generate, TP_fast_assign( __entry->sig = sig; TP_STORE_SIGINFO(__entry, info); - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, task); __entry->pid = task->pid; __entry->group = group; __entry->result = result; diff --git a/include/trace/events/task.h b/include/trace/events/task.h index 47b527464d1a..77c14707460e 100644 --- a/include/trace/events/task.h +++ b/include/trace/events/task.h @@ -21,7 +21,7 @@ TRACE_EVENT(task_newtask, TP_fast_assign( __entry->pid = task->pid; - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, task); __entry->clone_flags = clone_flags; __entry->oom_score_adj = task->signal->oom_score_adj; ), @@ -46,7 +46,7 @@ TRACE_EVENT(task_rename, TP_fast_assign( __entry->pid = task->pid; - memcpy(entry->oldcomm, task->comm, TASK_COMM_LEN); + __get_task_comm(entry->oldcomm, TASK_COMM_LEN, task); strscpy(entry->newcomm, comm, TASK_COMM_LEN); __entry->oom_score_adj = task->signal->oom_score_adj; ), From patchwork Sun Jun 2 02:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13682616 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 719D8C25B7E for ; Sun, 2 Jun 2024 02:38:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 08E096B00A2; Sat, 1 Jun 2024 22:38:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03D2F6B00A3; Sat, 1 Jun 2024 22:38:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E20016B00A4; Sat, 1 Jun 2024 22:38:38 -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 C25176B00A2 for ; Sat, 1 Jun 2024 22:38:38 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7EF7D140FBD for ; Sun, 2 Jun 2024 02:38:38 +0000 (UTC) X-FDA: 82184390316.17.383F7FB Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf26.hostedemail.com (Postfix) with ESMTP id B71C814000A for ; Sun, 2 Jun 2024 02:38:36 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mtDl1kaY; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.180 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=1717295916; 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=86BLVNhH4ic1Ff0npcvsPGdGMp4TM/B2Y17eUoaRoKo=; b=mRtdNoDRAJyrN6l+TuVZwxZt/olr5HXluCwS6YKkW9Rmc/Dh9uc08gXpBSGuRHCsu89RAO ZqYKH1bO3zp+6r3Mx9nPLNbHMvPrmWtfW9BfC8IxE2NEoVjKfKql9qyaQXfuarJlhTTCR0 VKiB2E5hMHdhDswJjbjW5CCYbCnjV00= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717295916; a=rsa-sha256; cv=none; b=suVM5Qz9283Ew0bp4FKH+kltIpzJZqnB1jNzjZ7lBNzpnHfOwAukT+vFij4YYYU4moD7ak YaIZAcRtxAK7Ut5d+gSgov645/LNO+UsU3kaS7ojpKCsb82yL92c4KrAoZwl/OtrwerrpW jXS27ybFaI0dazhpiP9Mrxu2eXuSigY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=mtDl1kaY; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1f62217f806so26792975ad.2 for ; Sat, 01 Jun 2024 19:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717295916; x=1717900716; 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=86BLVNhH4ic1Ff0npcvsPGdGMp4TM/B2Y17eUoaRoKo=; b=mtDl1kaY9GAmjdMfLHGHyOrRjGgX+N4FCTWxibtz1e9PCX3j5+uSx5st1QtttleiJ+ BwgZ69e4RJ5+GK561q+d9IVDA09eKdhC+C+VycXGFrN/a3B1iRXjXEs89OzFEFRFpr/8 MWcVMhE1lQuBjIPng7vaXf88+21p4HNy7mYz+mUYRONAq6f24S5SAgNMpDwM7SpXe3RC JeMU49cy+vgu/+ainIcxj2ghZoYDfnmGO86OTiNxdUafLD1bfEvbLwrcaFQfPzHtX9n1 m3UO6cmw7tqH+B3LBbaHe+yptERa93piASZUB+wTS2J6d11NUL742BnQAVmCiK6ICWxl 2DSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717295916; x=1717900716; 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=86BLVNhH4ic1Ff0npcvsPGdGMp4TM/B2Y17eUoaRoKo=; b=gdkb878EpzTJvHfS9984PJbgdEqE1Oi561990ih8rNV2dP9j4qdGT9BT9bd04/MhRD 0X+ZfMPObGeYscbpY5val7e7+qRCDKWi/UU5D4hqEiFDewmb6bDL3QIyxv6WqynRKHsA qEgXmE5PAedPw6/7zjCh5tmkPKFKSq5UuX+6MX0qDfjLmt6LFKI2lbtWsL+UAFE0hhSM YXrUtTaixWd9FzfHPVJyldqPxJpAWzI47mzid8bUl4ai7+6xItuNcIh0ERfh3g/xNFip FOHilVJwPZwVCk/LXaGf952Rn3F5sXTTVxji0ksHTM4TWXrkdhks+Xdk/442EJyLMv2W ZJtQ== X-Gm-Message-State: AOJu0YwvZILrYym2ThJFuDxO0pPluwKYaPcxLNsI/mIEgNr8idwkn2mu 3wkKopmJI43dCUaz92LqxWZqLvbaEmOna4ZagnXPLtWQMTXFydRY X-Google-Smtp-Source: AGHT+IGNFv/boPhAUu2B0W3t33lg4GlGND9qco4AaBPr3IkdnpkGlhsaTOMWXxep7jl0e5AswLTzAA== X-Received: by 2002:a17:902:c946:b0:1f6:6946:ef72 with SMTP id d9443c01a7336-1f66946f176mr13505155ad.36.1717295915514; Sat, 01 Jun 2024 19:38:35 -0700 (PDT) Received: from localhost.localdomain ([39.144.45.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323ea21csm39379575ad.202.2024.06.01.19.38.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 19:38:35 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: 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, Yafang Shao , Paul Moore , Eric Paris Subject: [PATCH 3/6] auditsc: Replace memcpy() with __get_task_comm() Date: Sun, 2 Jun 2024 10:37:51 +0800 Message-Id: <20240602023754.25443-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240602023754.25443-1-laoar.shao@gmail.com> References: <20240602023754.25443-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: ky7oogkw1oa8znrwfqme6rffedsqssna X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B71C814000A X-HE-Tag: 1717295916-869077 X-HE-Meta: U2FsdGVkX19cqlbneZAOE7Zm61E4hxVlp+VZoM/AbGFB92wN22i1qdaso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ClpHHaD1WixKDNxe5aMhjj1L8OtjVKKv8T0/dqw/sdLuBO6aOG+CKKu0cFGFSHb3QOYcWyruFIi+iE64truSPmNMX0RYi7kNDk57JM8rjPT71ugCiDAxmykFo4k65k9bPB2WEg0npGTFzyyErZt5mCd5GPms32YbJ0dit2hjOD4sgiGu5giGTUxMHl18pPq/Yg8Vs4mz9ePmqkZoW1TAOTABTlABzpxVfbe/rM6YiU5uk2ewPY1X7g4fQid8PapvZrTCLUtoE9EyM7Oq6gL9lSHCpYWMLW/HuCmPoHxdrZlgCTAoAFwFJly+UmpZ/2RFl5JjbJLZb7JY/P3OMUzz9p8MkxhDx1XOyAR/XEMSNYLzvAF3v/JqxujHZtcMokmbdC7n1O1GfJPL8TQxWo5JExXHAbs588wKRnVvbCELOvPr3KGGAB3T+9wMpOjv4ssZ1073eLC/+T7LREJRssV08TEmEgzmulAiZUFlhHMgpuVfoeawjMOf1LfrZXt4vK4FM+0FhZNRtF7zOUFGDiVU3RvbLjxipN65jEiqs= 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: Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: Paul Moore Cc: Eric Paris Acked-by: Paul Moore --- kernel/auditsc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 6f0d6fb6523f..0459a141dc86 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c @@ -2730,7 +2730,7 @@ void __audit_ptrace(struct task_struct *t) context->target_uid = task_uid(t); context->target_sessionid = audit_get_sessionid(t); security_task_getsecid_obj(t, &context->target_sid); - memcpy(context->target_comm, t->comm, TASK_COMM_LEN); + __get_task_comm(context->target_comm, TASK_COMM_LEN, t); } /** @@ -2757,7 +2757,7 @@ int audit_signal_info_syscall(struct task_struct *t) ctx->target_uid = t_uid; ctx->target_sessionid = audit_get_sessionid(t); security_task_getsecid_obj(t, &ctx->target_sid); - memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN); + __get_task_comm(ctx->target_comm, TASK_COMM_LEN, t); return 0; } @@ -2778,7 +2778,7 @@ int audit_signal_info_syscall(struct task_struct *t) axp->target_uid[axp->pid_count] = t_uid; axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t); security_task_getsecid_obj(t, &axp->target_sid[axp->pid_count]); - memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN); + __get_task_comm(axp->target_comm[axp->pid_count], TASK_COMM_LEN, t); axp->pid_count++; return 0; From patchwork Sun Jun 2 02:37:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13682617 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 C7F4EC25B76 for ; Sun, 2 Jun 2024 02:38:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 597E56B00A4; Sat, 1 Jun 2024 22:38:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5469B6B00A5; Sat, 1 Jun 2024 22:38:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E7346B00A6; Sat, 1 Jun 2024 22:38:49 -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 201306B00A4 for ; Sat, 1 Jun 2024 22:38:49 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id C7C68C012E for ; Sun, 2 Jun 2024 02:38:48 +0000 (UTC) X-FDA: 82184390736.12.65D4ED7 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf21.hostedemail.com (Postfix) with ESMTP id 106441C0005 for ; Sun, 2 Jun 2024 02:38:45 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BibTK9He; spf=pass (imf21.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 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=1717295926; a=rsa-sha256; cv=none; b=Iv1ljKd40kfOZTYF3zapfXF6Eh8yZfV9hLDjtq6jlr3Z5dsdMbYoR7u2MYo/iwrpvZZ8h1 hHXNg/LYuTNdp1cjV1eBiBoVf783z6NG3CaLLHROW+oTldVgO6cSze3Z4Lqjwol+/R/1M5 G0DuTmEnOKEFPX9oVHCl8kqiduF8JqA= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=BibTK9He; spf=pass (imf21.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 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=1717295926; 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=ZwXgac49vNiqQKiAaPBrbZsSURsGJANu7JDjc/AUCv8=; b=DrdI8kLWcMZwXnHIci+r6MYKG35gfoAyRs+aAEGNvufyBX0cWc902wa16ldECemoArC1Pb o7VZpI+7qb9cWxYIX0hiVnKuI30jHw+mxtKgOvjDCPozz0pUQqChcJXwRTSSs7nWY4l1n5 WGbv9MONaZ0FkmZvDwWHp9x1Wb7AnEM= Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-6cb6b9ada16so133133a12.0 for ; Sat, 01 Jun 2024 19:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717295925; x=1717900725; 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=ZwXgac49vNiqQKiAaPBrbZsSURsGJANu7JDjc/AUCv8=; b=BibTK9HenXwCbgoCm/9wea3Gv0uQapbgZLxRliE0KHgb5R5kltuE0d27CkINKqs5fR 4DvMILu1lxYqZqINaqnJ5FhWEKazAsm9rlgrpIr+GIBNeIzWO+VXm6Ek/8PasuNGuT2F zRCnGnaBzfG17htbUGrkT3ZxsvxoS8ZWq4oaB+X2NrDIGLD5XH4Pc2Ev1aut88wxeUVe GbcdODe7KHQ/1udgJP85R7Ndnt7P7+wUAe65O9dNN2gafTh5NgbVrEHZhYu/tRx1HRd4 DKN3MyBDT0bYmQcjrnHE5DOkg4E8DWQP0ePoPoxZVE3d8+mAHrgPsnSc3Yxpqt4HvrUI lA7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717295925; x=1717900725; 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=ZwXgac49vNiqQKiAaPBrbZsSURsGJANu7JDjc/AUCv8=; b=u5Hr6GAWISz1R9c9Tv994tjVg7L9R3ltm/wlZzcbxEUqkbfe0vU3gUbBNgqHAA2bQc cbQuos2M6MhwFrqsOvbSbfmxJM4QPr2JLxi/oe5usvHWMX+4j50EuD97X0mtUIenqC2o 0tTAHrKgYG37jyfC80Ewre1Bc3eQa6sSIRf/XOQKAkuW5hnYogOpx7pRlMMA4LBrpmt8 LoDbGyOdU3L1ympEzHxE68Xz+K5co9+pBv08bvd+LnDCIIgIntunYHNedbJd++EkbMV0 WDymNZbxxsqIBkA4autzjPXsiqDTwXkEGhyElaB8AHxxa0uofhrqRJrqTyE9dEnOUIE7 qssA== X-Gm-Message-State: AOJu0Yz1FrTpyBFoJ0OMdMMQ3kq3Pmmz59lWJatBEhJYrNCmjmJ9GlJs J+3wKfpI5Bk6r8rtt9Mv6bqZYcfwVwiusmfC8WkSJ+7zih16rN9Q X-Google-Smtp-Source: AGHT+IGxdz166Qj5hr7gPenbJxzI2r9mPKQqOG9IRmdP4Ad2EqUcAIvbF35C52RxuyHIZjzO8B2P0g== X-Received: by 2002:a17:902:7842:b0:1e6:7700:1698 with SMTP id d9443c01a7336-1f63706bba8mr56224725ad.35.1717295924813; Sat, 01 Jun 2024 19:38:44 -0700 (PDT) Received: from localhost.localdomain ([39.144.45.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323ea21csm39379575ad.202.2024.06.01.19.38.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 19:38:44 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: 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, Yafang Shao , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Ondrej Mosnacek Subject: [PATCH 4/6] security: Replace memcpy() with __get_task_comm() Date: Sun, 2 Jun 2024 10:37:52 +0800 Message-Id: <20240602023754.25443-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240602023754.25443-1-laoar.shao@gmail.com> References: <20240602023754.25443-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 106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BeniXxJr WeIwaQ4r Hi6SB8XeYqm24MungtMRJftgVzPRsdvKnqDOtM+Q1FA41qL3AoEAalERt4d5Ax2QSNP0/YxLHsKo7X8F/aXMG7PPS6DZLmC1pLZ2rjFbcKOStbzIhAsryTphWR5SaaFJKhGSgSBtwl6vS/Eeh6y0GLbqOARzw3My4v3GHXncX7QW5egQkq52iQsR8XrMcxKbeXr40LK9Wzl7LEaonTUvoufS1fhCDoVtvi9bJ8YGyZCSP+odrJYCaF/7rGZpqFp1f/K6OQXwaZnHL9m1bxhugt7BEAplPxqcGqgIVGDHthY57dNV2LR6uGF/EmCOjt7cEkqJwxR0Priuyttl7MRrGTTXXg+bsgr/8Z1fgw/BsUHaBBtH2HAGMyrwipaOys+1Jls+eGa/v5oaPbqhNlC7iNRFoZCuJ73HTC2UClUh/AviH7KuD8x1UTM7/8N9THs5T10xOZlDDZE00Xamvf4IZPjw+ZaGlF19W25wjA3XZL3PqqN8e2daMdcm2yUMdJxtvocvs/26ukWRbfzyNWme6HySDolFztB7dALKhkfoDcLnFvbAKTB+uf4Tv/EVJlqHDrbMCCNasspL2lMvSG+PNLZoPrHb/O1oLIE5lem/1uha+G4vYN41wU2s6W54QzKQsSf3+S2NBFm4wTKOyZkK2SyIaB3YT8etOmeRycCr96UgYEE7XgI6vP4nTbRNItsOHqko6KelNTsimFT0JRuFZrZD4XTB7l9EO6cxuMQRi4mIGoYJLFKz4jKD+AXONx2xan9j/6aBvarMLUYgqPM3pyJ+Za7aqb0Dr9zsJ7tSPIX197lXPzvEcoNIvT6YfDOHJgAzUursMbTUkSaZ7tUM0qxZSzv+lpja9Ql5E 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: Quoted from Linus [0]: selinux never wanted a lock, and never wanted any kind of *consistent* result, it just wanted a *stable* result. Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npJooP8chLPEfaFV0oNYTTBA@mail.gmail.com/ [0] Cc: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek Acked-by: Paul Moore --- security/lsm_audit.c | 4 ++-- security/selinux/selinuxfs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/security/lsm_audit.c b/security/lsm_audit.c index 849e832719e2..a922e4339dd5 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c @@ -207,7 +207,7 @@ static void dump_common_audit_data(struct audit_buffer *ab, BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current)); - audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm))); + audit_log_untrustedstring(ab, __get_task_comm(comm, sizeof(comm), current)); switch (a->type) { case LSM_AUDIT_DATA_NONE: @@ -302,7 +302,7 @@ static void dump_common_audit_data(struct audit_buffer *ab, char comm[sizeof(tsk->comm)]; audit_log_format(ab, " opid=%d ocomm=", pid); audit_log_untrustedstring(ab, - memcpy(comm, tsk->comm, sizeof(comm))); + __get_task_comm(comm, sizeof(comm), tsk)); } } break; diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index e172f182b65c..a8a2ec742576 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -708,7 +708,7 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf, if (new_value) { char comm[sizeof(current->comm)]; - memcpy(comm, current->comm, sizeof(comm)); + __get_task_comm(comm, sizeof(comm), current); pr_err("SELinux: %s (%d) set checkreqprot to 1. This is no longer supported.\n", comm, current->pid); } From patchwork Sun Jun 2 02:37:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13682618 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 EA1FAC25B76 for ; Sun, 2 Jun 2024 02:38:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 807986B00A6; Sat, 1 Jun 2024 22:38:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B7DE6B00A8; Sat, 1 Jun 2024 22:38:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 659896B00A9; Sat, 1 Jun 2024 22:38:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 43EE36B00A6 for ; Sat, 1 Jun 2024 22:38:58 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BB3481C19E1 for ; Sun, 2 Jun 2024 02:38:57 +0000 (UTC) X-FDA: 82184391114.11.1B76507 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf19.hostedemail.com (Postfix) with ESMTP id 064BD1A0005 for ; Sun, 2 Jun 2024 02:38:55 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PQl1so0H; spf=pass (imf19.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.181 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=1717295936; a=rsa-sha256; cv=none; b=23nuL/aYY2dQJDaolapGNMRvXwzuDzAbwmTdDcP0sL05GH+Mj2zjn+Aq58LZv2j+E84WPp QXSQmCcURSbHRJjuyGqzkhhPq6arEGvhPwNXSqk8GSK46hMMo3PoRoaUnYZCvlazn+2djy uj41xkQ/FlixHkniwCXdmXd5P8U0Hpg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PQl1so0H; spf=pass (imf19.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.181 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=1717295936; 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=3TpGu6Oq1vjxccb8W6xWjhiTwznYEKWGAfAIwahkDiA=; b=rXVQ56Hbi8Wr/WctzO0ZqGB3IfbaBzQFU2YRhpCHR26eaFqMHr4JagMwaInvbnYjM6WFdb Z8YbdxRSoU1QerEUT4dmSFwINkAbhWYAWNnBRmue5OeQqqfka1bDzPcX0qvAodwSEtnKH+ K+KqANR60o5tpm+WgfpTNBnBihjY/fI= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f4a0050b9aso18410685ad.2 for ; Sat, 01 Jun 2024 19:38:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717295935; x=1717900735; 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=3TpGu6Oq1vjxccb8W6xWjhiTwznYEKWGAfAIwahkDiA=; b=PQl1so0HvQ3sIPklSNvs/I+e91GgYimbA9KM3u9rD1kKNQvSvSgSDsd61UW8avxuaz cB8as9J0x7t0WlQ+1PquNgY3toXKSIAUy+6Vmr9uEc6YVcPOTK9VgKtbEmCJ2cTCGdJg R6RobZ0BDS+TqeHH+j7TYaN9V6o05PtFoA31tzuKWgvLM8WpCJDpOJ7uviOUvkCNM366 DihpXZ4Q/H85/ByBGorPVCfMmIA9IkqF+9NRskP7Z1VuKNTeKGTaCzRRQ1MtG6NUFEUR EAiBAkVZevnqiaNGRyaEJ0TVzHB9TjyB2OXiyKwgkQzPgOOzjatSbV5gQh5kcRlmZTmx jJwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717295935; x=1717900735; 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=3TpGu6Oq1vjxccb8W6xWjhiTwznYEKWGAfAIwahkDiA=; b=emqBKrBiX776DVBKfGZOp20/Pw6ik3n4Z64BfN3mA4RLUatPve8TkBYnRSsoJIOQsp K+85Qkv85BIixOrKdYFCWApt97i+vJasdrxHsIgOn8zi6hTkcOBFQh8Y9Id6PujK9wtJ 8U+r0QBNiQwz9BAsMcHNowwYtfoe53jDTt6OEcyY1NMrI0+DwykEdwawE0iRTYHUsQRe f5hMU+RssxMQoLZNQYsmbsiGPsSMWxsQx8LSKN1cy1yxWqPgtyxEblcLchqUcAqyBiMu ZzvrqW8QGWDd3n9aQcw9HnI4Le7+xMFKAUOJgD0BTfHcOcK2KdaxcYfvZm7OjKOsr/8t CKaA== X-Gm-Message-State: AOJu0YzF5GmtsMnfIlMTmMz2caRmsJNGAddXLIWN4d0Rt36xI+sC9l6/ dA58bQSlx9Y/5d8ob7FHl9qzJ+jclcu+itaamuxGUZQLrch0cN2R X-Google-Smtp-Source: AGHT+IGxvOn5+cLL6IQR7JJZSFxqN/pAIswbvkNRxUdWw/EDTeYezEeBw1uxYC432gXEUnzhdS2+uQ== X-Received: by 2002:a17:902:a38d:b0:1f3:903:5c9a with SMTP id d9443c01a7336-1f6370aa056mr64384745ad.58.1717295934923; Sat, 01 Jun 2024 19:38:54 -0700 (PDT) Received: from localhost.localdomain ([39.144.45.187]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323ea21csm39379575ad.202.2024.06.01.19.38.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 19:38:54 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: 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, Yafang Shao , Quentin Monnet Subject: [PATCH 5/6] bpftool: Make task comm always be NUL-terminated Date: Sun, 2 Jun 2024 10:37:53 +0800 Message-Id: <20240602023754.25443-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240602023754.25443-1-laoar.shao@gmail.com> References: <20240602023754.25443-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 064BD1A0005 X-Stat-Signature: q9r3jju79qjj499ouxsixg8mdgsscgp8 X-HE-Tag: 1717295935-651036 X-HE-Meta: U2FsdGVkX19kRocgkZBuFubL0rUo8/B6qFQ7JNhfE4ReAUyaQ35s/6NRufRhh0vXdV5VVKhH8W9pAirPqKrGnd0ocjgGn8LNj4cmxajcj1LGiTV9Xgh9gpAK9XWVyuRJHseXvPUGOIONyZF5c8kq7jBVVifsbZ285IKQLNRj4GCLEjmfREJiWf7EZLEkFj4GUCOYYHXiLLjSljjnwI8Xv3IH/Vbg+2KoSCVZsvBfqbSFMjn28Sjg5rcrD4gW2pyxY+KxKjezaA1lCgeTZ2+D5CJFCzIseAzAhHUwI+B8+bAePO3fEaBKL2ztK6BFK/GGnG6RhiVObLw6VTBPJz9og4ZPMeL+JLrfvGzEIE9vPyLpFAPke+36Aoy6OTV4dGkPDf1aHLYm1cm5Y4lmT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O9+6GD0yc6dybrC2+/DnYqIB99FeaZrm/DNtaX3GDZ57RROKgr7oB3vXgFpL3VcBMlYvDRNRgSgPQE6MSV0XpEA0Nj872LXkf2JQfq4SuKomVwoKD7bE4NXIEi4h X-Bogosity: Ham, tests=bogofilter, spamicity=0.000012, 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 Cc: Quentin Monnet 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; From patchwork Sun Jun 2 02:46:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13682645 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 BAA25C25B76 for ; Sun, 2 Jun 2024 02:47:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B06A6B00AB; Sat, 1 Jun 2024 22:47:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45FED6B00AC; Sat, 1 Jun 2024 22:47:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3280A6B00AD; Sat, 1 Jun 2024 22:47:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 127CE6B00AB for ; Sat, 1 Jun 2024 22:47:20 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 90D051A01F8 for ; Sun, 2 Jun 2024 02:47:19 +0000 (UTC) X-FDA: 82184412198.22.DAE7D07 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by imf16.hostedemail.com (Postfix) with ESMTP id D4E43180002 for ; Sun, 2 Jun 2024 02:47:17 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Xsc6F5no; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.42 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=1717296437; 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=bu3o/1wkpiEjxw3AW0N2UpaOJE3SQdUz6rVg/pLPlFs=; b=eRnWsOvVGV6l+yErTC7kwtsIdvCacBKQ0gUIx8HtO4+E645hsHt4bdtDc8KXbPWVQDtODO vdK3UEjig8XJeClZsERCnF2j1SmCRyQ+VKOy8MUpH+mjBNBJ4PLLjidn6fTQW2Y8w7W11W 3EPOAcdsLzEj0yeGsIeyWrmZrEQe3KA= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Xsc6F5no; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.42 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=1717296437; a=rsa-sha256; cv=none; b=ts0/aTqxkjqdFGUVjW1Cx2fYh/7Jw5yNzsOUueKvuTghmvcM+kKoeADlXmvBPAjSMfCkge X1aAROGBDVOP+0CFj8Noo/2VBKJZSArLin7cmLqe8zZ6fGxblQNKI2/tBmG/SthQfiRzpc bfFNujZo/dKO7rDLnygc/jn7A5NNDSU= Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-6f120ae1ca3so1844343a34.1 for ; Sat, 01 Jun 2024 19:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717296437; x=1717901237; 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=bu3o/1wkpiEjxw3AW0N2UpaOJE3SQdUz6rVg/pLPlFs=; b=Xsc6F5noDLDkZlg2ArthrlPQR9Oel+AzA+y88i/HRU0gDhx98rDO1w/amrnL63O6vk rQUeeiWznwv7BsKhiu59GYhCl1KWtgP3F2fHMthfQ2lH15kU1D+aMocKc0kEatlb+0gG B+03EwAjxii3oTza95ZnKTLhYTCrGgLMDd6X/jhqa4nSsG8F7HBunMcd8TFU4icnlNqS si5ugs9o5I+g+na9+j4XzCXvmn0wK+kfWEVu/xkI/ffbBMFOBI257YzDTbtyCoA2K1Mx Br7iKRS9UtO5DFVUmVzfLrkJlutPoywZY5k6dEdqSSMhbNJS+Hphv/AIxmlbxK/elEYl 4DKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717296437; x=1717901237; 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=bu3o/1wkpiEjxw3AW0N2UpaOJE3SQdUz6rVg/pLPlFs=; b=W8VQQaepiOp3GpAGCUOaHDaOLo0qoW5LeRt1cRN/FgU2R3rJNFRXxuPzjqtRsbrEsp YzclIii5IghRpzDpHebhsmAzgseIa31tYu+TU5WgiyzxJs1LBW1bw7x/+itxY0M14/H6 hZ6gzehn7eMW42pYqmcCNmlCF8XnSaZWCd4ssIBBBHjE5xhwqBC4CWDZvVTZpWXjWd8R IFb2NRWZOP+3PhkY6OcEf1Rx67IqJT+O/daVn7d+TKzCn3eXLkkUcLqtiEJOQIUS6GGh KfocA4XQaPc9T9UMT57y9M0sKcMlNT0nPpUXU4tb9TcuxzCcIRF/iKXrBMW8aMsigEVL elPg== X-Gm-Message-State: AOJu0YzrmezTW6QbgwBpYhMMzyxcqJZqSXLyaSL+fWW3xyQRh01FjAGy x8SaGq9+7AfrYBCEX4AEz34Ell+//gV4Mw18rgVPhv7Eb5+J6pk0 X-Google-Smtp-Source: AGHT+IFc6pB9c2/xDQu9bENUVRyBXhBelq6v1sdhKRdECc7iHQz2zEq+tFq0IQc1xoKSQZnnKrMN/w== X-Received: by 2002:a9d:6c07:0:b0:6f9:91c:f275 with SMTP id 46e09a7af769-6f911fba0c7mr5694846a34.38.1717296436688; Sat, 01 Jun 2024 19:47:16 -0700 (PDT) Received: from localhost.localdomain ([39.144.45.187]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6c353f0aef3sm3289959a12.10.2024.06.01.19.47.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Jun 2024 19:47:16 -0700 (PDT) From: Yafang Shao To: laoar.shao@gmail.com, torvalds@linux-foundation.org Cc: 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, Andrii Nakryiko , Eduard Zingerman , Mykola Lysenko Subject: [PATCH 6/6] selftests/bpf: Replace memcpy() with __get_task_comm() Date: Sun, 2 Jun 2024 10:46:58 +0800 Message-Id: <20240602024658.25922-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240602023754.25443-1-laoar.shao@gmail.com> References: <20240602023754.25443-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D4E43180002 X-Stat-Signature: cf5eb1rtfmea4qh9s5xs3sa46rmbb665 X-Rspam-User: X-HE-Tag: 1717296437-20961 X-HE-Meta: U2FsdGVkX1+fcjZmVOA9I5tCqE7PZzR0vWSuhGj+vWBQa4c728vK7cL6neGJYLrEpVo6aecKq9m3d5MDPx0Ua8IeAUzrWOL0hg6fx8uXmivgS+crnQZ62C68wBjOC0Sd7snXyU7o5S1SUrpJD3V8Zeg5e5v1HMb/HuQqiLdd0UGEzsrNzuzn8j/4//42BZVfSpPAL9ltQO7VN9aGDEifga89LDJjSR2mLN84c28fF9Ia9DjNjpStAiOCSJqQg4Fec6ozh5ekJCQy5fGkI+pcUf9CiOlmSsySuM9ahUlnRlK4CTeFdsuUueUM55Tg5tCJklz0yvhLvQAOmfmuTFK13AKSD1z33zv50N6nIRmFDYbCIGZI2z+7yl3H4PqkabEzjFl4zAp2xxHpbWFo4Uj/ykAnYKAmHtkpZG7Q4TqZ6KXrGa0aPT/gLLqbHk9BQgwSVP6db6QWxvlWeKdwqsyPEJXLMF3p3a/5NAEkzBA593kmTGAaGvLaqfbekzBJZvmwbVVbc5Ibt+Vt2yNHKJo8gNzVa2z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OUnf8emNavV4VyKXBONSXveiWvCr6/QrNp92bt3JwQsISV/Ie0pzzKb9Uv3Rxs6oSIVxGYDA3fdT2cSSY9V5qj1cN8gQha/BevcKAKo= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000116, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Using __get_task_comm() to read the task comm ensures that the name is always NUL-terminated, regardless of the source string. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: Andrii Nakryiko Cc: Eduard Zingerman Cc: Mykola Lysenko --- tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h index 11ee801e75e7..e5df95b56c53 100644 --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod-events.h @@ -20,7 +20,7 @@ TRACE_EVENT(bpf_testmod_test_read, ), TP_fast_assign( __entry->pid = task->pid; - memcpy(__entry->comm, task->comm, TASK_COMM_LEN); + __get_task_comm(__entry->comm, TASK_COMM_LEN, task); __entry->off = ctx->off; __entry->len = ctx->len; ),