From patchwork Mon Jul 29 02:37:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744220 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 7B52CC3DA49 for ; Mon, 29 Jul 2024 02:38:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 02FB16B008C; Sun, 28 Jul 2024 22:38:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F10546B009C; Sun, 28 Jul 2024 22:38:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD7E36B009D; Sun, 28 Jul 2024 22:38:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BDFC16B008C for ; Sun, 28 Jul 2024 22:38:41 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 22AF5402F8 for ; Mon, 29 Jul 2024 02:38:41 +0000 (UTC) X-FDA: 82391232042.28.43E2195 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf09.hostedemail.com (Postfix) with ESMTP id 4BCEB140008 for ; Mon, 29 Jul 2024 02:38:38 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Vl/Ix9uj"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.41 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722220679; a=rsa-sha256; cv=none; b=SUhoTiPRyreR7gg1FIMlBnWC/nG8FWNgo9GMEzrhUNFnLRKtdiVArRBh4KI0TvbGIUZBs1 a1FFwQ6kws3fi8Rrb0iYOBW/QF+gz+/aeieqs7wix6akjgwb24on04/n6VKgmsAspvRXKg 8dMelhNDz25+/JwBO5+nXxNFfYdJQso= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Vl/Ix9uj"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.41 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=1722220679; 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=/dYktotwfBu6Roz80A5YCXaIPxsklnKpN0JVw9YLBJ4=; b=ttsBvGFbWpn/G1teB1skJRsy0iabQN7Uu443hYqFqm8jiPkfh0jTzYnKu3dc9nf2y15oQ+ w+R8xl4Frd9xcu6VF74xUd2o2HD3PkarU839+Lee2FRrWq9z2PBDnBhTwXLb5u0R6jq9xD sZ82pDm6xG8voQKk5cohKdjyor/ZO6s= Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2cd5d6b2581so1625809a91.2 for ; Sun, 28 Jul 2024 19:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220717; x=1722825517; 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=/dYktotwfBu6Roz80A5YCXaIPxsklnKpN0JVw9YLBJ4=; b=Vl/Ix9ujRR4hHZhdUqmkv9+4IabdlgZ1UFR/3Zf2ul70L4AZ0n/YuuaE1cTAr/aBss dClVpriMJr+rMmIS/b5LThd+iFv+SHMDRwYGiAj5+fXsTgV/ZoZB/7SQNZTCyvPT5rrI 6pY1gYeqcpjo3xL3bsvT1haOwl06vVDf17VDsENpiU7AstHNb6EIqU8aNVl0HMcrCHHi c0LkyaXagSFVPm0Vwaixmsadx3HvT1f/L3LtE5gViDIzTpQvRfIZbxDCU1XBLyqqRQJT W9PM5OGT8bfrjOfZZmzvBkA4Z3YL1EeMGI2JXmdqh1ZflslRjoUlPAJqPHuXgAhCh4Se I0pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220717; x=1722825517; 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=/dYktotwfBu6Roz80A5YCXaIPxsklnKpN0JVw9YLBJ4=; b=p9MT0T3+6EJYFtgXq98ELIRhFVl3Xk0mycUHnlvkigPRlVp47NLC+wngKNGPo4fTZr kRkpgxaUXBZV9b7DTYxVEen47QtTBMPkVw1HA7sVVX+1/7Bmi9YQOs6nNQ2gzkPfQi0V TaqcCWrcYxoUK2DcmijTFpAvYCslfXWE7x8tocR30J3YsADfBQebGE/cxFRKKANVY/Cb OIoI36aZwceNa+YEd1FmJfkZ1nMWj6ONbulD+M5H8E9HQKsgSpfxxy/PItHZEJ+S+ZQg 6rUieIXzbTNzRsLOn56eoSSEuYhn+Hc5qvwiOZRGPGJLIW4fodtDX5dVz1igooKlpXrO T/Zg== X-Forwarded-Encrypted: i=1; AJvYcCW3PZ8qPaxPneb238+e9hVjkk08Ufw4UyjzMBqpkfp/oUUm/UoYBsJjE4hbQuM9M1LiQgiLzHYL8NVd+ux926uizNc= X-Gm-Message-State: AOJu0Yw3f6aqBMh4UVxSvK9lZKRN5Lx76tmJ0j0CO+4Gu3nX0gN9V+Ok J7pphwJ2ql4DC4o16BJ1HZRyHsw1TWaDGa5kvQ7VmVTTwjk/zS3S X-Google-Smtp-Source: AGHT+IEUvSCxvTt2iFtiQZnOEMmTj53JiCANDbCPnBaNHXCCebMev5gTq4Ke5agmpYOP2sLQoQ29tA== X-Received: by 2002:a17:90b:3793:b0:2c9:5c7c:815d with SMTP id 98e67ed59e1d1-2cf7e2275d2mr4251165a91.22.1722220716985; Sun, 28 Jul 2024 19:38:36 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.38.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:38:36 -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 , Alexander Viro , Christian Brauner , Jan Kara , Kees Cook , Matus Jokay Subject: [PATCH v4 01/11] fs/exec: Drop task_lock() inside __get_task_comm() Date: Mon, 29 Jul 2024 10:37:09 +0800 Message-Id: <20240729023719.1933-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4BCEB140008 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: b13mctxiwh4gqgghxogeu9ob57x6ozoe X-HE-Tag: 1722220718-673015 X-HE-Meta: U2FsdGVkX18qXY7QVGyLejdR3w8H9OfTJ3969lj5KVUkSFc9sTY2LfKZ+7S+dqEQChRouoFwHehWC8aV4pfvgN0CS5H7obF7IigZdwzDSA7cD/1Md6A8eMhJw1bAcYJ9KDs1TszhCX+vVy1oQugh5k8d2KG+tZ5mDi39rekMwvwhZ+Kgf//6AES+DnCZ/oHxQLrGgRWTfYrRKz/HMjfd1uwzyIAG01+GMwaIjZB/HSl3cEte86G984WL453U6X22FffXf2Spmlg2ZFlh3QvBM/4X89zsQE5x5pDUglx+0McWgq6sig8VhAuKN6BEMf1ocbSJtwm8WTxdkUpMquCbZYRF+cX/EpP1pA0Ih9Oru96R+ZHLb9deiQ1K1YqOJzjVRKr09mMmBdIwb2ptIOtOT4KBfsWTVw3iWpWQZdnZ1dFRPJi2Tj0yzWBdr9JbNYnQA07k2vK06RM6jr6SJG+nM9JoR1sbepI2xfMEv3Y+N7g47B4wy5tPBYnS7Tc5UezseYsEdKKOUrrq/pT9D7Y7rK3BX4LfSzoCNQ4MM5EPam+68x9+b9biqTYHlzrpKxi/f4UHW3ADzTRaUy2ZF6iadcL/d0fyT4qkGBTX0lifEGkILkcR8z02/HM+oIOJT2o4ZO3Mnl6v883n8AeslKud4Fa3pFvWSXsAoxQfnPg1s0Yrn38J5LvZQXIoiUfAQxi+nY8eCcXMxlSLHeEV8SUitnHXgWZy6ojY8UlQ94a/lAxy4bbwApSdtsp3XdZaq2fCpkdCMfiOh2PkCGW8aLIratFNk2Pcv8RNVeFH9iDP3HSfySfjJYz+cuaWkmd+V6AHSCfR6+y3DCiZnCz2EmidYj6FjnnQY9vZ2xtrWEmKbVyYHRqiJ3eNcRz6pnskt+46kE7+ZOO2LV1GfuAxII9+1g9cZsrjziCTJzPFFBZ/YfJiTAtYkzGzT44UzqnVj5d5Ut3F45u6E67tUpTN6I6 Y2cLKz1x rXzKnYgXKZYnJLCl9NdGY8sWptxFclUNP8MDqDWQATs3pH8DCClTgy2gHhtEfJAtmcv0U6ue3qmr7Yo/SWjpLE6PZOr9vUCpYIpEBQbcJy4gFsclJ94MBy8BqmesXNiluGWcQzotIULrBMC99Z9zo5mrucTlXz3TgC6EGowcT1Jbrn3I18F0RnkHS0vZRCqsZ6eDwN1NEzXZQxNKhJjYBeF8oM3KKbCvTgIBK33nvvvWl6+qSI3qwJL1EnOCyyOuDvXUG3SCh/V7wNdqFp3yYIr0tMWf8CIxL8NAYNVnw0xDuauaIn2PiA66X6jXJYu2Xrol5t6dIOCcHPvPjtfw+BgW5iYKu7SeodPAq2KcdcJgT/NuXnnrK8HrFXcHmKwlUZhDWlw/hJbqAk/f/EKvTi5Bw4gxudgelADLosZO1nzHpbR1IWqdzcQ5zqhaVI3taa7Rk4o+0BxnWaOQL6NJ2N5Eb+6he55RY/brlDY5KwhHaAeNqJIec+LuT/31bWAPw63kSGpP8QsOuXdP3rBfb0p3hfhGG4CeWTi6mwc+yq6YnitUVnyFBgkDHXsb5LcvtS8nAxOhXkTrfci9CKgdW5wgIOFkV9IaG6gjn0ycUq1oQCA9g19KbXEew9vCqgkA/ceHVZov4zs6i0AR6/hy4VZ4B7fBA6jy/WzIJAnxBMqPxnhU8a8PAExJmwdV/IMzK8JCE42RSyAo/LYwlMziiNPm5jFGeuExk+RRMiF4etCfyiQCg9UKYkC4mjwH8AxlN7aA4KIgKeGFwLriciuY0J9rIQuW42TNhCWoi9igomIO2YcM= 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: Quoted from Linus [0]: Since user space can randomly change their names anyway, using locking was always wrong for readers (for writers it probably does make sense to have some lock - although practically speaking nobody cares there either, but at least for a writer some kind of race could have long-term mixed results Suggested-by: Linus Torvalds Link: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npJooP8chLPEfaFV0oNYTTBA@mail.gmail.com [0] Signed-off-by: Yafang Shao Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Kees Cook Cc: Alexei Starovoitov Cc: Matus Jokay --- fs/exec.c | 10 ++++++++-- include/linux/sched.h | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 40073142288f..fa6b61c79df8 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1238,12 +1238,18 @@ static int unshare_sighand(struct task_struct *me) return 0; } +/* + * User space can randomly change their names anyway, so locking for readers + * doesn't make sense. For writers, locking is probably necessary, as a race + * condition could lead to long-term mixed results. + * The strscpy_pad() in __set_task_comm() can ensure that the task comm is + * always NUL-terminated. Therefore the race condition between reader and writer + * is not an issue. + */ char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk) { - task_lock(tsk); /* Always NUL terminated and zero-padded */ strscpy_pad(buf, tsk->comm, buf_size); - task_unlock(tsk); return buf; } EXPORT_SYMBOL_GPL(__get_task_comm); diff --git a/include/linux/sched.h b/include/linux/sched.h index 61591ac6eab6..95888d1da49e 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1086,9 +1086,9 @@ struct task_struct { /* * executable name, excluding path. * - * - normally initialized setup_new_exec() + * - normally initialized begin_new_exec() * - access it with [gs]et_task_comm() - * - lock it with task_lock() + * - lock it with task_lock() for writing */ char comm[TASK_COMM_LEN]; From patchwork Mon Jul 29 02:37:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744221 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 562E8C3DA49 for ; Mon, 29 Jul 2024 02:39:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A57826B009D; Sun, 28 Jul 2024 22:39:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A07AF6B009E; Sun, 28 Jul 2024 22:39:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CF276B009F; Sun, 28 Jul 2024 22:39:04 -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 6F8FC6B009D for ; Sun, 28 Jul 2024 22:39:04 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2F795801CE for ; Mon, 29 Jul 2024 02:39:04 +0000 (UTC) X-FDA: 82391233008.10.34FBB5F Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 6226820011 for ; Mon, 29 Jul 2024 02:39:01 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dgFfpeV2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722220738; a=rsa-sha256; cv=none; b=km+1k/C1xrhnQktsH9WJ6gS6z9HuX4Qqj98I9Xjge9Jc60Ac5wbiTy7qfmUjuNttgStHH5 L5f7GfE+FaBGuSvxLax/7zrbyWQ5SO8ayA2NsBAgDDSWdM4M8ZjS10gr6WFws7W7nYnlUX xLsqBeRzQKreMVMOlJiza5GQVWFq/gI= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=dgFfpeV2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.172 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=1722220738; 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=y+o2QcP3zzShPD5bpWdvqtRKk4SGVf/ncCjWPDHjjaM=; b=663gqRp6aMafRWC8Lfx6hrcdw0wDv7kE5ODsbFut0pGMPV8Ky64zDLrC80hftfitnRdnWZ WVm85wS9oXjdTlMCKZRfuQ0pl2KzpH+1vm7uQZrvO5ekA1OhFPYgsNMc3jnYVADM6tVlRr riWu7P6/xsiIB5DlsLKnCiiYRoAl9/8= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1fc47abc040so13094485ad.0 for ; Sun, 28 Jul 2024 19:39:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220740; x=1722825540; 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=y+o2QcP3zzShPD5bpWdvqtRKk4SGVf/ncCjWPDHjjaM=; b=dgFfpeV2utPAuhnZjmEmayqcFe+xGyWOGQIJPBNiKfKw1XJIG6/fsyT1nOAXPjdprP Pq6e5rdpknwTDRtHIQ6K5SRIq6y5GLLpX/Ok5us27/iuntenpACJ8gvvQzKwtWQyXbUJ 9k/YZsWr6kk7iLc8vgIGWvV2FrfhsEL90IEzYEXvgE7bU4ZqJdNs3pd4OsqK12U5Ghv7 uwSI63hpwDLwpWgSVxXM7YSkE7q2IiDJIfSZbtghlX2trv0YHRH/1twqu35/faODwwLP 1GAxKTnOXdmVuFHhKC/Qd7aZBrv9R6i6reBtDZFhlcg45yW3DnW7xh5K9zm8IxZQ84S0 W73Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220740; x=1722825540; 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=y+o2QcP3zzShPD5bpWdvqtRKk4SGVf/ncCjWPDHjjaM=; b=LzCOU2e2gjUq6soSMOECPE12iLjI+nuw69T8IT1jtZDxGm9xDIgWlq7HFP3gtGrx8K uacPkTyRjNr+I+xEnxIFG7tvrzWq78Ex6Mj11rso9TVEFTU1liQZdw1F6oANUew/3DYe 5YcsRCePa+aKgcGMhP06N0U5YzHTmctxqqP4VZ3ZjaLIPKHiOKzJU3YDa8o5WeZOkQb9 pvF+DRoAQl10r9xLPFShwipjluaEuC4W5iyS949Uv9Hoa73Wip6UGXkOUhMWSJoqSTdL tT9K5aUACvHOjVfUnXT7cEJPvfTjr8BVm+RY5nTtbrvPRCTgRiA0xlI3YWLJxr7pH/gw /A6g== X-Forwarded-Encrypted: i=1; AJvYcCVfcDMVdu7nufP0HDZAeqFpG8bo+k94wSHan6bJ8rEUh7wQ3mCkEkhP26e4cRArrFgId1EM+FDx36KMt8obZvWUivI= X-Gm-Message-State: AOJu0Yyfd8O6D4rim4kRQ8bLytsvil+I4aZdxzvJODn9r7m2/DkdY1na dd6tTs+qvFdUr5t9nn0f5FPCeix5M4prL0OF6nMPz4ZCzw0UKHJU X-Google-Smtp-Source: AGHT+IGBArXuQ6UfIKXak7ZIiMIQBzEmqSTo4bq3Ao5W++iZVvXLvRGW5ku9X9sKf2s7GMsSLwtHOA== X-Received: by 2002:a17:90b:1649:b0:2c9:6f91:fc43 with SMTP id 98e67ed59e1d1-2cf7e1a3e76mr4224751a91.3.1722220739919; Sun, 28 Jul 2024 19:38:59 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.38.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:38:59 -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 v4 02/11] auditsc: Replace memcpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:10 +0800 Message-Id: <20240729023719.1933-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6226820011 X-Rspamd-Server: rspam01 X-Stat-Signature: rnqf9ut4catks68hjg7fa3ax8o7bnzmm X-HE-Tag: 1722220741-193046 X-HE-Meta: U2FsdGVkX1+qqTOT34PfV9iHnjuouWsmxPzhmaQ3hn1w0WQ5kc5XvKpvBGpLameSCLjQPCuL8Cxo6DgSm+rxa8Imp3zsz6YOSxElLEziAVorsh+ebuctZmZmVwhvytGZ5qgexmy/KMERWFpMX9L07NgwZmVl6cSshnOyQkO3N6NxyD+Z9gaEinT2/5kbkbJK7n70Voy0wpDyHVMcAXg1eJjbldvbfrRWwpnZ7Aq5gHwoRSGOSINgYBeJjCtA36e+ChB5lJDgZxawbNhVirMH24u4sr3LAxA4gmTrS5xyVr+/WEaUleiLYvTiKr1Wg0yRi5FUDH2JBm/5Smsfxixwd83FoQSHGaJzDTHzNf0dQBp01FNcd8ZHcsYvvtdwF4aC3GnBl6OWMpEtYAHwC5VDGSjJRp5Zt9IFB7LSeHPXrfXVEEt6csz2nuOSKdqhUFOUhbLSnYTk1KulzwxlxviVlb3igvZg+nskMew9aeV2j5rLfE7Nr/Q1vSXDSMiZnd0hU4HVdfw1go8EyGMXdeZvijIyznHGDSxCD77ypOn21FYp4LJ4DPvIaYgrEug5lAjvJue5QGd7GoyTEu4KR3FGX79K8stb0bROuVpC6/LELz8CUzlohs2m+CeyeWD258o0HJN5+zf+T/iW54rtYBofGFWNhuVyQfThc5lLhSeOAwVvXuezP2v0QI6Ksx3hhDI67MiHrE5slre0lzy7dfERQNdCv1wW9Ror4CfPpe4hT5JRYvA8qQPRAyLVG9oQxYCmb1cq4+Zgl2L1xYKqdiSvFowA1Bc4EGmIgrOy/qU4xiLDYCGv7iJNsrohm6tcP8+yZ0I6xQKWAi8nD4CrlEVGAeT3PNgYc6jlnHUgBCfw0RT2CWnLq+/Cm3CZUmt05/dgp3EzhekbHiA8lpxHb3o/A53xMc17BYu0kbuNTN4PsJyyZy/HspfxddGwreXLi/O6zVeRrrH/PrNwTWf3wqf Q2LOa8br /dFPKuB6Q0gI8lirRO/QyRhy/BuTXW880nr5mmPhQNfHkN8K20FeXfmRjPyw/HuUjf+cU2mhuLkllvIDPyG0fmrlD7XmKLUYHjPrk3Ky0iYTJVcjn+uXk8Xo9dohKZ3w8mOwDymsi2gXRtYODz1WvdQyAFw7KGbRGFcgA/ebx70MQbTM87AY9+9t7+Xgq/zpFUWq7Sak0pT2C5ouFtKZTfTyNjsIHfuphol0WjkODtgf2Jp4RzwGDrOGSR5EkmBfOB1n7d7zYbzafBaQs72uh4Jok/PsnWYjQQzXgSjone7Iyp9KhkAURcMBU0OiSP+Atj1Gm8+CtOT4bZNtAKRzzwuu6sJ4ERa+14d96xLGRLr3FqoN9wUxa+Sf/hLtTLQv+Ax6GiyoNwtpbeIipwubioxi2A4Vspqx1ZtQzRFxuav7GI74Yg20puNeotbJe9JR5AgkQB6CG72orTvc87MGmNKyqBHyZgrC6B4ZmNQJhYSlu/4ki2pCeIRE5uDTMq2qnvfIXX/9hEe26vi1qO5cbMKTp71fHmEKu8VcaCcK0/a18QjvO9XRANx2vHJF7c+VtHIzJmuLHfOiSQP0= 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 __get_task_comm() 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..0459a141dc86 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); + __get_task_comm(context->target_comm, TASK_COMM_LEN, t); } /** @@ -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); + __get_task_comm(ctx->target_comm, TASK_COMM_LEN, t); 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); + __get_task_comm(axp->target_comm[axp->pid_count], TASK_COMM_LEN, t); axp->pid_count++; return 0; From patchwork Mon Jul 29 02:37:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744222 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 550CDC3DA49 for ; Mon, 29 Jul 2024 02:39:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E01A06B009F; Sun, 28 Jul 2024 22:39:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB1626B00A0; Sun, 28 Jul 2024 22:39:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7A006B00A1; Sun, 28 Jul 2024 22:39:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A8AD26B009F for ; Sun, 28 Jul 2024 22:39:31 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 614F6C0190 for ; Mon, 29 Jul 2024 02:39:31 +0000 (UTC) X-FDA: 82391234142.28.E93EED5 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by imf05.hostedemail.com (Postfix) with ESMTP id 8E596100002 for ; Mon, 29 Jul 2024 02:39:29 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZlL64ZNS; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 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=1722220699; 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=J+uQG4RKAtUTljj+c6PuEzvl8DtV0722F0vMFtL07WU=; b=PtjrkFnlN5XqjoUcPn8SQ/y782yz1BCn2PqOm7TrGCvGZOoRTNob08NvYOmMgVSVlD9Ya3 93fNEox1BhXJocJEgZTjdGTTfYATMhJfRtBi3Ub9MjJ0EGN6g7X9PqQ9cJZ9mXgP9Ta8LO X2eq7AYDAYDmr7xS/1ZqQrAt+E5BnVg= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZlL64ZNS; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.170 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=1722220699; a=rsa-sha256; cv=none; b=wZ6/SLEQNtRA2QwsaAgefEE1Bu8LxySZu0AneVqM9NRzMRvmuA9QTNXWAGT5NyV9Ft+Ued pz9fNyOFvDrZoqPG5+UUu6VHPQfB5XTp8EO/FQh1VZ1Nwk3naRb1FyLoaUj9IhBddGEcNT 1xl7QsNHCsFXP82obqlwPFY/kyRu7cQ= Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7aa7703cf08so2045616a12.2 for ; Sun, 28 Jul 2024 19:39:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220768; x=1722825568; 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=J+uQG4RKAtUTljj+c6PuEzvl8DtV0722F0vMFtL07WU=; b=ZlL64ZNS8UDqKxFuq26z7VoN3njNKdST0WbpaGqaXXdCoNdJEUNLD5VohTPdATRLn4 /1o5eDu/LeaGe70FQ5cC2iygT+NeP2MmZjDbykBuRezIVOtumruZUnHF3sFtAn0POEcb uvfDgiXVYau1J0fQVJGtWtThKfSQsNFqUTrzVYfQgIctnRI3vxOo4bSWOewlewbG0Tkj 1+3Pr7Yu3p9PfFDd2JjxaXpooEkA+qsepwgU5SqCop6gDyPh2H6Mrjkrb86fAq0j0Zm/ ZhNHf0iKuvbmNcPnZBW2EqOBZCLC1igTMMUAi2bsEQcJz6yPrRnI1AlnBjYwdJH+n7mW itlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220768; x=1722825568; 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=J+uQG4RKAtUTljj+c6PuEzvl8DtV0722F0vMFtL07WU=; b=h5dmlyjmHcq6MZGfCZWVDkw72+Y7nVB4nAkbVS9ZHLZ9rSXxNXs0yRrOjKsQGQ7tji +Z5onRPSzl9v0622cPFjLk66ZdDfm2nDTwFUwAQ+rn6T+neCG4kjZZk/Hom7Q5u2gbLd PHkWOzItVsBQTDTt/CJz/O4wjWMi75AlCUjhxgfsaFcBz/rG0BcvxwXsPKoK4aRh2LTR VN0Oo7cN0lG50A44sUIfbtKxiRTktCGhN03vZ/3xE0kxf87ReRjPfhX3SQfTEw9OcObn s5T9KBOWeBxrNM2N0oXoua0gWiKkIxEotAkI1wMAlNboRp6FLFu3pPq3bWI2mC3SqqAb jEJg== X-Forwarded-Encrypted: i=1; AJvYcCVJMkquiPghguXqicM5/ZM/voznWH67Cptd8RKjl7DSM8Vvnuvs5j3RUcwvedypO4nNGzJflitCqzIHrrb8jLwzN3I= X-Gm-Message-State: AOJu0YzBTZafdvcBaftpaE7H7EIHiTSJu1VHNMvuHYAKuJy8LfW/MmS/ JxGTWCItnYJXKJ4bh4sMgYyPy2YlKo3FcvHG67ar63Yn/fQv4pEe X-Google-Smtp-Source: AGHT+IGDDVacAHzuqJf1zY2UQsKDkDe/fVaez1tdPtuFhqBPLEHRkdQpCzionBNRtCrdgKFvX6YkKg== X-Received: by 2002:a05:6a20:d50a:b0:1c4:8bba:76e9 with SMTP id adf61e73a8af0-1c4a153afecmr8452767637.53.1722220768309; Sun, 28 Jul 2024 19:39:28 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.39.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:39:27 -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 , James Morris , "Serge E. Hallyn" , Stephen Smalley , Ondrej Mosnacek Subject: [PATCH v4 03/11] security: Replace memcpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:11 +0800 Message-Id: <20240729023719.1933-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8E596100002 X-Stat-Signature: dqb8p1fbhmgepewpih8xg7fkes19ay7c X-Rspam-User: X-HE-Tag: 1722220769-850977 X-HE-Meta: U2FsdGVkX19aDmrXX8XPn12cFBW4GvQQN6691LmiO2D7qNW+0fe1F9XdufJWtprzFoyNB1sbUWBBYudhiTiCZOReQfbYQsVb8yW4a69ltg/hW3XzLEpE1mf4QSCtVRWqyBvk3LY0kGFy0Nk9zydj2B9bjy0wmwYsRWOjNAnE+xL2lTbz9YoH5Vbut+ZczZNvENizqCaib/+q2MfTyhT9XQbXCSNToAfLqzbKMXNVxstV9Z2mwCu9HKV/pzRUSMiN+jLbmfIXABbnuKJ+ewaNw7mh/lVfTZC94iJXbbltnhVBLqGx/qsRxH0OF4QCSr2Ly8Pk713pttbvG2LT+Pmqtlm5Q02OGX2h37VolR6/8njM8UOLxYI7XZ9COaoBX2dYqimMaILpyuxGcxhBtQ0WoXSeeX9Tp8o6cO4mm0byVTsknpnNFJHT/cD5UPJRfJtPMMg0jS/M7GRH2Ln25XXxp0T5K/ju0L5tbh5lX/CdKrBoZnTsfEiNrhZxlktbUgAFLEeaGsBibRT/YQzEA64j4SkmeDi4UB5p0R6eziMDxfBky5GyZXEmkgZL3WC65GYcM6SWHSCaxvPzTcFgnrxagQiqa2/hQZGb3ZU/DmxXR2MxiPRz/oxk8l4gwdjPu1bMq2kRY4UB2g+dQIv2EUzErPBtdfRdvg3tZ85wbezavJbnoDjlH01UC/dn7DhKL15j+bCW/9nQpXwSvKOY6R0gam7H1Pc+9fqv36lSAqUsAShUQXwogPfbgs8w1FsgltbGiiFflA4BLLQ5EYoqdZn0tXuku0yjdmqgc4gprC/hgXYGCOGq1XWl6Yr5mG1Tg1sM9NfcUWD5eKBjZALf1PQIYrKxhVEFprR96SFeX2mrgQk1rEMREFSql8sxZVlWOBVM8T6XhOuf+o05mrl8AhcJEbFEOMnVX6lcPR/6uuh42tIAvz6mkOLG40ToHrjNxfL6FAq/VynJya6yciYZ2Aa 40bNR01v is4MxX3ghM5RMDDR4XPuJAU709QYSHfe+065bSkegjrID/xPJ4F3iJ1ve8OScMlDOkNLec4b4VobR5+UhCef/3/leQLdiwSIwsZRu/+GJQ5tRjXC+xH4IGQtOoTpBzutCvmKqJax5h/5NjK/A/FWUSgLs8tepL66cSBG0uKnkJ1TVk0YdFkydWisz06nAkE176e6eRs6FBvK6gMKj6gRxfiEEZFR7lEk1/imF8lc327BZDpvwJwZU0L95jV//i09Tx4p+kCmGaGfS4d+eMwUUm1jiy5Nt3ae75BBn8uVGHMCYTsGHc9or1xyXXMPjMSt2e+o+LKckNCpcJGbvV3G4teIIb/g22Rs55Sy083dgs82T8fEsketlS41jfjxo43RJ31QiJryb1Je8WiIsQkhvtiix32b8d1o7vT1ZSucJmrQkc5I05Xhs+4Cc8W0REBLVHgMKXdP5AFTKnpmCDrzsFVewWQV/CW9h5lq7GHhthYRS+BhHN36j/IGxAZg7ziBRq4KE1ChqV9Yt8WmSFj3P53zEtrojB8vUu0WxOYcrPYdw3lYq2M6Ae/AmliQFwWYIHRrcudEVoPBUPw7e7PWCwovmvdLwpdeSx5kTLDZUUakku8DO4PyOtQ1ZjEb4S/LdYof9ZkWnHrjTSgBfB3628DwZ7ccF4E3XMND4dbubn41PE2M5s6ph8bAcyWAOsZ4ENKzybpk6cIIfNs5YO+C8QzLIthOZwtEokj+TzUTZ5XlYNOV+qL/G0ppmfibr5eqGhacJ 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: Quoted from Linus [0]: selinux never wanted a lock, and never wanted any kind of *consistent* result, it just wanted a *stable* result. Using __get_task_comm() 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 LINK: https://lore.kernel.org/all/CAHk-=wivfrF0_zvf+oj6==Sh=-npJooP8chLPEfaFV0oNYTTBA@mail.gmail.com/ [0] Acked-by: Paul Moore Cc: James Morris Cc: "Serge E. Hallyn" Cc: Stephen Smalley Cc: Ondrej Mosnacek --- security/lsm_audit.c | 4 ++-- security/selinux/selinuxfs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/security/lsm_audit.c b/security/lsm_audit.c index 849e832719e2..a922e4339dd5 100644 --- a/security/lsm_audit.c +++ b/security/lsm_audit.c @@ -207,7 +207,7 @@ static void dump_common_audit_data(struct audit_buffer *ab, BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2); audit_log_format(ab, " pid=%d comm=", task_tgid_nr(current)); - audit_log_untrustedstring(ab, memcpy(comm, current->comm, sizeof(comm))); + audit_log_untrustedstring(ab, __get_task_comm(comm, sizeof(comm), current)); switch (a->type) { case LSM_AUDIT_DATA_NONE: @@ -302,7 +302,7 @@ static void dump_common_audit_data(struct audit_buffer *ab, char comm[sizeof(tsk->comm)]; audit_log_format(ab, " opid=%d ocomm=", pid); audit_log_untrustedstring(ab, - memcpy(comm, tsk->comm, sizeof(comm))); + __get_task_comm(comm, sizeof(comm), tsk)); } } break; diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index e172f182b65c..a8a2ec742576 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -708,7 +708,7 @@ static ssize_t sel_write_checkreqprot(struct file *file, const char __user *buf, if (new_value) { char comm[sizeof(current->comm)]; - memcpy(comm, current->comm, sizeof(comm)); + __get_task_comm(comm, sizeof(comm), current); pr_err("SELinux: %s (%d) set checkreqprot to 1. This is no longer supported.\n", comm, current->pid); } From patchwork Mon Jul 29 02:37:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744223 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 25B77C3DA49 for ; Mon, 29 Jul 2024 02:39:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B906C6B0085; Sun, 28 Jul 2024 22:39:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B40936B00A1; Sun, 28 Jul 2024 22:39:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A08CF6B0098; Sun, 28 Jul 2024 22:39:45 -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 8048E6B00A1 for ; Sun, 28 Jul 2024 22:39:45 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2B617801CD for ; Mon, 29 Jul 2024 02:39:45 +0000 (UTC) X-FDA: 82391234730.14.944A8C8 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf09.hostedemail.com (Postfix) with ESMTP id 570DA140008 for ; Mon, 29 Jul 2024 02:39:43 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KaejUm5U; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.179 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=1722220757; 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=QQdkC9XISn7BWPlTE5/iE7aUj/L2jeLonKoaBsbNpS0=; b=ahQnyn9e2wh4pJtbwCkB43R/mPG1n0GHq/bSV2KrVZJO1FVOHmUUxT4TV5GA7h0s5Kr5yR mKQTrFyj6N1P+mWIYg3YXszPEx5pNXuvWtOG+xj8UEmxd58Ep8/MWpzpKreFUMaZ0gApDb NQIerBaTrOKVqHNO0fuFcfMmWCUbPCk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=KaejUm5U; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.179 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=1722220757; a=rsa-sha256; cv=none; b=vWOa436xj55xzNQr90HhrN+/1ygjWo7NuNwEoMArCXKOx6eH8xZyakum4Yte1jMOQ91CHm TMruVTb5lSEv/zFHbgydh/cW6iM6x3RUITrn30zrf8+V+UGGbGQFIRlm4tjhhMusApC1X7 /WFN06Sd51r5Cb/TXl3hnN0lRvlxgV8= Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-7ab09739287so1461491a12.3 for ; Sun, 28 Jul 2024 19:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220782; x=1722825582; 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=QQdkC9XISn7BWPlTE5/iE7aUj/L2jeLonKoaBsbNpS0=; b=KaejUm5UPUsRElSnjdqwxWpYQMp6H96GPNEHpF+yRNwuhdPCKHSTtKJ+gnSMHzjtxf n8iPKcl9JzpIvjzdjJpxX0dDyZq9rJyuNOtdo3n6ak+pyYU/eB8YIy/UkwHrIZgS2T8x oVPaCFMYgsqKD/vqY7rlsB09X7zDTt9I+inJ6irabDvfosSsOkd4x5yWM5Ru1kXzmNoF 84RuC/vsaJ6FB2EVbTNTADyiJPWURLhcbL1OO7fM40g5m8AT0tg3x2fOjtIWO7+A8vXR 96Yi1ufsk23eaexhI9bRfFYdGd0I5ZSXJSEzTOHZonl/psixsBj6HojclRoNeQA3MiPa CwDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220782; x=1722825582; 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=QQdkC9XISn7BWPlTE5/iE7aUj/L2jeLonKoaBsbNpS0=; b=bQzvcQvztQ01m2N2XcBSOE2eJKf27lZQrXvovyMZf8dK+SkgBsP0e2b+Bc3EKyxJJ6 jbh4EeEYP937v8qvlOOt8EaiqJJPh17CW8/oK9NF+CqkIN+g6VvVBtKQAVinbyCilzFz GiCDOgKXYTsWSFAuYVBhRAMSNPKYIvUT3HB3tlx+VePKCWo1V7XCDqN7C6isMQmASV61 3YtZrGLz6IV6tvF7dlLvMnzkmY3AW7FilpOuFUNm8FcslaTOnTSpqXOmmYe8nCh2k2/J 3jVWHpeZnTIGIcj7PBA0Z0OK6uV6wrtTuBkFcJuMz4+3YEMm57sla7GYWJpHuDDmPZml A04w== X-Forwarded-Encrypted: i=1; AJvYcCUrQTG0H/c7F/v4rS4D5oQOPf/xGM5l/Nsk2pKleFrKCaMs8eVLDKtIGOVIHFn/y5ydjouaYtQXFVnp7GobEP3lCh8= X-Gm-Message-State: AOJu0Yzq/LHuRjd+2dAhaLhHLdGYZNuNk/JUOvzh4uiuuJjKgDRlmIRz pOoyO9R+gvRKLXYxYHMGLVP5WqsiLku6YjKviJ21ZDqDQGA5Na8S X-Google-Smtp-Source: AGHT+IEB8l3Gwpw2EoLQWPXs9e5ig3IiPuxqtfGfuMuw62eXKcBpM2d5t6Uy/en6iDAcfcY1gaCpLA== X-Received: by 2002:a17:90a:6581:b0:2ca:8684:401a with SMTP id 98e67ed59e1d1-2cf7e5f27a9mr4176294a91.32.1722220782084; Sun, 28 Jul 2024 19:39:42 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.39.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:39:41 -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 , Quentin Monnet Subject: [PATCH v4 04/11] bpftool: Ensure task comm is always NUL-terminated Date: Mon, 29 Jul 2024 10:37:12 +0800 Message-Id: <20240729023719.1933-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 570DA140008 X-Stat-Signature: 86f7tbrhpp54h9i4ttfnarezy16n87ok X-HE-Tag: 1722220783-413538 X-HE-Meta: U2FsdGVkX19zL4ifaZcBTF6YokEwCLzVWNlD/26aN4fsVRhQpyGEZYGvSMNSBPk8DJq8uWZzKjZqfANtWSc7pRUkAlu7NJzBXzN68+zQGbEfd2aC57owSMYTUgSrw8z1rYzWUf4lZ4aAuKBkyTtk8A1gbEIJczNWRdq0XPLra7/92Endgu67sBECm/XWTIIZbJisfJjbWM4pHCRPaqcdz2NldM65N8sQRCy+VgWnAIb7YHk/s+R56brQUghxwnnDkpy42OaGxb9/3XuqOfIzlkLo/hv+KP4BVd+xrAWpe1cM2q72AJT2jVea6Yf3iG2zS68CM1ZVjMGyO+WHUCxrNV84Gmk3TRjx5OYK16y2481E828SygPm/tYwVh/2MfRrwgYTIISz5xLJlFF9mukhqgKvs5jbM/6NY8TXa7fvfntiIyGBvqWf6154b/QdG6mSei011mAFPxQ3CNGKOnDwPvyheS0Mdq2hvsIgLdr9HU72BvcSi8pXZ7RYu46FckHM3+pQvh+HRqEbRZxyqL+awb8WnIpG6m2PJ9xS5YL0KzzTS391zLnjhtkNPF9cHhSs+s7Oq2l8oBHYGkZwZhhulzdJlyV621zrZn6A2M4hgUKGa/akNcxJWTqPUpzobI71Rj+hxDnp4MllUdlPlLCHA0cCefHDl0xkPu8Aa95v4GNTbOAMFAQaEL8LncOgtSmnidMS8N1miGIB5dfrNrIWQCrEARqQpZkEAneKl2LhSqEFmn30JDaM9R2o3qrSo43QEvCjvfDWSBUjgHkM5uut9acDvXVLJxflOqIKECy14Ddg2H/7BWCzO+OaZjJsQuOVn1zkzt7H3OhJPOuNcUbsNSqRYoje657s4Ozc8dLT8O55sgrgOESM8g92aKl9lmG2akLmbWbBFN8L9BytoIq7Saq03AH1tVLQ+P7cRy5qyaV0ejpMl/YlSVtFzf3HbwXoD83jnbn/gO6Mr4V1GON H3ejVgo6 9DfKF7ZqJc56JidyEKNGOCGqXXstMJv8AbpojAXxMW0kWjaGmYgFqGOqTGzFPjkkaDcwaRBey4OmCdydy005+iwF3TfBB6GBCwcotcF5ITH1Dqjrj7U3IFENgF6uE85OOLIs225fkSYUxLwbeC01JeJSx++Rzt7Hv/6iH4cXTQyBRg+Rt59QUOSGDm4CkVKfw0fMrmN3VhtClq49m7C4H7fJXFga+lb5pmpaPtzXvu/Fu3z+D0x9SQyQqIZugAidAP7UqBkwb1d95fsQ4vULWI6xUthnRQBkJu9A168TJYGmdwbYeKwZ2pwZSFQzh+Aj+U/1Wo3WVgB56sjfbCXTcHB1JV2wTdJjkJ261c/LQNSpib4/fUJ0QRCeHV1tRx89QXeQvJh8EETVbmyHOUIK1ea7FxnM4CztRmkIm23rSDYjx73yEvd0aAfvu3tA7IwOw6yWUB/yroRzTm2xFPgdux+mprz8z14I0Yju/lzrwsfvd/4tXlbdIrEVlQ8EP9LPpJQc4acKNL44o6zs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000027, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Let's explicitly ensure the destination string is NUL-terminated. This way, it won't be affected by changes to the source string. Signed-off-by: Yafang Shao Reviewed-by: Quentin Monnet --- tools/bpf/bpftool/pids.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c index 9b898571b49e..23f488cf1740 100644 --- a/tools/bpf/bpftool/pids.c +++ b/tools/bpf/bpftool/pids.c @@ -54,6 +54,7 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e) ref = &refs->refs[refs->ref_cnt]; ref->pid = e->pid; memcpy(ref->comm, e->comm, sizeof(ref->comm)); + ref->comm[sizeof(ref->comm) - 1] = '\0'; refs->ref_cnt++; return; @@ -77,6 +78,7 @@ static void add_ref(struct hashmap *map, struct pid_iter_entry *e) ref = &refs->refs[0]; ref->pid = e->pid; memcpy(ref->comm, e->comm, sizeof(ref->comm)); + ref->comm[sizeof(ref->comm) - 1] = '\0'; refs->ref_cnt = 1; refs->has_bpf_cookie = e->has_bpf_cookie; refs->bpf_cookie = e->bpf_cookie; From patchwork Mon Jul 29 02:37:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744224 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 37D50C3DA49 for ; Mon, 29 Jul 2024 02:40:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7B466B00A3; Sun, 28 Jul 2024 22:40:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2AF26B00A4; Sun, 28 Jul 2024 22:40:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF2B86B00A5; Sun, 28 Jul 2024 22:40:04 -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 926C36B00A3 for ; Sun, 28 Jul 2024 22:40:04 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 42D791401C6 for ; Mon, 29 Jul 2024 02:40:04 +0000 (UTC) X-FDA: 82391235528.24.8E38E8A Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf22.hostedemail.com (Postfix) with ESMTP id 685D2C0003 for ; Mon, 29 Jul 2024 02:40:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IywBYpxe; spf=pass (imf22.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.177 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=1722220732; 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=8rSpj4+mjUH2uIm/J6/DitPwV6C8fJ6cAywoYkpJrFY=; b=KY5xgkv5RK0LmASaUGK4k5JqKF1Qsvw2vhq9E7HENsuS9Fb7A07Huq49YzpyPfLKlk3csm RJUjlGRwx5SvZGX5/GsjEMZoVxV02I9ri7g4yfG27ben6BiX3mWMoZLo5iYEZ0AapkVWPs zqLimBYaZ+SnMnGx8w7XPsajZwXjY7I= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IywBYpxe; spf=pass (imf22.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.177 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=1722220732; a=rsa-sha256; cv=none; b=ycYPEii/5WVIoz14B7H8PHbqjUXfvlTBfFTjj2/bt7KV10OT5rnii4AwDMYH63dG83wG5N gKHuna8OOvWLR5XsNlzH1rHm8BAzikEtQcqeJs3xg0srgvVw7YjDB8ySMBVW8p+PiZGW+b BURr3mHCw3KuclfdYhxRs3T9/mi5xX0= Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7a103ac7be3so1445404a12.3 for ; Sun, 28 Jul 2024 19:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722220801; x=1722825601; 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=8rSpj4+mjUH2uIm/J6/DitPwV6C8fJ6cAywoYkpJrFY=; b=IywBYpxewk39XDOR+KqqJAlknasCulNgi11gogPy92fFoJMtR9OEV6zybIcDaMgsZ7 HyAI4+3AXCSJd9BHfyuODgZtkPU6cGKYuGK4aSXsoEZ6a4vXK7TpEPs+Lzhk1zwSrMZE eOqU3ZLw20EssFBxBi1lEckfzQI/EvlMPropSzH8dbbkXbS8zHQF3Y6ydszfKVp89SxX wO6DqNv5UGUHpq/yCdwxBkcO8poLrQSZjU/wEUL9kpJtLKP7RXfwrMvxozfa8WmH7KrG Zv7vzq8/PuqT+UctFqCCrO1Bz2SmcmYKfjdwiLE5sO3Rw4p8zRi8Ry+npeK4JwOWiukH TIQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722220801; x=1722825601; 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=8rSpj4+mjUH2uIm/J6/DitPwV6C8fJ6cAywoYkpJrFY=; b=J3iU78JMeby/+vm7HRV9M7Yt2EHHpvv9n+a/+FpZIof0r1Q6fR0/+6UTtfNkx1FSZm 7ZuL2GvzIdWntOpWXnAmuyAKvoqte3+oWZmnCaVJfRpDUz5W6TcigjQuhLepPDv/FoT9 W/oNkXHmvGWVmUld+TeHdlOKEMj/rB+Fav0fecbhsDa3YfS53ZPueAoxC6LwoYO0TPcv zW4ft2vRyT2F4d4wrjZA4t65kmfxuH1Zg9sSLWFMwlW7EpUf7s5qHHBAhjm00JuJjVxe fRPHBfUhIcSu49YCVSW9g6G/VHQ9kqLgaM/N1ZPPymvmKMa+VKzOmj+2KxEHt4emLn4n VrRg== X-Forwarded-Encrypted: i=1; AJvYcCWIPh7P+WuE4KPR1hRbeQARznmFN//C38VZC0Xs6yfw87Rq51E9uTlpRyP94MLe7C0zNbAxpQ5xhJ27zdqP8G/B+7U= X-Gm-Message-State: AOJu0YxpDFjzsSsWHlWLHor2wfoekq77BXTwUn971jLU3rpH9Zqwnv1S Hx3andM2Ka1+41/RDnwIYnAKK1N9vXvGJ72gY2ijkPePdoAzVWah X-Google-Smtp-Source: AGHT+IGTYP+13dgbaXUTcOaiyJPHukRZsfD9pPSgLtBCe0th4rvzpLqZDHRAsUFno3V6NU5AaOlIiQ== X-Received: by 2002:a05:6a20:a105:b0:1c0:f2d9:a452 with SMTP id adf61e73a8af0-1c4a12a2e61mr4874235637.13.1722220801130; Sun, 28 Jul 2024 19:40:01 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.39.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:40:00 -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 Subject: [PATCH v4 05/11] mm/util: Fix possible race condition in kstrdup() Date: Mon, 29 Jul 2024 10:37:13 +0800 Message-Id: <20240729023719.1933-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 685D2C0003 X-Stat-Signature: 7xauf8t6farby7awrq5koc3mq18bsprq X-Rspam-User: X-HE-Tag: 1722220802-855844 X-HE-Meta: U2FsdGVkX1/kTWqJD/FPpIgeNNz2Z/8yTkXEmgdG2gtpce+4spPZ/iDGemMn6/AyGGwEjSz36NTynHPiUsdVOhWgugZ3yAEHVuMSe9TlZOiNW2bSHxVmTzLDDC0st87/YrgdNh/qhEDizk45+6Q/pTfGnNIVouVsrw8seGd1r+wLgwlFEiNpcUrQ2bBhXlFhMQ91qfwWJcoU6XLZVdSMgPRfs55v7G9XTnJI96PdSfN5d7AW/hmYa80+C9EsUsU/MbXhdd9bVWIzfrjV7QK2g6Mva3QzZ2GgyLKI2ERvBTeFnD21lUYq9OrELRG5tvxvsLGM8KoebBdI5mmZr921BcRO9o637GcfY38qSwTsTw4GUjzbBoIjv19/LihmATbBZu39pXMPtlEKl+ExA50hwDYOqDnc7j5zK4KBePd6LhfR2ORcpUfSZtoY4wEluKf6A/vHULT4oVtl8sF/bdeP3wQUA+s18JewCoLKeof28greAZelDlfHYhlktxRLZRFmagmdadPKHGTV8kWPLsHDhieRtMKk3jNS9yUoYYMYnMufIztUT5UurYGwEGPMCJZn9ifZGapRjimC7pIUMzXsV4shWL5tLluebcJOKDYHNNForJdsj+BGo6Lil0+LupwDMsyFOtpYI1pdaKwAH5tqB1txEmsvZT+pR8hsih2mLHhmDBjnmirTfskqGyL/6WM05sv47K1w06NzHEky/eCow+304iy65k62cnWyMHjNo+hKVCd/Uc2ZWwDUJJy1YyLpeM7Ypc7LZIE8DQb5oydkfeArYOol6oobEw8EVHn5fdjQcU6atZt2zULcltNs6c/mNmtCPwLwqdq4S9atRYW8ZZotmO+LxLDCWRgVX4LaTJNyxo85+eM2IwBm3Rc7p57/BnhKhAlsNAGcg7bDgLj4dAhnqK4Q+P0sQ9+od3cgpzgmO4TVDkdJzduL+Y3PhiZxyst6T4UWR7h4jPo2EWI b0JHTRzq 7ew+ofFhXHFs0S0faNWrUFcEJaZFZxpRoq3TQfUzoBcOwNGW3wr4jgWORGoKfkzv1EDuz+fsjCbK8gROhjKDfXTFKRFzvv/5nf61TrmBj2IRdyXmmgtZRrgfalXokEBjMvlYUbMQvcyyujZk3/0GwmkSxkuyNUncXObJrhZQ7WMPB81DpzRHyFhMdg7SpXKqcriaSRYX2N5jnDguU4DiBKIiyD2axLW2BwFtz+kqTdeL2Q9FjXdAO3LgKbnlLtDl2MNRpOqytb+ZzjvRbMioXoxLvhePhOPvWmDuFXEq8qnve+lqWF2znZqUEx3W2QFSAUlUOb/NNH3Bkz/2EOVwL8nQydHPRZ0DypIRcUwOEpxKypOPIcKFB52V1bjgqvUs0ThHxykvRHSdwC+IynPGqsK4iEB5D8Gmo3DE79iRuySKtaZsgxrS4iCbDKP2OwMmE2da4vT2zSmpo+1br3B+brKSCBHpeCe82TW104HzBp6Kia5TVDcCU3cBlFnva9fTJOHHKk1+O4lVAAN8= 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: In kstrdup(), it is critical to ensure that the dest string is always NUL-terminated. However, potential race condidtion can occur between a writer and a reader. Consider the following scenario involving task->comm: reader writer len = strlen(s) + 1; strlcpy(tsk->comm, buf, sizeof(tsk->comm)); memcpy(buf, s, len); In this case, there is a race condition between the reader and the writer. The reader calculate the length of the string `s` based on the old value of task->comm. However, during the memcpy(), the string `s` might be updated by the writer to a new value of task->comm. If the new task->comm is larger than the old one, the `buf` might not be NUL-terminated. This can lead to undefined behavior and potential security vulnerabilities. Let's fix it by explicitly adding a NUL-terminator. Signed-off-by: Yafang Shao Cc: Andrew Morton --- mm/util.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/util.c b/mm/util.c index c9e519e6811f..41c7875572ed 100644 --- a/mm/util.c +++ b/mm/util.c @@ -60,8 +60,14 @@ char *kstrdup(const char *s, gfp_t gfp) len = strlen(s) + 1; buf = kmalloc_track_caller(len, gfp); - if (buf) + if (buf) { memcpy(buf, s, len); + /* During memcpy(), the string might be updated to a new value, + * which could be longer than the string when strlen() is + * called. Therefore, we need to add a null termimator. + */ + buf[len - 1] = '\0'; + } return buf; } EXPORT_SYMBOL(kstrdup); From patchwork Mon Jul 29 02:37:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744268 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 AA94EC3DA49 for ; Mon, 29 Jul 2024 02:44:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1816A6B009C; Sun, 28 Jul 2024 22:44:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10B826B009E; Sun, 28 Jul 2024 22:44:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC6D46B00A0; Sun, 28 Jul 2024 22:44:32 -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 CE0306B009C for ; Sun, 28 Jul 2024 22:44:32 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6A24F1602F1 for ; Mon, 29 Jul 2024 02:44:32 +0000 (UTC) X-FDA: 82391246784.14.22474BD Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) by imf13.hostedemail.com (Postfix) with ESMTP id 8998120005 for ; Mon, 29 Jul 2024 02:44:30 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IWEBgque; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.179 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=1722221017; 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=hxss6iSMiIilMwCNJtHyPtBSL44EBghXiK4U5v9w5a8=; b=QAM1VBUY7DNR1lZGe+1Vw2pyzaX5qBS9VFULGx83CKS6Lud4NuYeuIt17oXZCAPHhdkVkk 0+2s/HRAcrNgPeGTpHe+mLdWa12BsSOQ7IFFQ0ugBX0fppzHiy7TlDDAw3VBUUpvhMUqCc znTVsDdEhYBdBc2Y+nVBRw8qIaXB7Us= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722221017; a=rsa-sha256; cv=none; b=6JX+tsCPgi5nYDmdlkXGwxKfZUlFExMnIBL5zEv1aFclWQ0foTgirSB4OfALjioEEfQCYi NSbiNbcmH4TL+Gn3ashLc0UL/WNFoMTjIu+ILLpQ+Pimp1xPDkM+BwluhskWLxQa9oJsgp A1BqXOXVAantTJajE73g+OHQ/P5gODw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IWEBgque; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.179 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-70d19d768c2so1926184b3a.3 for ; Sun, 28 Jul 2024 19:44:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722221069; x=1722825869; 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=hxss6iSMiIilMwCNJtHyPtBSL44EBghXiK4U5v9w5a8=; b=IWEBgqueO8/h28dzI1K/+xr54RaDob5FRCPVNZGE6IG8SOpUBsNZYkOTzdy9EAIdVv yL1fIAAuG3JEXxiHJenrtkEz+nHzBRjAThYKsa/z6axIpXJOcsNJCfCO9rUyxFs89p90 DKbiOa6nF8VFjrITmjarYd6Xw3iW9/s3HHXLTiEb5Ef4OHtVwx/0G+ZTUwSBLis6F9lu 8bbIGaL0JL8w1iTxdFpilubN0jWgCd9ppC0leptBHl6mJ/mpdWdKkx9FyaWZt7EnJnsW KTmOVLwq4zRUk8ZdG+/Gmc3upZ2opJSVdMFwjEEwbqZbnyOKLJVfcRnTFgAibyn3x6Pf j50w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722221069; x=1722825869; 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=hxss6iSMiIilMwCNJtHyPtBSL44EBghXiK4U5v9w5a8=; b=fo+XN5iGAJ6n3AEhmIT4/Bv+Mt/3rvLHf4r8FNsJ/hlQqM4eL9fcFKgYwZIXeCNEDK sEagbUGLAdssxk/d3V9dm0Yp6pcqXtL79kcxBOgF3EX1i6hKhS1Cp3oCRRTvCJ6KybkP ZtIo3rK+SSBxx1K9lcKqkD5JOIcFrJAPhpq496rJejqQjACEw89vOR/Ej7koVmIiPJpV wTiCYPRpvAOaKBicACzM7UaAFrkKn6/vLoeXcLmy3HWmBHyWdK0TtsiiQRX+VZ1YiXSA /bnPOKvIum/86PZE/mJdFPAFkSdMkwCd2r7n8vaROVzP1fc3rA5Do/7+EZ9C3vqfv/sh QAGw== X-Forwarded-Encrypted: i=1; AJvYcCVr6aFYHQkj8ECO+6h4MsqEgx1rdMsoFdhx5gqBwFHMJvCz9Uva44MSS8LkNgOO118IVElMpQmK/Ujo8dtF0MChC8A= X-Gm-Message-State: AOJu0Yy9ObE+1BosGKxJyT5Jw05L9x2L5dBSoYNpwOyFQfdJnypdKunY lZ/szPmbYZikMOY7giM6BslkBKiyoZ8BONP+j95uT4i66bR4Te0E X-Google-Smtp-Source: AGHT+IG7/eKYXg7QfYOb1CdYS0BMtkGw6Mkjs56lIRKp/S/546Q1z5Hj0Wkc3TWWQHawrwJ+z6MQVw== X-Received: by 2002:a05:6a20:1582:b0:1c4:c7ae:ecea with SMTP id adf61e73a8af0-1c4c7aeefb4mr1212793637.11.1722221069087; Sun, 28 Jul 2024 19:44:29 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.40.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:44:28 -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 , Simon Horman , Matthew Wilcox Subject: [PATCH v4 06/11] mm/util: Deduplicate code in {kstrdup,kstrndup,kmemdup_nul} Date: Mon, 29 Jul 2024 10:37:14 +0800 Message-Id: <20240729023719.1933-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8998120005 X-Stat-Signature: iz3sbztjz8njsxakh49ndsut1c5iqgue X-HE-Tag: 1722221070-716670 X-HE-Meta: U2FsdGVkX19PQNKgRoJnNql99MCCgr6ROMR61diAaA7QDgszLEFn2K+H68pjeqAalLfb9IZMGklaDDiceMQqhuvLxpK98PNlL53kzd1kMeFTP9flu6Q4lIJa1NlJXGZB2la8dNeziQGR5+UDGJLWbocF7hSbclEoTUdk4+nAIVCc16IR+xHoGKlNJE9OKFXfvdcOCov8dot594P0QuAhaxQsGzlfTJdDX9pbht4tTTP+WbdooGNKv2kf9RT0A0e22m482RtZTL06GKi9jjqFQR4jyD66AOdjeRJpi1zvp4dd6UKFKl9EBb+HFieL70lksZjr+S3EyqHn1C+2zZoKuz/qzkHb75Q97ssvsL/yJHDvum5w3T5oOxxNqrY+Ne7JUZiZSWW+V5fQ/cp0ZVQ2UwRXKn4TxltKkaCa7TzklCUqR9XynRlbjSZzfIbhV5jEZJdwTWeo7QCRI5PyIIrOpVAQN9T6ruC7Uc7yvtqG5Dtg/3GIa7PMHd0t3rAU3SzMNiXMXpGYxGES2NhExroDWq+DAsGo4VPt1xABHPNoylT0uS6diDk5wn/MKTIs0i1bCnDGkAjMzAtRW0GS1S9dmonCT1IPcl9C9UrBXC/3J0sGTbhp/8iPRYSozIzcgdFjFFuPa6KVUiwKi5wPLL6xzca8BVDzwW0tpvFfFRXTqOord1mVyEY0iUKVVntr6vCq6lkSqJLws6Qv99xw2i34ZymoNINz0CF9IJI+HU1nrnXYAnA6bcm4KVjLkR7bIscTajAosBxRT/LgKkiMm4HnYMDGhias/W2YSovutjkh7QWyfjNEudZqGwtAjRSCjhJ6koudhOW0r06jPDdNFmC7a69f159aYSg8PrhfBnes44+2W0rO6hNYUVll4FOHLVwtFshAgjbNbD1w75Ve2qYhE86lJ1PIpHScVDHXPp3TRMhFdOnXdccFWA5Pghgoa0ilRslUUXw/w7WvBOcRWZY CNHjztxr lavMss1ilo1bJ/4IhsRIRbgJdWs0yRpEDygmfAsnZkjbK9do/Ua07LOV2cdQ/TZ1LgCwbTGvvSrt2kHd2n0o8qA5REqFVSuz0pSYoUOlqoFkJUXDt15BQiZ+eF8oYCoOZ7CmZmhPyFH1hyNjCI7t71TT2IPXtvD0Z3IARi9mp3hHLQoIQ/iNgS3lOYIqUSMCkIJCoQDpSEOsWvdHuxGKNGaqBiPr/UwBRQGPXfANYJIDLTYj3BikBs8Iqach3Zvjb5si1oOdCFqMsEOLMPw8OdS7ZgqPgf9eHCnQp40bombIIQBKtzrn7BF3k/5UjS2neCC+r+xcwSbAv7MSpyIkiTYG5+afEDsq7eHVnHBEjDAa2aWnYqlqcQ4X29XqL5dY3UmZf7DND0ZQTXpC1b3Mn7uUTR1GiB6un2PxVZVku99uPzvwuy8fCx7LumGAaBMuZZPLbMttWDruaFMSXnqkUgoMq+eSMAX4+4MfWq1HOBJ7ferjdJaRX1mdUvYSE/W+tK0AFBxJXPGIIJ1BLkcAKmOCHWJ83Ew0QO6jvUx4PgqO6npR5rUyBI21ouppzwOnwMGESbakHV9JHNK//2+yMJ/Q4LfZvde+umnyTFsCOid/Jfn7llyEQMmeJqQQ+Rcq4eTBWNdPg6ErCR2s4mq9Ja+rDmyDqs8yWXNpjsiNGpFlhGyU= 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: These three functions follow the same pattern. To deduplicate the code, let's introduce a common helper __kmemdup_nul(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao Cc: Simon Horman Cc: Matthew Wilcox --- mm/util.c | 67 +++++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/mm/util.c b/mm/util.c index 41c7875572ed..62a4686352b9 100644 --- a/mm/util.c +++ b/mm/util.c @@ -43,33 +43,40 @@ void kfree_const(const void *x) EXPORT_SYMBOL(kfree_const); /** - * kstrdup - allocate space for and copy an existing string - * @s: the string to duplicate + * __kmemdup_nul - Create a NUL-terminated string from @s, which might be unterminated. + * @s: The data to copy + * @len: The size of the data, including the null terminator * @gfp: the GFP mask used in the kmalloc() call when allocating memory * - * Return: newly allocated copy of @s or %NULL in case of error + * Return: newly allocated copy of @s with NUL-termination or %NULL in + * case of error */ -noinline -char *kstrdup(const char *s, gfp_t gfp) +static __always_inline char *__kmemdup_nul(const char *s, size_t len, gfp_t gfp) { - size_t len; char *buf; - if (!s) + buf = kmalloc_track_caller(len, gfp); + if (!buf) return NULL; - len = strlen(s) + 1; - buf = kmalloc_track_caller(len, gfp); - if (buf) { - memcpy(buf, s, len); - /* During memcpy(), the string might be updated to a new value, - * which could be longer than the string when strlen() is - * called. Therefore, we need to add a null termimator. - */ - buf[len - 1] = '\0'; - } + memcpy(buf, s, len); + /* Ensure the buf is always NUL-terminated, regardless of @s. */ + buf[len - 1] = '\0'; return buf; } + +/** + * kstrdup - allocate space for and copy an existing string + * @s: the string to duplicate + * @gfp: the GFP mask used in the kmalloc() call when allocating memory + * + * Return: newly allocated copy of @s or %NULL in case of error + */ +noinline +char *kstrdup(const char *s, gfp_t gfp) +{ + return s ? __kmemdup_nul(s, strlen(s) + 1, gfp) : NULL; +} EXPORT_SYMBOL(kstrdup); /** @@ -104,19 +111,7 @@ EXPORT_SYMBOL(kstrdup_const); */ char *kstrndup(const char *s, size_t max, gfp_t gfp) { - size_t len; - char *buf; - - if (!s) - return NULL; - - len = strnlen(s, max); - buf = kmalloc_track_caller(len+1, gfp); - if (buf) { - memcpy(buf, s, len); - buf[len] = '\0'; - } - return buf; + return s ? __kmemdup_nul(s, strnlen(s, max) + 1, gfp) : NULL; } EXPORT_SYMBOL(kstrndup); @@ -190,17 +185,7 @@ EXPORT_SYMBOL(kvmemdup); */ char *kmemdup_nul(const char *s, size_t len, gfp_t gfp) { - char *buf; - - if (!s) - return NULL; - - buf = kmalloc_track_caller(len + 1, gfp); - if (buf) { - memcpy(buf, s, len); - buf[len] = '\0'; - } - return buf; + return s ? __kmemdup_nul(s, len + 1, gfp) : NULL; } EXPORT_SYMBOL(kmemdup_nul); From patchwork Mon Jul 29 02:37: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: 13744269 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 F28F6C3DA49 for ; Mon, 29 Jul 2024 02:45:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 83A876B00A0; Sun, 28 Jul 2024 22:45:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7C21F6B00A1; Sun, 28 Jul 2024 22:45:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63C566B00A2; Sun, 28 Jul 2024 22:45:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 446DF6B00A0 for ; Sun, 28 Jul 2024 22:45:49 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EE90C1602F7 for ; Mon, 29 Jul 2024 02:45:48 +0000 (UTC) X-FDA: 82391249976.24.4872A4D Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf18.hostedemail.com (Postfix) with ESMTP id 27A5E1C001F for ; Mon, 29 Jul 2024 02:45:46 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RlBa2opC; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.41 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=1722221121; 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=K/nz1JHR4z8p+ajw1D912vGA5V6XqUcGmzMFKN4JA2M=; b=r17YD+InJgfp35VD5GvmuO+VNyRuvdafGRRFXWbWEUyHqfngDR9QSLSynmwxvevZkNeOBY 1XBq85KXxEwG0k7XrgCSpQeEUQOyZyNsF6fOrAlSMHvQ8gkX58YvEoW2jolN8/wcxt7QFH 7ZwRT5jYptZ26TxSr3leXWj5QdcAWbA= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RlBa2opC; spf=pass (imf18.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.41 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=1722221121; a=rsa-sha256; cv=none; b=b6+t52m+xf2YHIDD+e7AfzHuZjC36Rj4gF9K0JtZudEJ7xToCJTO3ewaPxmFmm6us5MuLO Y6CP+iPvMYtHcIO9o1rnLckhJc1iEZ5xqczWCt8c5L37RnlhBm+xG70tjjaJWeajEbcUQi 0t3aClKClWTUtsRCgF8Ncob2mj3AosA= Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2cb510cd097so2074537a91.1 for ; Sun, 28 Jul 2024 19:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722221146; x=1722825946; 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=K/nz1JHR4z8p+ajw1D912vGA5V6XqUcGmzMFKN4JA2M=; b=RlBa2opC6jdHimdXVLuVYFU9K0JNzMQmMbZbx7dtZpAh9K60GATllvgCAuiC0NHfYs stGIfJCOp+Jz72Wxoqw0yoIxKIQ8AdofE/rZCFUFOxG0ksxfX1n5tNeOMfr0nOZOHDgY IgMDqEGjXUXBdsOuhFVeBOoG++H/AI6Ys0BtqmxSQAY03+f4bfVahjhNiKvrtC4EJTUw zH6NkoFXRxFvzSCbHws4gIpjByelWN7dRx55y1J1vKwgoQ4jsdGswynSObm1QBRTpoQO Za0r9gbFN7NHfmteuNowYuZ+9uhu8+samD64QeRTSH1qsaZoN6Rwq+LlnlpocXOsXK7c dR8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722221146; x=1722825946; 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=K/nz1JHR4z8p+ajw1D912vGA5V6XqUcGmzMFKN4JA2M=; b=IGfUZ+SYwyW1QrGHLv7yvJifzpsLiqBtNlmpctBoCkwqtxwJsMplMMErutpCAndElP c0d1d6o/jGOz1nZZ2zp6p7TntmLMpFe3kYWDTtH+QMpCYsFaYB0hLEYnAfmWsv9RWyki WuE2B2CV1M/3FOm9AIJTs1qW0e9XIbD5h7z1IonTmo6errKKem7r9sfqSWao0F2YazHn iKDY5RCJGcvmMw7A7ps2KCHuCCHZjm1jl7r4sopoJNBW5kmkZmGP/A6haA1ZEJ23xmWl 8YeJQuP4xztNKwVlRwnrkWMAbK1Z6Qslxv+YIVb9iOXTXY3zzGMzKJavlJCiLLX8aDZK rmjQ== X-Forwarded-Encrypted: i=1; AJvYcCWrDWdOgmCvBezS4ubZ42Iu3ETEtnWf0niW6sftA2Iyby/VPmGg/mRfFOzXrVLfQDThTARWGi2Qehry+NPhe3uCoC4= X-Gm-Message-State: AOJu0YwFKiLjn5OGhKzUaGn/2E88VpAD0WVyXp7ZQOiK2cupRy0KPT/D SSpULfYpqO/xCyipLnQ+RMuJZy6OWbcYY89/sNCtTNWwCDV5w4Wf X-Google-Smtp-Source: AGHT+IENkAKdnpSBtIYs5HSWqyoiT1QcCfPMYBJH+JoZ3TUHyUdae/0TZfvoMrDMQbplggd9XcCiAw== X-Received: by 2002:a17:90b:4a03:b0:2ca:4fca:2892 with SMTP id 98e67ed59e1d1-2cf7e095c49mr6901128a91.7.1722221145808; Sun, 28 Jul 2024 19:45:45 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.44.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:45:45 -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 Subject: [PATCH v4 07/11] mm/kmemleak: Replace strncpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:15 +0800 Message-Id: <20240729023719.1933-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 27A5E1C001F X-Stat-Signature: z4x5eiu6y9xf9i1q9poa64ztuoxbj3fx X-HE-Tag: 1722221146-686612 X-HE-Meta: U2FsdGVkX19E2bSsOjYWVvgKE7SPzFFXhs1YLmpJqDM9dTpZ7I8II9yx2IMyCfiAyAmP+HzBdiCVyWtsucOQhdb0E2lnppnIdrnNdHLCeVSE3tilu7Xs5YvzkPd/zhhV58N0oryQEaH/XjwpaunPTHivx8VKbMI+/UHep8Cs6SUp2XVZ5t0CMzVTCjMCg8k7KLFJ/tXIKee7iFnQYYCX+XxLmNX9DrygSyB5bNn/mo3EqyyF4XN0E+hBE1ZoqDmdV2quWODkQkkSyERIk+kyj8i0oST4Pj0TPwz9PEycsQZ20TYko6XVsimVgZ3vFrh5PlN6MMqUUgpuwLWH/B4z6cfio8bD5YJ88lGdWXrfS3krlbjQXPAkbpdjRAuP5D5ZOCkvFt8iMNnhO7kSi0jmTCOcFF+Jsdc4kKdjVqyfnamlOJmqfpmXORqE9KTovGkrZjzGAZ0R0+9wND2tB/9cTDsRnjgwsRyw2IhEOGBsRHMTTOxYYb4Mf34LQj79qQGt9r7ObbrvaSwiRV4URZwRmmdNvw9JLz5pnR6ZCktB2Bc0ivdWmkzhdHOJVk+SBsSoBU28m+XNM0ZnQUHTr3mt39Ycfs/sgCFi1/mRtFBdThbv6GUUtmhzTfiVqCghH3t65EPYh9KeEhEcDwAUoWc2+Kw0Vpj4DUxQqcXZHKIduKDo7Np6KIHU0UODD6P55xB0GfOAme4khrdacAZBhG9ZsQPT+gDK3GnYRSbRpEXZb0VCwd2faG8qU70xSqpKyRf0+P/9NKaB135+9R1El0Z2DEo+ACB+O/FQRyHaPTg+dq4Q0cS1HMl3Z8gKD+t5I7hlHP6nMc2NMCAhWqUsoz9FugGZVAfpe/LXWFU84clAR5j5XWYJaWod/tPnto6reMy4+J5tZRrF8bdbj5LwNIzLtmp/DjQjk0xzXP2p87KVuBQe64lGGp5J7+rd+US+/bYUXfzNN78odUiiTWovu1L ScRX+5l0 9+ifRXNCljSn/o+aC8Ig3uTmBSk49HlDhYV/QrKqHJfXfPeDfq0yLMHQmEeMyoxeR0BeQCOvXUgJS6nmrk9sbvR9G+klclePTrWAJZ7RCNlfa+dhLei61HrLvRyCdjVu5N5nqolecZxDIYkzg+scmnrA7KnOzBMp+IYWPsCgCb8hys7GG91x+pUgOvRbcdFvnacKnM35C/ir0906uw2Jz49DyB5QB1GmP5tOp17zTZOg1Y/ovlPcZYrLBR+4dYjTWktcN6A5lp8ZghLRpXRrJDWeGtymJGuyLCxIBBj6FxhJOhEiQPsSvVjRigQrc+ZhNHKpdXDeU54qepD9/Jy9qu/RbcsWll1l4T9FtklKXMYgONE+lQiAlFt3B6+oVwjYp/UnIPS90cArgNukdlI6VJj5JOb1MKsjttNJjLywWXPChkydmnflBOZc3Ha0VX3l6bKc+9XAXlN6vwTk4hNRLN+YvZw5ptmJKJ0aqdzuj399Xw7+SbNEZ0FpdbndaUG5QUUMKlhJ4/ruT3LRLIygW1DxpvCvHcFA9Cjpv/zPUxyidRIzpgoB4Ke8nHLvJyo75f9zfapcxe9OpAH3MH1/NI4ooaFt/YqR/NR6SNobwSHHt67O9cEWFAI6pVg== 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: Since task lock was dropped from __get_task_comm(), it's safe to call it from kmemleak. Using __get_task_comm() 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: Catalin Marinas Cc: Andrew Morton --- mm/kmemleak.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index d5b6fba44fc9..ef29aaab88a0 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -663,13 +663,7 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp) strncpy(object->comm, "softirq", sizeof(object->comm)); } else { object->pid = current->pid; - /* - * There is a small chance of a race with set_task_comm(), - * however using get_task_comm() here may cause locking - * dependency issues with current->alloc_lock. In the worst - * case, the command line is not correct. - */ - strncpy(object->comm, current->comm, sizeof(object->comm)); + __get_task_comm(object->comm, sizeof(object->comm), current); } /* kernel backtrace */ From patchwork Mon Jul 29 02:37:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744270 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 095B4C3DA49 for ; Mon, 29 Jul 2024 02:46:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 971B46B00A2; Sun, 28 Jul 2024 22:46:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9225B6B00A4; Sun, 28 Jul 2024 22:46:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7EA066B00A5; Sun, 28 Jul 2024 22:46:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 58D756B00A2 for ; Sun, 28 Jul 2024 22:46:30 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 081F6A0248 for ; Mon, 29 Jul 2024 02:46:30 +0000 (UTC) X-FDA: 82391251740.18.B1AB69D Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf05.hostedemail.com (Postfix) with ESMTP id 2DAF4100005 for ; Mon, 29 Jul 2024 02:46:27 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YiULiF37; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.173 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=1722221162; 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=aN2V+duoRLP5mjQclolxXRJl1PN7YZIwA2PLtFFVKQo=; b=1pjCapklVn3dOBXb1i2wMmiETVZVRlEQNRVcNpQhsG7kTjk534j4u8vPAqUFRv5NspNjpP v7v10eN8eG6GfqzyA/0qCIvOgB91+8Xgnz20PXXsD098EgPtJVi+Wg1k+a9PLk+8lbm63v HvoedtEDx/7xtGtlkKlUiJvNOPWCfws= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YiULiF37; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.173 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=1722221162; a=rsa-sha256; cv=none; b=IhMO0WLxDSmSK8AOp5hlbkD4eRJZ+0pvHjU7nbH9xvaZUIgYQo6J4n+hIrs8XpzqT+NXd+ VBxdBGHied/ujR4IgXPDgQ5qaD8en8MLd65cFwROa3B+c3vrl1I3Bg3GoXEjMmcu8erIMu BYLybGCwenQgw4Ot8IYwoJTL1oSsLyo= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70d333d5890so2683617b3a.0 for ; Sun, 28 Jul 2024 19:46:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722221187; x=1722825987; 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=aN2V+duoRLP5mjQclolxXRJl1PN7YZIwA2PLtFFVKQo=; b=YiULiF37iet4iPUVlQlAxdpfoNkEvGR9QvkUwnPEELGzSpN9CXDHLuaqWPNkVss9Vi nbialFvuJY/E9go6AItMEMwVYcFs8mHnjIA9PtqQY9uMyQSmX6dSS0wcLaPVKtzgMlwL /IzpdCM4FYKc0AuqmCqc2QEUPCOftW6ERDqyLCjiI6OaF6a2K1HYYPkS1q4X7r4L6K0A blCZADDsSwwJTPdpO4FgoRnsfKEHNW3Gs+B2k/8pcd6CUSnb54kC+YciFtanWuATWSHu aZx12N2A8sUzlUMn4p5qYvZ4ABWdEqpUQwHv80Y/R02/vDH/VDOn9nsVku17Ts25Ikcx Zo3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722221187; x=1722825987; 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=aN2V+duoRLP5mjQclolxXRJl1PN7YZIwA2PLtFFVKQo=; b=SeTZuKOpdRq58xWJL1A6jwRVK0y3CAX2xbRzHv3A7TFBB7lHiyS8qISHGOTPrMIgs+ GKC4ipcmLyi6DdRaqwz39hzscLGEytITSk841uNpLqLXgG9o/f3LbN9XyAzU4qxZSoHX dKQ+sxRKhcv13O1D4MtVauHi5aNE+zAKKlU73mZeYcLYOw+jP/2nSJ+weNOghZt02dYO ozx3XFEwfjPsOGFnyl/TJWLAdRyL/Kv4mW00rc8ugdcBAc2XuczuLO6qVBxb7VGsEfhx 7gd3YBc6IBSqkDKHp0WYrNgeTUrDylpl+xHzIJe1dkL8Ej+KabzirkqsZa3yOZgz9hBH OywA== X-Forwarded-Encrypted: i=1; AJvYcCWMK9FmbQKd3oCJ7oIw/JquQ3HuuCGlyGsG9N7F2n/+4PQOs0fPj2G4YDG2I2tnzti4OLYXR8lOV3IO9p6GjzYjeaA= X-Gm-Message-State: AOJu0Yx1mdbuIbN09hB8aWBt+ycWt1BJSTfo8NsIQmD8m0FdkIDLh/D6 ExWkYWMh5duEoROH6z48TLRl/Om3Esim68a1Bb5W9RCPeF2UZBEY X-Google-Smtp-Source: AGHT+IFg6cYKlkoyAPcpyLktfLarITyb9Rzi/fq7hOtiqCqd30rMJ+pCgZRrHbxyCAgQM++WsL2P3A== X-Received: by 2002:a05:6a20:7fa6:b0:1c3:a55e:6199 with SMTP id adf61e73a8af0-1c4a14ded25mr9866605637.44.1722221186954; Sun, 28 Jul 2024 19:46:26 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.45.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:46:26 -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 Subject: [PATCH v4 08/11] tsacct: Replace strncpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:16 +0800 Message-Id: <20240729023719.1933-9-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 2DAF4100005 X-Stat-Signature: y4ofpg3srth191jxgq61gfx5e16ctpzi X-HE-Tag: 1722221187-705013 X-HE-Meta: U2FsdGVkX1+OF0h4A0Jhgw3YiGY2aAFm/5VNcxWWsW7y6SrpmRKLbC0sotMEs3CpvYskqtbTRUEuJ6l97xGrpnJ8qt+EF3lRsw+tzdkrJMb+AUv/AkmczlTyfd/aW+eKnxcY8jmB5QEtZfCY7mL0RXI/KgledUmKRd47zpvKlLEIRopYK/rQQo24dOoub1PDOLBj+9Qi6iH82KIBRPZuLknH/0gaWLs4atl+DSOvLBAqbKoK9MQGERZtwuEw7VrAukqcTHYVDAuMT/rSU7MKa29+QOYBPG1W/+14e41wQcjmgZvAp/93Kg0YRdL9Mqf9p79GqtIYI0U22r1ETvbkGA0GdBI3EseDv4LTfuqRA2FitgWZB8EPyeiqnKoJHLDLek/7ZvBGBzMDtIb6bp6Sm3UCcadv9omO+DPZpcE0/+YLUBS389D/eQiq6W8w2lI8baHRQg85jlUl4eQsm9VvlsoZnFh6jL3/3TYP+0rhuc/MtEe/Bkf/zwlKSluQ0rrCVxSutk+XdQUYtLrPUQJkgOYydYzYTIWsKj9v+1m1TM8xqPcg2+/pPxjVPUy8rKgkdwKyHwEOekr/GW20xczd7lM7VIg9tTNl+u/0EZxSyjBdghNXS/3CJAXbvwIjycgGyvdTvk07woG0DAuCrXEmbXtjvabAjL6WcTx8GzsIaTwGfawzBnAIuv4VgzhNGCcu3td9eMtOZ49NX5v9/s4Z9Hay0Bi8c7N73ZDD25ynDy1w8PliKObBSXsSU0g7yqcXMKKOBA69NEeAC045GIKJDvJE6OuFv80KPv8RD+D3u2PyZLZUy2Abbh+hvgJtGGkXQhqI83ifPY+dzDnNN6ZWTrE5biuXBi4dhsD9duAZ6KzI9gKpcE6a0883e+ko10coMmridGOR1XzsCaAC4Z/X73/yH1FwMC1Swa0S5TWbZgvmVroIaIk8kNQOsYWwe37fcOjO8S7LpCMMzaZJ/rT CEbGO1C7 ADt0r6o6FIMlhorh3xLqURtdc73uKLwplx47JMXD7I1G66quLjc2hXTGIsZ9H/zRZ8uEz/ORIXxc8uwK38ue+QkgFrZST8wfqcknaNOZItpjBNqWx9FU3xlqQ2kYfAhsV6TtFQpEUnq8jtH79liDS+iYzv2QPTNMV/TdK5uPsbtW8c2RFARyWBSMGwVy6g/B1eUoknPlcKw+S8JK4c9hUgOnWLqNsxRWN/GKYobgx5tya+ZLwRmS7jHpRwwAo5yAGza7zkFPwK1AzuJvVsDw+2zuWh7mwh9f6nw8XSa49JKhBSCzrElBscCGZAx8N70Vmx56gUmolmHTkTlurcD4ceLQuIN/iWDsPd5hZvz0CRPEoQzU3OkllnQaiXiCKp7TWcMV/v27TyFutc23JaTENPzwBOgqmeQnch1i4GXRAELp6XNci8YcZVTOoqsRhhC2mwN4xqMrYlZbDDgZOKeOiU/g8+2eKXjlEtUNaG6/807rCa78Jx7cIqszpWQ== 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 __get_task_comm() 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 --- kernel/tsacct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/tsacct.c b/kernel/tsacct.c index 4252f0645b9e..6b094d5d9135 100644 --- a/kernel/tsacct.c +++ b/kernel/tsacct.c @@ -76,7 +76,7 @@ void bacct_add_tsk(struct user_namespace *user_ns, stats->ac_minflt = tsk->min_flt; stats->ac_majflt = tsk->maj_flt; - strncpy(stats->ac_comm, tsk->comm, sizeof(stats->ac_comm)); + __get_task_comm(stats->ac_comm, sizeof(stats->ac_comm), tsk); } From patchwork Mon Jul 29 02:37:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744271 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 CC9CAC3DA49 for ; Mon, 29 Jul 2024 02:47:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 618806B00A5; Sun, 28 Jul 2024 22:47:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C8A66B00A6; Sun, 28 Jul 2024 22:47:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 468C66B00A7; Sun, 28 Jul 2024 22:47:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 27A8F6B00A5 for ; Sun, 28 Jul 2024 22:47:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E2EBC1602A8 for ; Mon, 29 Jul 2024 02:47:21 +0000 (UTC) X-FDA: 82391253882.10.4FD86E9 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) by imf13.hostedemail.com (Postfix) with ESMTP id 1340220005 for ; Mon, 29 Jul 2024 02:47:19 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WsBTTedI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.47 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722221236; a=rsa-sha256; cv=none; b=7Dhk9yXUmvuO7AGvLs5w4vB9iyG+MWNcTQY7warYWOXnUbuZG8O1vIkqJTeeX2FecU6lJf 1e1KhrJtKv8gIY521EbTrj9S+jbR9UBJgo/EOMyYy33dwogJy/swZAuvl8wPhcAzmFZmcd 3pLNfQhycxnEzN/O3XRulypP4JbjzRE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WsBTTedI; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf13.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.47 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=1722221236; 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=/Cv3tjdGG97YCwgOlXgEBsrvlHrrgiTFYRDjMKYVYxc=; b=7WBJYix9HUsif6rDAz2BIMf4Xp2CGbZxNL/xp8GJ25bnXxfIVAx38jN+EG+GaVvjqpdliH d6iVPCCyRQ6IkgD0LlWKRdkDgO9I+OURXLGpuGmfOaT6FTQyxscjggWztcffFrMdPWUDk3 MN9l5UV9smde640x1mUcYbPZ/KNrrUI= Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2cb5243766dso2083991a91.0 for ; Sun, 28 Jul 2024 19:47:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722221239; x=1722826039; 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=/Cv3tjdGG97YCwgOlXgEBsrvlHrrgiTFYRDjMKYVYxc=; b=WsBTTedIjVI4oZQDTKLmn3khL9viE8a+g/r6JAj7k3rXICk8YIi/I0rLATaMEpshaE vuv1MANK0r8vqxpvZQAnBS80j7Nk/0qU27i/MikvOiOAfKa9cVI1JbAd1JAn/teIcvkg VhyLda+IpHqzrF4oaSRbyhRD4EYSv1ex+zK2AtwJynTUCSu9L+VXiuFkdL0z/tC36sYy Yh8IMW8fxmdvr8ngkUr/LS1dD9+gMK6NupwdO/1kMgTtH5c/VrzeVuvrRLMqARtS4Uht cCJOd6M0R6rySy7aVveZlZ0RoZTce4ZEyttxbLh2i63pxQiITR3WtwW8IpIT0bg6JVjx CLxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722221239; x=1722826039; 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=/Cv3tjdGG97YCwgOlXgEBsrvlHrrgiTFYRDjMKYVYxc=; b=Yxbcnad34e1tjfH99R1wcsLicFvTBR484otGn/DmTTWYnjFrRhAdZ4nQcMRcIgSJ/p d07H3fuRJtIyN874qGf0WVsFVlChq/2vwafreSyl/TZ43yhdAHif+y6ShlJayRIc5GNR 2cBIXn7T/NVFArX0jEFvXZNqTR+igGb5puXpyVlqJXF/MWjH1Cbcrd+QX/ONCBwR5Fst c53dytcr8xmvaoLiRgWrVpMtmag4rp9o/pGE4Lo4ZPdc4aqL5RAddsWBmH4ZXe0WRfe/ tiADrlMjtWbfgcN7A0hnmLRL/by+U+4R5HAieQVonENa6/apP498WmObtaPAw3H+JPcB 6Oqw== X-Forwarded-Encrypted: i=1; AJvYcCUQkuxwAWLJPGV1xiya14yMI+ywXJ1n+wGe1gXTYXOEK9k1twPLL1fXZAlXo5o0Hf8vNKxgbnXwGUtdiYRbvp7UrWQ= X-Gm-Message-State: AOJu0YxXNJ1RM6H0n+PJKMoH5biC3akWY4GOYVcqXu+8ld799Y8z4qHQ PL+RTy90e9b2tWN2xAR35EEdHhuflbfDoNvq9nfg7/w3oY0uivkF X-Google-Smtp-Source: AGHT+IFj28K/vh2Wo2JpPTzYf/GZmJskWb9fJ0b0sRrDd73+gDsWQ9AUVDG1zRV3AS7zIGO4lNszYQ== X-Received: by 2002:a17:90b:4ecc:b0:2c9:6d07:18f4 with SMTP id 98e67ed59e1d1-2cf7e71b7b6mr7068182a91.35.1722221238743; Sun, 28 Jul 2024 19:47:18 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.46.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:47:18 -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 , Masami Hiramatsu , Mathieu Desnoyers Subject: [PATCH v4 09/11] tracing: Replace strncpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:17 +0800 Message-Id: <20240729023719.1933-10-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 1340220005 X-Rspamd-Server: rspam01 X-Stat-Signature: tzaa6zqxnurasrhhd9ytucy8kzpd8by3 X-HE-Tag: 1722221239-733104 X-HE-Meta: U2FsdGVkX18V48RTzE4KnG3JKgmQ3osZCZp29tqjkKfSZhfHjpDKtWLa4r9D9/leR+M6SCLFnJgvshOw95sfL8WQeNANWYGyssqfvipXvm4hKT6hZCW9Gh57+xDKkXR8sL5r9NWIyjleDgyQjWw2XERUAJiAIEP2t8C+HI3MgdMRxW6wgy4OXCPrdJXyBUbgJeewWRisgeXfjqBaJxbLNFjFYWyLlDYWM3yvTCrdQNG1a0l2ynipdlxhEtzzhU3fuZcTobnaE61+GFUZnI6bnaTIADiFkNycfHJrjcun2hk6kCyluO3MdmY0jY3GGtCv5nKCZ0d8qZwprYERkVVKEYf8DWXwNVqKTnFIxcnhsX+r91Tj6gYM5M6zPEq6TvqCfjBta00tMcOYpAAFvfv/oBId5/Ekhw90ONpMA/bxft4TK3u64mvI8WwqMB+HKO+zWHd/PaBR/bDJaQFN1LYwLYJPb954fCUlEyO3XxX3sOPF3dNK+WyKzyC2GOejFkwKX8Dt8c41GuuWVkoHYkOzGoZ73kh+C7RSYUY7pWQWRkHQItmzLCAtZymHpZkJY3O5fp9NVRkK9vexHO5qFxeO+yBy6nQnD7QNzz6oL5en/nCrwOLYE41ZNiS4LNg1VtZngJF1X9zYQrWDwgSKJYIeWYfpKHDMswpyy2M9F8H72i9znrlrPNrWe+Ktvo9g2dJnIQI38HRthdco+vhpn2+fa5h+hMB5j+06dU/GgXRF7cdRxg0jNSD4WckA6tqX+OFVDrhbNaGNi/Q7xDgpqxjluq+fjvIgR8ldiRSIZqDFZqbqS8FxHkSdUxNSM2w4gNcXGpnTtqZy64LKt+ij4PHkjGkmsu5bon6U7nFvnkzvGN2MwBGjK6bVrpxQXyIlmfdj2UAqsO/K02rgO77WSO5dGR2IDUZfgM7zhZT79pP89vQdmgkvXS/NxxVp+MWykAUDrrVNMYZY2GZ2nVqaVnh wJ/nIgxQ goPZWQ5WYNtpyaxHgbmJKvV32abgCAM5yaTgiz7QlT/ap5lSS0ykp9g7zczx6ZRVjufpJlvtZgPVKsRnvvEN0sWSFz33wDFExTywBAWhD3/6tXPHqVepgU22+SqcJIwn9CfrVeE/BT/Ly7z5E01lav6V+4YtHZ992PJf27L4kC+3iTOSVjnLrtaikf0I+b42Dmd8taTWyI0mlWH9xXPKRUtyDhT/55roLMNKbSQhHMsDVH0N5/iBs+s0AKw2vDjbfsByYoe5drozm56UmgqrSfVw3yCI6Y5povF/7IalH+08tSvOtH87Ic9PqXlqDPAEoIsZCbNBUzFh4yPHpVFHeOwU33pgVNBjI/rERAfvspxCuU77J1VrvJUXh9bCM9Ss44D5pHswPHjVHyIJ5kRMSUTuoNeC1lSR4BJ62JxrOpOkX1m95snyD2zhJY1LOMgS1dAoqNlgFoCKD6cXF/wxyyiN2R4vDxlinUL52cuIjmnJg53BjFByIMnhsbmHjS0Gnfmb2b0CbGMv6Nsq7ifdiYMYGTlWaZoX1zOJ1dhGnEpeikKIbg3jLWSUJNScFfefChhovL0Rttz8qsaHBP9hcycH6B5ETPouTV71y4doMWlSDKrz/MP9XaUol8ydWmmCcw6Tv96R7pjgS7wd7bDPUYSsGZSPotSO9AoJ6UGAyN6ZTErU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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 __get_task_comm() 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: Masami Hiramatsu (Google) Cc: Steven Rostedt Cc: Mathieu Desnoyers --- kernel/trace/trace.c | 2 +- kernel/trace/trace_events_hist.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 578a49ff5c32..ce94a86154a2 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -1907,7 +1907,7 @@ __update_max_tr(struct trace_array *tr, struct task_struct *tsk, int cpu) max_data->critical_start = data->critical_start; max_data->critical_end = data->critical_end; - strncpy(max_data->comm, tsk->comm, TASK_COMM_LEN); + __get_task_comm(max_data->comm, TASK_COMM_LEN, tsk); max_data->pid = tsk->pid; /* * If tsk == current, then use current_uid(), as that does not use diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 6ece1308d36a..721d4758a79f 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -1599,7 +1599,7 @@ static inline void save_comm(char *comm, struct task_struct *task) return; } - strncpy(comm, task->comm, TASK_COMM_LEN); + __get_task_comm(comm, TASK_COMM_LEN, task); } static void hist_elt_data_free(struct hist_elt_data *elt_data) From patchwork Mon Jul 29 02:37: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: 13744272 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 A9646C3DA49 for ; Mon, 29 Jul 2024 02:47:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CF386B00A7; Sun, 28 Jul 2024 22:47:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37E956B00A8; Sun, 28 Jul 2024 22:47:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2208C6B00A9; Sun, 28 Jul 2024 22:47:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0066E6B00A7 for ; Sun, 28 Jul 2024 22:47:57 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B994B1A02EE for ; Mon, 29 Jul 2024 02:47:57 +0000 (UTC) X-FDA: 82391255394.17.1C76FD1 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by imf27.hostedemail.com (Postfix) with ESMTP id E33A540016 for ; Mon, 29 Jul 2024 02:47:55 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZHusiAei; spf=pass (imf27.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.171 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=1722221272; 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=YS5JkKLpH7rBBlezu3RsuBopuhXkHEJwrCmaySM0BwQ=; b=envVdi8eFhzbPEggrY3dTEOynBVuRRAllncyx8uDd/XATLe+RKLp2Hw12qyN3oLLklHZ71 r9ZCZS1oW4eHH6bz/qJ5OnkrTWWj7yn87PnjG5n+frESCd3qK36eNsPoI15rVJZDDU1rQb hi7QE1+niaKV0WKcERKq5rZ0J73Yz1g= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZHusiAei; spf=pass (imf27.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.171 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=1722221272; a=rsa-sha256; cv=none; b=De+2aJLN8ZNQxSzkSTxvq9cuet57BfT+l+f8Bi8jO03UByf6L/sR4NPCCnjf7JoeDaSELJ X6RR2luywpJiw7cvDljlCeRAY+WkiHwde5qV8BsN2vMust3rz47Z5wY6G4VXwDSw/TpkoX W1qiZ/G+w/OxLq3bdP08LyLl61L4UGg= Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7ab34117cc2so1941562a12.0 for ; Sun, 28 Jul 2024 19:47:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722221275; x=1722826075; 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=YS5JkKLpH7rBBlezu3RsuBopuhXkHEJwrCmaySM0BwQ=; b=ZHusiAeio8y6LK3hoplsOztnB2w0NfFzlrhb3Wo2/X2QZ5JCP4cAi7ltYpo25R3B8g QMrPZ1w3YhKJBJqaLMPSw1gUe7eyFqIfXkpPEQd6jQqn+tNboO3DeSsbpGhsf1pjPRCi gJx6CENp02G1hW98UT0HQCA+UOKNxf/0biVF1DSyYhOGJV/sM32Cvr5xqcOxXHmAfCkt +CeKTNviiwQcFGbgX79Gh4uqtC4PPgey0AtwDJAbndj/9ZYhPULqUcFCY9OxC21wJNXa kY+LP+3dwznGhTMbq4oibnlzTjI1ugc+t7hiLRkLGmhe9xZQSSh/Va2NMfavv2Tq4hVz pyfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722221275; x=1722826075; 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=YS5JkKLpH7rBBlezu3RsuBopuhXkHEJwrCmaySM0BwQ=; b=LNw+QaoTY7Xck7p74ggdLN2p5uearjz5LlK45MVJ12Y+OdsHt/yuzHSupomsuniqR5 OVkWRo2jJK5DBNrcgwpI5Gio+oQl71ezepjO8veeG8ziZWHmak3PUnGQoY7BxGNZwLwM JKuKYHyqOQJ1Ep0xcJYntgGELr/d1svbtKzYVQ7y66L1aFSf3UcYb5XoNpKkjyGDFBw9 TlknKn8f3N/m/z4K8GKxpDVzZ5ZmbNbtIqh8IGCYlIOdsNwUg/GsTmydiqY29phZ4Adw +FbPPT6IOtB0ja7yMWbrzROoO5TtZCb4Vu8wcboTwhesQkTivGtKgGgNWibbOY5KoVvM fphA== X-Forwarded-Encrypted: i=1; AJvYcCUPVzfp9s070fKB4mDWuEgWiAnAwwUBZcuc+hJA93OagfXi/bqZrEPS/izWTjenYBrA7M0uMjg4eod7HI6ljzWWbKQ= X-Gm-Message-State: AOJu0Yx9ZR91U4OTkxECUWRXGzoz6FErs+B1/lQwpGFrM69FnxdJOmdB QDoLePWHfISt1I9ZYea+CEu7EoLn3G16GA+vovQCb/gxccH9DlKh X-Google-Smtp-Source: AGHT+IGXxWNnJLIJ5uPecbp6KsT2OOK8/ZuVg1FUEXn71WfglTXG9UPP1KLmHGuFVJ6pD1f6J8wciA== X-Received: by 2002:a17:90a:e00f:b0:2c9:7aa6:e15d with SMTP id 98e67ed59e1d1-2cf7e1fac4fmr7206984a91.20.1722221274655; Sun, 28 Jul 2024 19:47:54 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.47.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:47:54 -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 , "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v4 10/11] net: Replace strcpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:18 +0800 Message-Id: <20240729023719.1933-11-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: zp1bw5g7gssc7n8rye59f6kdue9rgxzj X-Rspamd-Queue-Id: E33A540016 X-Rspamd-Server: rspam11 X-HE-Tag: 1722221275-471378 X-HE-Meta: U2FsdGVkX1/bea126YSS9clVNOpGCfUIh75iB7oiredm1aAT82G4J+Pi+uQk5trEOZyKsLnCax9mzQElbFGc3VSVl9Eu9NYI/gikHD9YXe95gd5Gfo3QFUlIQ4aQZdLBDojcZJ7ID49r9NBBX6LQkIv/ym5GO5eBW/LAFWiFCIKJXpreSUz0LM9VGXpDvXWLfRdM9cfQkmoQL2uqRvi6bmyMQN2RetsSHgEZDHhcwKKCRb4Ab1X78S8X63rEoZrQQHeoX1TvJUeDwK1zpCsC24u7kmuXE4/oQTfm0liTA1IjukgV+hHqP8+FnkUfxcjqnvPG5iT1KTEjzJUuy9UvJ7yN2uedHWv0likuLNFUVocLMtelPAiZEZ0by9aSl6p4lCtZECKcQCAr/SHfpKfBpSrPnB0yJ1xoITbM6HLbe/bqNBkiWVg4KtJGXp2uRoCFzYof8Awm3jwgieVoO18XUywg3uppo0XT6v/Mm8I6tGdwPn9oTH9ZbLGRY4lr5tzK8BfvPTU3zgr3C5TtLUdYD9eQ5mw+3TiVZwykuERfx6cU3WZuBVQ5+rD+Yib288D0lydV/M2DMUsTPI05reNDYJhd5V61m6Ojshf+bNSk86GYK6mbvpWNWtGW7JaLsPUJZEZtFfSydqgxisS/xkraasRlJw2ikN4fNx4z/TljcJH6Xev5fqqhYOHUmkEMiW3zB68UBbyZr5g7y3WdVX8pKNKoTDX/4jGtp/4YuVnbbqTRNWCHUIU95S/mp0VfR046n29/15lHljJQZRVK/qocdDQn2x/RePTVZ5bhxDXIkLNHuX5b8Tg7ZAFklSBvx6nGqTQR30f704spYr1HrAIFwPjEYIuIrwUuXD9dmbJizejrVs8ORIQHJ4vgFZZfwf79wK6pXHHeZWHklfaE1N7n9L59gOYBsVftWNawCyZFkG8JsgCFrKv50F0EVR5PWFTmC/Lgb9CHPfJZPUs3DC6 h9fLMPwM uOQJE3FZlsdVGRUZ7XLCnSuYRf7zeutBC3SDdarsJzXDe8438roBhE/NEvLhRBvo8ZyzSaNOhBKnX0LS142UPrS9xUwVy2OjW4fVRwOnLXeo1Kq08M82JDu8qLwAjkV75yu0yC7Qwxcbyl7QLAEKoRZYTC9EcABuVJTlWK60gjahG91M9M5sfN/jEr7liQV3hozGVQD8vz0A/Cas1FAuDqacJvCYYYkwIboMq5uDasrbnik3yiYZ/7Xdbnnrsr0LJVfamyD0e5wO5PEKqx6Gx72JThWYK5Gb0LEOmPJ37OtaQO0BIj1CD7IeCuEfAvpHaCNDukWsQTc69QeodK1DHQiN6J4yia1nyTrDDmUV5XT78zUfVQxWj8Seorwd9Poh362a7FAxdOVSBw4/jOJKVuNZgQEQ5QejVy73bhdE9mGsOK9bQ1yDCInHFfBhU1iYcv3yX3LCIgYwdRhAp8DNtFGQXTTUB0kNICE58S0M39DmRAYn0G98blE0tsBVeDzHavKIoKgm/R1feKbB4BahjNG3SDEE49Lvjlo82jXWiiMK7BtTyX1du51jrEQuDkbsi/dJIlPZ7HIK7CZV89jl2f3qVZwUeeUWLniV7xDJ/2K//uARG5Hx2n3dxVT228lCaDQapG/EqWhSNv4x+TQOiDhb5KdxS75Qhj3Nr 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: To prevent errors from occurring when the src string is longer than the dst string in strcpy(), we should use __get_task_comm() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Cc: "David S. Miller" Cc: David Ahern Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni --- net/ipv6/ndisc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c index 254b192c5705..10d8e8c6ca02 100644 --- a/net/ipv6/ndisc.c +++ b/net/ipv6/ndisc.c @@ -1942,7 +1942,7 @@ static void ndisc_warn_deprecated_sysctl(const struct ctl_table *ctl, static char warncomm[TASK_COMM_LEN]; static int warned; if (strcmp(warncomm, current->comm) && warned < 5) { - strcpy(warncomm, current->comm); + __get_task_comm(warncomm, TASK_COMM_LEN, current); pr_warn("process `%s' is using deprecated sysctl (%s) net.ipv6.neigh.%s.%s - use net.ipv6.neigh.%s.%s_ms instead\n", warncomm, func, dev_name, ctl->procname, From patchwork Mon Jul 29 02:37:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13744305 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 A7FE7C3DA64 for ; Mon, 29 Jul 2024 02:48:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F4BA6B00A9; Sun, 28 Jul 2024 22:48:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A5C86B00AA; Sun, 28 Jul 2024 22:48:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 294926B00AB; Sun, 28 Jul 2024 22:48:18 -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 0AB596B00A9 for ; Sun, 28 Jul 2024 22:48:18 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B74381602A8 for ; Mon, 29 Jul 2024 02:48:17 +0000 (UTC) X-FDA: 82391256234.28.1C111F6 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf05.hostedemail.com (Postfix) with ESMTP id DAE9410000B for ; Mon, 29 Jul 2024 02:48:14 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Avy/g0t9"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722221255; a=rsa-sha256; cv=none; b=NoT4Vo5iLpghMkg1ILmhxRVaqO3zOJEOEhLiXyjJXG7Uq1qy04z+El3ZxdIsRVSP1w8/SC i+no8TTHmO6/SNvnb3LZHMRuKZcQ31B/hrSxGkfyI01rDHpRD9j5T322IMSsHlGX7Eexzo HgwpM0wTJOiS2SFpCiubwgeW98hljn0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Avy/g0t9"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.177 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=1722221255; 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=uws88M38Us6mZwthahlWUK7fM6+CMa7f0lHdNpc5/ec=; b=4YtBmnwPlBwi7HcU3T/JOkdPhhWg44Bn9ZtHMi/E+83MexKnJbGzEsEiVz3ibQrOKDPeyL vOokAPKNzVZoVRdhwCjN0b+kQjDOlUrxuRnVAOv6VcrNL8/hizRKTL6ngTp0E/8sNSWZgx QmFs6Jfm70t5yAlpMfmALLzIIw6tC0s= Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1fda7fa60a9so23399915ad.3 for ; Sun, 28 Jul 2024 19:48:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722221294; x=1722826094; 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=uws88M38Us6mZwthahlWUK7fM6+CMa7f0lHdNpc5/ec=; b=Avy/g0t9cPqUu7eOYyJHosHqYXIOffLMNW0a5kFSdgizUhOhV7sfTafXVXNZsbU/sW TJa/+4PQaY/9O+MNuYvDRcXbrTMT3Zx2mxF9ChVsgC43mbeifH7wfqZb1My9RmirklZb cEbq7J7swvCxnuQK/C01wxopYJtvgm9TVCHZnvTu41rzktv5OethPAvOVwS92IlRxU6V +A8KfUhqZOWpBAeWA3ZsKMDQTTjn+AVv2loF778s7UGer2lSpB3QONNRmc7Cu0Cfpeks GAO9fAyCmoQO622XMJT9O7aoXKK5u2hBf2GYf2+aAKdV4oZWtV49VH9xB6JKITbmBhBd wPZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722221294; x=1722826094; 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=uws88M38Us6mZwthahlWUK7fM6+CMa7f0lHdNpc5/ec=; b=qmi/XuqrYotoqVvdhzSz9qb+s1ChTI5h3QRAm1lUJyyHWpYtvkzU32G5CnIU/TxqXq lbRwaB3xoHky29rYEOOBgiV2yKlP4bWJ3xBpw9nQncjWRnLbdlw306cfr155eVR106J7 QwDdXbgpRpIo10IIyi9eqxGAR7ZqW+nt4l6+sWHgqMMUQ2Nv9ZCz4SEJFQwqCE/41gro b4a+8Eh6XhYjVi9oDdX7hr927ZJuMptoZGDTg0dLV2bQ2ldJ9jhUw9gLNcrRNLtU/+n9 neRbgc+mYRcVSsmK3yUuyuFSjCSly6JD97oBiiUKXJJ67zbI6RWvPQ+CAa/hL5nMKtYO SmEg== X-Forwarded-Encrypted: i=1; AJvYcCUqDdEc2Kt6Eur0t3zAm8fFq3nNx4EagnHcsJZ9vhttS8e7/DbE807q/yD2NZXj/7K8+rngTsF9guE/vb9LMX3oY14= X-Gm-Message-State: AOJu0Ywv06gxwm0rClTRjRIaJtArlwkbu57wa5V90IjSiDjlx+DYYBKK k80CwjltC032psPhL5N2HaJgqegmElZrBxhJi9Rki82/lnI4/YKP X-Google-Smtp-Source: AGHT+IGofcCeds74VK5yzpBY91R2MnaRyI1ieEFwQ1nBe/Bs8+j0QLJHRaMLwHU9stQw4nuIemwGyw== X-Received: by 2002:a17:90a:888:b0:2cb:55f9:b7c5 with SMTP id 98e67ed59e1d1-2cf7e1df02dmr7584677a91.12.1722221293603; Sun, 28 Jul 2024 19:48:13 -0700 (PDT) Received: from localhost.localdomain ([223.104.210.31]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2cf28c55a38sm7332247a91.10.2024.07.28.19.47.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Jul 2024 19:48:13 -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 , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Subject: [PATCH v4 11/11] drm: Replace strcpy() with __get_task_comm() Date: Mon, 29 Jul 2024 10:37:19 +0800 Message-Id: <20240729023719.1933-12-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240729023719.1933-1-laoar.shao@gmail.com> References: <20240729023719.1933-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: DAE9410000B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: xhwizgye63i459hde5mwbgsckex5dxdu X-HE-Tag: 1722221294-279621 X-HE-Meta: U2FsdGVkX1/fto8oyfEZOFddc/Qz4olf3nqZfpCILOoMaJjUrFVgBIK4opDSNnfPOfCK+6noTEfC12jiuCaVxYI7TAs+LSTi082VOYwwtOVaiDiYK1DOKsWWpGu94iW3Tiw2TNS6tnxSOOzgLjmIENl0R2Aq9YeHpFB3x9RwlDx5x3EbetW4XSUg8vRLSqWbYIJdoJERFQ0g9yiiuNNHF4iyptLjmtjWWzJVnpsIS+ozSPB0WR3r/d0SoyqzeZKRiZXqLWGgTvnLyYuVKlspXb0lNpeZ4lpcv61mpsRnUirTlSemCXGwtRSQi3vsFZueb0xt+IvYoCzRMf5j3Fv7WNYHxRmu3zVBceJxofPZYK8gKvy4uZQjZIODa6G+hZ5AjQX2CMCoekV+hFREWPewtRBle6nEVnEmzYPsxEggmkYzw0KOzPSpiT3U9q1P4l5qey3b8DL3vJ16QGBMab8mA6x/VsiMACKnSaUw1JzKqv93NjM3kUIXgtkl4MxhXZ34cJnYjbZkRk9WnEvzacjmKkW6/h5T1drLHcVI2afMHIEXLOvr3bmePdx0qvCrW6NqRm3TSvRnXtSPyEGJ0t81vXyMKWU2iFqYvMWrwVlQPImRlaMPh4v2DMWlsdcgXm9fv57m3w4RzWgPAOk6IWETcbcokiRKHfmk3QVjLJDBsApcnwGBAjEB+DlM2Aq0dPPxRm+9jg3aHyyGV0BCNEpxz/bYlLmCf2mBhu0Hp+DkKsKmjEJv2FAENbh2sLPWOPQ73wzSeF7UGwFC484hKN/w26hoJGyStUzXbYyIlFKLjaBM2uN6fEYxWuCd1ff5baGxxAnZpgWaBH0eI0eXoPHjmzqTzxBK15YrdFSlxKvbe5bA8NP8Zu+dzpEYy+vnZ3OgO6O7VvB451ly+pFfJO4vZQiDibzqia8LQmVfQ4Qnsl3uLymwJWLZwRaorZtO8BD1rlxsN683xrOWcSYDiMQ 3oMBYhDC kUlvMvmiX5xaWGbsieVlM2z7Ez/7YtkJzw526K6k7WRM+R6dzhmEoXm+AtCqQfE2U4Eqk6KD5+aufLPQG25cMD3y/HcMaDJ8ohfQKchkTOnYA5lT/SGH86a6LlzeurojRPeA9qOSKlJHt4jGDB/axzWsRDRJ/3kf9Zx6JHUImQhlAF53bSgmhiY+COKVyR11xtmc0gNxxB0Mfs3TDYAxfVKSHG8MpvQlDRVjeEf67GRE9xi6ZXFrdXJI2HqhBNzKZieAzrWW/16+/S2IVgMfbwOQIV/GbyTbW+vQVSbwFMLLIG2KkMtSzAT2mSMfxocYx5Mnd1o/qbsvYUG77SrfO8F+3Pu3qTaHpJKpYV4WTGMoRsXhXrHg2ft6aWOsK+RHqRpdBkNfhM3zYxR97RQuncUw1YDOxbIYTd/Ck5zbeS6ROnbySwQEES1Ny10chgPncYdJ45UW4dJBcx7qqDeq71ZxXMeBycOw+pYNlrLSY0wCzIR2K48ZXM9j9Xw466N9dgLgzyDPqYgyQ4WQ4wFUBzccXTaW5TjsqQeiV5ucLz4vIbg7aTWVSHWCy/KGG2R9MEtgMxC1YYvrtwAo= 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: To prevent erros from occurring when the src string is longer than the dst string in strcpy(), we should use __get_task_comm() instead. This approach also facilitates future extensions to the task comm. Signed-off-by: Yafang Shao Acked-by: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie --- drivers/gpu/drm/drm_framebuffer.c | 2 +- drivers/gpu/drm/i915/i915_gpu_error.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 888aadb6a4ac..25262b07ffaf 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -868,7 +868,7 @@ int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, INIT_LIST_HEAD(&fb->filp_head); fb->funcs = funcs; - strcpy(fb->comm, current->comm); + __get_task_comm(fb->comm, sizeof(fb->comm), current); ret = __drm_mode_object_add(dev, &fb->base, DRM_MODE_OBJECT_FB, false, drm_framebuffer_free); diff --git a/drivers/gpu/drm/i915/i915_gpu_error.c b/drivers/gpu/drm/i915/i915_gpu_error.c index 625b3c024540..b2c16a53bd24 100644 --- a/drivers/gpu/drm/i915/i915_gpu_error.c +++ b/drivers/gpu/drm/i915/i915_gpu_error.c @@ -1411,7 +1411,7 @@ static bool record_context(struct i915_gem_context_coredump *e, rcu_read_lock(); task = pid_task(ctx->pid, PIDTYPE_PID); if (task) { - strcpy(e->comm, task->comm); + __get_task_comm(e->comm, sizeof(e->comm), task); e->pid = task->pid; } rcu_read_unlock();