1. 01 10月, 2021 1 次提交
    • J
      SUNRPC: fix sign error causing rpcsec_gss drops · 2ba5acfb
      J. Bruce Fields 提交于
      If sd_max is unsigned, then sd_max - GSS_SEQ_WIN is a very large number
      whenever sd_max is less than GSS_SEQ_WIN, and the comparison:
      
      	seq_num <= sd->sd_max - GSS_SEQ_WIN
      
      in gss_check_seq_num is pretty much always true, even when that's
      clearly not what was intended.
      
      This was causing pynfs to hang when using krb5, because pynfs uses zero
      as the initial gss sequence number.  That's perfectly legal, but this
      logic error causes knfsd to drop the rpc in that case.  Out-of-order
      sequence IDs in the first GSS_SEQ_WIN (128) calls will also cause this.
      
      Fixes: 10b9d99a ("SUNRPC: Augment server-side rpcgss tracepoints")
      Cc: stable@vger.kernel.org
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      2ba5acfb
  2. 04 9月, 2021 1 次提交
  3. 17 8月, 2021 1 次提交
  4. 11 8月, 2021 2 次提交
    • C
      SUNRPC: Set rq_auth_stat in the pg_authenticate() callout · 5c2465df
      Chuck Lever 提交于
      In a few moments, rq_auth_stat will need to be explicitly set to
      rpc_auth_ok before execution gets to the dispatcher.
      
      svc_authenticate() already sets it, but it often gets reset to
      rpc_autherr_badcred right after that call, even when authentication
      is successful. Let's ensure that the pg_authenticate callout and
      svc_set_client() set it properly in every case.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: NAnna Schumaker <Anna.Schumaker@Netapp.com>
      5c2465df
    • C
      SUNRPC: Add svc_rqst::rq_auth_stat · 438623a0
      Chuck Lever 提交于
      I'd like to take commit 4532608d ("SUNRPC: Clean up generic
      dispatcher code") even further by using only private local SVC
      dispatchers for all kernel RPC services. This change would enable
      the removal of the logic that switches between
      svc_generic_dispatch() and a service's private dispatcher, and
      simplify the invocation of the service's pc_release method
      so that humans can visually verify that it is always invoked
      properly.
      
      All that will come later.
      
      First, let's provide a better way to return authentication errors
      from SVC dispatcher functions. Instead of overloading the dispatch
      method's *statp argument, add a field to struct svc_rqst that can
      hold an error value.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: NAnna Schumaker <Anna.Schumaker@Netapp.com>
      438623a0
  5. 10 8月, 2021 1 次提交
  6. 07 7月, 2021 1 次提交
  7. 22 6月, 2021 1 次提交
  8. 07 3月, 2021 1 次提交
  9. 26 1月, 2021 2 次提交
    • D
      SUNRPC: Handle 0 length opaque XDR object data properly · e4a7d1f7
      Dave Wysochanski 提交于
      When handling an auth_gss downcall, it's possible to get 0-length
      opaque object for the acceptor.  In the case of a 0-length XDR
      object, make sure simple_get_netobj() fills in dest->data = NULL,
      and does not continue to kmemdup() which will set
      dest->data = ZERO_SIZE_PTR for the acceptor.
      
      The trace event code can handle NULL but not ZERO_SIZE_PTR for a
      string, and so without this patch the rpcgss_context trace event
      will crash the kernel as follows:
      
      [  162.887992] BUG: kernel NULL pointer dereference, address: 0000000000000010
      [  162.898693] #PF: supervisor read access in kernel mode
      [  162.900830] #PF: error_code(0x0000) - not-present page
      [  162.902940] PGD 0 P4D 0
      [  162.904027] Oops: 0000 [#1] SMP PTI
      [  162.905493] CPU: 4 PID: 4321 Comm: rpc.gssd Kdump: loaded Not tainted 5.10.0 #133
      [  162.908548] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
      [  162.910978] RIP: 0010:strlen+0x0/0x20
      [  162.912505] Code: 48 89 f9 74 09 48 83 c1 01 80 39 00 75 f7 31 d2 44 0f b6 04 16 44 88 04 11 48 83 c2 01 45 84 c0 75 ee c3 0f 1f 80 00 00 00 00 <80> 3f 00 74 10 48 89 f8 48 83 c0 01 80 38 00 75 f7 48 29 f8 c3 31
      [  162.920101] RSP: 0018:ffffaec900c77d90 EFLAGS: 00010202
      [  162.922263] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00000000fffde697
      [  162.925158] RDX: 000000000000002f RSI: 0000000000000080 RDI: 0000000000000010
      [  162.928073] RBP: 0000000000000010 R08: 0000000000000e10 R09: 0000000000000000
      [  162.930976] R10: ffff8e698a590cb8 R11: 0000000000000001 R12: 0000000000000e10
      [  162.933883] R13: 00000000fffde697 R14: 000000010034d517 R15: 0000000000070028
      [  162.936777] FS:  00007f1e1eb93700(0000) GS:ffff8e6ab7d00000(0000) knlGS:0000000000000000
      [  162.940067] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      [  162.942417] CR2: 0000000000000010 CR3: 0000000104eba000 CR4: 00000000000406e0
      [  162.945300] Call Trace:
      [  162.946428]  trace_event_raw_event_rpcgss_context+0x84/0x140 [auth_rpcgss]
      [  162.949308]  ? __kmalloc_track_caller+0x35/0x5a0
      [  162.951224]  ? gss_pipe_downcall+0x3a3/0x6a0 [auth_rpcgss]
      [  162.953484]  gss_pipe_downcall+0x585/0x6a0 [auth_rpcgss]
      [  162.955953]  rpc_pipe_write+0x58/0x70 [sunrpc]
      [  162.957849]  vfs_write+0xcb/0x2c0
      [  162.959264]  ksys_write+0x68/0xe0
      [  162.960706]  do_syscall_64+0x33/0x40
      [  162.962238]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
      [  162.964346] RIP: 0033:0x7f1e1f1e57df
      Signed-off-by: NDave Wysochanski <dwysocha@redhat.com>
      Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
      e4a7d1f7
    • D
      SUNRPC: Move simple_get_bytes and simple_get_netobj into private header · ba6dfce4
      Dave Wysochanski 提交于
      Remove duplicated helper functions to parse opaque XDR objects
      and place inside new file net/sunrpc/auth_gss/auth_gss_internal.h.
      In the new file carry the license and copyright from the source file
      net/sunrpc/auth_gss/auth_gss.c.  Finally, update the comment inside
      include/linux/sunrpc/xdr.h since lockd is not the only user of
      struct xdr_netobj.
      Signed-off-by: NDave Wysochanski <dwysocha@redhat.com>
      Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
      ba6dfce4
  10. 09 12月, 2020 1 次提交
  11. 02 12月, 2020 1 次提交
  12. 01 12月, 2020 1 次提交
  13. 21 10月, 2020 1 次提交
    • M
      SUNRPC: fix copying of multiple pages in gss_read_proxy_verf() · d48c8124
      Martijn de Gouw 提交于
      When the passed token is longer than 4032 bytes, the remaining part
      of the token must be copied from the rqstp->rq_arg.pages. But the
      copy must make sure it happens in a consecutive way.
      
      With the existing code, the first memcpy copies 'length' bytes from
      argv->iobase, but since the header is in front, this never fills the
      whole first page of in_token->pages.
      
      The mecpy in the loop copies the following bytes, but starts writing at
      the next page of in_token->pages.  This leaves the last bytes of page 0
      unwritten.
      
      Symptoms were that users with many groups were not able to access NFS
      exports, when using Active Directory as the KDC.
      Signed-off-by: NMartijn de Gouw <martijn.de.gouw@prodrive-technologies.com>
      Fixes: 5866efa8 "SUNRPC: Fix svcauth_gss_proxy_init()"
      Signed-off-by: NJ. Bruce Fields <bfields@redhat.com>
      d48c8124
  14. 11 9月, 2020 1 次提交
    • A
      SUNRPC: remove RC4-HMAC-MD5 support from KerberosV · e33d2a7b
      Ard Biesheuvel 提交于
      The RC4-HMAC-MD5 KerberosV algorithm is based on RFC 4757 [0], which
      was specifically issued for interoperability with Windows 2000, but was
      never intended to receive the same level of support. The RFC says
      
        The IETF Kerberos community supports publishing this specification as
        an informational document in order to describe this widely
        implemented technology.  However, while these encryption types
        provide the operations necessary to implement the base Kerberos
        specification [RFC4120], they do not provide all the required
        operations in the Kerberos cryptography framework [RFC3961].  As a
        result, it is not generally possible to implement potential
        extensions to Kerberos using these encryption types.  The Kerberos
        encryption type negotiation mechanism [RFC4537] provides one approach
        for using such extensions even when a Kerberos infrastructure uses
        long-term RC4 keys.  Because this specification does not implement
        operations required by RFC 3961 and because of security concerns with
        the use of RC4 and MD4 discussed in Section 8, this specification is
        not appropriate for publication on the standards track.
      
        The RC4-HMAC encryption types are used to ease upgrade of existing
        Windows NT environments, provide strong cryptography (128-bit key
        lengths), and provide exportable (meet United States government
        export restriction requirements) encryption.  This document describes
        the implementation of those encryption types.
      
      Furthermore, this RFC was re-classified as 'historic' by RFC 8429 [1] in
      2018, stating that 'none of the encryption types it specifies should be
      used'
      
      Note that other outdated algorithms are left in place (some of which are
      guarded by CONFIG_SUNRPC_DISABLE_INSECURE_ENCTYPES), so this should only
      adversely affect interoperability with Windows NT/2000 systems that have
      not received any updates since 2008 (but are connected to a network
      nonetheless)
      
      [0] https://tools.ietf.org/html/rfc4757
      [1] https://tools.ietf.org/html/rfc8429Signed-off-by: NArd Biesheuvel <ardb@kernel.org>
      Acked-by: NJ. Bruce Fields <bfields@redhat.com>
      Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
      e33d2a7b
  15. 24 8月, 2020 1 次提交
  16. 20 8月, 2020 1 次提交
  17. 08 8月, 2020 1 次提交
    • W
      mm, treewide: rename kzfree() to kfree_sensitive() · 453431a5
      Waiman Long 提交于
      As said by Linus:
      
        A symmetric naming is only helpful if it implies symmetries in use.
        Otherwise it's actively misleading.
      
        In "kzalloc()", the z is meaningful and an important part of what the
        caller wants.
      
        In "kzfree()", the z is actively detrimental, because maybe in the
        future we really _might_ want to use that "memfill(0xdeadbeef)" or
        something. The "zero" part of the interface isn't even _relevant_.
      
      The main reason that kzfree() exists is to clear sensitive information
      that should not be leaked to other future users of the same memory
      objects.
      
      Rename kzfree() to kfree_sensitive() to follow the example of the recently
      added kvfree_sensitive() and make the intention of the API more explicit.
      In addition, memzero_explicit() is used to clear the memory to make sure
      that it won't get optimized away by the compiler.
      
      The renaming is done by using the command sequence:
      
        git grep -w --name-only kzfree |\
        xargs sed -i 's/kzfree/kfree_sensitive/'
      
      followed by some editing of the kfree_sensitive() kerneldoc and adding
      a kzfree backward compatibility macro in slab.h.
      
      [akpm@linux-foundation.org: fs/crypto/inline_crypt.c needs linux/slab.h]
      [akpm@linux-foundation.org: fix fs/crypto/inline_crypt.c some more]
      Suggested-by: NJoe Perches <joe@perches.com>
      Signed-off-by: NWaiman Long <longman@redhat.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Acked-by: NDavid Howells <dhowells@redhat.com>
      Acked-by: NMichal Hocko <mhocko@suse.com>
      Acked-by: NJohannes Weiner <hannes@cmpxchg.org>
      Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
      Cc: James Morris <jmorris@namei.org>
      Cc: "Serge E. Hallyn" <serge@hallyn.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Matthew Wilcox <willy@infradead.org>
      Cc: David Rientjes <rientjes@google.com>
      Cc: Dan Carpenter <dan.carpenter@oracle.com>
      Cc: "Jason A . Donenfeld" <Jason@zx2c4.com>
      Link: http://lkml.kernel.org/r/20200616154311.12314-3-longman@redhat.comSigned-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      453431a5
  18. 25 7月, 2020 1 次提交
  19. 14 7月, 2020 1 次提交
    • C
      SUNRPC: Augment server-side rpcgss tracepoints · 10b9d99a
      Chuck Lever 提交于
      Add similar tracepoints to those that were recently added on the
      client side to track failures in the integ and priv unwrap paths.
      
      And, let's collect the seqno-specific tracepoints together with a
      common naming convention.
      
      Regarding the gss_check_seq_num() changes: everywhere else treats
      the GSS sequence number as an unsigned 32-bit integer. As far back
      as 2.6.12, I couldn't find a compelling reason to do things
      differently here. As a defensive change it's better to eliminate
      needless implicit sign conversions.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      10b9d99a
  20. 12 6月, 2020 3 次提交
  21. 08 6月, 2020 1 次提交
  22. 29 5月, 2020 2 次提交
  23. 27 4月, 2020 3 次提交
    • C
      SUNRPC: Revert 241b1f41 ("SUNRPC: Remove xdr_buf_trim()") · 0a8e7b7d
      Chuck Lever 提交于
      I've noticed that when krb5i or krb5p security is in use,
      retransmitted requests are missing the server's duplicate reply
      cache. The computed checksum on the retransmitted request does not
      match the cached checksum, resulting in the server performing the
      retransmitted request again instead of returning the cached reply.
      
      The assumptions made when removing xdr_buf_trim() were not correct.
      In the send paths, the upper layer has already set the segment
      lengths correctly, and shorting the buffer's content is simply a
      matter of reducing buf->len.
      
      xdr_buf_trim() is the right answer in the receive/unwrap path on
      both the client and the server. The buffer segment lengths have to
      be shortened one-by-one.
      
      On the server side in particular, head.iov_len needs to be updated
      correctly to enable nfsd_cache_csum() to work correctly. The simple
      buf->len computation doesn't do that, and that results in
      checksumming stale data in the buffer.
      
      The problem isn't noticed until there's significant instability of
      the RPC transport. At that point, the reliability of retransmit
      detection on the server becomes crucial.
      
      Fixes: 241b1f41 ("SUNRPC: Remove xdr_buf_trim()")
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      0a8e7b7d
    • C
      SUNRPC: Fix GSS privacy computation of auth->au_ralign · a7e429a6
      Chuck Lever 提交于
      When the au_ralign field was added to gss_unwrap_resp_priv, the
      wrong calculation was used. Setting au_rslack == au_ralign is
      probably correct for kerberos_v1 privacy, but kerberos_v2 privacy
      adds additional GSS data after the clear text RPC message.
      au_ralign needs to be smaller than au_rslack in that fairly common
      case.
      
      When xdr_buf_trim() is restored to gss_unwrap_kerberos_v2(), it does
      exactly what I feared it would: it trims off part of the clear text
      RPC message. However, that's because rpc_prepare_reply_pages() does
      not set up the rq_rcv_buf's tail correctly because au_ralign is too
      large.
      
      Fixing the au_ralign computation also corrects the alignment of
      rq_rcv_buf->pages so that the client does not have to shift reply
      data payloads after they are received.
      
      Fixes: 35e77d21 ("SUNRPC: Add rpc_auth::au_ralign field")
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      a7e429a6
    • C
      SUNRPC: Add "@len" parameter to gss_unwrap() · 31c9590a
      Chuck Lever 提交于
      Refactor: This is a pre-requisite to fixing the client-side ralign
      computation in gss_unwrap_resp_priv().
      
      The length value is passed in explicitly rather that as the value
      of buf->len. This will subsequently allow gss_unwrap_kerberos_v1()
      to compute a slack and align value, instead of computing it in
      gss_unwrap_resp_priv().
      
      Fixes: 35e77d21 ("SUNRPC: Add rpc_auth::au_ralign field")
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      31c9590a
  24. 26 3月, 2020 1 次提交
    • O
      SUNRPC: fix krb5p mount to provide large enough buffer in rq_rcvsize · df513a77
      Olga Kornievskaia 提交于
      Ever since commit 2c94b8ec ("SUNRPC: Use au_rslack when computing
      reply buffer size"). It changed how "req->rq_rcvsize" is calculated. It
      used to use au_cslack value which was nice and large and changed it to
      au_rslack value which turns out to be too small.
      
      Since 5.1, v3 mount with sec=krb5p fails against an Ontap server
      because client's receive buffer it too small.
      
      For gss krb5p, we need to account for the mic token in the verifier,
      and the wrap token in the wrap token.
      
      RFC 4121 defines:
      mic token
      Octet no   Name        Description
               --------------------------------------------------------------
               0..1     TOK_ID     Identification field.  Tokens emitted by
                                   GSS_GetMIC() contain the hex value 04 04
                                   expressed in big-endian order in this
                                   field.
               2        Flags      Attributes field, as described in section
                                   4.2.2.
               3..7     Filler     Contains five octets of hex value FF.
               8..15    SND_SEQ    Sequence number field in clear text,
                                   expressed in big-endian order.
               16..last SGN_CKSUM  Checksum of the "to-be-signed" data and
                                   octet 0..15, as described in section 4.2.4.
      
      that's 16bytes (GSS_KRB5_TOK_HDR_LEN) + chksum
      
      wrap token
      Octet no   Name        Description
               --------------------------------------------------------------
                0..1     TOK_ID    Identification field.  Tokens emitted by
                                   GSS_Wrap() contain the hex value 05 04
                                   expressed in big-endian order in this
                                   field.
                2        Flags     Attributes field, as described in section
                                   4.2.2.
                3        Filler    Contains the hex value FF.
                4..5     EC        Contains the "extra count" field, in big-
                                   endian order as described in section 4.2.3.
                6..7     RRC       Contains the "right rotation count" in big-
                                   endian order, as described in section
                                   4.2.5.
                8..15    SND_SEQ   Sequence number field in clear text,
                                   expressed in big-endian order.
                16..last Data      Encrypted data for Wrap tokens with
                                   confidentiality, or plaintext data followed
                                   by the checksum for Wrap tokens without
                                   confidentiality, as described in section
                                   4.2.4.
      
      Also 16bytes of header (GSS_KRB5_TOK_HDR_LEN), encrypted data, and cksum
      (other things like padding)
      
      RFC 3961 defines known cksum sizes:
      Checksum type              sumtype        checksum         section or
                                      value            size         reference
         ---------------------------------------------------------------------
         CRC32                            1               4           6.1.3
         rsa-md4                          2              16           6.1.2
         rsa-md4-des                      3              24           6.2.5
         des-mac                          4              16           6.2.7
         des-mac-k                        5               8           6.2.8
         rsa-md4-des-k                    6              16           6.2.6
         rsa-md5                          7              16           6.1.1
         rsa-md5-des                      8              24           6.2.4
         rsa-md5-des3                     9              24             ??
         sha1 (unkeyed)                  10              20             ??
         hmac-sha1-des3-kd               12              20            6.3
         hmac-sha1-des3                  13              20             ??
         sha1 (unkeyed)                  14              20             ??
         hmac-sha1-96-aes128             15              20         [KRB5-AES]
         hmac-sha1-96-aes256             16              20         [KRB5-AES]
         [reserved]                  0x8003               ?         [GSS-KRB5]
      
      Linux kernel now mainly supports type 15,16 so max cksum size is 20bytes.
      (GSS_KRB5_MAX_CKSUM_LEN)
      
      Re-use already existing define of GSS_KRB5_MAX_SLACK_NEEDED that's used
      for encoding the gss_wrap tokens (same tokens are used in reply).
      
      Fixes: 2c94b8ec ("SUNRPC: Use au_rslack when computing reply buffer size")
      Signed-off-by: NOlga Kornievskaia <kolga@netapp.com>
      Reviewed-by: NChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
      df513a77
  25. 17 3月, 2020 3 次提交
  26. 16 3月, 2020 2 次提交
    • C
      SUNRPC: Trim stack utilization in the wrap and unwrap paths · d162372a
      Chuck Lever 提交于
      By preventing compiler inlining of the integrity and privacy
      helpers, stack utilization for the common case (authentication only)
      goes way down.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
      d162372a
    • C
      sunrpc: Fix gss_unwrap_resp_integ() again · 4047aa90
      Chuck Lever 提交于
      xdr_buf_read_mic() tries to find unused contiguous space in a
      received xdr_buf in order to linearize the checksum for the call
      to gss_verify_mic. However, the corner cases in this code are
      numerous and we seem to keep missing them. I've just hit yet
      another buffer overrun related to it.
      
      This overrun is at the end of xdr_buf_read_mic():
      
      1284         if (buf->tail[0].iov_len != 0)
      1285                 mic->data = buf->tail[0].iov_base + buf->tail[0].iov_len;
      1286         else
      1287                 mic->data = buf->head[0].iov_base + buf->head[0].iov_len;
      1288         __read_bytes_from_xdr_buf(&subbuf, mic->data, mic->len);
      1289         return 0;
      
      This logic assumes the transport has set the length of the tail
      based on the size of the received message. base + len is then
      supposed to be off the end of the message but still within the
      actual buffer.
      
      In fact, the length of the tail is set by the upper layer when the
      Call is encoded so that the end of the tail is actually the end of
      the allocated buffer itself. This causes the logic above to set
      mic->data to point past the end of the receive buffer.
      
      The "mic->data = head" arm of this if statement is no less fragile.
      
      As near as I can tell, this has been a problem forever. I'm not sure
      that minimizing au_rslack recently changed this pathology much.
      
      So instead, let's use a more straightforward approach: kmalloc a
      separate buffer to linearize the checksum. This is similar to
      how gss_validate() currently works.
      
      Coming back to this code, I had some trouble understanding what
      was going on. So I've cleaned up the variable naming and added
      a few comments that point back to the XDR definition in RFC 2203
      to help guide future spelunkers, including myself.
      
      As an added clean up, the functionality that was in
      xdr_buf_read_mic() is folded directly into gss_unwrap_resp_integ(),
      as that is its only caller.
      Signed-off-by: NChuck Lever <chuck.lever@oracle.com>
      Reviewed-by: NBenjamin Coddington <bcodding@redhat.com>
      Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
      4047aa90
  27. 08 2月, 2020 1 次提交
  28. 04 2月, 2020 1 次提交
  29. 15 1月, 2020 2 次提交