From patchwork Fri Jun 28 09:05:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13715777 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 C0DB9C2BBCA for ; Fri, 28 Jun 2024 09:05:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A9096B0099; Fri, 28 Jun 2024 05:05:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 558956B009B; Fri, 28 Jun 2024 05:05:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4207F6B009C; Fri, 28 Jun 2024 05:05:40 -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 21C6E6B0099 for ; Fri, 28 Jun 2024 05:05:40 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C873812112F for ; Fri, 28 Jun 2024 09:05:39 +0000 (UTC) X-FDA: 82279714398.20.0553561 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf16.hostedemail.com (Postfix) with ESMTP id 71E5718001D for ; Fri, 28 Jun 2024 09:05:36 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=C9bjDiZN; spf=pass (imf16.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=1719565518; 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=y+o2QcP3zzShPD5bpWdvqtRKk4SGVf/ncCjWPDHjjaM=; b=ycZuF1eIG4QWbwG6ncQK2IFt/AF+ua13JkEuH6DjFcydaAr+48wqv7sfxkOp3QBGB4+WOo JxNpBVO/dx+N9QLrtqmuMml5EcQynXIkbkjWaaJ7JFbbJJSuk/KRNy16cg+7s9ScQpocHm l1pcT6HqRfVXx0YkCW6fpoab8pO1Inc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719565518; a=rsa-sha256; cv=none; b=CipZfo2zUteOWMjNfkJMxdzxmPyQ6h/vrwt2xEE5IwICBRgu9Sa2U+bcyIidVLh65/7oyo 3oFxPAmrLdpmWqMzZjoIiBvBTsBnY7UEphNHxrG/hfF/uOOfbS1oj79P8bnr8Jrm9ujgvR 8Ogur+vAreoKnamds4vPY+pD3xRcW18= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=C9bjDiZN; spf=pass (imf16.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 Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-72c03d2926eso222898a12.2 for ; Fri, 28 Jun 2024 02:05:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719565535; x=1720170335; 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=y+o2QcP3zzShPD5bpWdvqtRKk4SGVf/ncCjWPDHjjaM=; b=C9bjDiZNc+UigBFT8sob9tA6tWoNlaUVFgWhcV7EB8h9dgSX6T1KwoaFXELipzDQzJ jFs2pJix3JIicxrcQmLU2pKqp1eFZnSxeaJV0iBsYV07nDyaknORcenMSTZt85Pyfeu8 AfMMLqzskYuERX5RZXydvig4FdpHMUEgpR9W4rGAejwS2/w3zLDnf54eYQGu/KMceNbr ksHXHprU7oy2TFmfDYGLIJqexVJww8GCgfJM47cj+0PNbes3S4efGoql9C4R72mmxYXg ZwlJeJxmC0Y0ctkrdLiiDSW4oldDSW84X4HY06l+tXZnwMqQEP0MngZzMkJxNvIB/jts FnBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719565535; x=1720170335; 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=y+o2QcP3zzShPD5bpWdvqtRKk4SGVf/ncCjWPDHjjaM=; b=MJGC25PGU+petoAuYYAPtksw7ZnuD+1jj+QuQbu/0ioO69rd7+ZzA/mHviCJGI0bT5 1aZflC9/2RAuADNMc/wtKTNNEozD+4CU4E4DfGYyZa6+2RJOm41NtjE5f83kYIEuBzA+ jNjf90VByYGrSrr+Y18xRDrXWtc4Z0RA5qyHfDav6LrYxRdQW6IBmqKd1AbVk1uBadaC 7vHi6psQ3EcGSssOQtr3viH2PYo3I2I2tWBgIoxCpYrTHzO8CmMUzKmaUjLrukM2IqrV cDUChFe8DSalt3cEj/y6I0HzZ7fK+WeMKcCgmZsAGleFuZo+dvJEFt0OUQVIjqOHhWiS Opog== X-Forwarded-Encrypted: i=1; AJvYcCV7QKNMKQRaOqupQQKNkNc4X8RmBKUcQzuJBA8ZhEsp73KoaWguel8a0aRp9hFe6n8yahKxFN8Pu8LNLNh5N/3EyyU= X-Gm-Message-State: AOJu0YxJQBj+zSBlocQoz+UQxwRxf05JsjKhmV3D6PfnLs6t2tqvrUfY Bxvf2tEFkSh5st7BvzKbL3g6r4JIZEnknJgQcSqjbUcmUTGxHDi1 X-Google-Smtp-Source: AGHT+IGiL1nE/JPCYxh777n4qtTvEfwnEp1By9NjDz6oRHtLGf4s+XwALk3c6cvWzb1jiZh3cdfwuw== X-Received: by 2002:a05:6a20:c325:b0:1bd:2267:b45e with SMTP id adf61e73a8af0-1bd2267b4edmr8264153637.50.1719565535182; Fri, 28 Jun 2024 02:05:35 -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.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Jun 2024 02:05:34 -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, Paul Moore , Eric Paris Subject: [PATCH v4 02/11] auditsc: Replace memcpy() with __get_task_comm() Date: Fri, 28 Jun 2024 17:05:08 +0800 Message-Id: <20240628090517.17994-2-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 71E5718001D X-Stat-Signature: 9gnaffq9xoq9oqcjjqhjp3ag3aamfi6r X-HE-Tag: 1719565536-167035 X-HE-Meta: U2FsdGVkX1/kz8+xDar7xqgJBkiMXT9NCz55AJAHQD9vJqI69bwhkT4Leswj8Yg8F7s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fChMopUEY+J6If4CGfe7Sm2mkHmf1jot2fEphfi68Eu80JDlZ6S6RK/UTLz2Md+nhhsjo1deyxiieSDYsA03dHuShB8BsbjlHx7Wa8foPt3fq3dx7IArgnKNUiYV/B6SBAXr+EKMPd7JqMOJ0EyKKPz7WbJ2hCxETWVf5enoNiSz5/D5TkPTM3PWZK9YV0inPq8YkgATF2vyK1UsEmcxonoUkopL4tsmv+Wq6not7iVIBE8qHRoMb1Nzka9Y3zcaVe5S98DiLZzTPhrGqXnTVz91IHS9L7V4Tl5mmDm3zkJ0uN70pISX8bYQDMHjd9sjq1f7TrB007fpQB0K04TdubcAKBeL5oBuNtdztfQfcW1gR7GNGVC5xJcrsAGNEXdTp/CGu/1dy6xDIT+nthSvu3Mbg+gtw1lsQ= 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 Acked-by: Paul Moore Cc: Eric Paris --- 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;