netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH v3 6/7] tc/m_xt: Fix for potential string buffer overflows
Date: Mon, 21 Aug 2017 15:23:40 +0200	[thread overview]
Message-ID: <20170821132341.23118-7-phil@nwl.cc> (raw)
In-Reply-To: <20170821132341.23118-1-phil@nwl.cc>

- Use strncpy() when writing to target->t->u.user.name and make sure the
  final byte remains untouched (xtables_calloc() set it to zero).
- 'tname' length sanitization was completely wrong: If it's length
  exceeded the 16 bytes available in 'k', passing a length value of 16
  to strncpy() would overwrite the previously NULL'ed 'k[15]'. Also, the
  sanitization has to happen if 'tname' is exactly 16 bytes long as
  well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 tc/m_xt.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tc/m_xt.c b/tc/m_xt.c
index ad52d239caf61..9218b14594403 100644
--- a/tc/m_xt.c
+++ b/tc/m_xt.c
@@ -95,7 +95,8 @@ build_st(struct xtables_target *target, struct xt_entry_target *t)
 	if (t == NULL) {
 		target->t = xtables_calloc(1, size);
 		target->t->u.target_size = size;
-		strcpy(target->t->u.user.name, target->name);
+		strncpy(target->t->u.user.name, target->name,
+			sizeof(target->t->u.user.name) - 1);
 		target->t->u.user.revision = target->revision;
 
 		if (target->init != NULL)
@@ -277,8 +278,8 @@ static int parse_ipt(struct action_util *a, int *argc_p,
 	}
 	fprintf(stdout, " index %d\n", index);
 
-	if (strlen(tname) > 16) {
-		size = 16;
+	if (strlen(tname) >= 16) {
+		size = 15;
 		k[15] = 0;
 	} else {
 		size = 1 + strlen(tname);
-- 
2.13.1

  parent reply	other threads:[~2017-08-21 13:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-21 13:23 [iproute PATCH v3 0/7] Covscan: Fixes for string termination Phil Sutter
2017-08-21 13:23 ` [iproute PATCH v3 1/7] ipntable: Avoid memory allocation for filter.name Phil Sutter
2017-08-21 13:23 ` [iproute PATCH v3 2/7] xfrm_state: Make sure alg_name is NULL-terminated Phil Sutter
2017-08-22  0:28   ` Stephen Hemminger
2017-08-22 11:05     ` Phil Sutter
2017-08-21 13:23 ` [iproute PATCH v3 3/7] lib/fs: Fix format string in find_fs_mount() Phil Sutter
2017-08-21 13:23 ` [iproute PATCH v3 4/7] lib/inet_proto: Review inet_proto_{a2n,n2a}() Phil Sutter
2017-08-21 13:23 ` [iproute PATCH v3 5/7] lnstat_util: Simplify alloc_and_open() a bit Phil Sutter
2017-08-21 13:23 ` Phil Sutter [this message]
2017-08-21 13:23 ` [iproute PATCH v3 7/7] lib/ll_map: Choose size of new cache items at run-time Phil Sutter

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=20170821132341.23118-7-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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).