From patchwork Mon Oct 7 14:49:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13824826 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 9BC27CFB43F for ; Mon, 7 Oct 2024 14:50:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E55C6B009A; Mon, 7 Oct 2024 10:50:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 26DA86B009B; Mon, 7 Oct 2024 10:50:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E81D6B009C; Mon, 7 Oct 2024 10:50:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E1D426B009A for ; Mon, 7 Oct 2024 10:49:59 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 92316160704 for ; Mon, 7 Oct 2024 14:49:59 +0000 (UTC) X-FDA: 82647090918.19.CDFCD37 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf25.hostedemail.com (Postfix) with ESMTP id B4924A0007 for ; Mon, 7 Oct 2024 14:49:57 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JapusFmd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.175 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=1728312450; 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=4ED8sTWekie9637+cHBCmQFpLStnm64j/0llImVgOxU=; b=jI7xEZGF9g8/3jbcngJytzLHMynUluYxS2xo0UF2gY+gEwfKTqOzlmFH6TvPA0GZGvHckL vpIfGpGIdsgAYKF2nr+995d52NlP6E2R4SrZh+gxxbhicMpzsUcYy5tfWlAh/TYTtvgiNc nbgbxYTcUNALgjjKfrI4ySxXwgJFoc4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728312450; a=rsa-sha256; cv=none; b=Gu2xTLmfEML0y+37HEdXqhxDMBV9vfl/8whmfQKu6wjk0jRQIEXSYBLUWV3AbekyIi4XGD 7zfSKece+sTSUTAXJEBS0jmqf1mW+f0gjiMU4y7CVO4bG1nwY2D1Xjrz5G0dDWXDFXv3ce Y66y78twR6PeLou1wREEbmr4ELjNOfY= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JapusFmd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71dfc1124cdso1150434b3a.1 for ; Mon, 07 Oct 2024 07:49:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728312596; x=1728917396; 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=4ED8sTWekie9637+cHBCmQFpLStnm64j/0llImVgOxU=; b=JapusFmdsG3uGSdVzwi//ujBKcrm1BuTbYKBVGHMXhJl/fDH4Pfp44ZFn+JeYj/GL1 2SK2ijitgJvtGtyPjURS6tYgrbiysy4h6gMMvY3Bb0rvAllQdp6wHsgNVNRal5q8b5l4 lsdMk22tfsm+fn8y6E41dHUCR9UCEmDnvRmzT6dSwujPnBn/RpcKyPtQI36oc/U6hIzk 2/w1x6vpNYLFco7PDT0FPHz+JI9WIXbdlvU/0RC1cnDmgV4TpFViugimCfbjx8th5RLr qTGzmiWTmsb+r+z58ySn9/mqPSJFDqEWgzoyklx01I7AAriXBGyF3VYcAfZn8kHGAQJy f6ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728312596; x=1728917396; 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=4ED8sTWekie9637+cHBCmQFpLStnm64j/0llImVgOxU=; b=IaOu4p0REq+v/BWf/eJpSoxVLUIJReaH7fwCbroMbb6/3fgaG5c/7b5n7Q9c+dx7IV mopU3pO2ygBztNEpo7KfSU045FbvHWgpJIz/GrkPJJJZucQG847jPkl2OZhz+08ZRrKD TG1cdjPYrTEIoOQ47rSW2Fv87x05yyh9LM2nob+/bMcQAil+Uc37AIzjk9ix5buQlx0d zNmf6dsDAxWgX/yNCzKk5G5r2I4J1AjBpgUITq8EE3E/qFU4ITseZgmqCNyTUD5wGegm P2bV7cTuzqUb0JzKik65lCzAoZCVvfeLUYh1zFudYlh+ILZT1jJjb9f63eq1ihkTr8Pz w1sQ== X-Forwarded-Encrypted: i=1; AJvYcCVF7n3izfBr7P8JJFbtLT7WXci9RhjkyATZfvwBImDJeAHXWIqIGeNBscxZIkFQooFnGxEOhlsDwQ==@kvack.org X-Gm-Message-State: AOJu0Yw2CV75DJ4n5g/KxXXpRBq931x6VegtNve+IHie9M6VpKAvg9Z+ +jS3cc+6hp0N7x5QDIDuBg2TbCKrmZaF7V0FsRuTLcNcFciDe7VX X-Google-Smtp-Source: AGHT+IFSfr8aGR6hntBNP4HQUskHiw0vm/RzkrWx6VpNUZENgDQ4iLauIOQbi4o7xjraSFHRBCGRjw== X-Received: by 2002:a05:6a00:2316:b0:71e:1ad:a4a2 with SMTP id d2e1a72fcca58-71e01adb733mr6378569b3a.13.1728312596499; Mon, 07 Oct 2024 07:49:56 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.43]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71df0d7cf82sm4466432b3a.200.2024.10.07.07.49.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2024 07:49:56 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, keescook@chromium.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 v9 2/7] auditsc: Replace memcpy() with strscpy() Date: Mon, 7 Oct 2024 22:49:06 +0800 Message-Id: <20241007144911.27693-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20241007144911.27693-1-laoar.shao@gmail.com> References: <20241007144911.27693-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B4924A0007 X-Stat-Signature: otix9wp4a439z1yuc4dg3r7m7mmfjf6p X-Rspam-User: X-HE-Tag: 1728312597-949147 X-HE-Meta: U2FsdGVkX18Nk1HQGIwY0IxxJpGaPL12xjtRXZnhFNa6hDh+2ubW7rWrVvMjvY/BCakZ1N1ttBGZ/hhub7jSFiTBiyu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TS95wVIzgwOs7GhtNobwz6JTbwMQs/iGf62XiRphQ7gTDfVNdE0ev8m6O+8twCoPCbI1LTL1lghP+i+97/VcjZiNljkftfT5juSYV2XyDtnXGfxr6vpaDg6YtlJ5ItyR3dELDywhWxBeJ6tDUrV1+MexMhJmdhUeEy61i7zmXMfLv4E24gZnf6ukhcai1vXaa4FEp1UG32zuhEAl8UbagvVROKRCbDNysh4fz0tXuxoUbyCrJrZTSEhh/cwwLxUliTxYZjX835/HmModofr53DGtYsuCYJLUJKgCIHfsotcmANVpdvgUF5iAmCA6mNlbx2irth2YSW0O6MzV+t4UHQ0vkuLpVB1yyLwYDCvij8tfHDV0xoFXy6iQG728kurtwUn427jZ8qMUGaSQWdvPg== 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 Reviewed-by: Justin Stitt 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 cd57053b4a69..7adc67d5aafb 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;