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/AbGFB92wN22i1qdasoc5Rlknjovrl36Wu//OVe6Vi88+0yv9MjubAhHPiAj8ETROmxJAmIMK5r+lohXL1SR2mZx1Zb/3+Sh+ZLVZVNOMYPAHUBBNGGqSSAWgQpFX4GSCsGWDo2nZ3kuzvNjv/+Wmb8POYI05l+usaAOs/zBmJxoU52QX2fvL/SntbKYjlayuD0c0dAiX/n7+3Q2r9qgm147T8RO/VLe02JNF4nbZTBF8uYGcstN9nvoGZZE/TK9qnCTRQ4UjPn5WsGiRgKwDX37lyLQ8KCeNxI1iXVwYgINid99Qr2SizFJUd/XWLeOobQIS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+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;