From patchwork Mon Jul 29 02:37:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744221 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 562E8C3DA49 for ; Mon, 29 Jul 2024 02:39:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A57826B009D; Sun, 28 Jul 2024 22:39:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A07AF6B009E; Sun, 28 Jul 2024 22:39:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CF276B009F; Sun, 28 Jul 2024 22:39:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6F8FC6B009D for ; Sun, 28 Jul 2024 22:39:04 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2F795801CE for ; Mon, 29 Jul 2024 02:39:04 +0000 (UTC) X-FDA: 82391233008.10.34FBB5F Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 6226820011 for ; Mon, 29 Jul 2024 02:39:01 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dgFfpeV2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722220738; a=rsa-sha256; cv=none; b=km+1k/C1xrhnQktsH9WJ6gS6z9HuX4Qqj98I9Xjge9Jc60Ac5wbiTy7qfmUjuNttgStHH5 L5f7GfE+FaBGuSvxLax/7zrbyWQ5SO8ayA2NsBAgDDSWdM4M8ZjS10gr6WFws7W7nYnlUX xLsqBeRzQKreMVMOlJiza5GQVWFq/gI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dgFfpeV2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722220738; 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=663gqRp6aMafRWC8Lfx6hrcdw0wDv7kE5ODsbFut0pGMPV8Ky64zDLrC80hftfitnRdnWZ WVm85wS9oXjdTlMCKZRfuQ0pl2KzpH+1vm7uQZrvO5ekA1OhFPYgsNMc3jnYVADM6tVlRr riWu7P6/xsiIB5DlsLKnCiiYRoAl9/8= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fc47abc040so13094485ad.0 for ; Sun, 28 Jul 2024 19:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220740; x=1722825540; 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=dgFfpeV2utPAuhnZjmEmayqcFe+xGyWOGQIJPBNiKfKw1XJIG6/fsyT1nOAXPjdprP Pq6e5rdpknwTDRtHIQ6K5SRIq6y5GLLpX/Ok5us27/iuntenpACJ8gvvQzKwtWQyXbUJ 9k/YZsWr6kk7iLc8vgIGWvV2FrfhsEL90IEzYEXvgE7bU4ZqJdNs3pd4OsqK12U5Ghv7 uwSI63hpwDLwpWgSVxXM7YSkE7q2IiDJIfSZbtghlX2trv0YHRH/1twqu35/faODwwLP 1GAxKTnOXdmVuFHhKC/Qd7aZBrv9R6i6reBtDZFhlcg45yW3DnW7xh5K9zm8IxZQ84S0 W73Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220740; x=1722825540; 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=LzCOU2e2gjUq6soSMOECPE12iLjI+nuw69T8IT1jtZDxGm9xDIgWlq7HFP3gtGrx8K uacPkTyRjNr+I+xEnxIFG7tvrzWq78Ex6Mj11rso9TVEFTU1liQZdw1F6oANUew/3DYe 5YcsRCePa+aKgcGMhP06N0U5YzHTmctxqqP4VZ3ZjaLIPKHiOKzJU3YDa8o5WeZOkQb9 pvF+DRoAQl10r9xLPFShwipjluaEuC4W5iyS949Uv9Hoa73Wip6UGXkOUhMWSJoqSTdL tT9K5aUACvHOjVfUnXT7cEJPvfTjr8BVm+RY5nTtbrvPRCTgRiA0xlI3YWLJxr7pH/gw /A6g== X-Forwarded-Encrypted: i=1; AJvYcCVfcDMVdu7nufP0HDZAeqFpG8bo+k94wSHan6bJ8rEUh7wQ3mCkEkhP26e4cRArrFgId1EM+FDx36KMt8obZvWUivI= X-Gm-Message-State: AOJu0Yyfd8O6D4rim4kRQ8bLytsvil+I4aZdxzvJODn9r7m2/DkdY1na dd6tTs+qvFdUr5t9nn0f5FPCeix5M4prL0OF6nMPz4ZCzw0UKHJU X-Google-Smtp-Source: AGHT+IGBArXuQ6UfIKXak7ZIiMIQBzEmqSTo4bq3Ao5W++iZVvXLvRGW5ku9X9sKf2s7GMsSLwtHOA== X-Received: by 2002:a17:90b:1649:b0:2c9:6f91:fc43 with SMTP id 98e67ed59e1d1-2cf7e1a3e76mr4224751a91.3.1722220739919; Sun, 28 Jul 2024 19:38:59 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.38.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:38:59 -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 v4 02/11] auditsc: Replace memcpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:10 +0800 Message-Id: <20240729023719.1933-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6226820011 X-Rspamd-Server: rspam01 X-Stat-Signature: rnqf9ut4catks68hjg7fa3ax8o7bnzmm X-HE-Tag: 1722220741-193046 X-HE-Meta: U2FsdGVkX1+qqTOT34PfV9iHnjuouWsmxPzhmaQ3hn1w0WQ5kc5XvKpvBGpLameSCLjQPCuL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7KGbRGFcgA/ebx70MQbTM87AY9+9t7+Xgq/zpFUWq7Sak0pT2C5ouFtKZTfTyNjsIHfuphol0WjkODtgf2Jp4RzwGDrOGSR5EkmBfOB1n7d7zYbzafBaQs72uh4Jok/PsnWYjQQzXgSjone7Iyp9KhkAURcMBU0OiSP+Atj1Gm8+CtOT4bZNtAKRzzwuu6sJ4ERa+14d96xLGRLr3FqoN9wUxa+Sf/hLtTLQv+Ax6GiyoNwtpbeIipwubioxi2A4Vspqx1ZtQzRFxuav7GI74Yg20puNeotbJe9JR5AgkQB6CG72orTvc87MGmNKyqBHyZgrC6B4ZmNQJhYSlu/4ki2pCeIRE5uDTMq2qnvfIXX/9hEe26vi1qO5cbMKTp71fHmEKu8VcaCcK0/a18QjvO9XRANx2vHJF7c+VtHIzJmuLHfOiSQP0= 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;