netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Simon Horman <horms@kernel.org>, Jakub Kicinski <kuba@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	jmaloy@redhat.com, ying.xue@windriver.com, davem@davemloft.net,
	edumazet@google.com, pabeni@redhat.com, netdev@vger.kernel.org,
	tipc-discussion@lists.sourceforge.net
Subject: [PATCH AUTOSEL 6.6 033/139] tipc: guard against string buffer overrun
Date: Wed, 25 Sep 2024 08:07:33 -0400	[thread overview]
Message-ID: <20240925121137.1307574-33-sashal@kernel.org> (raw)
In-Reply-To: <20240925121137.1307574-1-sashal@kernel.org>

From: Simon Horman <horms@kernel.org>

[ Upstream commit 6555a2a9212be6983d2319d65276484f7c5f431a ]

Smatch reports that copying media_name and if_name to name_parts may
overwrite the destination.

 .../bearer.c:166 bearer_name_validate() error: strcpy() 'media_name' too large for 'name_parts->media_name' (32 vs 16)
 .../bearer.c:167 bearer_name_validate() error: strcpy() 'if_name' too large for 'name_parts->if_name' (1010102 vs 16)

This does seem to be the case so guard against this possibility by using
strscpy() and failing if truncation occurs.

Introduced by commit b97bf3fd8f6a ("[TIPC] Initial merge")

Compile tested only.

Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20240801-tipic-overrun-v2-1-c5b869d1f074@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/tipc/bearer.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index 878415c435276..fec638e494c9d 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -163,8 +163,12 @@ static int bearer_name_validate(const char *name,
 
 	/* return bearer name components, if necessary */
 	if (name_parts) {
-		strcpy(name_parts->media_name, media_name);
-		strcpy(name_parts->if_name, if_name);
+		if (strscpy(name_parts->media_name, media_name,
+			    TIPC_MAX_MEDIA_NAME) < 0)
+			return 0;
+		if (strscpy(name_parts->if_name, if_name,
+			    TIPC_MAX_IF_NAME) < 0)
+			return 0;
 	}
 	return 1;
 }
-- 
2.43.0


  parent reply	other threads:[~2024-09-25 12:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240925121137.1307574-1-sashal@kernel.org>
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 007/139] ice: Adjust over allocation of memory in ice_sched_add_root_node() and ice_sched_add_node() Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 010/139] wifi: cfg80211: Set correct chandef when starting CAC Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 011/139] net/xen-netback: prevent UAF in xenvif_flush_hash() Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 012/139] net: hisilicon: hip04: fix OF node leak in probe() Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 013/139] net: hisilicon: hns_dsaf_mac: fix OF node leak in hns_mac_get_info() Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 014/139] net: hisilicon: hns_mdio: fix OF node leak in probe() Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 018/139] e1000e: avoid failing the system during pm_suspend Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 020/139] net: sched: consistently use rcu_replace_pointer() in taprio_change() Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 030/139] l2tp: don't use tunnel socket sk_user_data in ppp procfs output Sasha Levin
2024-09-25 14:27   ` James Chapman
2024-10-11 13:52     ` Sasha Levin
2024-09-25 12:07 ` Sasha Levin [this message]
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 034/139] net: mvpp2: Increase size of queue_name buffer Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 035/139] bnxt_en: Extend maximum length of version string by 1 byte Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 036/139] ipv4: Check !in_dev earlier for ioctl(SIOCSIFADDR) Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 038/139] netfilter: nf_tables: don't initialize registers in nft_do_chain() Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 039/139] ipv4: Mask upper DSCP bits and ECN bits in NETLINK_FIB_LOOKUP family Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 040/139] net: atlantic: Avoid warning about potential string truncation Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 042/139] netpoll: Ensure clean state on setup failures Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 043/139] tcp: avoid reusing FIN_WAIT2 when trying to find port in connect() process Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 046/139] wifi: mac80211: fix RCU list iterations Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 050/139] can: netlink: avoid call to do_set_data_bittiming callback with stale can_priv::ctrlmode Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 054/139] net: tls: wait for async completion on last message Sasha Levin
2024-10-02 12:50   ` Jakub Kicinski
2024-10-06  0:31     ` Sasha Levin
2024-09-25 12:07 ` [PATCH AUTOSEL 6.6 056/139] nfp: Use IRQF_NO_AUTOEN flag in request_irq() Sasha Levin

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=20240925121137.1307574-33-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=jmaloy@redhat.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=tipc-discussion@lists.sourceforge.net \
    --cc=ying.xue@windriver.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).