From patchwork Mon Nov 8 08:38:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12608055 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BD59C433F5 for ; Mon, 8 Nov 2021 08:39:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F3C9C6125F for ; Mon, 8 Nov 2021 08:39:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org F3C9C6125F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 8DAAB6B007D; Mon, 8 Nov 2021 03:39:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 88A6B6B007E; Mon, 8 Nov 2021 03:39:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72BC56B0080; Mon, 8 Nov 2021 03:39:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0064.hostedemail.com [216.40.44.64]) by kanga.kvack.org (Postfix) with ESMTP id 6524C6B007D for ; Mon, 8 Nov 2021 03:39:43 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0AA10181D2FC2 for ; Mon, 8 Nov 2021 08:39:43 +0000 (UTC) X-FDA: 78785114646.03.B0996B1 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf18.hostedemail.com (Postfix) with ESMTP id A28034001E84 for ; Mon, 8 Nov 2021 08:39:42 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id b13so15323688plg.2 for ; Mon, 08 Nov 2021 00:39:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F4COnTTRSC+CwVYNV8z9S/6Jkdf+sp3tFqGz0D2qNdM=; b=U86xcKBeIe8C88277Vsloks1Il0hC3nKHvJ/vLLriTNMrA4feGBNC9/5t3C0NY+mi9 k0apksnAx8GSlr8XnRgNkC8844s/oe6uT6IeRT8NMnfS5P9gWmzIciQcWKweRk337tMM R3L91x8yeBo2/haXhaqtndWPD6n8XuzekdRzEsz8nNn7HRSWliVlH0LPwgXImKNIjwQ2 xoCSgy0W1Vs7L0FngeHa0k78vc5RyDzj70ZshBdBDQgi/63wTJb6dzkAPPAtavkIcUhF cHf1P8FNWZhJm4reblZI3cL2DEbGnpDfkzUJN82a3bqfg9jjPHX+Tkv91UClqAX7MNq+ CKQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F4COnTTRSC+CwVYNV8z9S/6Jkdf+sp3tFqGz0D2qNdM=; b=Mz0UeKrMhSvZMC9auRox9QoSFK57W0JVSEa67ttYHz0CD2CWmw2DSBs6kPU9GEcZqf 0FnrgXygIb67HsMDIkJzc/se4gBtSFHX4qmbdHjFkRH/g32ZpCYCg36/HJeWQN+O2ABU 3Lxk8+q2BANmQZsUlyKcdy/vUbKZJGaygCQODfFwIiD/qg8QdaKCWORUCOJwsE5JuV/M V74P3fNdVfCtpNrlL+9VoM7yydRAgWDblIvkdz2qAGRY+6jo38W5FsmojbX7zOL7xG2V HlUnHGdN4pAcZrmG0m6KIg2CAgnRfpO6Dp0IzaQq51cUKnoPI4qA0D2wWeD9Yl8j9Jru +6ng== X-Gm-Message-State: AOAM5301RAr3i12QpvSwp08YnMC8TGs1ySZ3u7IEgiYIpKrebFgWrF03 chtYlF9mlcBNrHrliTYLOW4ZFRTJMvUEz7Epvj4= X-Google-Smtp-Source: ABdhPJz6TyXtOl9PVb+CV7JTpxefSEYXhcK6oHfHEwQaGhLu5wThf9piHTh4Fia/b/8GTiLgxUtiQw== X-Received: by 2002:a17:902:e849:b0:142:c85:4d3d with SMTP id t9-20020a170902e84900b001420c854d3dmr40721527plg.75.1636360781841; Mon, 08 Nov 2021 00:39:41 -0800 (PST) Received: from localhost.localdomain ([45.63.124.202]) by smtp.gmail.com with ESMTPSA id w3sm12253206pfd.195.2021.11.08.00.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 00:39:41 -0800 (PST) From: Yafang Shao To: akpm@linux-foundation.org Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Kees Cook , Mathieu Desnoyers , Arnaldo Carvalho de Melo , Andrii Nakryiko , Michal Miroslaw , Peter Zijlstra , Steven Rostedt , Matthew Wilcox , David Hildenbrand , Al Viro , Petr Mladek Subject: [PATCH 4/7] fs/binfmt_elf: use get_task_comm instead of open-coded string copy Date: Mon, 8 Nov 2021 08:38:37 +0000 Message-Id: <20211108083840.4627-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211108083840.4627-1-laoar.shao@gmail.com> References: <20211108083840.4627-1-laoar.shao@gmail.com> MIME-Version: 1.0 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=U86xcKBe; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A28034001E84 X-Stat-Signature: 7gjebmddiss8z9rqgbijiwazo39ktutt X-HE-Tag: 1636360782-216229 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: It is better to use get_task_comm() instead of the open coded string copy as we do in other places. struct elf_prpsinfo is used to dump the task information in userspace coredump or kernel vmcore. Below is the verfication of vmcore, crash> ps PID PPID CPU TASK ST %MEM VSZ RSS COMM 0 0 0 ffffffff9d21a940 RU 0.0 0 0 [swapper/0] > 0 0 1 ffffa09e40f85e80 RU 0.0 0 0 [swapper/1] > 0 0 2 ffffa09e40f81f80 RU 0.0 0 0 [swapper/2] > 0 0 3 ffffa09e40f83f00 RU 0.0 0 0 [swapper/3] > 0 0 4 ffffa09e40f80000 RU 0.0 0 0 [swapper/4] > 0 0 5 ffffa09e40f89f80 RU 0.0 0 0 [swapper/5] 0 0 6 ffffa09e40f8bf00 RU 0.0 0 0 [swapper/6] > 0 0 7 ffffa09e40f88000 RU 0.0 0 0 [swapper/7] > 0 0 8 ffffa09e40f8de80 RU 0.0 0 0 [swapper/8] > 0 0 9 ffffa09e40f95e80 RU 0.0 0 0 [swapper/9] > 0 0 10 ffffa09e40f91f80 RU 0.0 0 0 [swapper/10] > 0 0 11 ffffa09e40f93f00 RU 0.0 0 0 [swapper/11] > 0 0 12 ffffa09e40f90000 RU 0.0 0 0 [swapper/12] > 0 0 13 ffffa09e40f9bf00 RU 0.0 0 0 [swapper/13] > 0 0 14 ffffa09e40f98000 RU 0.0 0 0 [swapper/14] > 0 0 15 ffffa09e40f9de80 RU 0.0 0 0 [swapper/15] It works well as expected. Suggested-by: Kees Cook Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Michal Miroslaw Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Matthew Wilcox Cc: David Hildenbrand Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek Reviewed-by: David Hildenbrand --- fs/binfmt_elf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index a813b70f594e..138956fd4a88 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1572,7 +1572,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p, SET_UID(psinfo->pr_uid, from_kuid_munged(cred->user_ns, cred->uid)); SET_GID(psinfo->pr_gid, from_kgid_munged(cred->user_ns, cred->gid)); rcu_read_unlock(); - strncpy(psinfo->pr_fname, p->comm, sizeof(psinfo->pr_fname)); + get_task_comm(psinfo->pr_fname, p); return 0; }