On Feb 3, 2023, at 5:35 AM, Kanchan Joshi <joshi.k@xxxxxxxxxxx> wrote: > > Use O_RDONLY flag when read is requested on char-type files. > > Signed-off-by: Kanchan Joshi <joshi.k@xxxxxxxxxxx> > --- > > Before this patch: unexpected permission-denial for unprivileged-user. > > $ ls -l /dev/ng0n1 > cr--r--r-- 1 root root 242, 0 Feb 3 16:30 /dev/ng0n1 > > $ ./fio -iodepth=1 -rw=randread -ioengine=io_uring_cmd -bs=4k -numjobs=1 > -size=4k -cmd_type=nvme -filename=/dev/ng0n1 -name=t > t: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) > 4096B-4096B, ioengine=io_uring_cmd, iodepth=1 > fio-3.33-71-g7d7a > Starting 1 process > fio: pid=131312, err=13/file:filesetup.c:805, func=open(/dev/ng0n1), > error=Permission denied > > filesetup.c | 5 +---- > 1 file changed, 1 insertion(+), 4 deletions(-) > > diff --git a/filesetup.c b/filesetup.c > index 1d3cc5ad..d77b8ba4 100644 > --- a/filesetup.c > +++ b/filesetup.c > @@ -768,10 +768,7 @@ open_again: > else > from_hash = file_lookup_open(f, flags); > } else if (td_read(td)) { > - if (f->filetype == FIO_TYPE_CHAR && !read_only) > - flags |= O_RDWR; > - else > - flags |= O_RDONLY; > + flags |= O_RDONLY; This will break sg like interfaces, where a read is done by writing the command to the char device. — Jens Axboe