From patchwork Sat Aug 17 02:56:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13766924 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 87C91C3DA4A for ; Sat, 17 Aug 2024 02:57:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2600C6B03F0; Fri, 16 Aug 2024 22:57:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 210686B03F1; Fri, 16 Aug 2024 22:57:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D7A16B03F2; Fri, 16 Aug 2024 22:57:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E38A76B03F0 for ; Fri, 16 Aug 2024 22:57:11 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 70E96A0485 for ; Sat, 17 Aug 2024 02:57:11 +0000 (UTC) X-FDA: 82460225862.08.6030F39 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf19.hostedemail.com (Postfix) with ESMTP id 7F3B61A0008 for ; Sat, 17 Aug 2024 02:57:08 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GXWsv8eX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723863414; a=rsa-sha256; cv=none; b=8SXLbx6HDhFw0iJ3h+8fA+msbxhvgTmANTC6DCXrjb94X/8WrokO6jdxKM+AIlSijdn6F8 S7h1f5EHaDTHin8Gl/6JtRyEvTnuMV/VepPmGFwxdiE2i+duzMaCc9wKblqFDgMpTXsfwD Goso851/QOxoE8iWCC+T0RimZkBfUlY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GXWsv8eX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 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=1723863414; 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=5BtxbE2g5fb3/O5dUsU58E0P/t/4qpH1zRkpv67tjidp8he1XXecMRDEBwFo74U9VcrS+h HkvOR1BleH7PBE0O7EBdAiQn3QX8+gSupMhNYriurf/p/t0UOH9yq7wHtnoktr8gPgX1Xc W0IpqIBm1kgdFUHjyYRwit2S6aAUDTQ= Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7a0e8b76813so1964985a12.3 for ; Fri, 16 Aug 2024 19:57:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723863427; x=1724468227; 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=GXWsv8eXr5bZE06RGy7XZqAwqEDnBollwj8q6ud+aGrzg81GZRTzqL8T+DSUHEtzjM 3qYjwe3w4pDacgaYD/svu108iECZT3DZ2p9qiZbrXgvLJAZ31oCqn1zH8x9fsv8bYUeH Lqry2qq6446nV8GIRRBOebddOSn6hVz2Xik9UIcTKRBMNAnm+37lmc/Ih0ofhVt5L7yh DLmKCz6Ux/RD/NVsyhVv/BAaa+WLANK8z0e05RnZ60ExP6b1rBsVWayfGZMikpzKMehj o1pw9bdEruuvfeBwUZ6oynI6mqGkkKSotHaJ1azSceVQBsO/8nYMmfL4qAmCYpYxGzwj 1qaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723863427; x=1724468227; 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=cV8m6nKYEjQs3bMb+jaiWx4Pa7W5hTz6D6Ks3f88cdOxv7suM92iNB5IbRfjA0a6jF pokdaisFGGx4f5STH8OTEK48MLSHTHDGeZ2LscxARLOHUOjfaSgixfwBE91zjJBBXuSJ WN0zjqs1tmnGPd3eq0/gdYLMtBZ/AzEAZqB3KCjoUjuL5Jrd6oV10k8mlzhY5cmEFl16 DsWjOROnaFR+sLKDQ1IJbzZod/Nq90l4ZnRLoER35X6UV/tnEtxlsopCryJXvoLuq4Hj q0uMq/zGhVlkxKWlmr9glyy1ZK9TNckaigKh2/5Qpw5TRDHhUIP/uNzocLi+Q1/2YK0S e4Vw== X-Forwarded-Encrypted: i=1; AJvYcCUSD4+/G4ThLzREtNBswc2q3T0H+qmsy7hmdWn+WKJy24CRSbWEH00W+wXle1F+VOybbUlJ1l2Wnn2QG91VDF8ZdvA= X-Gm-Message-State: AOJu0YzFy95i41Pqj/Dbb1dBDuDyy2Ya11IjBCFwHotqBV0aKBM/KBcX qLhj6wg7TgkAgqdJ18EAn65/Vr5VU0eqSv5HlVnOkZP5vPjDzDBAOalJbq6S+MU= X-Google-Smtp-Source: AGHT+IGloZlxC12N+ArnDbFHNJc7Yrc4w00KFUrCatU21ag0p56SeEdkfwKvEveNvVnkzBGuU5AKpQ== X-Received: by 2002:a17:903:32c9:b0:202:bc3:3e6e with SMTP id d9443c01a7336-2020bc33fc8mr44372525ad.33.1723863427201; Fri, 16 Aug 2024 19:57:07 -0700 (PDT) Received: from localhost.localdomain ([183.193.177.10]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-201f031c5e1sm31801785ad.94.2024.08.16.19.56.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Aug 2024 19:57:06 -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 v7 2/8] auditsc: Replace memcpy() with strscpy() Date: Sat, 17 Aug 2024 10:56:18 +0800 Message-Id: <20240817025624.13157-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240817025624.13157-1-laoar.shao@gmail.com> References: <20240817025624.13157-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 7F3B61A0008 X-Rspamd-Server: rspam01 X-Stat-Signature: msho9ftsje9om5yz6ys11iz7jcsbrdca X-HE-Tag: 1723863428-507341 X-HE-Meta: U2FsdGVkX18sBF1WsLw+Ls4/2RJ371TiUCXWt6mB/FL9MU+33F3Y2yUEXd2Ni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vD5lllnOqKwjIjk+bjhbbbpDyihJGcKEYv4FZabBZxb1mUYdDTU4r4m/6sv5MVBzYUwQOHkYxiiqswRCSZ3JMvUlyWCiPGhHHfmnrb8cpMevZwpefGupwk08feVMuMo4Pq2KafwCBR8xq0pWCYqS9OCNz+ZRy3+J0LLBhNuq8RqGJ97dqZF8AD9jqdjpKGWlibHqNqUpw1q/p1boW5jqaCsJbajveDg/ldUu1QuNgCLjIM1Qrmvdu7uUbmHfM3xczl2L1KAo8llggZtktUdGv8MS/VIWyjwX1pUi0ibX5tPVFe86QaLiqP+5PIT/amj+uMxUZtgq/2QsdtrGC9h71e9IdmgSxSsiWuVfHlemxkqbqS120pRuyMks/i/VQEqOonefxE760MC0GrsAgccBtQ964HQnV4UwoDlptZ4+QjhArqNYet+ByUBfvcKSkYIDvHl7/0hb0dAG/8jk/lvdo= 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 --- 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;