netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netdev@vger.kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	<netfilter-devel@vger.kernel.org>,
	Justin Stitt <justinstitt@google.com>
Subject: [PATCH net-next 09/10] netfilter: xtables: refactor deprecated strncpy
Date: Tue, 22 Aug 2023 17:43:30 +0200	[thread overview]
Message-ID: <20230822154336.12888-10-fw@strlen.de> (raw)
In-Reply-To: <20230822154336.12888-1-fw@strlen.de>

From: Justin Stitt <justinstitt@google.com>

Prefer `strscpy_pad` as it's a more robust interface whilst maintaing
zero-padding behavior.

There may have existed a bug here due to both `tbl->repl.name` and
`info->name` having a size of 32 as defined below:
|  #define XT_TABLE_MAXNAMELEN 32

This may lead to buffer overreads in some situations -- `strscpy` solves
this by guaranteeing NUL-termination of the dest buffer.

Signed-off-by: Justin Stitt <justinstitt@google.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/netfilter/xt_repldata.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/xt_repldata.h b/net/netfilter/xt_repldata.h
index 68ccbe50bb1e..5d1fb7018dba 100644
--- a/net/netfilter/xt_repldata.h
+++ b/net/netfilter/xt_repldata.h
@@ -29,7 +29,7 @@
 	if (tbl == NULL) \
 		return NULL; \
 	term = (struct type##_error *)&(((char *)tbl)[term_offset]); \
-	strncpy(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
+	strscpy_pad(tbl->repl.name, info->name, sizeof(tbl->repl.name)); \
 	*term = (struct type##_error)typ2##_ERROR_INIT;  \
 	tbl->repl.valid_hooks = hook_mask; \
 	tbl->repl.num_entries = nhooks + 1; \
-- 
2.41.0


  parent reply	other threads:[~2023-08-22 15:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 15:43 [PATCH net-next 00/10] netfilter updates for net-next Florian Westphal
2023-08-22 15:43 ` [PATCH net-next 01/10] netfilter: ebtables: fix fortify warnings in size_entry_mwt() Florian Westphal
2023-08-23  2:00   ` patchwork-bot+netdevbpf
2023-08-22 15:43 ` [PATCH net-next 02/10] netfilter: ebtables: replace zero-length array members Florian Westphal
2023-08-22 15:43 ` [PATCH net-next 03/10] netfilter: ipset: refactor deprecated strncpy Florian Westphal
2023-08-22 15:43 ` [PATCH net-next 04/10] netfilter: nf_tables: " Florian Westphal
2023-08-22 15:43 ` [PATCH net-next 05/10] " Florian Westphal
2023-08-22 15:43 ` [PATCH net-next 06/10] netfilter: nft_osf: " Florian Westphal
2023-08-22 15:43 ` [PATCH net-next 07/10] netfilter: nft_meta: " Florian Westphal
2023-08-22 15:43 ` [PATCH net-next 08/10] netfilter: x_tables: " Florian Westphal
2023-08-22 15:43 ` Florian Westphal [this message]
2023-08-22 15:43 ` [PATCH net-next 10/10] netfilter: nf_tables: allow loop termination for pending fatal signal Florian Westphal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230822154336.12888-10-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=justinstitt@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).