From patchwork Thu Jun 13 02:30:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13695928 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 D0B96C27C6E for ; Thu, 13 Jun 2024 02:31:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C59A6B0089; Wed, 12 Jun 2024 22:31:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 674FF6B00A6; Wed, 12 Jun 2024 22:31:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53C8A6B00A7; Wed, 12 Jun 2024 22:31:53 -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 362426B00A6 for ; Wed, 12 Jun 2024 22:31:53 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DB480160577 for ; Thu, 13 Jun 2024 02:31:52 +0000 (UTC) X-FDA: 82224290064.03.6607D60 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf09.hostedemail.com (Postfix) with ESMTP id 1834F140008 for ; Thu, 13 Jun 2024 02:31:50 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WY+v7k3c; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.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=1718245910; 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=rI/qiwYumUf9WdznWs8PjjNV1aSEYVRYeuHEKQmKc7Y=; b=wjyw+TdY+gCnFmsaAsCudwZl4lzwOsnWuT59R+v1o+Uh/TDLQP4SjFkG8CVN5qlEVt9A1s PoRYfwvFrdKuoVX4+AfTnCXFNOYpWmwtKEiOibXJyos/kVNkCQvw4/lWPd4FjhdMv+lZMB YRjhuhJG/GbzsrK9lstvk3MzjPY2Hxc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718245910; a=rsa-sha256; cv=none; b=uwOSS+/4BrTgMgntxWxM0o4wuQEtpWIEAIrO7lljRliuFShKBs6rYENgSivsTLRGisdTPR VE1A0hwkplmmkb+XGmK7MwLMBm8ZATcYAyvOazoeA98e6+1Telmq5cIL7eQ4fmTsi6WnR1 sSamAzyws1E3pP68Pw3aPr3Biej+aBU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WY+v7k3c; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1f480624d10so4675695ad.1 for ; Wed, 12 Jun 2024 19:31:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718245910; x=1718850710; 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=rI/qiwYumUf9WdznWs8PjjNV1aSEYVRYeuHEKQmKc7Y=; b=WY+v7k3cLuKMpzbaUs4CWSwqE7SUO8OhvH+cpgmMOZS2P1zeO0S7mUJsKr91UOXujV RYJVLpfinACUs0lmJYdMhJ0oAY9bahJF76NKQuCVhumhLg8QlSoyl4SntnjZq16/JXCj 9CjSu6WNfDZoD3K6sKmTHfyBRxiylha6I6v+pGVFkIT0Y74WtpSpZ813xYOvN04Ox6E8 q/EW0R5dCKvn9DLXgddekMZILGJfpOoeBZ/8iyhHrHjXYq9sQQGgN6fvrmb37wN7j4wp M93S0vpE2xZB3hfElJlbkp1OvN3kXH/ljUwFgoGdrCGnEPlXrwXdnVEGJqfPR9XUjzRO 66uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718245910; x=1718850710; 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=rI/qiwYumUf9WdznWs8PjjNV1aSEYVRYeuHEKQmKc7Y=; b=U2Ae7M+ImwnAeLuBmMm81sZOZK0obTOrd15T5B0JlEj3kALOLaKvgPBAgIj6qaJCRm i/KqvUVphbLT7cfBAA+eE3eJzzqbGA8AZ+G6OpyoP5rMVPbhFkp2ERAd5KA1Bkmu7UuT 95w3SxAbt30+jWNHwTisbqbuuj3ybWWAnBTwwX5G7F2m20l0fL8wxXpyXq+/kBbCUIPp JkyYHDwgVu9KGag2KuWeIYQkLji+yZOmtEp7dceEwAQ/jVCyosrQMwqe9A+DehdRMzNw gzW0aZNGCjskhOBiECBDqCNJGp/iyOlYBslvgsmYvJRsXHVylrYnMLAnffw8+nMOROoD GMjw== X-Forwarded-Encrypted: i=1; AJvYcCWAqEjPcHpBr8mJD9SaM4+F/HGAg3RVzorDi3DvI8dyP/B2VkSCEb5fDYTzqBMKL7gNRfabwIRAZt77nwPoQORbbsA= X-Gm-Message-State: AOJu0Ywi8ip3UP7V58jnmr16luNK6iIzz4Ex/js/p3Cyl5lX6GO6ONdC 2/LaLQiOrBA8chQVM6OsaKgHKenktMifveqLimc7TTin98cARXtA X-Google-Smtp-Source: AGHT+IEHZPxKX/RP4SBm4cAnIghTfWMy7FOuVWWLSjXVUtL6OKmdClkmrYCnnZGc6EFhsF+GbPMHHg== X-Received: by 2002:a17:902:d2c9:b0:1f7:22bf:57f4 with SMTP id d9443c01a7336-1f83b730b3dmr43536295ad.55.1718245910002; Wed, 12 Jun 2024 19:31:50 -0700 (PDT) Received: from localhost.localdomain ([39.144.105.92]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855f4d159sm1755695ad.289.2024.06.12.19.31.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jun 2024 19:31:49 -0700 (PDT) From: Yafang Shao To: torvalds@linux-foundation.org Cc: ebiederm@xmission.com, alexei.starovoitov@gmail.com, rostedt@goodmis.org, 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 , Catalin Marinas , Andrew Morton Subject: [PATCH v2 06/10] mm/kmemleak: Replace strncpy() with __get_task_comm() Date: Thu, 13 Jun 2024 10:30:40 +0800 Message-Id: <20240613023044.45873-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20240613023044.45873-1-laoar.shao@gmail.com> References: <20240613023044.45873-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1834F140008 X-Stat-Signature: zg7x1ip4sk4o35eggfy9re1s9durpfqx X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1718245910-512165 X-HE-Meta: U2FsdGVkX1/lcKGYaoXFl/t1+0T/ip05YdSgQhtAjSvpLfxE6I/+uUbQf3wa1PMznlKe0rj7jgrtziBOyKTvpIfwXDvNaCz/LhBq0b6r6i6xCH5UMLhFoiYJ1F8wFlJT4Jqf1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kBN6hb9BkUdXNIfiTepJHtXfegF2UbtDS9bcU3x3nB3remo0nNhmhJGx1iqeCqo6aYvprr0e3SDrluaHPupOI+4or+CCqHqnwEGiqNizaDO68nn9FzJK1/c42Dx7rjQEhlJZcyo0GSn54nGenCayTEtmcelvGUAMfRSbeGlDPEHfe7j1ro4mxOA/Y2O5550CtUPbvYO6ARTTFFSP5DwqySfMiUmu9WBeFRqeoN1eLUkkC1VsKFbvRJaS1IKrm2eN6LEPf+ZYXaQdMGm9Ey9E94lpwTIwy96jVHYpuQXrxYEcozG4XhLwxCaXhl2QKuh/eYisCfeXd6nUaqXrXL5tLa/T8Wt5ZEiisFcmi0dx1Uj6l4eTV7tocLB4qBfcTs9x5vd62ocd/9QH2zYntSRhwg== 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: Catalin Marinas Cc: Andrew Morton Acked-by: Catalin Marinas --- 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 */