[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20191115024106.GB18865@dhcp-12-139.nay.redhat.com>
Date: Fri, 15 Nov 2019 10:41:06 +0800
From: Hangbin Liu <liuhangbin@...il.com>
To: Eric Dumazet <eric.dumazet@...il.com>
Cc: netdev@...r.kernel.org, Eric Dumazet <edumazet@...gle.com>,
"David S . Miller" <davem@...emloft.net>,
Jiri Benc <jbenc@...hat.com>
Subject: Re: [PATCH net] tcp: switch snprintf to scnprintf
Hi Eric,
On Thu, Nov 14, 2019 at 06:28:35AM -0800, Eric Dumazet wrote:
>
>
> On 11/14/19 2:28 AM, Hangbin Liu wrote:
> > snprintf returns the number of chars that would be written, not number
> > of chars that were actually written. As such, 'offs' may get larger than
> > 'tbl.maxlen', causing the 'tbl.maxlen - offs' being < 0, and since the
> > parameter is size_t, it would overflow.
> >
> > Currently, the buffer is still enough, but for future design, use scnprintf
> > would be safer.
> >
>
> Why is it targeting net tree ?
I though this is a small fixup. Maybe my though is not rigor enough. I don't
have much intend to net or net-next.
>
> How have you checked that it was actually safer ?
No, this patch just from code review. I only did a test in user space
that snprintf could cause overflow. But I found some similar fixes
in kernel.
63350bdb3845 staging: vhciq_core: replace snprintf with scnprintf
37e444c8296c usb: Replace snprintf with scnprintf in gether_get_ifname
bd17cc5a20ae test_firmware: Use correct snprintf() limit
e7f7b6f38a44 scsi: lpfc: change snprintf to scnprintf for possible overflow
>
> This looks unnecessary code churn to me, and it might hide an error in the future.
Not sure if I understand correctly, do you mean we may rely scnprintf
to much, and not set size correctly and got truncated message?
>
> We need to properly size the output buffers before using them,
> we can not afford truncating silently the output.
>
Yes, I agree. Just as I said, the buffer is still enough, while scnprintf
is just a safer usage compired with snprintf.
Thanks
Hangbin
Powered by blists - more mailing lists