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: <1622d9ff-feed-4a12-9d8d-3f00088c9edf@app.fastmail.com>
Date: Mon, 08 Apr 2024 20:26:00 +0200
From: "Arnd Bergmann" <arnd@...nel.org>
To: "Dan Carpenter" <dan.carpenter@...aro.org>
Cc: linux-kernel@...r.kernel.org, "Viresh Kumar" <vireshk@...nel.org>,
 "Johan Hovold" <johan@...nel.org>, "Alex Elder" <elder@...nel.org>,
 "Greg Kroah-Hartman" <gregkh@...uxfoundation.org>,
 "Arnd Bergmann" <arnd@...db.de>,
 "Christophe JAILLET" <christophe.jaillet@...adoo.fr>,
 greybus-dev@...ts.linaro.org, linux-staging@...ts.linux.dev
Subject: Re: [PATCH 10/11] staging: greybus: change strncpy() to strscpy()

On Thu, Mar 28, 2024, at 16:00, Dan Carpenter wrote:
> On Thu, Mar 28, 2024 at 03:04:54PM +0100, Arnd Bergmann wrote:
>> Signed-off-by: Arnd Bergmann <arnd@...db.de>
>> ---
>> This is from randconfig testing with random gcc versions, a .config to
>> reproduce is at https://pastebin.com/r13yezkU
>> ---
>>  drivers/staging/greybus/fw-management.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>> 
>> diff --git a/drivers/staging/greybus/fw-management.c b/drivers/staging/greybus/fw-management.c
>> index 3054f084d777..35bfdd5f32d2 100644
>> --- a/drivers/staging/greybus/fw-management.c
>> +++ b/drivers/staging/greybus/fw-management.c
>> @@ -303,13 +303,13 @@ static int fw_mgmt_backend_fw_update_operation(struct fw_mgmt *fw_mgmt,
>>  	struct gb_fw_mgmt_backend_fw_update_request request;
>>  	int ret;
>>  
>> -	strncpy(request.firmware_tag, tag, GB_FIRMWARE_TAG_MAX_SIZE);
>> +	ret = strscpy(request.firmware_tag, tag, GB_FIRMWARE_TAG_MAX_SIZE);
>
> This needs to be strscpy_pad() or it risks an information leak.

Right, I think I misread the code thinking that the strncpy()
destination was user provided, but I see now that this copy is
from user-provided data into the stack, so the padding is indeed
stale stack data.

I could not find out whether this gets copied back to userspace,
but adding the padding is safer indeed.

>>  
>>  	/*
>>  	 * The firmware-tag should be NULL terminated, otherwise throw error and
>                                       ^^^^^^^^^^^^^^^^
> These comments are out of date.
>
>>  	 * fail.
>>  	 */
>> -	if (request.firmware_tag[GB_FIRMWARE_TAG_MAX_SIZE - 1] != '\0') {
>> +	if (ret == -E2BIG) {
>>  		dev_err(fw_mgmt->parent, "backend-update: firmware-tag is not NULL terminated\n");
>                                                           
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> More out of date prints.

I had thought about changing it when I did the patch, but could
not come up with anything that describes the error condition better:
the cause of the -E2BIG error is still the missing NUL-termination
in the provided string.

Maybe we should instead not print a warning at all? The general
rule is that user triggered operations should not lead to
spamming the kernel logs.

     Arnd

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ