From patchwork Sun Aug 4 07:56:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13752525 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 DCC36C3DA7F for ; Sun, 4 Aug 2024 07:57:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4432A6B0089; Sun, 4 Aug 2024 03:57:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F3616B008A; Sun, 4 Aug 2024 03:57:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294146B008C; Sun, 4 Aug 2024 03:57:23 -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 0BF0E6B0089 for ; Sun, 4 Aug 2024 03:57:23 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 84B43161813 for ; Sun, 4 Aug 2024 07:57:22 +0000 (UTC) X-FDA: 82413807924.23.14F4F06 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf19.hostedemail.com (Postfix) with ESMTP id AA9BA1A0008 for ; Sun, 4 Aug 2024 07:57:20 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EQ+i0aBI; spf=pass (imf19.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.176 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=1722758211; 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=9th/bKhMjvRAjGGVHBeVqs/CIYRU9eynsJIFdR021yc=; b=bD0DuQkC/gV3JXmUYBPo8jiWLY1fTUBRkUKkv6WiunsdSrt1l4q/8bAQw4/2llcMUu/kqb z7PpfGUNb/j2ETplHHoR8aDCAJBIv3bgL+TlbDwmlJV7QrJGOWCphRcW+wExXWXwhc/MbY ZTd8MrcM3RdJabHEJc2akDpVsEImBig= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=EQ+i0aBI; spf=pass (imf19.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.176 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=1722758211; a=rsa-sha256; cv=none; b=nFNdbPaz0ton/em4XP5EYyVLAQJd7fUM5bjq0F3dWdgM/Vcb8U1+1xZ+XG2a3XWH6DbSmx LkVMAQk30jearxKTNJK5cIPMEIvWm/VwOmI5+dMnsTBsAE6OetByi6BCS2FscL0eedqi5u mOyM3abRej68P6Cu0T9Ks+1ingXLUJg= Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1fc5296e214so78016975ad.0 for ; Sun, 04 Aug 2024 00:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722758239; x=1723363039; 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=9th/bKhMjvRAjGGVHBeVqs/CIYRU9eynsJIFdR021yc=; b=EQ+i0aBIpjvGm7kqRzV45IDG2ujpUc9wXUHTyq1SRa07QUFJ8uN6r6+Zi+p9RLQEE4 uma/CIH5FHYCjq+GT26U/93uVBDMdtsBqf8uWCdV97mGBaFQExRHnSe/H62/nPn2WDcM y3YkLWSv+ob1eSBwFGxQTb7TNTX8gHZBke0ejDgefqLP+7KIUZ6oapu7ppBvuvXCW+dp +fqagZHFF/3vVScYmLFmM5/a67oMwT+ruVyLlkqOXCUTaqhondfSa+DlVU/fvyp2GzjS XgQb6qb4vPGcnLbk2EtKlDWp+4/o5tGwXyU2p7/+EurartbEUwQ51tzZ9hH6NrLKhlZQ nB4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722758239; x=1723363039; 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=9th/bKhMjvRAjGGVHBeVqs/CIYRU9eynsJIFdR021yc=; b=CzI0jBWAOh9FZ602Ahyhg2y4DUMX70Gug/CkIkL3PJLaLDfzKAj8X0WJyiR73SUhdS DFZmWaRbeWZDWtOIYh7dd4HeGHlloxglihUHImIA+sFuEEXottqACmXMI02IaojQt+s6 gvKan9MmjfSc3GpAkAtjVCTcQZPqUA/WU2T7D2+4XEeofIaniEGKdkPE1AxyCR33kpey VsCSr5YPT8wp/pUp5TA26B9IGLj83bmVZdNS5Qax1QjoK/Q2NGVwxLfskcYBkadfPfTz bDfPV3CNyvnsZHw1nOWd8bFJsGRu+3PqO7W2AmEtrMMWVGdu460iX9pmQewiMeG9JtXY YhCg== X-Forwarded-Encrypted: i=1; AJvYcCWI4nh7HELAcWQLoHn8Rxpk9ubCFvrXka7MVCrOxQDFyKqAhWkAvh9U5UD8g7D2K9cmgzc8ymtJCkR13QKDHQwveMY= X-Gm-Message-State: AOJu0Yx10D7Ml5pFUfDfvB1i+DvVhmQ1nCsrxPyeiDFiMCETYQ2yAyk2 jzmhGyLmdoNZ5FEMyWYO08RI3yPh1qAsMyhAmRT8L5QUSuxoROgMOdRIq2f+OPo= X-Google-Smtp-Source: AGHT+IFtTPhQAQmKp5sRT0b26x8NVcEvgcuc+FRvXvXgBRo6DjcIq8upCUyDVHbaNG1PlsqP6YWdLQ== X-Received: by 2002:a17:902:cecb:b0:1fc:5ed5:ff56 with SMTP id d9443c01a7336-1ff574a1977mr137301625ad.61.1722758239497; Sun, 04 Aug 2024 00:57:19 -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.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Aug 2024 00:57:19 -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 , Paul Moore , Eric Paris Subject: [PATCH v5 2/9] auditsc: Replace memcpy() with __get_task_comm() Date: Sun, 4 Aug 2024 15:56:12 +0800 Message-Id: <20240804075619.20804-3-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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: AA9BA1A0008 X-Stat-Signature: exfazimso4yoxt9ekbis7wpy94se9z4t X-HE-Tag: 1722758240-76243 X-HE-Meta: U2FsdGVkX1+tYa2lXEjD2jmPa01tHstHyc1cDVRR7iCrtY4Plv44H60ma1lJM0QbR7LrvaxU/uXunUIriuB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piDzr33oqv1X8QcWM/PvZl5eLPRRsPdN7d5Sii/NMzFqZDOSFCSPnan4NnmmAEONbw+xRxbesFYW3UruDhzA74SGrxf9eX9MUjSt3l0ZCSJXQUD94QgwRe7rtDRqoQaPXtibHI/vzW7f3/KXrQCs1KkG69fR6OWX4K9gfXa0I++pLDbNAfy0QVjLVaIX5gS9mV6khij5mdMGxrmJ9NEUMEO4VJXIXX9ooHkI2DIYBBrzNmUor0Y6eNjVnnedzjnQJEZMHQrZSscbybcxjtjT2pfnSUo3jgvVYc72L/ai+Tf/rpQjFh6mU0JwyKOb9ogxSYCxOVXs/fZGutgRzIcWxkPGNefQ3PFhftPGKXeVaCYtyRqCW85d936DyW1GDP6iMOpIF2LrOivHO/ZCI1GrkjTSKzm2I= 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;