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] [thread-next>] [day] [month] [year] [list]
Message-ID: <f0419f6428ad404386ebca813dc1ec03@AcuMS.aculab.com>
Date:   Mon, 28 Aug 2023 17:18:37 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Heiko Carstens' <hca@...ux.ibm.com>, Jens Axboe <axboe@...nel.dk>
CC:     Stefan Haberland <sth@...ux.ibm.com>,
        Jan Höppner <hoeppner@...ux.ibm.com>,
        Peter Oberparleiter <oberpar@...ux.ibm.com>,
        "linux-s390@...r.kernel.org" <linux-s390@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-block@...r.kernel.org" <linux-block@...r.kernel.org>
Subject: RE: [PATCH 1/1] s390/dasd: fix string length handling

From: Heiko Carstens
> Sent: 28 August 2023 16:32
> 
> Building dasd_eckd.o with latest clang reveals this bug:
> 
>     CC      drivers/s390/block/dasd_eckd.o
>       drivers/s390/block/dasd_eckd.c:1082:3: warning: 'snprintf' will always be truncated;
>       specified size is 1, but format string expands to at least 11 [-Wfortify-source]
>        1082 |                 snprintf(print_uid, sizeof(*print_uid),
>             |                 ^
>       drivers/s390/block/dasd_eckd.c:1087:3: warning: 'snprintf' will always be truncated;
>       specified size is 1, but format string expands to at least 10 [-Wfortify-source]
>        1087 |                 snprintf(print_uid, sizeof(*print_uid),
>             |                 ^
> 
> Fix this by moving and using the existing UID_STRLEN for the arrays
> that are being written to. Also rename UID_STRLEN to DASD_UID_STRLEN
> to clarify its scope.

If you embed that char[] in a struct and pass the address of the
struct then sizeof will return the correct value and you get the
size checked properly.

...
>  	if (strlen(uid.vduit) > 0)

Does the compiler know enough to optimise that brain-dead test?

> -		snprintf(print_uid, sizeof(*print_uid),
> +		snprintf(print_uid, DASD_UID_STRLEN,
>  			 "%s.%s.%04x.%02x.%s",
>  			 uid.vendor, uid.serial, uid.ssid,
>  			 uid.real_unit_addr, uid.vduit);
>  	else
> -		snprintf(print_uid, sizeof(*print_uid),
> +		snprintf(print_uid, DASD_UID_STRLEN,
>  			 "%s.%s.%04x.%02x",
>  			 uid.vendor, uid.serial, uid.ssid,
>  			 uid.real_unit_addr);

or:
	snprintf(print_uid, DASD_UID_STRLEN,
		"%s.%s.%04x.%02x%s%s",
		uid.vendor, uid.serial, uid.ssid,
		uid.real_unit_addr,
		uid.vduit[0] ? "." : "", uid.vduit);

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ