From patchwork Wed Jul 10 00:13:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13728647 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 3DBB6C2BD09 for ; Wed, 10 Jul 2024 00:13:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 91D786B0089; Tue, 9 Jul 2024 20:13:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8CDEA6B008A; Tue, 9 Jul 2024 20:13:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 794F66B008C; Tue, 9 Jul 2024 20:13:17 -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 5B97D6B0089 for ; Tue, 9 Jul 2024 20:13:17 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id D53B912168B for ; Wed, 10 Jul 2024 00:13:16 +0000 (UTC) X-FDA: 82321918392.01.577F244 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf26.hostedemail.com (Postfix) with ESMTP id BCC22140002 for ; Wed, 10 Jul 2024 00:13:14 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=icHRJ8B0; spf=pass (imf26.hostedemail.com: domain of kees@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720570380; 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:references:dkim-signature; bh=CzKTUwiCPYZQF6mnisETCx/904hJVzGXce/vC+Xre2I=; b=LJW4K02oQRWBLitSQtpEPkr8olyxa3gbGcYeMLqREgxUpy9aCbSh316cH7uD0NiUWeZzMu j7LRIPR8Ob3n+QuYNPxEJc1RC0bHoEmhqOZwNKs0TqYrjjh7BC/QSH8IPVBki1cJMAZSuF TM0wwKJwoou62Q+9e0h3maYLAlii1oM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=icHRJ8B0; spf=pass (imf26.hostedemail.com: domain of kees@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=kees@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720570380; a=rsa-sha256; cv=none; b=Nl/kO99I00Gq3DKh7ewa3chG6qYPXRUiEuaY6sua/Oll5pEmnW3R7Q+Lit6Pe5QOTx1pRy ncCcN0sYYlH+9ZfqWP8NCH6ZbvNYtP2uoYOcx/Mw76yuYNRtreHRSxdBsY1oDRiz5LXXGk 3zJwYhPN0pLe50snfDfpCX0ZXMUQNEo= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 36BC6CE13B5; Wed, 10 Jul 2024 00:13:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BCC3C3277B; Wed, 10 Jul 2024 00:13:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720570389; bh=hH6XjJwh6V5T6DG7L0RoEforFSSEUVc2U+XkuNZxBNE=; h=From:To:Cc:Subject:Date:From; b=icHRJ8B0eDG1Qx8r/n3MURe/rvL4idQyb6BGWWs/sO4Jg5Y51b+mldfvf7Z7lGL8s RekzE5wmoMzjHzw6cibrKx49F9Y9dJpdnD/h/xl4tQ/8qnDUhIEJJ1qzE8QFAhWQum kjetS56rHjDPBx1egrKvrm8jY/rgM7VgU4a7yR8dJdUO+xuedI3x+Rd2i3KVaiZFEs w1NQzZLibrCX0NogCxW3EESNz3Lm/W12j+7L6UYkfiJpBWpe9ibNlOUx99qDG71i54 7xIVpAgFW8EJrEmLppexjOC9tQq6Nkq1W1rPKGCNTYezFS9wwNx7yEGYdHPld7Cdp+ zVJcilc4Lxu6A== From: Kees Cook To: Catalin Marinas Cc: Kees Cook , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] mm/kmemleak: Replace strncpy() with strscpy() Date: Tue, 9 Jul 2024 17:13:08 -0700 Message-Id: <20240710001300.work.004-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1360; i=kees@kernel.org; h=from:subject:message-id; bh=hH6XjJwh6V5T6DG7L0RoEforFSSEUVc2U+XkuNZxBNE=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBmjdITQN4XGi2gMp0xUR/LaBXup1y35hiihuVMJ 0WIjbRi1FGJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZo3SEwAKCRCJcvTf3G3A JlRiD/9yskQJyvP7pOcththEpmK24+FXaILTCqWmbqZgjvaF2/vGJO6zo74E5dBy1rTLJwRNJET UEEke92ESGPIy/VGTuFrSrbsUqqwP+uwq7RK/hde0EwXFQAYnvHeIu2tyl9Z5ZEtp3N3oTYUAY+ 6ui4VWM0EYrasSssRaGuCxawfBCt/YsGj9lGi644Hf2X/rz8HcE8DUWSYhEU+q4hgo04m6lxC/o InBKlWGH0lmcJdnlGO3zMAQjkxhmROVUzUHVSdkIVSIaGgewAjgafPR+XGIf9HCvKl5ZSRDGRAZ b2WZKknsgRrjdRAqlhBkC+W+MOHXm82Ue5JeMNhvYHc3ydvFInBWiOo0Q5ST9T0upsAlB1woe9g ypnHKWU0bGWqj35Gd2pBGrmEFurtoOIkQuZSseXdU7E3R/YNSTu7iHLnu4YDpbKuYxsivtso2po cimMrWcHZ8b2izLOHeVu7AllZagdP8PIny9J+m4urxt+ec6YUl6MRTFEg0xgGxxRbmVzpMrCy5G 2YSVeYTNBKVaVndVRcEdnUGRBw5HTZcgLjCLGV+Vn5DMAyAYxusnDkfjzHRMhZUPwov6YmjKA03 eYleQ+a12Aop6lsd5vVoD2JlUbtw8AYabkFiTj4ISXIh2ANXHvo4kM1AYeBM0rdvOYI6mez3/ph TU6iG eSfeAMoa 3A== X-Developer-Key: i=kees@kernel.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: BCC22140002 X-Stat-Signature: tgj476repxw5jn8mp1pynoudttqcc1ne X-HE-Tag: 1720570394-213032 X-HE-Meta: U2FsdGVkX18Z8w3SkVwIvq3AYczt8fT7lTa4WozcFjS+bLOp0FrOK/HciH9pcJZXfd708h/zh7Hex2KB6oHWuQGDjdp0pyqk1/VC6Sp0wxhlegWymJIx0aVyql276/Ktmd9HTaznfzu4b7PyjCyivtP7VCH9nxwSaKfdp+bGaU1qUxn/x07tRMUvTgDXELN6jeaesOoR1P4/p9YhrCBm2drLIAD4jVOqQEphouCzh46cV47RLIxMLu2j89jCKW4RlaDV/Gz03Sr2P+BNoEROrhcMUN3DZe13DOVk65htHaoHdxBMyod3565hzK1OLau2Gbx9t1KLVqB6YL9vt2D2tINrLOrAMD3kZMvyVKXFqLZqFq0fuDHfVwEvoTl3KfXnC9a3YX7mMRu/aU8k6pAlaCxqIyxgTYDo7m3S29zc9CtP7PuPSx+j2kPJDZrMGtpZPmqgvuKvqZG5fFx1RpyhgpzWww8Ha022jzK8eLDFADmaiuBkDYfpiG2faVnWHxvQqYdyWxxyWiKa1vNnF6euTJ6Fv0Rtd5iQ0wqZrBwYrtVoZ8YPDYaLf4i8Cy6NvCXfjnsQkA9mlKlcDuaM3BM4JO7jcmv6P+tt3Ro97vLeV57/WJQaxp8BE2C04qaWJgJwfVaAsSh3q/wC2AwKyzQPLX8cuDx99RBooLeXVhgk/2p/JiLgIFuLSVsODkBRzQXwGX2oPX81QNaQWb8oJWzXr6jJuAWV9WZSlIava+iA9fArhFJuE6wXSx27COjlgXeRT0gtqeo4M7pLlFlUmpkT2ZZPpu1clnmf0GN1XlbE6Jfk3WLs8veStubdfVKcuwl7C3kaehg/I8HyimsoCkg/Ek68vqIV+Qp0lZHH1IwQ0Vij74jSnqP+Jfg1Vdvcel6FY7PRWHHu0ka1Hx91RKq2ngdZguzY80zLFJv4lJYs1YZShDhHSDTBaIvtUDdQKjsM5YBM9bHNVnd8xlN6au6 8CqoU/UK PSMciu6GQySCpYu7prGzs4IGa5MSuprHLb9dZQIxcd4Txs3AEAmCpzosZ+qJ0QWbuwjLRkOQjznoEq4Znv9nJjIlf5M7nkRK0WAWpTtE1tf4fiQk3zlewg7oxajSsqy1mAWU2PeN9DEPBowfPk1uzaw2S6RPBntXhsWVF4cWJb+kewVccxa9oY5bLZd5nAKLn8mk+hQ64BQ2XelO+1BZoAMDC9FE92TSLnIGTkEXfNshHlkg101qOrY479h651HeEJGWAHOLkeA6rWus0baQVWeakSwpuQIMuL7OCHkLIONTwu6uk0hoKsBJRRPi0sETyenz3yvyfugsiPJV5CiP5cld6LonmeQjGE2hL/Y/ZGAMtijPmDIx0rm04kOBKeFxCkgQ1UBU9vq8LqdCxz07A9NDa4CcufXgVEkoeb5OukpoMYEOtZX7NWgKuGA== 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: Replace the depreciated[1] strncpy() calls with strscpy(). Uses of object->comm do not depend on the padding side-effect. Link: https://github.com/KSPP/linux/issues/90 [1] Signed-off-by: Kees Cook Acked-by: Catalin Marinas --- Cc: Catalin Marinas Cc: Andrew Morton Cc: linux-mm@kvack.org --- mm/kmemleak.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index d5b6fba44fc9..764b08100570 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -657,10 +657,10 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp) /* task information */ if (in_hardirq()) { object->pid = 0; - strncpy(object->comm, "hardirq", sizeof(object->comm)); + strscpy(object->comm, "hardirq"); } else if (in_serving_softirq()) { object->pid = 0; - strncpy(object->comm, "softirq", sizeof(object->comm)); + strscpy(object->comm, "softirq"); } else { object->pid = current->pid; /* @@ -669,7 +669,7 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp) * dependency issues with current->alloc_lock. In the worst * case, the command line is not correct. */ - strncpy(object->comm, current->comm, sizeof(object->comm)); + strscpy(object->comm, current->comm); } /* kernel backtrace */