1. 13 7月, 2017 1 次提交
    • J
      nfsd4: factor ctime into change attribute · 630458e7
      J. Bruce Fields 提交于
      Factoring ctime into the nfsv4 change attribute gives us better
      properties than just i_version alone.
      
      Eventually we'll likely also expose this (as opposed to raw i_version)
      to userspace, at which point we'll want to move it to a common helper,
      called from either userspace or individual filesystems.  For now, nfsd
      is the only user.
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      630458e7
  2. 24 5月, 2017 1 次提交
    • J
      nfsd4: fix null dereference on replay · 9a307403
      J. Bruce Fields 提交于
      if we receive a compound such that:
      
      	- the sessionid, slot, and sequence number in the SEQUENCE op
      	  match a cached succesful reply with N ops, and
      	- the Nth operation of the compound is a PUTFH, PUTPUBFH,
      	  PUTROOTFH, or RESTOREFH,
      
      then nfsd4_sequence will return 0 and set cstate->status to
      nfserr_replay_cache.  The current filehandle will not be set.  This will
      cause us to call check_nfsd_access with first argument NULL.
      
      To nfsd4_compound it looks like we just succesfully executed an
      operation that set a filehandle, but the current filehandle is not set.
      
      Fix this by moving the nfserr_replay_cache earlier.  There was never any
      reason to have it after the encode_op label, since the only case where
      he hit that is when opdesc->op_func sets it.
      
      Note that there are two ways we could hit this case:
      
      	- a client is resending a previously sent compound that ended
      	  with one of the four PUTFH-like operations, or
      	- a client is sending a *new* compound that (incorrectly) shares
      	  sessionid, slot, and sequence number with a previously sent
      	  compound, and the length of the previously sent compound
      	  happens to match the position of a PUTFH-like operation in the
      	  new compound.
      
      The second is obviously incorrect client behavior.  The first is also
      very strange--the only purpose of a PUTFH-like operation is to set the
      current filehandle to be used by the following operation, so there's no
      point in having it as the last in a compound.
      
      So it's likely this requires a buggy or malicious client to reproduce.
      Reported-by: NScott Mayhew <smayhew@redhat.com>
      Cc: stable@kernel.vger.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      9a307403
  3. 17 5月, 2017 1 次提交
  4. 15 5月, 2017 19 次提交
  5. 11 5月, 2017 2 次提交
  6. 10 5月, 2017 1 次提交
  7. 27 4月, 2017 1 次提交
  8. 26 4月, 2017 6 次提交
    • N
      NFS: don't try to cross a mountpount when there isn't one there. · 99bbf6ec
      NeilBrown 提交于
      consider the sequence of commands:
       mkdir -p /import/nfs /import/bind /import/etc
       mount --bind / /import/bind
       mount --make-private /import/bind
       mount --bind /import/etc /import/bind/etc
      
       exportfs -o rw,no_root_squash,crossmnt,async,no_subtree_check localhost:/
       mount -o vers=4 localhost:/ /import/nfs
       ls -l /import/nfs/etc
      
      You would not expect this to report a stale file handle.
      Yet it does.
      
      The manipulations under /import/bind cause the dentry for
      /etc to get the DCACHE_MOUNTED flag set, even though nothing
      is mounted on /etc.  This causes nfsd to call
      nfsd_cross_mnt() even though there is no mountpoint.  So an
      upcall to mountd for "/etc" is performed.
      
      The 'crossmnt' flag on the export of / causes mountd to
      report that /etc is exported as it is a descendant of /.  It
      assumes the kernel wouldn't ask about something that wasn't
      a mountpoint.  The filehandle returned identifies the
      filesystem and the inode number of /etc.
      
      When this filehandle is presented to rpc.mountd, via
      "nfsd.fh", the inode cannot be found associated with any
      name in /etc/exports, or with any mountpoint listed by
      getmntent().  So rpc.mountd says the filehandle doesn't
      exist. Hence ESTALE.
      
      This is fixed by teaching nfsd not to trust DCACHE_MOUNTED
      too much.  It is just a hint, not a guarantee.
      Change nfsd_mountpoint() to return '1' for a certain mountpoint,
      '2' for a possible mountpoint, and 0 otherwise.
      
      Then change nfsd_crossmnt() to check if follow_down()
      actually found a mountpount and, if not, to avoid performing
      a lookup if the location is not known to certainly require
      an export-point.
      Signed-off-by: NNeilBrown <neilb@suse.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      99bbf6ec
    • N
      nfsd4: remove pointless strdup_if_nonnull · 2f10fdcb
      NeilBrown 提交于
      kstrdup() already checks for NULL.
      
      (Brought to our attention by Jason Yann noticing (from sparse output)
      that it should have been declared static.)
      Signed-off-by: NNeilBrown <neilb@suse.com>
      Reported-by: NJason Yan <yanaijie@huawei.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      2f10fdcb
    • J
      nfsd: check for oversized NFSv2/v3 arguments · 51f56777
      J. Bruce Fields 提交于
      A client can append random data to the end of an NFSv2 or NFSv3 RPC call
      without our complaining; we'll just stop parsing at the end of the
      expected data and ignore the rest.
      
      Encoded arguments and replies are stored together in an array of pages,
      and if a call is too large it could leave inadequate space for the
      reply.  This is normally OK because NFS RPC's typically have either
      short arguments and long replies (like READ) or long arguments and short
      replies (like WRITE).  But a client that sends an incorrectly long reply
      can violate those assumptions.  This was observed to cause crashes.
      
      So, insist that the argument not be any longer than we expect.
      
      Also, several operations increment rq_next_page in the decode routine
      before checking the argument size, which can leave rq_next_page pointing
      well past the end of the page array, causing trouble later in
      svc_free_pages.
      
      As followup we may also want to rewrite the encoding routines to check
      more carefully that they aren't running off the end of the page array.
      Reported-by: NTuomas Haanpää <thaan@synopsys.com>
      Reported-by: NAri Kauppi <ari@synopsys.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      51f56777
    • J
      nfsd: stricter decoding of write-like NFSv2/v3 ops · 13bf9fbf
      J. Bruce Fields 提交于
      The NFSv2/v3 code does not systematically check whether we decode past
      the end of the buffer.  This generally appears to be harmless, but there
      are a few places where we do arithmetic on the pointers involved and
      don't account for the possibility that a length could be negative.  Add
      checks to catch these.
      Reported-by: NTuomas Haanpää <thaan@synopsys.com>
      Reported-by: NAri Kauppi <ari@synopsys.com>
      Reviewed-by: NNeilBrown <neilb@suse.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      13bf9fbf
    • J
      nfsd4: minor NFSv2/v3 write decoding cleanup · db44bac4
      J. Bruce Fields 提交于
      Use a couple shortcuts that will simplify a following bugfix.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      db44bac4
    • J
      nfsd: check for oversized NFSv2/v3 arguments · e6838a29
      J. Bruce Fields 提交于
      A client can append random data to the end of an NFSv2 or NFSv3 RPC call
      without our complaining; we'll just stop parsing at the end of the
      expected data and ignore the rest.
      
      Encoded arguments and replies are stored together in an array of pages,
      and if a call is too large it could leave inadequate space for the
      reply.  This is normally OK because NFS RPC's typically have either
      short arguments and long replies (like READ) or long arguments and short
      replies (like WRITE).  But a client that sends an incorrectly long reply
      can violate those assumptions.  This was observed to cause crashes.
      
      Also, several operations increment rq_next_page in the decode routine
      before checking the argument size, which can leave rq_next_page pointing
      well past the end of the page array, causing trouble later in
      svc_free_pages.
      
      So, following a suggestion from Neil Brown, add a central check to
      enforce our expectation that no NFSv2/v3 call has both a large call and
      a large reply.
      
      As followup we may also want to rewrite the encoding routines to check
      more carefully that they aren't running off the end of the page array.
      
      We may also consider rejecting calls that have any extra garbage
      appended.  That would be safer, and within our rights by spec, but given
      the age of our server and the NFS protocol, and the fact that we've
      never enforced this before, we may need to balance that against the
      possibility of breaking some oddball client.
      Reported-by: NTuomas Haanpää <thaan@synopsys.com>
      Reported-by: NAri Kauppi <ari@synopsys.com>
      Cc: stable@vger.kernel.org
      Reviewed-by: NNeilBrown <neilb@suse.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      e6838a29
  9. 21 4月, 2017 2 次提交
  10. 13 4月, 2017 1 次提交
    • O
      nfsd: fix oops on unsupported operation · 05b7278d
      Olga Kornievskaia 提交于
      I'm hitting the BUG in nfsd4_max_reply() at fs/nfsd/nfs4proc.c:2495 when
      client sends an operation the server doesn't support.
      
      in nfsd4_max_reply() it checks for NULL rsize_bop but a non-supported
      operation wouldn't have that set.
      
      Cc: Kinglong Mee <kinglongmee@gmail.com>
      Fixes: 2282cd2c "NFSD: Get response size before operation..."
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      05b7278d
  11. 11 4月, 2017 1 次提交
    • N
      sched/core: Remove 'task' parameter and rename tsk_restore_flags() to current_restore_flags() · 717a94b5
      NeilBrown 提交于
      It is not safe for one thread to modify the ->flags
      of another thread as there is no locking that can protect
      the update.
      
      So tsk_restore_flags(), which takes a task pointer and modifies
      the flags, is an invitation to do the wrong thing.
      
      All current users pass "current" as the task, so no developers have
      accepted that invitation.  It would be best to ensure it remains
      that way.
      
      So rename tsk_restore_flags() to current_restore_flags() and don't
      pass in a task_struct pointer.  Always operate on current->flags.
      Signed-off-by: NNeilBrown <neilb@suse.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Mel Gorman <mgorman@suse.de>
      Cc: Michal Hocko <mhocko@kernel.org>
      Cc: Peter Zijlstra <peterz@infradead.org>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NIngo Molnar <mingo@kernel.org>
      717a94b5
  12. 11 3月, 2017 4 次提交
    • N
      NFSD: fix nfsd_reset_versions for NFSv4. · 800a938f
      NeilBrown 提交于
      If you write "-2 -3 -4" to the "versions" file, it will
      notice that no versions are enabled, and nfsd_reset_versions()
      is called.
      This enables all major versions, not no minor versions.
      So we lose the invariant that NFSv4 is only advertised when
      at least one minor is enabled.
      
      Fix the code to explicitly enable minor versions for v4,
      change it to use nfsd_vers() to test and set, and simplify
      the code.
      Signed-off-by: NNeilBrown <neilb@suse.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      800a938f
    • N
      NFSD: fix nfsd_minorversion(.., NFSD_AVAIL) · 928c6fb3
      NeilBrown 提交于
      Current code will return 1 if the version is supported,
      and -1 if it isn't.
      This is confusing and inconsistent with the one place where this
      is used.
      So change to return 1 if it is supported, and zero if not.
      i.e. an error is never returned.
      Signed-off-by: NNeilBrown <neilb@suse.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      928c6fb3
    • N
      NFSD: further refinement of content of /proc/fs/nfsd/versions · abcb4dac
      NeilBrown 提交于
      Prior to
        e35659f1 ("NFSD: correctly range-check v4.x minor version when setting versions.")
      
      v4.0 could not be disabled without disabling all NFSv4 protocols.
      So the 'versions' file contained ±4 ±4.1 ±4.2.
      Writing "-4" would disable all v4 completely.  Writing +4 would enabled those
      minor versions that are currently enabled, either by default or otherwise.
      
      After that commit, it was possible to disable v4.0 independently.  To
      maximize backward compatibility with use cases which never disabled
      v4.0, the "versions" file would never contain "+4.0" - that was implied
      by "+4", unless explicitly negated by "-4.0".
      
      This introduced an inconsistency in that it was possible to disable all
      minor versions, but still have the major version advertised.
      e.g. "-4.0 -4.1 -4.2 +4" would result in NFSv4 support being advertised,
      but all attempts to use it rejected.
      
      Commit
        d3635ff0 ("nfsd: fix configuration of supported minor versions")
      
      and following removed this inconsistency. If all minor version were disabled,
      the major would be disabled too.  If any minor was enabled, the major would be
      disabled.
      This patch also treated "+4" as equivalent to "+4.0" and "-4" as "-4.0".
      A consequence of this is that writing "-4" would only disable 4.0.
      This is a regression against the earlier behaviour, in a use case that rpc.nfsd
      actually uses.
      The command "rpc.nfsd -N 4" will write "+2 +3 -4" to the versions files.
      Previously, that would disable v4 completely.  Now it will only disable v4.0.
      
      Also "4.0" never appears in the "versions" file when read.
      So if only v4.1 is available, the previous kernel would have reported
      "+4 -4.0 +4.1 -4.2"  the current kernel reports "-4 +4.1 -4.2" which
      could easily confuse.
      
      This patch restores the implication that "+4" and "-4" apply more
      globals and do not imply "4.0".
      Specifically:
       writing "-4" will disable all 4.x minor versions.
       writing "+4" will enable all 4.1 minor version if none are currently enabled.
          rpc.nfsd will list minor versions before major versions, so
            rpc.nfsd -V 4.2 -N 4.1
          will write "-4.1 +4.2 +2 +3 +4"
          so it would be a regression for "+4" to enable always all versions.
       reading "-4" implies that no v4.x are enabled
       reading "+4" implies that some v4.x are enabled, and that v4.0 is enabled unless
       "-4.0" is also present.  All other minor versions will explicitly be listed.
      Signed-off-by: NNeilBrown <neilb@suse.com>
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      abcb4dac
    • K
      nfsd: map the ENOKEY to nfserr_perm for avoiding warning · c952cd4e
      Kinglong Mee 提交于
      Now that Ext4 and f2fs filesystems support encrypted directories and
      files, attempts to access those files may return ENOKEY, resulting in
      the following WARNING.
      
      Map ENOKEY to nfserr_perm instead of nfserr_io.
      
      [ 1295.411759] ------------[ cut here ]------------
      [ 1295.411787] WARNING: CPU: 0 PID: 12786 at fs/nfsd/nfsproc.c:796 nfserrno+0x74/0x80 [nfsd]
      [ 1295.411806] nfsd: non-standard errno: -126
      [ 1295.411816] Modules linked in: nfsd nfs_acl auth_rpcgss nfsv4 nfs lockd fscache tun bridge stp llc fuse ip_set nfnetlink vmw_vsock_vmci_transport vsock snd_seq_midi snd_seq_midi_event coretemp crct10dif_pclmul crc32_generic crc32_pclmul snd_ens1371 gameport ghash_clmulni_intel snd_ac97_codec f2fs intel_rapl_perf ac97_bus snd_seq ppdev snd_pcm snd_rawmidi snd_timer vmw_balloon snd_seq_device snd joydev soundcore parport_pc parport nfit acpi_cpufreq tpm_tis vmw_vmci tpm_tis_core tpm shpchp i2c_piix4 grace sunrpc xfs libcrc32c vmwgfx drm_kms_helper ttm drm crc32c_intel e1000 mptspi scsi_transport_spi serio_raw mptscsih mptbase ata_generic pata_acpi fjes [last unloaded: nfs_acl]
      [ 1295.412522] CPU: 0 PID: 12786 Comm: nfsd Tainted: G        W       4.11.0-rc1+ #521
      [ 1295.412959] Hardware name: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 07/02/2015
      [ 1295.413814] Call Trace:
      [ 1295.414252]  dump_stack+0x63/0x86
      [ 1295.414666]  __warn+0xcb/0xf0
      [ 1295.415087]  warn_slowpath_fmt+0x5f/0x80
      [ 1295.415502]  ? put_filp+0x42/0x50
      [ 1295.415927]  nfserrno+0x74/0x80 [nfsd]
      [ 1295.416339]  nfsd_open+0xd7/0x180 [nfsd]
      [ 1295.416746]  nfs4_get_vfs_file+0x367/0x3c0 [nfsd]
      [ 1295.417182]  ? security_inode_permission+0x41/0x60
      [ 1295.417591]  nfsd4_process_open2+0x9b2/0x1200 [nfsd]
      [ 1295.418007]  nfsd4_open+0x481/0x790 [nfsd]
      [ 1295.418409]  nfsd4_proc_compound+0x395/0x680 [nfsd]
      [ 1295.418812]  nfsd_dispatch+0xb8/0x1f0 [nfsd]
      [ 1295.419233]  svc_process_common+0x4d9/0x830 [sunrpc]
      [ 1295.419631]  svc_process+0xfe/0x1b0 [sunrpc]
      [ 1295.420033]  nfsd+0xe9/0x150 [nfsd]
      [ 1295.420420]  kthread+0x101/0x140
      [ 1295.420802]  ? nfsd_destroy+0x60/0x60 [nfsd]
      [ 1295.421199]  ? kthread_park+0x90/0x90
      [ 1295.421598]  ret_from_fork+0x2c/0x40
      [ 1295.421996] ---[ end trace 0d5a969cd7852e1f ]---
      Signed-off-by: NKinglong Mee <kinglongmee@gmail.com>
      Cc: stable@vger.kernel.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      c952cd4e