From patchwork Thu Jun 13 02:30:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13695898 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 488C3C27C6E for ; Thu, 13 Jun 2024 02:31:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA1AF6B009E; Wed, 12 Jun 2024 22:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D52156B009F; Wed, 12 Jun 2024 22:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF23E6B00A0; Wed, 12 Jun 2024 22:31:22 -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 9C0986B009E for ; Wed, 12 Jun 2024 22:31:22 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2BC6DA3A5D for ; Thu, 13 Jun 2024 02:31:22 +0000 (UTC) X-FDA: 82224288804.28.089AFDA Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf17.hostedemail.com (Postfix) with ESMTP id 55FA14000A for ; Thu, 13 Jun 2024 02:31:19 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iIq6HEcG; spf=pass (imf17.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.175 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=1718245878; 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=j1cpGZH9ekrwOk4ggaybwp6iXeGg5lCIICWIGBwiSB0=; b=VftyL1uO+bA2siohZL5rOPjnSHCX/GTx70K2mJl0g2eu9vSNBMBTkmBT8dgQv/8630T+go XIO2i/SRi4Umu0U3Lcd1GSINtc3L06Y2X0IPUxAboaSsFOhmw6WSA/hhK7l/wGW+7QnnOK d6zzggEZLY7/i//dQnASxL9ap4vbKi8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718245878; a=rsa-sha256; cv=none; b=bV4KCUn3SMRINhGL1lWfILdHlFas1lE7FtdqgrFpxQCgTojrO7HC9jCt3Rhy+2VGIaeGfR NePOTxKhlToGI5diXGqpUJm/wuCVql40yThQPfFRW7hr6eddakuBGr8UgEzoVA8CT4pGaB N2Z3GdIgNIQq41jxEVqDkM7C3ZWUzGc= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iIq6HEcG; spf=pass (imf17.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-7041a7d4beeso460265b3a.2 for ; Wed, 12 Jun 2024 19:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718245878; x=1718850678; 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=j1cpGZH9ekrwOk4ggaybwp6iXeGg5lCIICWIGBwiSB0=; b=iIq6HEcG3BGfrgyhOOZ7yY3x00ICiuGxfdMYnFzBDOUePYqX+Lwe4NnrsyrVJ+DnPH nMnbVAH3PlOYs6phJfe9o1z9GY/mIx4yvedSngu5612UNP9OLmES4wcM/CD+H/udquSc vQOLhnqAOh0MCjIrgkqr6ZlLENpBVKHxyMxAut/8oa/8GQtZWhL0YDeysFo8nlPsmwN0 LxeiJLKhjMGsPTNAZ7UekqFC3P7iLhiRfdBd8P5Ys8tWagru2Iwy19QVoaSzfivoqzQ1 Rapgj+3RTJsiDZ1ij8rSakvxiXWHAIotZD8HF7SjaM53pMYZXmeleZy0NHMs/96H9F34 U28A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718245878; x=1718850678; 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=j1cpGZH9ekrwOk4ggaybwp6iXeGg5lCIICWIGBwiSB0=; b=f79oBAyQRYLfsig05TVhF1U61spO7judJcH19MqEQ7zt63/HGTxdbVYvBGg/ZHprGk USVumy/xW3PE3Gk1MFQc7v5Pi0014voAQ6YKuQMVTi1KeQSMMFRi357S6E9MD49HChx2 2kdMnQYGaNF1NwvN3a0A770KCNbnnIpa1xorn8r65ndjLCnGuodSMhW/SDP2flQGsP5d g7e9nybYiNxBEfOGiLYF/SB84lhFZBcxhbLvxR8mAkLr3qXJPaD6xK1t8ZTn4lke785B XBnQF9mm+epkJzAqy9jX/HV0lZBRPdsF4bxr83ZOqokgaAsPdD2QPYqicHe3k1+3BP9G mnvg== X-Forwarded-Encrypted: i=1; AJvYcCUkuFcyPHSYr6SKxnT86vYSCFiq7pU5tEo+0Z8UgCx8ToWzIrSm6EYuPmISDk1pVqD+XslQAC8nYHX1sbG0p/kx7Wk= X-Gm-Message-State: AOJu0YxfvljcfZO2BEY/WaYBihQZpcDWqNyAWm6Utdml9GDZGzM29Ld3 DRWBVcdTNiDEsQPTh/yoQ9LRH/KkHn2qpM7gVYDiK/H6z7zfKa7u X-Google-Smtp-Source: AGHT+IHxE49dVlqeBIraoeODhxKMszGj4KYKBCDFAoiQKvyi2cHrcHMBy4aCqKmXdfgNqTCtDPqmtg== X-Received: by 2002:a05:6a20:3948:b0:1af:8fa8:3126 with SMTP id adf61e73a8af0-1b8a9b773c5mr4249289637.6.1718245878051; Wed, 12 Jun 2024 19:31:18 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.92]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855f4d159sm1755695ad.289.2024.06.12.19.31.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2024 19:31:17 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, 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 , Paul Moore , Eric Paris Subject: [PATCH v2 02/10] auditsc: Replace memcpy() with __get_task_comm() Date: Thu, 13 Jun 2024 10:30:36 +0800 Message-Id: <20240613023044.45873-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240613023044.45873-1-laoar.shao@gmail.com> References: <20240613023044.45873-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 55FA14000A X-Stat-Signature: 93eoc6auucun1y9946kzbekufbqoz8zh X-HE-Tag: 1718245879-723912 X-HE-Meta: U2FsdGVkX1/P6YCfThKWYOKolbIXYHKU40yTOHWLXo8bx7lPz6+CtlOph+AbKvUrcA2sFqj168q2ItKgguODSjlN1t9FRlFOmNQHRYbOZwc/c+206jJmznFScne7TYBU5j9fuAQlpZio2jx8agQmxjmYDL2YMbrfJW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kgT3NuHy2yNV/tW6BCeCf9Mv0DZLoopv2WVM4zXPyUi0QfEfF9X8h2od70R1jIRdIPPuJvihvy77vfhzdFahC8i6etzQEabGoZduderQpaLHtQZjGe8UZRqdH7S2624CVDC8udcaSxAEBAmOYyHrDshhBYMoPGJI3Juo5tXA+Jsg9ZwLaWZhvai5DwB7qzaD3BbloVY76f/+aivjy8h3IYJJSxwoQdeRzYs79AEFka0auqCeEF1XGxXYZN8t0f6ZGf2IhQlZem5MoJ9AA+iC14eXLZA4hkV2XmdxGm+XbumpfiQ3TO6bcIN0hhwldk4YoMzV7jffe8kE8= 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;