From patchwork Fri Jun 21 02:29:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706693 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 2195EC2BA18 for ; Fri, 21 Jun 2024 02:31:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A37416B033F; Thu, 20 Jun 2024 22:31:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E6C36B0341; Thu, 20 Jun 2024 22:31:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 813136B0342; Thu, 20 Jun 2024 22:31:00 -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 615026B033F for ; Thu, 20 Jun 2024 22:31:00 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 19B79A20CE for ; Fri, 21 Jun 2024 02:31:00 +0000 (UTC) X-FDA: 82253318280.02.BD3E2F5 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf12.hostedemail.com (Postfix) with ESMTP id 3D27D40009 for ; Fri, 21 Jun 2024 02:30:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=j0Oo9MDS; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.182 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=1718937053; a=rsa-sha256; cv=none; b=VG3LIPA3MxIMzRzICTUrBIK39QMwUEczYs4vqw1bcxh1mvbGIT8cuBcfvSPMTKvHUN0kxA 6Uk51pMWc9CfPzssxixKGgbxlR9bwUWVNYXDuOvXCCoE0qDvmiGATjnFmNf3i4mUSmIC7l /JIJXpwc1mOf5o+4CH5soqvgR2xK6pQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=j0Oo9MDS; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.182 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=1718937053; 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=fN3dalfcPI4D5pf8YvFHTrCX9QsmHz+XBCvEwyZJhYNg46EEWJVI2Dt/sJITLDjIYcGMhc TUU3SrqCXQ/j1La2q2SsBLEJE9dSN1hQSM/UlxngRC5MKjoLsPGKWXzNOlU3owUmv6eXAg IeLGnPTl+wlij5FSiobxlyGF0UuUjrQ= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-70599522368so1241453b3a.2 for ; Thu, 20 Jun 2024 19:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937057; x=1719541857; 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=j0Oo9MDSYcEOdcD1t/w3obmjWHmZKg3sBYjLtF1PPmttJaiIXvxXqvlr3E2BKHt49N aoc/bc4GoI/LNwSCWprccOJtrSXowu3aDR1DRoruzeSI/4q5RS+zDVXDWGG0mHXgRkIC 32qFjsmqP3ce5hPOORVFjK04Es294pr3BjrPbVJ9xzLkfYRTd3PDrsNaXn5giIG9gvsR yTv1Vgc5eb6TTZ6jJY4eCFwf6DNtpGB3K8XUip6jaZ8Xm+3itkv054heri6ZcmpDcZqg rYlnoXpb56qG1NcuT4A+ur52AZhfeXTq0gW2XWpKPdGkprVBGNIKZDoVg6iNvRHUBucV duog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937057; x=1719541857; 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=V8wXsf+aSyJhHW0TTMkKrU5QHLQ/wT/g+Spb0BEepxlx6JbMuyFDfv2yjArbKNngxk pA1nKn/uRI6gpS31hdAchIfC59K77kJapSe/JBCILyVVlF5Sbhj3v5NkhvqLCyS+2dVN A/6v+2bwb+F/puErfqvtHp6RAITQ5xf3KbR91X6pSB8ENcJOGWoYEjq/PQ/ifn7Pg9A2 jT5gs4/jUPjYwFx5qRQbIzcSgzbG3OgABhQSNXpIrSFOsy5ak7oQS0EiENbVyw/AUvJD OhoS7nGtlczspvDGhdbnNJCm8gcSizB6wlIjb8ZfbXnqOt7+bl95zc7y/LDqBquyGpIC PDQw== X-Forwarded-Encrypted: i=1; AJvYcCXR/AA6wwgAvfThEONgqLlY2LzIKDZ/jIawawyoqROaStVqBGzBnfTutz8iVU3gzT9hssxytWqaivADIU9SETHwMC4= X-Gm-Message-State: AOJu0YwKyiyogckEyhXUe8SkG6q+2VTn6XCX8gKGea4gf7Zikefu52kG B4LErG926CWxasr/AngeqdvinYx5S2Zp7pUlpBMwKFLlgbZpk5d0 X-Google-Smtp-Source: AGHT+IEXObDJFHHEU4ritIMxu9doHb5HpGV/yXlLGQ5OCeoryIQ6hRw+mWkpUWLLJXrRfBg1YmPPYg== X-Received: by 2002:a05:6a20:9313:b0:1b8:b517:9bf9 with SMTP id adf61e73a8af0-1bcbb574a9cmr6631143637.25.1718937057021; Thu, 20 Jun 2024 19:30:57 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.30.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:30:56 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 02/11] auditsc: Replace memcpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:50 +0800 Message-Id: <20240621022959.9124-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: cqdrnkqffrithcuksf4mimxua5pae7yx X-Rspamd-Queue-Id: 3D27D40009 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718937058-983764 X-HE-Meta: U2FsdGVkX1/pZ2ceVSc/71CzthcFATSuIqT8iDYIu5Ud7+E7aJYXrfVo5fjc1PZvvDb67NSB0KSg5z3jr45W5X8O5nbKW0+1tFt4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0KqshiU+MAUzMF1q9Hwdw5Dd3hUGAh9W3UKGJL0Fq6IfojXqILY4/lANWDRps8fmzOihM3KjlIScYm5kfpFx5gbE/aRujQyO4ebXQS7QXm76K3DsCwd9zBlfpT5/uNRviMgwJtItrlhEhugnjjx+WwhCpxSearUwWtPhe5W6tshYBXZD65ETg1PkptjxlW8lCznuvdn5Rme3jxh9TsRxPKMuV5tzUHGMY2S0PIaAWiu/3OrsHnkM606t/tlUqshPIMivXCchU7FZkUO6IxB0JInOZbmtb3M037NQKvKNAjTiS8SfEP5TufxxKlFjr12cKPFJXM+1bKUoClZXy8qUsjL3nhwNGp3T86YyRKkQ6zqAPAt1fG4S/+ZnNc67MagozGrw1hBCbdq8kvalZcFg0= 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;