From patchwork Wed Aug 28 03:03:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13780362 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 E7F36C54749 for ; Wed, 28 Aug 2024 03:03:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80A876B0089; Tue, 27 Aug 2024 23:03:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BB036B008A; Tue, 27 Aug 2024 23:03:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65B916B008C; Tue, 27 Aug 2024 23:03:56 -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 44FAE6B0089 for ; Tue, 27 Aug 2024 23:03:56 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C9D7F41C34 for ; Wed, 28 Aug 2024 03:03:55 +0000 (UTC) X-FDA: 82500159630.14.2EC1C02 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf01.hostedemail.com (Postfix) with ESMTP id DFF9840008 for ; Wed, 28 Aug 2024 03:03:53 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="kt/MiHTr"; spf=pass (imf01.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.52 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=1724814189; a=rsa-sha256; cv=none; b=YNmBj52OmFy4AYwLsKe++xyBrWiVco7fMd/DlnIVYwZvXF2zIYr5yOV7IyHWKgH7wFoQGc 2BQjwohtayIk+p8O0OD9FwkSbT5LOyVlqKFWrm1XjLV+qfOCVZev0tElmeHhXk2Eqw15yH SKwW6j/W7alLWBqY4JITGy0v3HNQTSo= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="kt/MiHTr"; spf=pass (imf01.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.52 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=1724814189; 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=+RcIZVYUDMrvydSLTObUn9UWjAdkDM4CrmA64YTz3G4=; b=bAvAFcXqwploidrGPjM3yjKHBUq1Id14cj7qHNDBvfYzqh8d48JKgy/vy5nftMr2OmMX+l /xgitCq/KURktMa0by1u2yaCuFyRMob8NO01hpSLU1e3rt/Mrwis0KwP/2M5v0+L7RxrEv YdN4H3c6cnAx/NtDMpEfFvFgT2xfmTQ= Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2d3ec4bacc5so121223a91.1 for ; Tue, 27 Aug 2024 20:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724814233; x=1725419033; 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=+RcIZVYUDMrvydSLTObUn9UWjAdkDM4CrmA64YTz3G4=; b=kt/MiHTr6JssVuwpy9NTa+CyfZrQBTEpfYQSNuPeIH6Mh3JH+THEISnEHZl3Fhqiq3 W2CTrH4jVBAf2xKbBdSwQ7QMWh4ugybWvQIw6fX2mLjoA4nQ9xnxpYj34K2KK/9CfCst 7TOYq4fH6897OQligXQ90nK2dvuh5dfrAlAXbpIv+W/4bx9JcDLg3Sr4SzdnscJ3AtdO TLt9at9PeUJd+yQCgvh/X1qVi1pQ6Ad74COWV6dXQiUAWeZw746bQ/9FY8uWR+y2RDA3 ec7duagmeGFWvHxq3ay5hAkMMJK2UHlPsLfdZ+p2tMu5jdeeDw/9bsVFFHz63NTpI0SJ DgQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724814233; x=1725419033; 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=+RcIZVYUDMrvydSLTObUn9UWjAdkDM4CrmA64YTz3G4=; b=NYGCm035T1kZMWTb24zJySm9SIv4ClAaW2LKodQmiQvjPaDn1qFbLYnjxPqCGJclDd LonuTFQYpGZOrKhpx97/RAGGVRuTUDvWGMzTmKtVpaOHTzdiAU5Wj06Pt9jPD6UALq+B HWOp9C6cKedcuI/mK8MEtrCS6Gs3/OR0A60T+iyw7xIwLOR+GRsnBCi68h7CLYE7qWDS bHtu0RpxVt4mrGj3uxWEHrf+K3i8tkeBwqfRpYt++C9d6s9MNqfAef0oC3/qzUUHrjfi 8jMxV1/gMBMYghzulmR5vu37Li/F0K9OAkkMrPa9IUcz5ncUIkNW9cXbHOarqK29360j PqDw== X-Forwarded-Encrypted: i=1; AJvYcCWyxhKJvZjxn2JfuYfUIaPQsDKi9h+npyDR+Rwqgd+AdWyjya0YVCL7voGhIZF1KquCdMOZwYmNGg==@kvack.org X-Gm-Message-State: AOJu0YzV7ptCPD4hx4kfcMrhrUN3W1n6hFGur5DuD52Oy3IE36b09sA/ viV4NKrD/wyMXw01Kqj6VXkeDqtBIGDqi6OW2iXu3Nu6jvkDaSMS X-Google-Smtp-Source: AGHT+IGFzzoi8lpwMf6Iv4C1DEmxZSABK+5V2UtAilXgBtIiNQOvP4ALnfkUbY0O1vyUXWVYARLCDw== X-Received: by 2002:a17:90b:d83:b0:2d4:91c:8882 with SMTP id 98e67ed59e1d1-2d843c839efmr1207327a91.11.1724814232595; Tue, 27 Aug 2024 20:03:52 -0700 (PDT) Received: from localhost.localdomain ([39.144.104.43]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d8445db8f6sm317977a91.1.2024.08.27.20.03.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Aug 2024 20:03:51 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, alx@kernel.org, justinstitt@google.com, 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 v8 2/8] auditsc: Replace memcpy() with strscpy() Date: Wed, 28 Aug 2024 11:03:15 +0800 Message-Id: <20240828030321.20688-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240828030321.20688-1-laoar.shao@gmail.com> References: <20240828030321.20688-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: dzgio59eq5entpfxz7xhf6ibnwg14cox X-Rspamd-Queue-Id: DFF9840008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1724814233-589490 X-HE-Meta: U2FsdGVkX1+H6Kml3uluIL2po771jUruaPHHZSQLYestqbUkRBT+dAqzBVOyhVUNDkfdh9du0X2RMt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cpAJT//mTQUcl4tHGmCW8eH/slytfMqX+Gj/kqZBQ+3qcENqYnU2bpDzjxMxfKUtFF2K4hsiG+Y6M1TdMQ8LTug7gbsM4b3AcTYaySbqN5yILLPglhZ4Fz9FRbrGvoL2JQ9POW5jeCp7Kzd8K0IYLQWsswQ4WLCaGTN2/Bf2x/Jpa9+k603LS6JxcPuBmlLANLHTqxX5TMZ1G7VGHOghX57FHykqdsxsZDEXlzG+WutfYwHtSV0jvoDPL5hXhSNTtpeDF3lT+3wftkdKXsTDTrsRwqBXwCGhAooVwgcxbrFjUdsBmqmG//bZS7rBtWp0zI4MXKUUVORRfkYNEOFY61VJzDKXusxHQZLPFBmyHJvjx8W43mRPyDRV02AzHQ0lxnsoRVTQTy/Xyth9e2OdBSLukdgAyGbOVqTjc46/1TaFW+kqhuxEGHrrQiJySP69rKbftkCOQ0/m+Fw7XRekNGcy3N 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 strscpy() 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 Reviewed-by: Justin Stitt --- kernel/auditsc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 6f0d6fb6523f..e4ef5e57dde9 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); + strscpy(context->target_comm, t->comm); } /** @@ -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); + strscpy(ctx->target_comm, t->comm); 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); + strscpy(axp->target_comm[axp->pid_count], t->comm); axp->pid_count++; return 0;