lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 9 Feb 2023 10:38:15 +0100
From:   Simon Horman <simon.horman@...igine.com>
To:     Alexandra Winter <wintera@...ux.ibm.com>
Cc:     David Miller <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>, netdev@...r.kernel.org,
        linux-s390@...r.kernel.org, Heiko Carstens <hca@...ux.ibm.com>,
        Thorsten Winkler <twinkler@...ux.ibm.com>,
        Jules Irenge <jbi.octave@...il.com>
Subject: Re: [PATCH net-next 4/4] s390/qeth: Convert sprintf/snprintf to
 scnprintf

On Wed, Feb 08, 2023 at 07:19:29PM +0100, Alexandra Winter wrote:
> 
> 
> On 07.02.23 16:42, Simon Horman wrote:
> > On Mon, Feb 06, 2023 at 06:27:54PM +0100, Alexandra Winter wrote:
> >> From: Thorsten Winkler <twinkler@...ux.ibm.com>
> >>
> >> This LWN article explains the rationale for this change
> >> https: //lwn.net/Articles/69419/
> > 
> > https://lwn.net/Articles/69419/
> > 
> >> Ie. snprintf() returns what *would* be the resulting length,
> >> while scnprintf() returns the actual length.
> > 
> > Ok, but in most cases in this patch the return value is not checked.
> > Is there any value in this change in those cases?
> > 
> 
> Jules Irenge reported a coccinnelle warning to use scnprintf in 
> show() functions [1]. (Thorsten Winkler changed these instances to
> sysfs_emit in patch 3 of this series.)
> We read the article as a call to implement the plan to upgrade the kernel
> to the newer *scnprintf functions. Is that not intended?
>
> I totally agree, that in these cases no real problem was fixed, it is
> more of a style improvement.

My feeling is that it isn't an improvement and therefore probably
best not done. But that is just my opinion.

> [1] https://lore.kernel.org/netdev/YzHyniCyf+G%2F2xI8@fedora/T/
> 
> >> Reported-by: Jules Irenge <jbi.octave@...il.com>
> >> Reviewed-by: Alexandra Winkler <wintera@...ux.ibm.com>
> > 
> > s/Winkler/Winter/ ?
> 
> Of course. Wow, you have good eyes!

Only on my good days.

> >> Signed-off-by: Thorsten Winkler <twinkler@...ux.ibm.com>
> >> Signed-off-by: Alexandra Winter <wintera@...ux.ibm.com>
> > 
> > ...
> > 
> >> diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
> >> index 1cf4e354693f..af4e60d2917e 100644
> >> --- a/drivers/s390/net/qeth_l3_main.c
> >> +++ b/drivers/s390/net/qeth_l3_main.c
> >> @@ -47,9 +47,9 @@ int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr,
> >>  			     char *buf)
> >>  {
> >>  	if (proto == QETH_PROT_IPV4)
> >> -		return sprintf(buf, "%pI4", addr);
> >> +		return scnprintf(buf, INET_ADDRSTRLEN, "%pI4", addr);
> >>  	else
> >> -		return sprintf(buf, "%pI6", addr);
> >> +		return scnprintf(buf, INET6_ADDRSTRLEN, "%pI6", addr);
> >>  }
> > 
> > 
> > This seems to be the once case where the return value is not ignored.
> > 
> > Of the 4 callers of qeth_l3_ipaddr_to_string, two don't ignore the return
> > value. And I agree in those cases this change seems correct.
> > 
> > However, amongst other usages of the return value,
> > those callers also check for a return < 0 from this function.
> > Can that occur, in the sprintf or scnprintf case?
> 
> I was under the impression this was a safeguard against a bad address format,
> but I tried it out and it never resulted in a negative return.
> Thanks a lot for pointing this out, we can further simplify patch 3 with that.

The advice elsewhere in this thread is that perhaps leaving this as-is may
be best after all.

* https://lore.kernel.org/netdev/63c6825fc2c94ad19ac7de93a6f151f6@AcuMS.aculab.com/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ