From: Takashi Iwai <tiwai@suse.de>
To: netdev@vger.kernel.org
Cc: "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
oss-drivers@netronome.com
Subject: [PATCH 4/7] nfp: Use scnprintf() for avoiding potential buffer overflow
Date: Wed, 11 Mar 2020 09:37:42 +0100 [thread overview]
Message-ID: <20200311083745.17328-5-tiwai@suse.de> (raw)
In-Reply-To: <20200311083745.17328-1-tiwai@suse.de>
Since snprintf() returns the would-be-output size instead of the
actual output size, the succeeding calls may go beyond the given
buffer limit. Fix it by replacing with scnprintf().
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: oss-drivers@netronome.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
index 8fde6c1f681b..cc311989e3d7 100644
--- a/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
+++ b/drivers/net/ethernet/netronome/nfp/nfpcore/nfp6000_pcie.c
@@ -616,7 +616,7 @@ static int enable_bars(struct nfp6000_pcie *nfp, u16 interface)
if (bar->iomem) {
int pf;
- msg += snprintf(msg, end - msg, "0.0: General/MSI-X SRAM, ");
+ msg += scnprintf(msg, end - msg, "0.0: General/MSI-X SRAM, ");
atomic_inc(&bar->refcnt);
bars_free--;
@@ -661,7 +661,7 @@ static int enable_bars(struct nfp6000_pcie *nfp, u16 interface)
/* Configure, and lock, BAR0.1 for PCIe XPB (MSI-X PBA) */
bar = &nfp->bar[1];
- msg += snprintf(msg, end - msg, "0.1: PCIe XPB/MSI-X PBA, ");
+ msg += scnprintf(msg, end - msg, "0.1: PCIe XPB/MSI-X PBA, ");
atomic_inc(&bar->refcnt);
bars_free--;
@@ -680,7 +680,7 @@ static int enable_bars(struct nfp6000_pcie *nfp, u16 interface)
bar->iomem = ioremap(nfp_bar_resource_start(bar),
nfp_bar_resource_len(bar));
if (bar->iomem) {
- msg += snprintf(msg, end - msg,
+ msg += scnprintf(msg, end - msg,
"0.%d: Explicit%d, ", 4 + i, i);
atomic_inc(&bar->refcnt);
bars_free--;
--
2.16.4
next prev parent reply other threads:[~2020-03-11 8:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-11 8:37 [PATCH 0/7] net: Use scnprintf() for avoiding potential buffer overflow Takashi Iwai
2020-03-11 8:37 ` [PATCH 1/7] net: caif: " Takashi Iwai
2020-03-11 8:37 ` [PATCH 2/7] i40e: " Takashi Iwai
2020-03-16 20:32 ` [Intel-wired-lan] " Bowers, AndrewX
2020-03-11 8:37 ` [PATCH 3/7] mlx4: " Takashi Iwai
2020-03-11 8:37 ` Takashi Iwai [this message]
2020-03-11 11:01 ` [oss-drivers] [PATCH 4/7] nfp: " Simon Horman
2020-03-11 21:44 ` Jakub Kicinski
2020-03-11 8:37 ` [PATCH 5/7] ionic: " Takashi Iwai
2020-03-11 11:01 ` [oss-drivers] " Simon Horman
2020-03-11 16:45 ` Shannon Nelson
2020-03-11 8:37 ` [PATCH 6/7] sfc: " Takashi Iwai
2020-03-12 9:53 ` Martin Habets
2020-03-12 11:38 ` Takashi Iwai
2020-03-11 8:37 ` [PATCH 7/7] netdevsim: " Takashi Iwai
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=20200311083745.17328-5-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.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).