From nobody Sat Nov 30 10:46:04 2024 Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64C5218C927 for ; Mon, 9 Sep 2024 22:48:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725922123; cv=none; b=M+B4Fqi30GSMZqKVJ/ic7exRH9Ohb03xVOOYzetbugb6jAHMRFUGglsoGqpO/lyMWhI572/yjy20bf4i1PKmzXgWO/9FK4/0A4/phgpeiPdy7pVlP7OIkl/otug36H3A+zMratojIHdEX5ujId5ezkOs29U/n1S23UmJOppA8+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725922123; c=relaxed/simple; bh=rkdImjUZtrp4ImzZRS226DW6+1fYM9yBBOJuj2dWu6o=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=ElK+d+QnpY4Ne1qEbxZTx21uCFz0Z2qZHM4bkmRCKmDHs27hDbtVKKqfVSLJ+0tUwsignIEABzrlkMpJgxKY83t9NW85nArSrielyvARGuUTBFkOWuSYHBGpieORx4MJ/AqvqRcObPsvJitgi1MyTjZdEhDHyjjkA5onNpNwz3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=I+yNb2kM; arc=none smtp.client-ip=209.85.166.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--justinstitt.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I+yNb2kM" Received: by mail-io1-f74.google.com with SMTP id ca18e2360f4ac-82aa8af04feso506003139f.1 for ; Mon, 09 Sep 2024 15:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725922120; x=1726526920; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=NLDyWzTfZuqsLoIb9DG2Ov0GNSs+nA5mIhE6ZJufYmM=; b=I+yNb2kMUloQgz1J5RZqZrtDFuSyw4WcBY0P/JUr11mQeUJjWKmYrRcvXTny183w/g C9kwjcgDJmNssFRYi0Vl1P0ZskY85GxZTMaG1T8ijkel+Gmn+4Un27Ukwuy+NEOd37HF mcQ7zUrK6ctUs+C+R/0mEuz+HRdNgxuLIs0ycNpObZRcz2J8VVtJnivK186IL7pDLvYV PAVB129z87uiuUjLTsOjwyFPTzqivjbprktfPD5RZB1MlRrdAjRe9+EItPCtPCLzjXhJ qH99VlhYTOvTV8Kt0C8wYAMqf2xRJE+UGxbJigyX46Kxg81GEIwqU6oyg3QgDnjq+kD4 T6zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725922120; x=1726526920; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NLDyWzTfZuqsLoIb9DG2Ov0GNSs+nA5mIhE6ZJufYmM=; b=qpF/zRI5l5Lhd9SAnXmp3cNPxHfuOnmbwkawW1wwGdkBzL8+VKYFxc1fdCkizj0CD3 V7M/wIJkM8d+gl9+ucAdivAgBGqvkNT8+C7mUJo6MaD4Y7Ojb0K0PxZcsoeREbM25e9G BNVjK/j4w/UwV4FPkWff7sGl02cYrw7sLYNgQvfd/a1+So5i7zmDHARYrosersiCZ8uJ hITItBeo5+3LumxlVdsQ2ykFC6saY2ZmZM/bY3FabPI3p1LkQSMhK67ZsYO0GxYtO/O/ AOSJ2TE4GLrnWqv5SCnNOMrTIu+3g/IRxkjMW+7ZfYv7hvlkWA/+Ol2Kz30rFihnUhRg 32ZQ== X-Forwarded-Encrypted: i=1; AJvYcCWiN21fYIM/MtndkWaaqIAty5bT/XyBv3o/LRV8NPU+Te8Faxi6VJuwQzMCOrywZuMt56sKsIm03WypVKQ=@vger.kernel.org X-Gm-Message-State: AOJu0YySLJ44HO8onUMYbMKChR3lirlt7t3j2fSYWWrPzkL0eiot3qsA 8pJIdRO48OfYh1Bxrp5Ev+ID59EDlZoXU9WHHlgNWJptw0udTEet1kbWylF1m3kocesHhFrzy4Z evN7C+1FTDrKXiwQG0vbBgg== X-Google-Smtp-Source: AGHT+IHW9HlvXZZMt0RnOBn0kfRYjrcTlLFf/BWUyQHziXtf3ECYT6VFohieaTDTa3LBmOc4V5HiWGQM4zyJT8JI+Q== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6638:204a:b0:4c2:7945:5a32 with SMTP id 8926c6da1cb9f-4d08501de57mr562213173.5.1725922120651; Mon, 09 Sep 2024 15:48:40 -0700 (PDT) Date: Mon, 09 Sep 2024 15:48:39 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAEZ732YC/y2NUQrCQAxEr1LybWCtIl2vIlK2m6wGNJbsIkrp3 RvEv3nMY2aByiZc4dwtYPyWKi912O86yPekN0YhZ+hDfwwxRKzNNM9fVG44mZAbHos8GhtqaeO TWxr/TcYQiYaUEh2GE/jobFzk8zu8XNd1A/k72yuAAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1725922119; l=2091; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=rkdImjUZtrp4ImzZRS226DW6+1fYM9yBBOJuj2dWu6o=; b=RpBy5WGk7841aMAXjLBUnNV+WM74QAmVjxplAH9jkIJQv+5Ll3/fWHnPQ4vkG0vDP88xEPF8T nCGCLbpgdzoDWhCuqbZ6sFgO7Ai3Stk/gJZ1EJbZ9wU5CpMLoIBzPon X-Mailer: b4 0.12.3 Message-ID: <20240909-strncpy-net-bridge-netfilter-nft_meta_bridge-c-v1-1-946180aa7909@google.com> Subject: [PATCH] netfilter: nf_tables: replace deprecated strncpy with strscpy_pad From: Justin Stitt To: Pablo Neira Ayuso , Jozsef Kadlecsik , Roopa Prabhu , Nikolay Aleksandrov , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt , Kees Cook Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable strncpy() is deprecated for use on NUL-terminated destination strings [1] a= nd as such we should prefer more robust and less ambiguous string interfaces. In this particular instance, the usage of strncpy() is fine and works as expected. However, towards the goal of [2], we should consider replacing it with an alternative as many instances of strncpy() are bug-prone. Its removal from the kernel promotes better long term health for the codebase. The current usage of strncpy() likely just wants the NUL-padding behavior offered by strncpy() and doesn't care about the NUL-termination. Since the compiler doesn't know the size of @dest, we can't use strtomem_pad(). Instead, use strscpy_pad() which behaves functionally the same as strncpy() in this context -- as we expect br_dev->name to be NUL-terminated itself. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncp= y-on-nul-terminated-strings [1] Link: https://github.com/KSPP/linux/issues/90 [2] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html Cc: Kees Cook Cc: linux-hardening@vger.kernel.org Signed-off-by: Justin Stitt Reviewed-by: Simon Horman --- Note: build-tested only. --- net/bridge/netfilter/nft_meta_bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bridge/netfilter/nft_meta_bridge.c b/net/bridge/netfilter/= nft_meta_bridge.c index bd4d1b4d745f..2a17e88ab8ee 100644 --- a/net/bridge/netfilter/nft_meta_bridge.c +++ b/net/bridge/netfilter/nft_meta_bridge.c @@ -63,7 +63,7 @@ static void nft_meta_bridge_get_eval(const struct nft_exp= r *expr, return nft_meta_get_eval(expr, regs, pkt); } =20 - strncpy((char *)dest, br_dev ? br_dev->name : "", IFNAMSIZ); + strscpy_pad((char *)dest, br_dev ? br_dev->name : "", IFNAMSIZ); return; err: regs->verdict.code =3D NFT_BREAK; --- base-commit: 521b1e7f4cf0b05a47995b103596978224b380a8 change-id: 20240909-strncpy-net-bridge-netfilter-nft_meta_bridge-c-09dd8aaa= d386 Best regards, -- Justin Stitt