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:   Tue, 29 Mar 2022 13:56:16 +0000
From:   Trond Myklebust <trondmy@...merspace.com>
To:     "anna@...nel.org" <anna@...nel.org>,
        "chenxiaosong2@...wei.com" <chenxiaosong2@...wei.com>,
        "bjschuma@...app.com" <bjschuma@...app.com>
CC:     "linux-nfs@...r.kernel.org" <linux-nfs@...r.kernel.org>,
        "liuyongqiang13@...wei.com" <liuyongqiang13@...wei.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "tao.lyu@...l.ch" <tao.lyu@...l.ch>,
        "zhangxiaoxu5@...wei.com" <zhangxiaoxu5@...wei.com>,
        "yi.zhang@...wei.com" <yi.zhang@...wei.com>
Subject: Re: [PATCH -next 2/2] NFSv4: fix open failure with O_ACCMODE flag

On Tue, 2022-03-29 at 21:44 +0800, chenxiaosong (A) wrote:
> 在 2022/3/29 21:05, Trond Myklebust 写道:
> > No. This will not fit the definition of open(2) in the manpage.
> > 
> >         Linux reserves the special, nonstandard access mode 3 
> > (binary  11)  in
> >         flags  to mean: check for read and write permission on the
> > file and re‐
> >         turn a file descriptor that can't be used for reading or
> > writing.  This
> >         nonstandard  access mode is used by some Linux drivers to
> > return a file
> >         descriptor that is to be used only for device-specific
> > ioctl(2)  opera‐
> >         tions.
>  > Your patch will now cause FMODE_READ and FMODE_WRITE to be set on
> the
>  > file, allowing the file descriptor to be usable for I/O.
> 
> Reproducer:
> ```
>    1. mount -t nfs -o vers=4.2 $server_ip:/ /mnt/
>    2. fd = open("/mnt/file", O_ACCMODE|O_DIRECT|O_CREAT) = 3
>    3. close(fd)
>    4. fd = open("/mnt/file", O_ACCMODE|O_DIRECT) = -1
> ```
> 
> When firstly open with O_ACCMODE|O_DIRECT flags:
> ```c
>    path_openat
>      open_last_lookups
>        lookup_open
>          atomic_open
>            nfs_atomic_open
>              create_nfs_open_context
>                f_mode = flags_to_mode
>                alloc_nfs_open_context(..., f_mode, ...)
>                  ctx->mode = f_mode // FMODE_READ|FMODE_WRITE
> ```
> 
> When secondly open with O_ACCMODE|O_DIRECT flags:
> ```c
>    path_openat
>      do_open
>        vfs_open
>          do_dentry_open
>            nfs4_file_open
>              f_mode = filp->f_mode | flags_to_mode(openflags)
>              alloc_nfs_open_context(..., f_mode, ...)
>                ctx->mode = f_mode // FMODE_READ|FMODE_WRITE
> ```
> 
> Before merging this patch, when firstly open, we does not set
> FMODE_READ 
> and FMODE_WRITE to file mode of client, FMODE_READ and FMODE_WRITE
> just 
> be set to context mode.
> 
> After merging this patch, when secondly open, I just do the same
> thing, 
> file mode of client will not have FMODE_READ and FMODE_WRITE bits,
> file 
> descriptor can't be used for reading or writing.

I see. OK, I'll probably not apply this for the merge window (since I'm
pretty much queued up to send the pull request at this point), but it
might go in as a bug fix in rc1.

-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@...merspace.com


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ