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]
Date:	Wed, 30 Sep 2015 09:27:38 +0200
From:	Rasmus Villemoes <linux@...musvillemoes.dk>
To:	Mark Brown <broonie@...nel.org>
Cc:	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH 1/2] regmap: debugfs: remove bogus check

On Tue, Sep 29 2015, Mark Brown <broonie@...nel.org> wrote:

> On Tue, Sep 29, 2015 at 12:29:01AM +0200, Rasmus Villemoes wrote:
>> snprintf cannot return a negative value (unless map->dev->driver->name
>> happens to be over 2G long). So remove the bogus check.
>
>>  	ret = snprintf(buf, PAGE_SIZE, "%s\n", map->dev->driver->name);
>> -	if (ret < 0) {
>> -		kfree(buf);
>> -		return ret;
>> -	}
>
> It's hard to see a great value in removing error checking, even error
> checking that's currently unlikely to ever trigger...

I agree, but only on the word 'great'. There is value in removing such
bogosities (or rather, their presence provides negative value). It makes
the code harder to read ("why is this instance checked, but not any of
the other snprintfs?"); people may think that it's trying to check for
truncation, but it does no such thing; and it contributes a few
worthless bytes to .text (and the source).

If you're worried about map->dev->driver->name actually ever being > 2G,
returning some almost totally random negative number isn't really
helpful (the function is supposed to return a -errno). And what makes
you think that in some hypothetical universe where the kernel's snprintf
explicit returns a negative value that it wouldn't just return -1 (aka
-EPERM)?

BTW, if it's the truncation thing this was supposed to check for and
there was any non-zero chance map->dev->driver->name would be longer
than around PAGE_SIZE, this would be an excellent info leak: ret is some
fine positive number somewhat larger than PAGE_SIZE, and we go on to use
that to determine how much to copy to the user.

Rasmus

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists