netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] q_tbf: Fix potential static-overflow in tbf_print_opt
@ 2024-07-07 17:55 Maks Mishin
  2024-07-10 23:08 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: Maks Mishin @ 2024-07-07 17:55 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Maks Mishin, netdev

An element of array '&b1[0]' of size 64, declared at q_tbf.c:257,
is accessed by an index with values in [0, 74] at q_tbf.c:279,
which may lead to a buffer overflow.

Details: Format string: '%s/%u'. Size of buffer parameter is 63;
Specifier '%u': min value '-2147483647' requires 10 character(s),
max value '2147483647' requires 10 character(s), so the buffer needs
enough space to receive 10 character(s).
Size of the string except for specifiers is 1; Total maximum size is 74.

Found by RASU JSC.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 tc/q_tbf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tc/q_tbf.c b/tc/q_tbf.c
index 9356dfd2..b9f4191c 100644
--- a/tc/q_tbf.c
+++ b/tc/q_tbf.c
@@ -254,7 +254,7 @@ static int tbf_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *op
 	double latency, lat2;
 	__u64 rate64 = 0, prate64 = 0;
 
-	SPRINT_BUF(b1);
+	char b1[74];
 	SPRINT_BUF(b2);
 	SPRINT_BUF(b3);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] q_tbf: Fix potential static-overflow in tbf_print_opt
  2024-07-07 17:55 [PATCH] q_tbf: Fix potential static-overflow in tbf_print_opt Maks Mishin
@ 2024-07-10 23:08 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2024-07-10 23:08 UTC (permalink / raw)
  To: Maks Mishin; +Cc: netdev

On Sun,  7 Jul 2024 20:55:38 +0300
Maks Mishin <maks.mishinfz@gmail.com> wrote:

> An element of array '&b1[0]' of size 64, declared at q_tbf.c:257,
> is accessed by an index with values in [0, 74] at q_tbf.c:279,
> which may lead to a buffer overflow.
> 
> Details: Format string: '%s/%u'. Size of buffer parameter is 63;
> Specifier '%u': min value '-2147483647' requires 10 character(s),
> max value '2147483647' requires 10 character(s), so the buffer needs
> enough space to receive 10 character(s).
> Size of the string except for specifiers is 1; Total maximum size is 74.
> 
> Found by RASU JSC.
> 
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
>  tc/q_tbf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tc/q_tbf.c b/tc/q_tbf.c
> index 9356dfd2..b9f4191c 100644
> --- a/tc/q_tbf.c
> +++ b/tc/q_tbf.c
> @@ -254,7 +254,7 @@ static int tbf_print_opt(const struct qdisc_util *qu, FILE *f, struct rtattr *op
>  	double latency, lat2;
>  	__u64 rate64 = 0, prate64 = 0;
>  
> -	SPRINT_BUF(b1);
> +	char b1[74];

Looks correct, but wonder about other alternatives here.
  * printing buffer and cell log as combined value was a mistake.
    ideally, json should be one value per key, not something like "10K/4"
  * not sure how sprint_size() could ever get large enough with any realistic input.
    that makes this a theoretical problem.
  * the use of sprintf() in q_tbf.c is leftover historical bad C practice. Should be using snprintf always.
  * do not like introducing magic constant 74 here, why not just 2*SPRINT_BSIZE (ie 128)


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-10 23:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-07 17:55 [PATCH] q_tbf: Fix potential static-overflow in tbf_print_opt Maks Mishin
2024-07-10 23:08 ` Stephen Hemminger

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).