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-Meta: U2FsdGVkX19c8rRDrSnMEnDQ+FxA0Qi9rr7c4qmvC96UxAS6YSU8KNntuJQvOA1u/66UbRyUfqCBZRIlu0M/NPwmjYsQQTdcXlapqm1c1dliigpxpSQotnbmwTbxjM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2qyLiZmMclL8CS+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 */