From patchwork Fri Jun 21 02:29:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706692 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 E36BDC2BA18 for ; Fri, 21 Jun 2024 02:30:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 729E38D011F; Thu, 20 Jun 2024 22:30:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DA1E8D0111; Thu, 20 Jun 2024 22:30:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57BCA8D011F; Thu, 20 Jun 2024 22:30:50 -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 32A698D0111 for ; Thu, 20 Jun 2024 22:30:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CF8671A081C for ; Fri, 21 Jun 2024 02:30:49 +0000 (UTC) X-FDA: 82253317818.16.5A87957 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf01.hostedemail.com (Postfix) with ESMTP id 05B3B4000F for ; Fri, 21 Jun 2024 02:30:46 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="G/tQ1dRD"; spf=pass (imf01.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=1718937037; 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=Zt6Zo0BQwE9mYz3Q0zCJOWUGA/XKEFxfC7Idotg6GZ4=; b=pLcgwh53bH29iMo4EFs4XkMCnjjQQHTrbsxykxempg+olLyAQ6ykgUjNsjBcfm3iMjcd2N M9yqjhJNI8B6dUgSnNTF6kfBIKammHsrp00jpvkOcxCpupGNNQjpcWl0n40CoQNDGiW/vh hbGWdnkr1AeYuG8ocomNoz9IU1x0KPU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718937037; a=rsa-sha256; cv=none; b=P2pgMW7KbI4TRCP9eIlj6u2HFkO7crwPzN5MaML461IOFk0fX2YI+40vsefv/pPkYG06rN fZ0pV/Adbo0j9B42MjS9jsMAU8rjv1Kx2J2eEQmjYiE0lHxZxZm6m+amb7kGQCdepdogXj JMdmVDDyIsSkma6a4yAhKlHubLLhTEA= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="G/tQ1dRD"; spf=pass (imf01.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 Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70436048c25so1557847b3a.0 for ; Thu, 20 Jun 2024 19:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937046; x=1719541846; 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=Zt6Zo0BQwE9mYz3Q0zCJOWUGA/XKEFxfC7Idotg6GZ4=; b=G/tQ1dRDP9NgmrPantwEnY3Ed/N9d4jjfymGEGhSRQF1BBsM57As1mDVJByDnybDmY 5DIITEpPbkpj+96mqKG3E8FmAH/Jd9ITkEVL+wgivgEMmRA6y8K/7vu7+EGiXkAoAa5i lQrYHEnXQjlpoLC69o07kkKhw+jLf30+tIYkcNlhCVmyhsgfWAUMishW8JmV2OBs/Q33 YFbsLVED05V4+m4CbBgIshaYIQEQqjI9xyFDHWVO5a3Ax6xzok5rmlL7BSFUp81r1rp6 +qhGR1+v8b9S7pY+rjABbRfD4y3GhROCwQBilq2jl7TLrUHHzlqlDTjtfL3ybaOZfa33 GNYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937046; x=1719541846; 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=Zt6Zo0BQwE9mYz3Q0zCJOWUGA/XKEFxfC7Idotg6GZ4=; b=BFL8OlBCBTVV3MaMxf2LoBUhidV3bOS2OgvQo4y4eXK+JxV5Phl2WjBHRsPjdU9pPc H1+yjK0Jmz1U9Ds6beEscpXUTWJ+/qk+kDFAei5JySwANuRNH5P53SL4kECofHFwqwW5 4B/bgNrgqCPwlvxu2qFQRXD5T2D4FqWC5NFw51gHCuCNSzXeMQnnqTymJwv/EHTxfbCe eEeztTc1wX22QKxNy+T+9rzIvx2QdN3E/YXSUrAs/I11Wb3l1IYoX0ypiz6DBjnaqwfg d3MwTdjJ/OQ8e13oRsiVW9c+cDInM1ncE9+wcrTk3lwt9KKLsv9kCwgAgQmMhN0UM9jL pafA== X-Forwarded-Encrypted: i=1; AJvYcCWbXs5hIyhHLd0ov4Q/jI9Um7nlq7WEkwG7mZg5TqjU/DS4zo1nO39GqgA3pzdRQ6IafAiCPPOVXnC+h8xOjqXO7tc= X-Gm-Message-State: AOJu0Yy/IhJV3J5fdJRI4+sveqvb3qTjyKaTqBh3YNN2RZWqAXXf+qF1 VI5Pwxri/uIA0lYcYjjc3kJpgFqQJFvAEI7kTZ7Ujwy63aSXeSvgB7CaRKsF X-Google-Smtp-Source: AGHT+IGtfjPn4RgUkASb+Xbc5n3FAl++/e74fQb3jmqCcMo9NRTzTfAqzNgZkCzFDeDT/EYbemTCfA== X-Received: by 2002:a05:6a00:22c5:b0:705:ddbf:5c05 with SMTP id d2e1a72fcca58-70629c4204cmr9525016b3a.11.1718937045659; Thu, 20 Jun 2024 19:30:45 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.30.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:30:45 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 01/11] fs/exec: Drop task_lock() inside __get_task_comm() Date: Fri, 21 Jun 2024 10:29:49 +0800 Message-Id: <20240621022959.9124-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 05B3B4000F X-Stat-Signature: cwbsaifitnq5he7qfcqim1kxrbc7oc7o X-HE-Tag: 1718937046-944758 X-HE-Meta: U2FsdGVkX195hpjrficwqcDbR0vatW6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EMvHOAqThQg7XXJf6makH9Mqq1pcKBa+XDDoBLvoGHLAd49v/GuxrxH9QojAy09kEaGk141+T+p0cTwcxqSVVEplujEoU3z7yOxZ8YRmS+Ux7i3/ZE0kxkswhrd4bSUPl/AVJBo+ORIOt50Zf1NDnNGZyecub0VLzEbGL67AOJZ3Pm+LSREwgZRcbISo5peX4nM+lSCl12UIia301Trkd7WvZSZHKY9EPU3/X7aIPJofkvAXL6oP9yqKoxTxyqU39/YxuF1wTz8F5iZMekzPltSr3SLF/pjbCbgj5Y4jNJJAZ3OXkhBQ57MPs08Uex7RzYnL7AEYEmk8IMbdnUJ+G8NOKUtG0+0q4AM5/TQfly7Hu3ETOQ8Vw74jNUWENKWkLgn5ZDstYyS8MDByRlxrxh77aBhICZTVRGVO6lw09E9tSM0yHncN9pY+FH4uzSdZhcJNukbXXSBajov+jVwZRVj8jO0Zc/NdZmm4WVH6tLj0yOFxsrLBKqpAQidG098iAxjFnymUk29hTfhWcEORKRLf0amKurutjvjADRy4FV+e/A0D2KDGrcwaG3rV5HrvAnX8/f+UtOJfbD/+gX4Zm0RfGn3IJduVI/CkXmCDADq9JkOuWIFmBXO1SW7VaDK82OmbU40g/zicFY48JomGhEKKB9hNSXJbFfxoUWm9HgiugRpHEMjL/uCAaYf3WBVNFz8JNa+A= 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 Fri Jun 21 02:29:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706693 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 2195EC2BA18 for ; Fri, 21 Jun 2024 02:31:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A37416B033F; Thu, 20 Jun 2024 22:31:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E6C36B0341; Thu, 20 Jun 2024 22:31:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 813136B0342; Thu, 20 Jun 2024 22:31:00 -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 615026B033F for ; Thu, 20 Jun 2024 22:31:00 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 19B79A20CE for ; Fri, 21 Jun 2024 02:31:00 +0000 (UTC) X-FDA: 82253318280.02.BD3E2F5 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf12.hostedemail.com (Postfix) with ESMTP id 3D27D40009 for ; Fri, 21 Jun 2024 02:30:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=j0Oo9MDS; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.182 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=1718937053; a=rsa-sha256; cv=none; b=VG3LIPA3MxIMzRzICTUrBIK39QMwUEczYs4vqw1bcxh1mvbGIT8cuBcfvSPMTKvHUN0kxA 6Uk51pMWc9CfPzssxixKGgbxlR9bwUWVNYXDuOvXCCoE0qDvmiGATjnFmNf3i4mUSmIC7l /JIJXpwc1mOf5o+4CH5soqvgR2xK6pQ= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=j0Oo9MDS; spf=pass (imf12.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.182 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=1718937053; 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=j1cpGZH9ekrwOk4ggaybwp6iXeGg5lCIICWIGBwiSB0=; b=fN3dalfcPI4D5pf8YvFHTrCX9QsmHz+XBCvEwyZJhYNg46EEWJVI2Dt/sJITLDjIYcGMhc TUU3SrqCXQ/j1La2q2SsBLEJE9dSN1hQSM/UlxngRC5MKjoLsPGKWXzNOlU3owUmv6eXAg IeLGnPTl+wlij5FSiobxlyGF0UuUjrQ= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-70599522368so1241453b3a.2 for ; Thu, 20 Jun 2024 19:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937057; x=1719541857; 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=j1cpGZH9ekrwOk4ggaybwp6iXeGg5lCIICWIGBwiSB0=; b=j0Oo9MDSYcEOdcD1t/w3obmjWHmZKg3sBYjLtF1PPmttJaiIXvxXqvlr3E2BKHt49N aoc/bc4GoI/LNwSCWprccOJtrSXowu3aDR1DRoruzeSI/4q5RS+zDVXDWGG0mHXgRkIC 32qFjsmqP3ce5hPOORVFjK04Es294pr3BjrPbVJ9xzLkfYRTd3PDrsNaXn5giIG9gvsR yTv1Vgc5eb6TTZ6jJY4eCFwf6DNtpGB3K8XUip6jaZ8Xm+3itkv054heri6ZcmpDcZqg rYlnoXpb56qG1NcuT4A+ur52AZhfeXTq0gW2XWpKPdGkprVBGNIKZDoVg6iNvRHUBucV duog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937057; x=1719541857; 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=j1cpGZH9ekrwOk4ggaybwp6iXeGg5lCIICWIGBwiSB0=; b=V8wXsf+aSyJhHW0TTMkKrU5QHLQ/wT/g+Spb0BEepxlx6JbMuyFDfv2yjArbKNngxk pA1nKn/uRI6gpS31hdAchIfC59K77kJapSe/JBCILyVVlF5Sbhj3v5NkhvqLCyS+2dVN A/6v+2bwb+F/puErfqvtHp6RAITQ5xf3KbR91X6pSB8ENcJOGWoYEjq/PQ/ifn7Pg9A2 jT5gs4/jUPjYwFx5qRQbIzcSgzbG3OgABhQSNXpIrSFOsy5ak7oQS0EiENbVyw/AUvJD OhoS7nGtlczspvDGhdbnNJCm8gcSizB6wlIjb8ZfbXnqOt7+bl95zc7y/LDqBquyGpIC PDQw== X-Forwarded-Encrypted: i=1; AJvYcCXR/AA6wwgAvfThEONgqLlY2LzIKDZ/jIawawyoqROaStVqBGzBnfTutz8iVU3gzT9hssxytWqaivADIU9SETHwMC4= X-Gm-Message-State: AOJu0YwKyiyogckEyhXUe8SkG6q+2VTn6XCX8gKGea4gf7Zikefu52kG B4LErG926CWxasr/AngeqdvinYx5S2Zp7pUlpBMwKFLlgbZpk5d0 X-Google-Smtp-Source: AGHT+IEXObDJFHHEU4ritIMxu9doHb5HpGV/yXlLGQ5OCeoryIQ6hRw+mWkpUWLLJXrRfBg1YmPPYg== X-Received: by 2002:a05:6a20:9313:b0:1b8:b517:9bf9 with SMTP id adf61e73a8af0-1bcbb574a9cmr6631143637.25.1718937057021; Thu, 20 Jun 2024 19:30:57 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.30.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:30:56 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 02/11] auditsc: Replace memcpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:50 +0800 Message-Id: <20240621022959.9124-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: cqdrnkqffrithcuksf4mimxua5pae7yx X-Rspamd-Queue-Id: 3D27D40009 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718937058-983764 X-HE-Meta: U2FsdGVkX1/pZ2ceVSc/71CzthcFATSuIqT8iDYIu5Ud7+E7aJYXrfVo5fjc1PZvvDb67NSB0KSg5z3jr45W5X8O5nbKW0+1tFt4RGK4oLks27Vx0ORkTpC0IxRISIDRF23oVjYwh+zd34bH9RoUsXiKfuq1AyN8Mk0KSVfbIIV3SyCn9YghDx3hESnlCB2/zP24L3TRei1PK0nBahx36Q3i/Uz84j9M5y6YvwJvQ5ayltUmHwXZAWWy/WqYMKRuUZC8DewQ1WaojeVozXf4AHihpY6cuIqZXQUUgy9RPyUjaOYvCdiNircRLlGPwbwtWAl+/SEW7NbZxEE1iLWLikYOjktPb/4jqqkG1ciilyk5kLJ8vJPaFdLCyFuCFkUmtAZRJhvd6NpE+HFXKZuu7n7t3FCxUVGgjgsMmOjyKht6LQlYiZervDetFxZ/jBkGaFC98EeZtPfXgN5aCRVnhkaJJ/WbG1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1hBCbdq8kvalZcFg0= 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 Fri Jun 21 02:29:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706694 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 82D46C2BD05 for ; Fri, 21 Jun 2024 02:31:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F41768D0120; Thu, 20 Jun 2024 22:31:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EF1D98D0111; Thu, 20 Jun 2024 22:31:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D428F8D0120; Thu, 20 Jun 2024 22:31:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AD2108D0111 for ; Thu, 20 Jun 2024 22:31:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2F529407A3 for ; Fri, 21 Jun 2024 02:31:13 +0000 (UTC) X-FDA: 82253318826.21.ADCD407 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) by imf02.hostedemail.com (Postfix) with ESMTP id 593848000A for ; Fri, 21 Jun 2024 02:31:10 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AgwnvLU0; spf=pass (imf02.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.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=1718937060; 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=nQwUpm7TadSQyuNlGOfh8JWtJNghSVDBcHtu3NLgdvg=; b=0jBwL5yrlXr9fXVtTA5RuSP0t4vwxPLHpkO5BpKmZJXAQR3iy5wz6e3kiq/RJrU9vztqT1 /nLReGsQtxK8JZF4NEu5yBPtGQLI7VEq/Cz223ryesIm4gznh4yB1Kjm2WVv7snF6Cp59+ Fw1WRE7L24QYKEM/WARrgWOfwMb+iAA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718937060; a=rsa-sha256; cv=none; b=UcUS9JFTQ2GYFEoGmdyx4ubYUDHS9aTBe1dB+kiJ976sZY1CQGI6GC7ou+Dx4OpN9yKuYI GCyU4FD3d9D7jEGFEehB68KLkPsw6zumxg0rvz9SBremF4VeabgysJm7YXtlM8E8Qj9LTM NMSScP6IxeC3zzNPLmXhq7mFX/SnpoY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AgwnvLU0; spf=pass (imf02.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.179 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3d21f7cc6c0so868393b6e.0 for ; Thu, 20 Jun 2024 19:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937069; x=1719541869; 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=nQwUpm7TadSQyuNlGOfh8JWtJNghSVDBcHtu3NLgdvg=; b=AgwnvLU0KKc5eOe7HDyHltJscjGBoLk8eSl7qrw4eN3zncyspPJg8pcWBZZ+hiihRj pR8kOPPVy5t1pMV/lVJuG05iUktKeZ6rQGkcZAdLsG1WDJouyTpPih1s30tJToBKER5e MEVbyGNVkvQVQf5JFRPp7JVekDIgtdo0Uwr07IP6Sa8cykL3VAH/clw4QfD8sx2u+3cH 1V3C6SnElC1OuYrf7myUUk9dbZeEb93JyDL+LeCa3feNWpZOtf2+9MRz7jgPG6ndYYPY +fZLvRoqAdBCv8jPQy47263m/CPvbGFCcwlUdIbx7BS2hGKnXuCEBg+j0oXcUteFY9gd LXtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937069; x=1719541869; 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=nQwUpm7TadSQyuNlGOfh8JWtJNghSVDBcHtu3NLgdvg=; b=uM2KfQa3dW7+yiwC/BpHoTE2T3vpjJ/tzHOhPQ8yHihS7NwAFKuF9KnTwrxK5TwuoB pJaJttdLcl4x9Rum8v/ot7mHvVJlgmahY+oyYAzkTlASHD5WXToQb+TUg2N5N8IselkO w+yj324O8Jga7K1+Sh3ec3Y0POfuHncTEnYmxpHogpMG+DYsmwOV0bFfkcXmk8fo9Rlv WYAeheSxJvafcOlmx8JEaxo5VGkSB1d7Bllc7k/MwYDB+i3yYHZe6gdvItnbiGxuUP7l m5g9dVy4L8WvE/6EX/ifaCiRBRws2WBmZ+WuqpDeb2lPKSvljontzxxghCbmTO2cISKZ cLRw== X-Forwarded-Encrypted: i=1; AJvYcCUEgfLdfGeRBzvKmUmqF2OZeCOE1za5XPTuIg1UMR7eUXNVhmV3G0SOhZmPQ9qITc1Ydxsu5WztXFzpDXcBfhjh2kE= X-Gm-Message-State: AOJu0Yz8voVkbCeV60McojuI5esg/ZSA6AFdUfD4xZ6Lc+XYGGNUcwFl pBnlzs7fJdMEqivT79ABV4OyUn03h9h04NV2tqVAsFLf1XDAbjGc X-Google-Smtp-Source: AGHT+IF9RQI6I8fwWnu/VEcjE+HIUegV9PWFNk6TPRJqj9VSP13v0pKuFsE10NjsKk43i459GXxRWg== X-Received: by 2002:a05:6870:b52c:b0:254:7a82:cb3f with SMTP id 586e51a60fabf-25c94a2368bmr7837289fac.25.1718937069341; Thu, 20 Jun 2024 19:31:09 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.30.57 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:31:08 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 03/11] security: Replace memcpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:51 +0800 Message-Id: <20240621022959.9124-4-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: ofzm35a6w8ofg3kbkyys9jke7b4jud1u X-Rspamd-Queue-Id: 593848000A X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718937070-641272 X-HE-Meta: U2FsdGVkX18OoTdBBi7XL7GAiUpN7QgPkU5B+Y3vDCT+ixYHZpy/qzFzOAm54+41fphwBMGst/9w8UIcbfPZ6p0Te+6Nv/U5o6l17Yt22XwAFfRmVKNl0//9I8+2dw3jVcLtyBjfzaiOKTc5OLNe+hrtJcdeqB3KvaUIrjct+u2/RT2pK78j4/D41uWgOt97gVtyzi0WDyyeH3vOMV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PqJDTiJEYdWSB6NI5E5934wQsNsPHMf5ohweUH+8qz1jTFJtoVCawJYA2KfDzFdxD+ObfNwr2gz8AvDHyfJbMiycTJ9CUeCy8YZ8QgODxdh/Up6kvYEb/ABnjqjH0dMJKXWQ0W0aTi9fm4nAAF/N3U2Ns8v5KhKCre+TDmKxf1pKydz2qaC1lcLbjEp4QVUREmyM4ELdzmmBPoaX/2zAP/tMkaieDUjEGDafzsd0MDs7UZfhaO7o9Y20uyvhLVV2iMnQ+tu6ZoBIg1RCXqugOWsV9iIWagDXFIGJ0PyzZ5feYUCM8sz+DVf4ezu+FSWdXIsvc098cQd7cnKPUdAw3DKY2553TF8DtySlz6tjNIQa4XosVf6tP/FaYgowiWUJNH1QKP8km2vt1PvZXdoBoF0YHESzUiRuj2abBEChQ4jmIGj755HdK6SXAXK0VqQ2x4Ze+lF3JSPzuxXpnKk2gbXL 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 Fri Jun 21 02:29:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706695 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 6093FC2BD05 for ; Fri, 21 Jun 2024 02:31:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AACDB8D0121; Thu, 20 Jun 2024 22:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A5C2F8D0111; Thu, 20 Jun 2024 22:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D7898D0121; Thu, 20 Jun 2024 22:31:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6B0338D0111 for ; Thu, 20 Jun 2024 22:31:22 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 265831C1581 for ; Fri, 21 Jun 2024 02:31:22 +0000 (UTC) X-FDA: 82253319204.22.8573D6E Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) by imf15.hostedemail.com (Postfix) with ESMTP id 57262A0008 for ; Fri, 21 Jun 2024 02:31:20 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A4lussnk; spf=pass (imf15.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718937067; 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=c7QH8g7nY2INvVrL4NU75ftNhN6FL7HL04IiCAjwJmE=; b=osoC4U7Y0C9ACOKAIUjSNeibUsmpVBMpEI4tZ2I8Hp9bU5whttQ9BPvmaOBEoxdOj7FsAN EfuQld+7aY/SNlo3UJ3hMmZrtpQIr4srEHdP83yu7I0iy6zcii4NjQA+nrGD2+hYz9pHA4 iKzdaQ7oaSywMoGd7VWK73omQRPGUMA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=A4lussnk; spf=pass (imf15.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.181 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718937067; a=rsa-sha256; cv=none; b=ddJ9uCkWk1emAMzmC9N6wuiLYGWUGp/pULrR+OxfU98xQQvDqIN/Zps3JsqBBQ6NZ+nnfQ VozwaZBDvG1rxyOwpLsVmMlSx+mu8eIFyFeSJWGpfPobI7z6qWgJZuTcSU4DoSirOx3Ax8 G8fz+3gwwAlUyiuaGUBbyi5PfiTy+RY= Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3c9c36db8eeso781772b6e.0 for ; Thu, 20 Jun 2024 19:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937079; x=1719541879; 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=c7QH8g7nY2INvVrL4NU75ftNhN6FL7HL04IiCAjwJmE=; b=A4lussnkyrXSPjAKckzIo5jKQtdPUFA7L/QEVxBR53A+anHzJbDFWU6HCw/W/RUPVG SPaO0imYnYXNfAsF9PHhb7nURCY7ZNhsqGv8NVnDzLKD1UyIyi6Z6CXhpRGuRaXTdfh8 wx671b42OZF9Y/43nxuE4Zk9tG9fBaPV/S5cxbWbs93GAwNnuvuOs5NQuOTqIoBUoBO+ G7Ju7NmdaS7/lY1+qChOiGtlt0c7VEFhBml+jsjMRkRQcovnpu0+qkh/kbw2Nd9OBffp 8y9vEQFaUvdf3pYfKvIVqQilUAY75fhWgW1i3s+mqi7TWExBXkOBP0BxYTt5rOh4Csbb /B/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937079; x=1719541879; 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=c7QH8g7nY2INvVrL4NU75ftNhN6FL7HL04IiCAjwJmE=; b=hEjAtNnaptyDzIDHYZK8xP9c0vQqoQFhZZmDJs/DVrD2vklBWhucDngF02xQ/DJv32 337bqRDcccHDBn6N15wD9V2Il495hAtwAkP/U08ziF8ffZCtTyhtpPObEniDz+Tg0W+2 cgm/8GlvNaZZgaQiGRELfwB9fHb35fz23tp++4prGtOR47bBOuapqpS3reaoXUmtvIi9 /DpTYrU5ejbGZdMh37GOt7HxQ1Be8uxVH/EMcdwmWg6gREipQdv4ro4kbA+un4+6UuTI aDUlRlFacDCfRZRSKBXALsTRXYwkj8SnNiwE63xgGi6tKF4qYPLUok9D+nOfeHGa4CNX cpGw== X-Forwarded-Encrypted: i=1; AJvYcCU33nVAAqe2IJqoVvl4wbjBa+saMt/gKTY5cXDhsHFnQcDatr1crVqehZVwKLJkhFJVEZzyKlEMMhAAuTfaL9a4wm8= X-Gm-Message-State: AOJu0Yxl3/YqNFiT/ILPrUZCOC7dsA2BMJ4fiEUjBZbHg1p3mN9R2vbE r26Hd3mwiqyV5VP8fvFpeQJngwSgwDKZevpoKsDsm2aF/78kABmb X-Google-Smtp-Source: AGHT+IED/biJ/4HZ3XKtIPvcAUdQBx9cm4PcU9a703LBYQtgmllriwsa8W5+N5BARKh/qYuDuJagiw== X-Received: by 2002:a05:6808:f07:b0:3d2:21a7:8629 with SMTP id 5614622812f47-3d51bac4b56mr7794777b6e.41.1718937079354; Thu, 20 Jun 2024 19:31:19 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.31.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:31:18 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 04/11] bpftool: Ensure task comm is always NUL-terminated Date: Fri, 21 Jun 2024 10:29:52 +0800 Message-Id: <20240621022959.9124-5-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 57262A0008 X-Stat-Signature: q7rywh35dhb5xnhjfkzx3bi9rpcyw83a X-Rspam-User: X-HE-Tag: 1718937080-842974 X-HE-Meta: U2FsdGVkX195WQ2P29m2Xw1tu8onLQMUkgUtg6Hpyc8J7tPSR9MjgtjlmjXjCaZU0H5gArYRrWQYgXfPM87KKicGbA3auSrblGsCb7MCnvIvgUs3v1x1oUW4Bzk83mZQtAvzq478ziwaIeSOiBa4dNL4qSq58ibG1CSDXpua1ZVli0d8bB4QrtMU5XD9qT0s/sjjL1j/9bmU/YVPuq/cIcPF2AjcbN3BUAdSxBKEEO/SMGb2U3IxuYUXRljoAOLZV3mD338WrUjOm3jD8wVzLmVBdcSKtUkb9ySxKVZQNzUrZ7DrLmu1gMwZRl9AjsA895KBk1swlyDjH32UEjPQTUckumTxqXQ+kD9c1kgRfwTQoylareOvJLuroh2wwVraNiAYTODKOKl/etuN/R3zPabmrFttBJtmEWGm3GZDEvgS6/WsmVVf1VeJsf9+GvhRnjNNxFv5crN107YNW3N06h0oSsYUWiuzg/rqd3hL0BRg9SAdb9a7LY5YM0HBWxszoND2oJvCExXSdKEZcomO1LAlOowtfEKGW932GgqOYHctRoH7Bn0TsOv+5sepIfq4ofor8DA6xgGTwRnWJy2F2G2FH8XpSYKbRie4SlFUll+XWYsO9PD3Khu4/O1u/XolvyOYp7XmbHMsjvj7ZDHOulXuZNU1Rbni6jjGEw22qtf+Q7BeTvIAdY3TiwN0VxXWkk3Jh6IFH0u/j+78a/dft8i1wm/qp78tfGAGqxlSg+bbbv2FtFjrQOOoSUidT7axwptvNk51WcAfSTqMzUoXkU+UXpLBtiH6BNuPruPkH8fLgC3KECCaN9W+Yhmhs/Ye/O6zMzwQokU03n+rgspbmpeMOEwwoS4nVgdN5ASqqszhWhvKNEpL/+nhsxDqHJXphnqvbzpbGXU0uGh+mmFgwcU+f9CK7oBu9aEyPpP3OquDHWBYiEfLuOydgNo1ql2ExQ05DyoiY0deIVRSMsv AMoTDPMy DiWU2m8SLJ2GaWsYHHKuX5gG2iYflzKZc++5nyrWasPigZNGYCXr6EQxFNLCwtS3Vgy2szI6hyi/Vix/7hFT+apUo7HFF+g+itaLWBNa3olSkOU8yXET5Tq5IvvS9cSKVfg3LSyLbRSKZml5xu4XnL8/rNTg8Lpun5J941FtWmcyPgr/795c8PvyZGQUVkOC79NdPYJDDjtMXrLgn2lqSvGBU+FpTEupvPpNn2tp7jmXpXjILUM9PaG3X1do4Nbu1CmW6e2FAVjqmqOYTEAadmdNuBCGgUt5W02ohYkyI61hFNSwrS2WDPNEtLLzewO9iTizUpVBkBGqVBy6XlKr4pg7p3vOr535maFv7qWPrfQwBty9wcTZkYZbl0UzUB5NdK+VruAKVnaedHzG7SYp997T1PuQPg1MxoDygbnFwgfWQqMBtQpuHRISWKIvk0Vj+M4nfr1jN8lwjcpCPTsGneq3N39baoGGUD6+rRBMm2SIsDZLUnqW1Ewk68AucHTop3wekZpqJEz1hr3M= 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: 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 Fri Jun 21 02:29:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706696 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 C6CFEC2BD05 for ; Fri, 21 Jun 2024 02:31:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 333736B009F; Thu, 20 Jun 2024 22:31:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E2A96B00A5; Thu, 20 Jun 2024 22:31:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 185D46B00A4; Thu, 20 Jun 2024 22:31:33 -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 E3EA38D0111 for ; Thu, 20 Jun 2024 22:31:32 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 885188078A for ; Fri, 21 Jun 2024 02:31:32 +0000 (UTC) X-FDA: 82253319624.23.8A6C4B4 Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by imf08.hostedemail.com (Postfix) with ESMTP id B7ABA16000A for ; Fri, 21 Jun 2024 02:31:30 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="ZJOivL/E"; spf=pass (imf08.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.182 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=1718937086; 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=1K+hSkFBa/z9wm4YENh0APfdLPb/9OfvoDMj7Q9JegI=; b=6/e+Igt8RqEZMKoCeO+xXkcrAHrCYXYyzrOnXqYKGTR0rLhKjkdDP9WLqi8aFOPyuEv0u1 YnI0LRhSSf81+6L+jtKFnRxYYLefA2ydwTRVh9hZL4cO5q5YMmeqms2cBujy+AW8Me82Wv bvBxqGBTXx7+qikZ6a9+3g7ELsWWBgg= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="ZJOivL/E"; spf=pass (imf08.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.182 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=1718937086; a=rsa-sha256; cv=none; b=qw2fgkX92tUIW47S7VoMvXtWcQT9ta4f1LPpr7D3CxBi40lR+sijmE/8R6xJYiCFAxrl9V Zhk7iBsw6BFKPHWR5DQYzCZ9AMe3bq5y/P3uco677S1+SXTuhopy27+3vFb7IvN4/cmzLs SbF0+b76TtXooJebgwyzdT/hLpFTTTc= Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3d22802674cso823194b6e.2 for ; Thu, 20 Jun 2024 19:31:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937090; x=1719541890; 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=1K+hSkFBa/z9wm4YENh0APfdLPb/9OfvoDMj7Q9JegI=; b=ZJOivL/EFnpT3BFYzaIDvr6lJKWX8SzaimWOXPRMhM0leRgFcZpYKLgKCydzYoNROI 7MPaeP7nzPbinpB6g3giiko/zzqtkxpV+KFmr/wbJom7iwEsiM8UiVvlcrY7ZVBtn6+N ZtoudbEtIHx3/KCIsiHG+xhrXTWMsf+11ljQiBDyPfsH1UBTCfeyWSTk88oKhuithAJF e3RAv8a2/c/f7wWGMbGCeUVh/bBr8iZAVAguRbSxOoX/GmVqM4fvYjO0niREWs4NFTLl U9bBiCTF9UC+pGgv6hDxdlIDdKvvGgKsUhGKd+4hOlQTIynhrW7ML9EDvCXAz9T6jh8d O1lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937090; x=1719541890; 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=1K+hSkFBa/z9wm4YENh0APfdLPb/9OfvoDMj7Q9JegI=; b=cgRXkoVzrUjdO/HeW4z+gHFhFD8wSPo6B8uxfcwpOTC2GcvlN/fKPQiAF/uTWDpPhG vnfqvDOLpgFe/oY1I9xxhIJQIksKrcCHVmc9e9hEbihv417ZOP3DHD6fSSVFYRwsfFF0 6ha25jxUz4cChbFlbYT+E0NtU5ZLiPigSFRuD1pUhbHs2tjni4ZAOzIPOd/SnAkz19uN zohM/vRz+b5IDaYc2tk6SqcW/Yiw1PyyZkLyPTKpv7X/icQfqVbSthxJU9pnK1Bii4FF 6avJOQ2abxmwczpAS0GZw1bRg1gLYziWmxtJWMs7iqhfDnyEhjlPB8/GZ3e3L+S2qxG/ +EQA== X-Forwarded-Encrypted: i=1; AJvYcCWShx/7X4B/BYl3zJsD+VA3RTFH3HzoP7Mn+iTiAC3qSofuoiX3CFmN4fQs4Lhp6DHUBtrOIU7el0NYTRy1+hwroeg= X-Gm-Message-State: AOJu0YyOngJ9mjhOrGEy3ZaDcIHpuSuL1vo4DqWd+b3WdZvlUeYS/4YM xoyi5S/31bo84UuvSlWoH7VxbtClkBYMZQYgu3tK4LrHv+jNIjoX X-Google-Smtp-Source: AGHT+IGPBhm+odN2LJAX3QWj+Jlu2WkC5FUNop9iFT0Xeg6XFGC2MN7wYjSEAKCdXzo9nJ50WQHXKg== X-Received: by 2002:a05:6808:1789:b0:3d2:19da:9573 with SMTP id 5614622812f47-3d51b97ee20mr8962729b6e.15.1718937089513; Thu, 20 Jun 2024 19:31:29 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.31.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:31:29 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 05/11] mm/util: Fix possible race condition in kstrdup() Date: Fri, 21 Jun 2024 10:29:53 +0800 Message-Id: <20240621022959.9124-6-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B7ABA16000A X-Stat-Signature: zhqy1o4w1npoohwhy4ycno9a59t1wwt6 X-HE-Tag: 1718937090-181944 X-HE-Meta: U2FsdGVkX19OjSEHU5elFQnW1MDca3AsNqa7dT9NFeRmHuk7jh4AhyX6MD/OgkKAk1/gBGQ2wus50vilrBqmdbojvI0+vnndYqGDGGTkqolM2lNjjNXYdNQIjI7l1llVYKu4N+zz2ukiRCoV4cBvfJmRfdGgQDvcX90uqF30B+QUXS+wLMj1Xc277ePtN14SS4eoeFkRSi3f2NzycvTDPRawUezkLVpMQCk12Y/yzTnV8kPQi9f/IeZgCPdVtVsePjpQDc8fXBN6jO+NB+qDTMQPlu8Je7BJZ0fBlal7CE3aYIavF2nCgBe9jFaHNvJ8JYQ6clmeA4EChKJ51Cmv9QwzD31e12epB3DTq8SRqviNe9B/hXBaSSGM58xRzUmAzSaaEyriaNO1fdZWQRfGWVXUX9HyjHsdaAmD5Gts1SQG/Z3ljnwzSAiNAlGs4ev1lGpngBazcnppa1rpTJSvpHR1sZ4uk1xd70ZvDKpIdFsoRBZe8nxZWN1W6Qaj10NToqcwY6aD/whjggpKTevk9zpy3wqO1SXQ/7ilVQnYhXPy+xVEdgNIZSjiGRIIw+zvPk6HzXXxVYqY8nXyhssr1C88uReP3+ttiAfnb1JPmiJxX9/gYMW4Mq7+MCVNjoSI4VY/ksiPQozoQQUBObdhc5y49ACoP6RwXon4CLpEYDwUUey3kpZgf2U93gLMQnUJ81ZqgO+Tt6GhV1PU11tiK57V40Rjr1wtrE9rkP6NbB/TVFnAgbQ4qwecL7Vd3z5Xp6+H9WKgbaVWN7Ey4PeqkA5D/mRpEt1gBCC0uI7jhsbc7gfImK8QH3QeYO+PLwDwPLl0HH3ALzdGRH+EkjXR+NSCps8LgJKkjBon+gzkkhdnDq/dy4etzWOChqT1Ws6fQADy2vkhrKd4G+QDep8ig9K98QrCgdCLnrTdk7/hig0FXE+6v8M14VJFngoJe7MzZ/93QhKLxJasxd0m0Ae zp4o377p 2inRipzaognVJCJ0/oRNFi4+t/YDIOFHMvyPuS878Q10q4EZjrQhqqWVyvyZdnE0HrbyGEsdes+PnIpdYanayiwzFaHnebQsXF5W7XAjOHXJXoW+ksZONkc/v/6MrXQUiM3kInU16iq15ddoJ7A6v10LAaI1RrzjUPIOHr8pBajPNyD6HHQ2bCGCbmFr0ds/xIvucTizY5t577uj7U07oXZ6tufzqIRDT/Udnu5OBCKcQVaXnx+8MgUjLVIFbKDTqhqXX6yxm9Mq1tfqoCYaEdpN1d5vJo4Pq2WZaSqN8mplVkCouPHhsjdf+djQLjnP46/lP9c5ZcwQADiX1QHkdZ2GRdBVm7nqbYYHMDWaS/cke79oKr4FRln/oM4dQ98edFnAqXXI2Y5I4rXoy5N8vFoFjpsRJZwRdrbRW/Oa0e9266KTmS6voh9qjOmExakDKqMjNauS2aSfrKkONtD/RJskK8SsR2hi3x+I78xHEnZt5z5Vlj29nKtH2niHpo2JLXVn7aA/J5VEffGE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000023, 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 Fri Jun 21 02:29:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706697 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 C391DC2BA18 for ; Fri, 21 Jun 2024 02:31:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A3CB6B039C; Thu, 20 Jun 2024 22:31:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 553AE6B039E; Thu, 20 Jun 2024 22:31:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F4526B039F; Thu, 20 Jun 2024 22:31:44 -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 21E6B6B039C for ; Thu, 20 Jun 2024 22:31:44 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D4194A2212 for ; Fri, 21 Jun 2024 02:31:43 +0000 (UTC) X-FDA: 82253320086.11.14E9ADE Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf28.hostedemail.com (Postfix) with ESMTP id 0C1F1C0017 for ; Fri, 21 Jun 2024 02:31:41 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fMjF904q; spf=pass (imf28.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.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=1718937097; 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=gIxIpX3fSDij30wx/6pUEm1wGM6JrlT5xZ3d0lBG2nM=; b=f97TpSbFRQO9fwcr9XNtVEvZ74HjO23zBExKqIB/Yi9aR1oUn0mfwo6fSeFLW/4Qj3zVIn G6chTGHycADFB33FprLlPRc1SWImf5oX6n6qyhXo2RgQ8gOgV4jaMgVoxh3Xc13BvkFbXs PwPrWubV+sgXag6XCR8SYJuS/tJ/JOc= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=fMjF904q; spf=pass (imf28.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.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=1718937097; a=rsa-sha256; cv=none; b=dCFzV8k8/bW6oDPHilixLK7my/gtgzJaLCs4G+iHEYVrD3Z1baw3Blhx/6Yxi95lZs9ZoD /3cAX0eyroMpM5wTJ67mZ+kNREopGm8a0MqZS4W0Ns2wxLcVPELaAPgUqRULLRgjd4RSSU yDiCMjRQO3AM/AD/Tg0VkXSWUueOoJ4= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-705d9f4cd7bso1409227b3a.1 for ; Thu, 20 Jun 2024 19:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937101; x=1719541901; 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=gIxIpX3fSDij30wx/6pUEm1wGM6JrlT5xZ3d0lBG2nM=; b=fMjF904qm7Zp6br20HkRR/HOJ/z9EuxW/QAmUwkSj9FlkGzD8jWkgMSLZUnfXNPBGz gTGcUBoOjf9pTwrHfl/k7XwY0H+2TnF9WgNBhHiGl0qsk4zHLp2Vh+B5iZrJquHgQVGR ccIxdYuwAyS5x9uoeKoBsZHNz/eWCS4gngSS2h0NNzph2cotie4kHAGVclahEOXTAfVF jqVESJHi9upWw1JgRdFLFZvX7U5l8rQYODnZJc+suDMxpcTrCGHnuTZJ/yDl57+RWlVa va8yYA2GsMasq/A+xmxoYes3gqgdCElu7nvopzegTyuLON3ujj3l9ffC12X0wnFRiXX/ nzow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937101; x=1719541901; 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=gIxIpX3fSDij30wx/6pUEm1wGM6JrlT5xZ3d0lBG2nM=; b=EWpJmFitJGazyNxLN0g19RT+fBK9ip8+7MeWLOYdrss9twRa6KVruH0H+0nQXK2JVU bvMJLzkPi4rN4bDd1Hx0rg9ptfxZvs2JGSKNBDsMkrIKTP8ebOChHBThX1e00utCTC24 FCdXE7msjWpvQS8vXkrj5hraXoQD2iO3Nw1+S4sOzJMe8pUKG76bkx22F8l14rnZ5b0j 21z1J5mglRpqYBoI6uTEVhssqINeL9qLgzAomPhZkvaaeBiZmOiB+hSao1BvdcvWCW/0 SJLBzhpajE494/aHWyQSVWweXZYyOTJrBrdmaR/FrCZG09eHEs1jzVVZ6t6jBgZv5bUo /6qQ== X-Forwarded-Encrypted: i=1; AJvYcCXkZj1XbYc0EZHR+we3P0U2njhWskHPge4t/nY9VKpAX7zxpG8PaDoSQ3TBmgGNpJgdNNda9/DTq+1alymPDfNvtlA= X-Gm-Message-State: AOJu0YyFNTfByPdgUVlCcuvaGgkWMoyyqGmAR6BT8Adnqup4k4LMISw1 Y1MrkqsDC8mWLnX3CvlezhJLdiiWRMzHtnbhUbUrwdSxU65WqgIA X-Google-Smtp-Source: AGHT+IGYNoV/DB/o6zRof24rJ6xmZEwxYI9LpBEDyg5OiYjfuVgaYmaCgemL5OUn4y/KnIdaoKGjig== X-Received: by 2002:a05:6a00:2f43:b0:704:2d64:747 with SMTP id d2e1a72fcca58-70629c1dcdbmr6929306b3a.7.1718937100840; Thu, 20 Jun 2024 19:31:40 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.31.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:31:40 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 06/11] mm/util: Deduplicate code in {kstrdup,kstrndup,kmemdup_nul} Date: Fri, 21 Jun 2024 10:29:54 +0800 Message-Id: <20240621022959.9124-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0C1F1C0017 X-Stat-Signature: g895t6cofmswzr8ndbh4xc9717w383t9 X-HE-Tag: 1718937101-161768 X-HE-Meta: U2FsdGVkX18Dp7IUlmp8Epy/Z81O5is7u/R+Tjq925/1voV6a7LHJbMh1E8EqegFwENmPTuu6UIG+Nn79SuR7fjV54ljOl+U2x5XMEXpCNIzv8H4SMZthML5LmQyFVwmIs5w3G1ag2nPV46usTMv3VYsMB2X61Yy1h8e2NSMHHIi7DF4IvptKPLAuhxrtX6xsiFRmIntXOIB6PkiNt2T4E+RqiipmUWd4hMgcS07l+8hFEBySvxsvRDVkvyWCTaC0FzahYAUYj6Ca8/eeH6W9sq4391lyEvGYQG3C2/u7a8wPJV5YD2gWQ0ziVDnx6vW88MDtlXjdaTlhUZva0Csl4bvZhoeaaqD20K1Z++LKU2d1eQFYHHRjzQnRFcn5CrNS4pJJy85wgGVdXjycbcBjRB13ToC0Jj61OwuD748UuDoLeoVIB3hXy6EO3V60CJEZ2AJFB9MJJf4Hs9q1gREK9mDPFueAd84qMzwTmSALCGv66VqnUlU6eJAYWVQDeDCQz2mZkTbwe6Q3326m+hnArIKyzrMpxac8LvukXOV1ad2pp601uf9aRR97CjbCFs9DXv49Okt47yJHtCk+JazHPHaz9yvjprMHYIzNrzTmZkofGR0xVC8gBqpLEbhAL5i4t+syzCZmkEBYDtF+chZLs89qwE/S2Zsq0loirOgqefNAn0BQgTfPkAFaWVsZJyIKvzTHhV1e+MuAOHv/kTM66QGqj/X66I6WKlwj9hQsRbMoeGMS1c2i0bec/n5Tsf2cjgFlnMWdV90JwEQPuPTQJSGcTg8HYqXOF/1EuRhDT6Hc2Q7x82hmf8OocNUnDvB5unaZbHIwFCyXD+aEsaI68FhnRLkGU8UPk65MKYWjM4sH2uFf0/WgD26r8kB7Qh3oXMv6/iSlwjyWYC1BazpHDY8/+OezJ09Rf2XwfBoIHlAlnoYus1hxBYeDqFJGROp2cOGOahtIKbejvfFyq/ DcodAQk4 XyWi46tKKHeeaGu++Cmgd8DE2F/TueZ1L401lc/XmXlm78Vhii3/7y5fhVesRS64s8hBtAOEnDuQhxcCdRCj87rPpfBMGFJoUHfhojyRgsGDijTzPHUEKV+4WzIeCz2IVVzg4N2rUir1L+QmQSWozx2lNAyx1FBpfeB648CaHL3RoFq4WTjzZ9EiMMNTlZOjD0vwKRtr8RolQ/3ahQJ8KFsZgC2Pa13F2fMmi9xyKtMTEBErTK6b8uywFrCyq3iRRNdDGdvxnsX4wAYpmO+y8kTNdcXD8xDYZTEQyBU9g7ykFPaoqieq++9of+92ZebCR2di2hecGiOrai+h6sjTPQaFKOGDV+9Qohfd6KJHFX3SSoE4m/OZKimDS3EOZ3KJCds4qh02K0NwR4BW7JuI1vW8d2pvRhYDBdIzsQN3ngjtNN9/PqumBobInto/h06PNuZja/hDAGeusTnV2Xeu2sS2+6xGDrwcTFJimdZNPu402lw2FgWryxK5m5GEwbbuCczWRu1z8cUbzKqbftOfVLW1bdzhYXgWvWI9UDlEfL9JJzHYUckWrqSxyTw== 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 help __kstrndup(). Suggested-by: Andrew Morton Signed-off-by: Yafang Shao --- mm/internal.h | 24 ++++++++++++++++++++++++ mm/util.c | 27 ++++----------------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index b2c75b12014e..fd87f685739b 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1521,4 +1521,28 @@ static inline void shrinker_debugfs_remove(struct dentry *debugfs_entry, void workingset_update_node(struct xa_node *node); extern struct list_lru shadow_nodes; +/** + * __kstrndup - Create a NUL-terminated string from @s, which might be unterminated. + * @s: The data to stringify + * @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 with NUL-termination or %NULL in + * case of error + */ +static __always_inline char *__kstrndup(const char *s, size_t len, gfp_t gfp) +{ + char *buf; + + buf = kmalloc_track_caller(len, gfp); + if (!buf) + return NULL; + + memcpy(buf, s, len); + /* Ensure the buf is always NUL-terminated, regardless of @s. */ + buf[len - 1] = '\0'; + return buf; +} + + #endif /* __MM_INTERNAL_H */ diff --git a/mm/util.c b/mm/util.c index 41c7875572ed..d9135c5fdf7f 100644 --- a/mm/util.c +++ b/mm/util.c @@ -58,17 +58,8 @@ char *kstrdup(const char *s, gfp_t gfp) if (!s) 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'; - } - return buf; + len = strlen(s); + return __kstrndup(s, len + 1, gfp); } EXPORT_SYMBOL(kstrdup); @@ -111,12 +102,7 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp) 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 __kstrndup(s, len + 1, gfp); } EXPORT_SYMBOL(kstrndup); @@ -195,12 +181,7 @@ char *kmemdup_nul(const char *s, size_t len, gfp_t gfp) if (!s) return NULL; - buf = kmalloc_track_caller(len + 1, gfp); - if (buf) { - memcpy(buf, s, len); - buf[len] = '\0'; - } - return buf; + return __kstrndup(s, len + 1, gfp); } EXPORT_SYMBOL(kmemdup_nul); From patchwork Fri Jun 21 02:29:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706754 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 927BCC2BA18 for ; Fri, 21 Jun 2024 02:31:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 297316B0120; Thu, 20 Jun 2024 22:31:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2473B6B0121; Thu, 20 Jun 2024 22:31:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E8A66B0124; Thu, 20 Jun 2024 22:31:55 -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 DC65E6B0120 for ; Thu, 20 Jun 2024 22:31:54 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 760E2A2432 for ; Fri, 21 Jun 2024 02:31:54 +0000 (UTC) X-FDA: 82253320548.14.C4C2736 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf14.hostedemail.com (Postfix) with ESMTP id AC911100002 for ; Fri, 21 Jun 2024 02:31:52 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jeum3M1T; spf=pass (imf14.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.178 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=1718937102; 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=WYd5YNknE07k5DuwDR8qZLFs+IUn8eRucnjF7OV4ohA=; b=5dPeuAEa4ZT4gwUazhrm1p6+9YzSkCCsk7P0rKhoqOTmrynyRPpRWJbiuV5qHfsGU+JuxL rwpO31jNnOvHEPim6WNYrPualQedQAwbWbaF7C9o4c+KjYa0+x/DREs1Bx8v9qwZO93gyt JbWl2JgLPXbTFq9mcIlkKD8a5HZXPc0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718937102; a=rsa-sha256; cv=none; b=InTjvIRkcd7k68HVfz9vqH1JmMGVAT13olgXVYc+C7a3bBlrINLUSS3ZmGHmd9TSXuoFmV oeg5ODz41bKnG9GbxEZDe6H4IBbqa17qMS9Sjz8ynPfRs9pNR1IM8GJy2g/tctH0ec7vy8 6NOLx8w8wZliC4NjP45QDL75TNI39RQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jeum3M1T; spf=pass (imf14.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-704189f1225so1617180b3a.0 for ; Thu, 20 Jun 2024 19:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937111; x=1719541911; 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=WYd5YNknE07k5DuwDR8qZLFs+IUn8eRucnjF7OV4ohA=; b=jeum3M1T1tyZIgM8sRk3BQWaW5al0xAgfakQd0LZ/YXsbpjMNIMDLr9HPlfDN31oru 9SZMSPi3ppzQu4UcgLjOyLybvt1rIC87CpfgL8GU1ifj1Ht+xD9YDDCdCtIv/8kzLHrf qGJ4SyIT9h5scQgIXtRzqm2UCS6m/TQSRfUsNFfNHOlUjZx4Y2Wkj88Io5Yiw4O3jubV D17Cm8zDHSLrYUGs/3bpJri0AKh4X2l9Ehwn3S7mLx8H/KT8o01TDj5xcbmqYPkxjqrq ILipct5igeGOlyBhJRZUAIMeWG6Qk3GZCI7WINHovzHqpr31qNHSleuiIdMczwFPHoMn VSpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937111; x=1719541911; 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=WYd5YNknE07k5DuwDR8qZLFs+IUn8eRucnjF7OV4ohA=; b=mAN9/+kb81ETLSMWaOcBdEKlify3uE2kryJlAo4Rnkw6OztNV23EovedYfiCI1CKIS caCEFW3nju7JK+F7XCkzVUxPJxYsCZ4GAvWdgay7bM2niJKLojSXTIyz6tM2HzXEPwGu 2RIsWvpr3vVOjckATCQhzQsRfQTUt0l3YeVydUl7sD8I77QZ2kh5U95/a5jlIFg8PqLb HRuAPGllWGgKgKn/q4p1UI7aSOZUIraiiFLxP2CIh06zyKLtyg4TFMDvArQOJ1PJgRa4 NO8fTAJjQMi3CqxAofTVXovs8IMF0F+KyZjZtII8ih0g7NPCIaS+kNlUK6EUTKyIcFsR CcYw== X-Forwarded-Encrypted: i=1; AJvYcCXZz5Wrst8pPmNE7CFLak3Le+WJydRajVqZsLzFy218bj4dpWImg0jIw4SnoxFMT508iDp0Qhew71IeIOne/hemOZk= X-Gm-Message-State: AOJu0YwylekrGRYj34m/Poc5hPCSF32t1HpsGVz6s7wQnVzANolM8kJ4 B9ekSzSfqt+QVjNb0gce4X5lYhYgIDy4aPycpelYJbJPLd8KG+cc X-Google-Smtp-Source: AGHT+IE3vqRU4TDjYUtGu1BjTuY8WxnNKb7eQY82UPvhwXZyWJtswQi4+ta6VB9SmiN5potLRkiFDg== X-Received: by 2002:a05:6a00:853:b0:705:ed06:cc64 with SMTP id d2e1a72fcca58-70629c521cfmr9225541b3a.16.1718937111523; Thu, 20 Jun 2024 19:31:51 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.31.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:31:51 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 07/11] mm/kmemleak: Replace strncpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:55 +0800 Message-Id: <20240621022959.9124-8-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: mbsg4kn1rb9571jionar8xp4xq3k9c48 X-Rspamd-Queue-Id: AC911100002 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1718937112-781408 X-HE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vnJNs1s9z6f7CYSKdHefZrTy6w5hC7dqcOrUbY+sGH0QAmp5XwYXts/iZfKAyjOinVRQybo3R+U7Z3WHWNvHxeRfz66nmKVWYnMyzwC9UVi5a4kNCgqSuXXIun0AgbQ3en2qyLiZmMclL8CS+ZLfT3nQI6JYCmFH005qfyEH6GyD/GWr2/9RNWwjWIMBRR9RdszyLb3vCSD9+FrJ/59toGtO6VeBRbJkKj5ffqDo2q5rwAHxoWk/4Tffm3am91iHeK2/XeZv40Gw4ynA8QtVQcVIN2+1bfcbeZElRxgJyGNG4XZoXgAnSbpongHFXEIycndHMYxiLXlw8iSclAuwVLomiAS6WQjlAcEfX4uqE4TIWv91HC872oXfE5B3KIQ2P/oLMZ2/rZdRerhP+QxqSR0+E31c7vlqhPXGZIUQUtUQpGpT4BBaBbhTrFgwd2jTgeV4KRCyP9sraEUaFVcCi4ObN+nhYPlPc6b0r0iIpGCuRW8wx3gjAgh4tdA4CHFxpCqBN716sptK/Q== 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 Fri Jun 21 02:29:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706755 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 5AF77C2BA18 for ; Fri, 21 Jun 2024 02:32:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA5216B041E; Thu, 20 Jun 2024 22:32:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5F0E6B041F; Thu, 20 Jun 2024 22:32:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF52F6B0420; Thu, 20 Jun 2024 22:32: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 AEB116B041E for ; Thu, 20 Jun 2024 22:32:04 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 476621A081D for ; Fri, 21 Jun 2024 02:32:04 +0000 (UTC) X-FDA: 82253320968.01.F22205D Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by imf26.hostedemail.com (Postfix) with ESMTP id 6DEF7140006 for ; Fri, 21 Jun 2024 02:32:02 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="itRsIEi/"; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.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=1718937109; 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=MqSWr/pfZwtTIRxMBQN6sYuDk2R2VvioPDgEPjsCPow=; b=YLBTtkMiqpwrbmX5moG/Cui3KrNWoKaBHXqSp1BnarheP1OWBJ6lNdxPjHhrxwGLpY/MEC q9kpjKUA4aXV7YIssnYYNdNB5d0efzO6CAxPOmdE/4KaIB12yBMLUXmcI6t8bRorKzNm6o bLS+GhgzZrYuh0jk4y2LtgT3Xx29FAY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="itRsIEi/"; spf=pass (imf26.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.167.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=1718937109; a=rsa-sha256; cv=none; b=ezs3epWdrXCsiB5dwZoL71lLzB8yQwgiu5tyawKdtbZyW51gn64x5/WIaROKLf4Ja10TB6 tn0ipWrH8934qQTL2Ws/sluoh36qXNEvN8XaN2JnIeFiLKnpui99r+mhN4Abv3Pzrs3+/S 1USI8kzIQecx8ocZz6/y9kABSJS+oBs= Received: by mail-oi1-f173.google.com with SMTP id 5614622812f47-3d21b3da741so775444b6e.2 for ; Thu, 20 Jun 2024 19:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937121; x=1719541921; 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=MqSWr/pfZwtTIRxMBQN6sYuDk2R2VvioPDgEPjsCPow=; b=itRsIEi/IiiLG5nWRJ461ggqXrqI5O3KUMkboiPbDpPfM/GxOmRtb9Lmr39GBUeYcB N+FHhtNybpVSKFhx3bxGPcjocfxjIMbSJHoSl3+vbM+8TTPcJavdlKLOnxbqoJtpXGki SjPHBlY/Kj41CKixre3HC38aTZTVP4/Z83jaNWovsCf64iwvQzNN+uy8HWJRw4f0lArm lvOYN1fGKQivaX/3FdbqTyIJkohaRhGgkLNdRuGGsJuXYLwlHFVs6acu8DMBVArEyVPJ 6n6RbyVxGXeTLHgfvCpT4zvcWK1TkUK3Il7gB8ISpsTBYNJP4QYtwo/+XbBBUnPAiFmH hweg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937121; x=1719541921; 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=MqSWr/pfZwtTIRxMBQN6sYuDk2R2VvioPDgEPjsCPow=; b=OQBpfedrJsA/zT57moYUAOvtdjWTOkpv2qiuHKZ8CWMVIPgI0StNrmkvOosm4gWvGd TrNeG1Rfr5a2kmtZdnchD/KXNVUGiQI8OT4ZNB2pqC2vGwSdmorQeQLpRuxJORqLPMTL ddkUUezngKlHmLRnKfIJw9+jD8ssl93E06YwmijgTootT8Qn615QktB3z0JFIoAOSpQ/ iGLgUVc0rXyKrf5XUIdkpjn6DkajwCnu8oVjU55yCt+9FPHzwvkJNSjUM5Z+aFWuxXh/ txgqtxrShI+SCelTGvjP4LdaZlvdcprOH9Xq7sntoKtuTZ/EvhI2QKJyCM2/c+PGyYXl YJAg== X-Forwarded-Encrypted: i=1; AJvYcCUvE30Tv9M9e9Y8QHjaJKrjHJOJqOIzALPwEuTKsnPIaCoEKqE3JwLz8FQ+BNKY8IULhAEmLvcCWkEBfbS/RpBmtpg= X-Gm-Message-State: AOJu0YwJvSy7p0ihAQ9J92zKXw6hfE2u+k6+fUcdvxZHy99TbmgKNT69 DYlQqurL8e//fP6F/NHQ6ZnVEgPV04FsjzpzvPy/DmI/VBKwwRtCq7g6JpTH X-Google-Smtp-Source: AGHT+IEDLpdYIw99Uz7LWzb9Zy/b+1+lbeIcbqra7aNgXOpLlSyDlDvG9wKvxKsFRnB2arbPqu9IVw== X-Received: by 2002:a05:6808:130b:b0:3d2:4a08:2cc8 with SMTP id 5614622812f47-3d51b9b4558mr8069073b6e.23.1718937121450; Thu, 20 Jun 2024 19:32:01 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.31.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:32:00 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 08/11] tsacct: Replace strncpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:56 +0800 Message-Id: <20240621022959.9124-9-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6DEF7140006 X-Stat-Signature: 3tpb8yxjr7k8y1gxyqizpddkat9myx1g X-Rspam-User: X-HE-Tag: 1718937122-320319 X-HE-Meta: U2FsdGVkX1+mtaoewMZxU2jc4b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TH4jSycsZZsB0BLpqOsjg7ZCoWLbf8Zzq4REAg4M75G61VuI0l7cg+cEZEu5NsYVsDbLY+7el9dEB0LZ+PH5X45n/15JqbLeY9AqHNdA9ApqTHfp6lUa0bszqCicc3jQT9Ch0zGKxwJBTZ134vlz1pfYfuo9M9x7vW7AJOY9D3NMQhX5i2mnE6+E4IlNTdJByZzInHHF1SYSQXpS4M4pjH3g3rdwkifkiVvg7pmEuN4Ajv/8Iv1VdWtMWOqwRU8swvwwIxFYjrlaLfDtNGBGbxrG84f1uEtPNbID+BLiSSuB2+TwJIyoZsQsrLE8Il09x/0T67u8qHXiM7yqhZe4TVu4dvMGgArOebNU53tD14nAh2ENbGvEE264yO6K8o45WNbA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000713, 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 Fri Jun 21 02:29:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706756 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 C71B2C2BBCA for ; Fri, 21 Jun 2024 02:32:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4BA026B019A; Thu, 20 Jun 2024 22:32:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 331556B0446; Thu, 20 Jun 2024 22:32:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 135FC6B0448; Thu, 20 Jun 2024 22:32:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E30356B0446 for ; Thu, 20 Jun 2024 22:32:28 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8AD33A076C for ; Fri, 21 Jun 2024 02:32:28 +0000 (UTC) X-FDA: 82253321976.19.4641D75 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf09.hostedemail.com (Postfix) with ESMTP id B849014000D for ; Fri, 21 Jun 2024 02:32:26 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GiUuIhQ9; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.172 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=1718937141; a=rsa-sha256; cv=none; b=8o/jDlZOUg1aY0ogMRHKZYJfQdtyoB3Xm3fUboQHooCx1kgfhBcXibsfPCqSxiJ8XNYagT ZohmeFMfFkrREieyMgrioo4bT2Z+A3e6lpKAAims6OVIlb9MfA4qgndwpRFkFpXAnoJH3Z 0Db3GyLctji6aaKGbldx9cgv11tKLiA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GiUuIhQ9; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.172 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=1718937141; 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=HQT31JSkonb7Xmqn+k1uqrjgngeoHr6IFKrX/+KN6Ok=; b=pPogLx2keZj1I2Cj1ySvQz1bLDwzkk6X4fKMw8q5/dAXCnjvG7F5BlOi55gXAnuqhjbgiT Wk6zkxADzKXaJsGEv8s29HiDNhldqxd1VYji443O7ymYLGdBxKRpIV6b4WvI0lyeH0ZxvI 4E65Iu2JYXlkhQF0fESvMTJUykHU0ok= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7062c0ee254so1351113b3a.0 for ; Thu, 20 Jun 2024 19:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937145; x=1719541945; 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=HQT31JSkonb7Xmqn+k1uqrjgngeoHr6IFKrX/+KN6Ok=; b=GiUuIhQ9d2Nv840iJwHBkyL81yDITagKBrh6n362NEO5vbizTgSxrFWs0+XPUBV+VD 3PsjWCqF03ru4aaSCAYOAupEa+172nsKZqsuQHhmKDAa37g77b0XAXxCFLiDNwgUsBlH 1nHnMpFgmRy6V5TuKDcSSFZOHzojsFl7PluQcWHnMLhRB6wG7Zkc+1wrcBiK7yzz326K 9qQD5ao/2z3zvOQqitCh3EJIAcxZ302JfYRsN+qnWsli+YP0pdwUC0WUJh3UL9ife7Be SWN3EVSQLCBxA7WtUFHRHpbpNf3KzGcmYwJREtMirJtRztp6IyoNExZbOvvdm1+eOmQo MD5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937145; x=1719541945; 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=HQT31JSkonb7Xmqn+k1uqrjgngeoHr6IFKrX/+KN6Ok=; b=Z2OAzJWn24w50+RiaRih45ZI8FygAxED2rS3f8R3YkeFSUx3M0YS2IjO3CtgzWcLDf I5+pOIWvCnKZoT9rGIvbGeMdYSS7FGPnl/mjlzf8C/TX0IHoiS1vTN1/T9m0P0n4eEVy DguZ4bd+mrpd2cpy1dP5vRe+y9Xw5tnyMJzBZ8euiybeoHS0yZIvF4Qw/EkbM2UE/vLT BFmWElah6UyMDoxKz+KpfbUpt6ElX+dnAoPt+bBkiYrK1zufGEZP/gZKxR4ZPSvVEGub 2kkJQxv/PRxI2x/ZtpEAQxGXBireGW+LMe0fnjblylWhL3a6pTbXcudcRFxbgMScq5kW scvg== X-Forwarded-Encrypted: i=1; AJvYcCVQxvHW5y6x+CXeB3GJoSMMpg9D7o+vHEgfiV4dJrsk3LdoGhs1iZEmwnrcE649R/jMiBAw4IZI75V6wL6LTG1hAWs= X-Gm-Message-State: AOJu0Yywx2oIDZCwlPOP+G1WL2zx1HNpvnvWcaR+Q0YUlWvlsUfvK4CN eXLtp/Y/Mmx09OIykU7ZJpDIHnmcPK461zIc/rPDBcw8hzwCossV X-Google-Smtp-Source: AGHT+IGhhQvd2U/sH2KdV0ZtBjJthL8CznXxKI/3OBzCZg9mpyXqgc1aLbbwbnNImYe317PDiBUknw== X-Received: by 2002:aa7:8b0f:0:b0:705:d9e3:6179 with SMTP id d2e1a72fcca58-7062bf98e16mr5991736b3a.26.1718937132481; Thu, 20 Jun 2024 19:32:12 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.32.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:32:11 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 09/11] tracing: Replace strncpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:57 +0800 Message-Id: <20240621022959.9124-10-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: f16ky7c8xgmahxfapyicen791gjir5o7 X-Rspamd-Queue-Id: B849014000D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718937146-803795 X-HE-Meta: U2FsdGVkX19+sRR9A9jlmnXWTvQ4PZstRSdWlX34xmIKWalOEAXu8mWThKdJpBYvxCPY23UKr0d58eNfswVRySazvFBL5Y4karaLtAIMmfmeQj2TokWxXiuchNqu7QuFNpm11si6A5Hh0Ow5FNA7sEdOizSNwO45UsYx8KAKBBMNFkPwSe8TIDN2bs1fhov9Rj7xXtUNnzW/jjmGVdJYpfC+DHI0ikMRv1JZuVi/XhBlShvvFv4ggI/fuSpk5KZQ/Kk6Ykq90Qz5Dm7qleh6kteJkgHAYL0/LgdbrLU3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C16nnnR4fbEE3uTEb1OmngCLt4cH+hTRoGQFxcIL3yllIjI0qR7HofGIKybiH0YEO81jZb55xminlFhIVDXQsVeni0DBoHyp7ELgVzUgRcdT0fNum3oR9w5Z0M/dJy32cZmie2/DR6hZd3wAKdUf65p+QLC3EIKQb4YsRUYkGRqETLUTW7cQJtIPYewQiK9Z9DbLqZ1e2hTi6fX5/zml8OFL4KRGkemrOOlGfyBfNpAtmnzyCQUL6iD+lb+++RVZVI9Tv0aY+tqezd0uf4tBeZO+SbFByWT9o+56AGUlCxblc= 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 Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Acked-by: Masami Hiramatsu (Google) --- 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 Fri Jun 21 02:29:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706757 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 9E52CC2BA18 for ; Fri, 21 Jun 2024 02:32:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BF626B046C; Thu, 20 Jun 2024 22:32:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 273FB6B046E; Thu, 20 Jun 2024 22:32:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0744E6B046D; Thu, 20 Jun 2024 22:32:40 -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 DA3286B046A for ; Thu, 20 Jun 2024 22:32:40 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A531B160543 for ; Fri, 21 Jun 2024 02:32:40 +0000 (UTC) X-FDA: 82253322480.17.6BBBB74 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf22.hostedemail.com (Postfix) with ESMTP id D9F50C001D for ; Fri, 21 Jun 2024 02:32:38 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=M53frfms; spf=pass (imf22.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.169 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=1718937151; 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=mM/1S9T2tBYoZCgE31Q/lEbGdBggp1bwKT3yTD3UzMc=; b=mndeSSCkxyOX/+cPT1tBZBeHtzrTG7qvtgA4yxkNCU+9CBtxJi5BmFb6yAZ6szdNL2QhVy g/cenXc0CpxSfu2lTJBMdNmroDwHHhCmI27uk2X87SOkeXIXH5r6Sahe3gs3g8auqcsEfS xyY7W+wXtQA4dxwVMNufdsMJljndw9w= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=M53frfms; spf=pass (imf22.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.169 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=1718937151; a=rsa-sha256; cv=none; b=KRICp6gQnCq9Ku3JFluVYDyMWq1UZIrcKZjapUlazMA2LJBpyXPetGaphRqmkS9r1jC10v HazdtBg43C0dDO9fev1N5rwd4Gh0jb/iHYuZVntqDdxZr1hafjToUgzPk0rTQxcyxy6yAW 86vZ0n71UxC2DIbY92Tu3cEQoTDQiVA= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-704090c11easo1257624b3a.2 for ; Thu, 20 Jun 2024 19:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937158; x=1719541958; 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=mM/1S9T2tBYoZCgE31Q/lEbGdBggp1bwKT3yTD3UzMc=; b=M53frfmsfdIzSGuHb/4yzpvOtGT6BY9g7aHiBSk3WJ+TibMugdYlr7I4rVKYO1pZZ3 DH2AFpTKHij7D/YKLcusP/S0NYPqfyGmG5ktOll0QtcWqfHadarEohhKeRAZ0K+ydq9G bIZeDdTi/WBZkSZmqld6EgiyuZ0FopyF3rEeZho0zigjR/hu/HAUKiZwsoTAdLeQ/VK0 kqmObo+XVAfvBDPRHHUCfCeKkAB170TY+ZybFz/+A3D3dfrxjYT7tDvswfjQ8YrMtlRK +Cf7LzPwllRAV5CdkQZiwXuWGBdMUZl8I2KyL3QIBtu7YnLGSO2QBlVQDD52st4hjYNC 3V7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937158; x=1719541958; 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=mM/1S9T2tBYoZCgE31Q/lEbGdBggp1bwKT3yTD3UzMc=; b=EvVofHp6ceO28dvVxHtW/atPTRgHFA2cKyYNMhXEa7wrdQhBRf+f7c0uM4dnEwEFbj n76M3cIvWEXzrXXLnTw7R/gIShmgJtisPFTgxcWSHgUsPbfo/PtwhbsvDaPpGGNNEYmx dEr4rcZl7Rgv8Go80XxqhGciA5Y0YpN87bJ428gtgJIWfzFoZmA6ebn+NhraNbmKmVTj 7P/Ub6khd/wOZ2nkIpKSVkHFPxPjiO6/NEsNQNC1CoF5vdrktVbIljmAGXnqkwq2H5xp ToBsCcKs4uKJU7psCku5VuLEENqX7YWZ3iBhq2tXA0ZB9JnJg5kuFnyO4ZNgMOIG8BC8 srvw== X-Forwarded-Encrypted: i=1; AJvYcCVYS4RgYmVDBstbxM0scSKu4XwcCbEc8qvzB3hnUykRBlsSTdSi0oXjvg5LUo2cDl+mVuF5D1E2xXTo+Zwx9NcbfZ4= X-Gm-Message-State: AOJu0Yzcv5kVtxI2DPdwiQxg3OikJGNmiRGCEYAPxWlkKFxLZu8+stQ+ pxH2nsYwWJ0TPgtwJKYbUXYB7OkIvWzd69B6wCz+dSUk9j5GqCKM X-Google-Smtp-Source: AGHT+IHxOQrDg8mR1N6VheTp8u8eV+XoRh0OG7Yl/1zkogSK0YkzXLknkEls7rTyfvffHbYdw2ahAQ== X-Received: by 2002:a05:6a00:9289:b0:705:9992:d8ad with SMTP id d2e1a72fcca58-70629c6de86mr9102308b3a.19.1718937157754; Thu, 20 Jun 2024 19:32:37 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.32.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:32:37 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 v3 10/11] net: Replace strcpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:58 +0800 Message-Id: <20240621022959.9124-11-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: pjb6ace3m6xoxryrqti1akaiegy3wtd9 X-Rspam-User: X-Rspamd-Queue-Id: D9F50C001D X-Rspamd-Server: rspam02 X-HE-Tag: 1718937158-713270 X-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Y7Ha+Qj46i4fkLOus7pZukcNjTjn1vKSDce4PJ6p2M/HcKXA6NAFTY7qnnbjIqh+hB6kXxC21TUF+ScB5sYQyWtpGe3nrG7z28fkG1PVnyb3cFvNZrqAy3FEfgNT5vFGgyRnCYMckUjkzGAzM/6R1ohgz/QQB/RMlL/pYk9nkiupc/c9VYZHYCpB5QE7fEDtGNRou0dIn66ab1bJftiGcSkd3UG+ge+4pP9bE91W8xqKZsg2ojEPTtMYqg0886NuV4xOO+PVW4ALmmstdQZBp0/CVKtEAYRkSzxquIT2G/C83Wr+vAtljVFmkiYTlRiWEWYdQo2D+kydGN805GRbxYa/ekApCabrbqoHhT+pQ1xAxNQKRCUmha2yEsLct3L3p91UoqSh6h+Vvt4dew9cMawZZ5/svffu0btEWzETMlUOFUF6wVQGQPZQo3DjOZGpSc02G8L3rDVlYEXtzj1JlItsBzNN0rn1xK5ajJx3NfyZIxrmuoCcLZlzmwk/u7PmUQB7RUTtYSem3TqQ+1Y+6aCuPtZwyCex2k5T+who1AhWSsThxJFf9A5DJVxhoA02XF5D8ICyQJ 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 Fri Jun 21 02:29:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13706758 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 DC7C5C2BA18 for ; Fri, 21 Jun 2024 02:32:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66A8E8D0122; Thu, 20 Jun 2024 22:32:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 619738D0111; Thu, 20 Jun 2024 22:32:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 491AC8D0122; Thu, 20 Jun 2024 22:32:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 29EA48D0111 for ; Thu, 20 Jun 2024 22:32:54 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id ED153A2432 for ; Fri, 21 Jun 2024 02:32:53 +0000 (UTC) X-FDA: 82253323026.29.125747C Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf29.hostedemail.com (Postfix) with ESMTP id 1717D12000F for ; Fri, 21 Jun 2024 02:32:50 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="G42c/aBc"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718937163; a=rsa-sha256; cv=none; b=Y/RcK5o5B/sVnOrSk87l5MWMQnet9EBblcSuOFGV8JmVxNP0Z4dZEo7FhTtiqvQ/5vlOC4 xlRNvsJzzP/ri6wtDEG/ajgG0ZyM9BrRh+OQQC4ZQmj9NtAxnD2zUIGTwCYINt4H+o9DlB xpVvwZwPBZxMaXjOnzFJhwHiDo0AyAU= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="G42c/aBc"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.169 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=1718937163; 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=ByPZqEdQZBBtzQ6Ut5Ro8SR1Vw4SYts83oZvgSR+UR8=; b=wehLAVuRLVV4Lfli5I7g5BgSRFgB8ZOGmpEeEqOsPzjlfI0ziT8zz67jull1zwfspO0n41 bI3liddH3rvkWH4xNvGKtI3/fXRId7YDLxlFanv3znN3A6y6FFqoJvFkSbPaMUefkFaMRd BOTLUM7pCZ4mHZy1yAHFR+3GNTRDp1o= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-7062bf6d9a1so1241643b3a.1 for ; Thu, 20 Jun 2024 19:32:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718937170; x=1719541970; 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=ByPZqEdQZBBtzQ6Ut5Ro8SR1Vw4SYts83oZvgSR+UR8=; b=G42c/aBcs2hbclrRGv++ozCjSFv4PnL795F2CD/h1SZirIzsn8VeH3j1ur7/xdTYq3 P5sfi6Su4ytiqpb6vzgXXZjBvq43sXSER37L4NKmnsuqfBWFXw7BiQIoeBtB9nj2MPTr jQgW6rUcTDf4oaPGt8XiOQeAfByicSa0KxFOwMX5ZmL1blhd46lTIwiUVeS1JF5Z86GI bH8d/vHWX6JQDBoCGfHtkvierY8Fo+2exGdomBzbE5RzZKm1Q1F4qlJcV2iSJjJB5/ex xPhTFFcol2aZ/AUOAOkneB+dPmu/L+ddBlTzSN7x4aZYFAbxq/aI2T3dzvrd5XAmH0QM jw5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718937170; x=1719541970; 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=ByPZqEdQZBBtzQ6Ut5Ro8SR1Vw4SYts83oZvgSR+UR8=; b=gxcQvyvHBumOkGDzr/WaQWhilH5MEV5l3/WlxRFEtexukp72NzmR4T27are4hfheTe 0clsG6yic2KVng87oqiSENRNDxvtfuAWVLnKgqfwEwInYv5OxUby1EgwThRhhFi8vxN5 T0Apa1q29yGWHQyLD5nSnMrZ6rxLpuwJFQ9VwVDRoQHVxJzcNm7Lf+GG07jeyGzkgkd6 WV1WLyM1NLwUJIgsxDFZWcViJ3HR8N+N26NAxrIRKPNGdb3hZKENHOjcqogFQEE7st3f vsgwH6luicyUFHOsjPTuZ0V6cwAerkyEznlJO0kblQSVJ6qoiWfNLwzGl+eHfQJ3PeQK CCCg== X-Forwarded-Encrypted: i=1; AJvYcCUoH/1Qa0bwBKOkqv2GzRrR1nsR73FjtxQTIuaQphVryfTzTG9Sx0mwHnt+M6K9b/XBqe6I8u8BqukIDRVw5qYJ8Bg= X-Gm-Message-State: AOJu0YxNnu3pBNGYjgwnda4h75MGrWuV9znXHAhDw42hNT/jVQkLiMll 02to2vkKUqIAw5jBUqR1XYvpSTcb+DiCkk6hcyiWtkLOVTa7tG2e X-Google-Smtp-Source: AGHT+IHwLzKazOZk9J+TnuaENF2GrO7T5JApXVTdzZDurk6fW60Sg+sw/brS6M3qBlKISuVvI9yc+A== X-Received: by 2002:a05:6a00:4d91:b0:6e7:20a7:9fc0 with SMTP id d2e1a72fcca58-70629d0d58cmr6849890b3a.34.1718937169948; Thu, 20 Jun 2024 19:32:49 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.24]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-706511944d2sm332488b3a.70.2024.06.20.19.32.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jun 2024 19:32:49 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, catalin.marinas@arm.com, akpm@linux-foundation.org, 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 , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter Subject: [PATCH v3 11/11] drm: Replace strcpy() with __get_task_comm() Date: Fri, 21 Jun 2024 10:29:59 +0800 Message-Id: <20240621022959.9124-12-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240621022959.9124-1-laoar.shao@gmail.com> References: <20240621022959.9124-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-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xhHdOwN1Ep r05UJaUF ImGCVHvYVEiHcHukA4Od+MDc9V7EMI5y6yUMEFfeUD1rjeoe9/D1rkiQbnMuh+xYCuCydi2FcucTF9LKAYaQelfa7D/r1ZPlANeR3o6JiKOc6Z8hvX2YZ0w/FB4Eet0Epa69k/gE7oKS6Zeo7kWEQJy2qtiSmHT32bAB5Wyeq64yfh49ERGfPQu3vMvfYG4Rs537KG6lbaEtOqB5i8l6Ch4sm9BdXdqT/7I4SvQhCwzPQAjEv8kZy+eCXOq0JOayt5bmCHHsPRHhdBsnvTYIUqZ2KlQpS5j3Z+1zYpETeGTImwY2P+DL/q5bbaRha3Vfk8ZJyC+7wl//IIZllAf1UC+IfJ/idXhoEQqjhqRxXH1kwjMXCUm/gjxEUJoSTxnyq+69SJYHJyw0LCQWM1cqz2VkyR+BW7LXovgH6YRaxqFwb2Dlsc6A1qyABThTa/0ocddzkd6fh+kckTZHWSdeeEL+UghPC/SglVhUV0qyFRgsKoeqlPDCbQ724liQGJf6rH+fuFcHZjTVtWvj2RyrTlbhBVGXSGOlesNe53ixN6dEJt5Qvp9jdETaYZc+1qXPwIG/f3i/WSmuwxI4= 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 Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: David Airlie Cc: Daniel Vetter Acked-by: Daniel Vetter --- 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();