From patchwork Mon Aug 12 02:29:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13760006 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 273F8C52D7C for ; Mon, 12 Aug 2024 02:30:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AE9126B008A; Sun, 11 Aug 2024 22:30:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A70A96B009E; Sun, 11 Aug 2024 22:30:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EA386B009F; Sun, 11 Aug 2024 22:30:48 -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 657806B008A for ; Sun, 11 Aug 2024 22:30:48 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E9BDEA7851 for ; Mon, 12 Aug 2024 02:30:47 +0000 (UTC) X-FDA: 82442015334.27.9C504C3 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by imf11.hostedemail.com (Postfix) with ESMTP id 2A2214000D for ; Mon, 12 Aug 2024 02:30:45 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l9J+LFrZ; spf=pass (imf11.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.181 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=1723429812; 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=zoIFivrPmimQFCGo/41HPdx35H3kdQIF/qhwBf2evw8=; b=TbDInQNhjwMiibIyZrxUDvKdTudJZibau5ze3TJwQ9brLNkYz+EHDQmWWNmxlYdhgnvE8N s8BwMGsWo1T6NSZKFMYyIFpETx5UZD5+5EpTk70CSHh/rWk7XEY9QVkyaiDem9c7iqNMbb f+7AGY2EWmLf4Z2h3hUMIXpAtKVA6DQ= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=l9J+LFrZ; spf=pass (imf11.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.181 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=1723429812; a=rsa-sha256; cv=none; b=uVngYNLyUqC4Y/1Jbr7/nRVE70mTZj3u7VEHpcl4o5wow0sz9SkXnUYjUVte220vmN2MUg ht9n3ScULyK/TMOjZerrDBbYPCSOZprjrouP8I3KSheuw1XqZbanMrC2PSk9Jd2Gaekpm4 HzEJFygnlXfx+2uaJY1LhDCWF/gEc+o= Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1fc65329979so35794475ad.0 for ; Sun, 11 Aug 2024 19:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723429845; x=1724034645; 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=zoIFivrPmimQFCGo/41HPdx35H3kdQIF/qhwBf2evw8=; b=l9J+LFrZFoitmaU45R/u2khvseWwXl4HILgsKQt4XyYgv6KtA3V33Ft1VGbrmkWD5q FrsyJvrhHmENjdFLmCM9dUSevvv2MuRpwlslOgVAZePGCYw6Z0+b5jBbHR9CniNIWd+Q WbVYZtIlE1XJeh3lFedxPC+BW66v+lGz9nWzRHsKv426hjtGqX2clRIiTUcqRsN6TOOk EbQqsVp1YUHiI1hKiV6HzTY7w0QtGt2KBUY+4ewUbvS+YF2EEv6rqAdhpW69zh1w2chT hYimQyHffKJiGEZD7cDd65IJXKHdAIcS9tyAIYKEAQXqHcgC0x+cvrSlzlYrGdKhXyqH f7bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723429845; x=1724034645; 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=zoIFivrPmimQFCGo/41HPdx35H3kdQIF/qhwBf2evw8=; b=tkAfy+XTSbI+O0qzlZmcefj5Hzt4JWcVyQAmg+OGahg+pEsWN4JIB+czmmTSq+E8cn A6zBryZXo+HKLcgT5lJX0NcmrPG4aw7plZ4M+T/CiPa5NUvQFO1QtoLEeUEbN9SU9mgu 3F5avlP5tFC44vrkPlmBPQ0xLGiFWHc9roRBgN6tBiXQVrv9j23Gvc3+a+vinCKxZlXP UIW/Os9hpjzt1jqmQEzQJ6HuR43lVX4EArQbxxnr1lDWDdWBpUCPlzO1zHnnAhoLVOGE dUKO8OC7pGFliTxV0ZlyQi/w4isQshoNieajPXYr0PnEcG9q6WjjNM7+M34XNi0sjFBV dQUQ== X-Forwarded-Encrypted: i=1; AJvYcCXl4/w9xN/3XoWGxQK9dfjeSpBaZ7WPbc+Xlizrt4FLBCA/yIHViePj0YJ2o2RPMtS2fXN2B48ikZRJNbNZqQ33JLE= X-Gm-Message-State: AOJu0Yyn1iDd4bRR/l3SNtpDS4Isbec44ehKtDRpFC4RfkNhOh0FG9BP Q+0XZOsLILlHnUA1CmBbFUuxCKMcWssgrImT9FDtmYgCWb5ZZO6G X-Google-Smtp-Source: AGHT+IHsiTPfsy98RJjC8wpBNmaXvnlNH5fflWZLUy6tj95HlXDW+LhDZRUML9DQTQa1nKZJvXQLvQ== X-Received: by 2002:a17:902:db05:b0:1fd:a0e9:910 with SMTP id d9443c01a7336-200ae5e811amr99536005ad.62.1723429844807; Sun, 11 Aug 2024 19:30:44 -0700 (PDT) Received: from localhost.localdomain ([39.144.39.162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-200bb9fed69sm27884765ad.188.2024.08.11.19.30.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Aug 2024 19:30:44 -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 v6 2/9] auditsc: Replace memcpy() with strscpy() Date: Mon, 12 Aug 2024 10:29:26 +0800 Message-Id: <20240812022933.69850-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240812022933.69850-1-laoar.shao@gmail.com> References: <20240812022933.69850-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 2A2214000D X-Stat-Signature: adzqyqgmfkj78im6b8f3qw9thcom5qde X-HE-Tag: 1723429845-713314 X-HE-Meta: U2FsdGVkX19C9IBfGcf+thDRcreoAkOJ1HxGwolywlG9QfK8FmmkT4qM8+UM5+tRLIejvw5eUQz5ydypgttbJHCxz4AIZgC6g6ngWoGB2N/enZdA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ouR4ULK98nZJQYNEwbU+kRavIs9ISUBKNKqICk7zKJhyCoz6tPGlqLDVdY2k8agtSJiTxotSmG+u7dUIWoxysZtAjfyBg16uAtREL5+bZtXZ5jzjot9Q9S8KvfKxkMOoIbU2Xt+gqHLSD2r+rbByAIUIrTkOToIBbGUY1hhz+KiB1tQfSis3vcThN8SlnsKKrepBPTDXSn+faxJKBHjUfxMBR8TcWV8vBU1Q1jCiBz9Hs3Kt3MOas75CuobEY3kBY7kqFNlxJ9NB3Cgnrn1S9NWQAmfBFSw/tIOVKxSlYMIjqcX9ZpIMieRNREIJq3a6E3/4+o2ayfHXML2KsdzYrixG1862y7zysE2iNVUiR0AfO06Yg9uLqmJu4xbgoZ77MQE5JUYoptY+xYmsSoX26WHLgGogz+FDVeLjLI3XTUg= 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..7cbcf3327409 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, TASK_COMM_LEN); } /** @@ -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, TASK_COMM_LEN); 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, TASK_COMM_LEN); axp->pid_count++; return 0;