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: Thu, 8 Feb 2024 13:34:45 +0800
From: Wen Yang <wenyang.linux@...mail.com>
To: Eric Biggers <ebiggers@...nel.org>
Cc: Christian Brauner <brauner@...nel.org>, Jens Axboe <axboe@...nel.dk>,
 Alexander Viro <viro@...iv.linux.org.uk>, Jan Kara <jack@...e.cz>,
 David Woodhouse <dwmw@...zon.co.uk>, Matthew Wilcox <willy@...radead.org>,
 linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] eventfd: strictly check the count parameter of
 eventfd_write to avoid inputting illegal strings


On 2024/2/8 12:33, Eric Biggers wrote:
> On Wed, Feb 07, 2024 at 12:35:18AM +0800, wenyang.linux@...mail.com wrote:
>> By checking whether count is equal to sizeof(ucnt), such errors
>> could be detected. It also follows the requirements of the manual.
> Does it?  This is what the eventfd manual page says:
>
>       A write(2) fails with the error EINVAL if the size of the supplied buffer
>       is less than 8 bytes, or if an attempt is made to write the value
>       0xffffffffffffffff.
>
> So, *technically* it doesn't mention the behavior if the size is greater than 8
> bytes.  But one might assume that such writes are accepted, since otherwise it
> would have been mentioned that they're rejected, just like writes < 8 bytes.


Thank you for your commtents.
Although this behavior was not mentioned, it may indeed lead to
undefined performance, such as (we changed char [] to char *):

#include <sys/eventfd.h>

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main()
{
     //char str[32] = "hello world";
     char *str = "hello world";
     uint64_t value;
     ssize_t size;
     int fd;

     fd = eventfd(0, 0);
     size = write(fd, &str, strlen(str));
     printf("eventfd: test writing a string:%s, size=%ld\n", str, size);
     size = read(fd, &value, sizeof(value));
     printf("eventfd: test reading as uint64, size=%ld, value=0x%lX\n", 
size, value);
     close(fd);

     return 0;
}


$ ./a.out
eventfd: test writing a string:hello world, size=8
eventfd: test reading as uint64, size=8, value=0x560CC0134008

$ ./a.out
eventfd: test writing a string:hello world, size=8
eventfd: test reading as uint64, size=8, value=0x55A3CD373008

$ ./a.out
eventfd: test writing a string:hello world, size=8
eventfd: test reading as uint64, size=8, value=0x55B8D7B99008


--

Best wishes,

Wen


>
> If the validation is indeed going to be made more strict, the manual page will
> need to be fixed alongside it.
>
> - Eric


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ