NFS: fix open_owner_id_maxsz and related fields.
authorNeilBrown <neilb@suse.de>
Wed, 4 Dec 2024 02:53:09 +0000 (13:53 +1100)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 17 Mar 2025 20:51:53 +0000 (16:51 -0400)
A recent change increased the size of an NFSv4 open owner, but didn't
increase the corresponding max_sz defines.  This is not know to have
caused failure, but should be fixed.

This patch also fixes some relates _maxsz fields that are wrong.

Note that the XXX_owner_id_maxsz values now are only the size of the id
and do NOT include the len field that will always preceed the id in xdr
encoding.  I think this is clearer.

Reported-by: David Disseldorp <ddiss@suse.com>
Fixes: d98f72272500 ("nfs: simplify and guarantee owner uniqueness.")
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/nfs4xdr.c

index e8ac3f615f932eaf1c094637c3ee0a8994d2caf5..71f45cc0ca74d1600ee2bf70ded41ae958123d72 100644 (file)
@@ -82,9 +82,8 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
  * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT  >> 2)
  */
 #define pagepad_maxsz          (1)
-#define open_owner_id_maxsz    (1 + 2 + 1 + 1 + 2)
-#define lock_owner_id_maxsz    (1 + 1 + 4)
-#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
+#define open_owner_id_maxsz    (2 + 1 + 2 + 2)
+#define lock_owner_id_maxsz    (2 + 1 + 2)
 #define compound_encode_hdr_maxsz      (3 + (NFS4_MAXTAGLEN >> 2))
 #define compound_decode_hdr_maxsz      (3 + (NFS4_MAXTAGLEN >> 2))
 #define op_encode_hdr_maxsz    (1)
@@ -185,7 +184,7 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define encode_claim_null_maxsz        (1 + nfs4_name_maxsz)
 #define encode_open_maxsz      (op_encode_hdr_maxsz + \
                                2 + encode_share_access_maxsz + 2 + \
-                               open_owner_id_maxsz + \
+                               1 + open_owner_id_maxsz + \
                                encode_opentype_maxsz + \
                                encode_claim_null_maxsz)
 #define decode_space_limit_maxsz       (3)
@@ -255,13 +254,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
 #define encode_link_maxsz      (op_encode_hdr_maxsz + \
                                nfs4_name_maxsz)
 #define decode_link_maxsz      (op_decode_hdr_maxsz + decode_change_info_maxsz)
-#define encode_lockowner_maxsz (7)
+#define encode_lockowner_maxsz (2 + 1 + lock_owner_id_maxsz)
+
 #define encode_lock_maxsz      (op_encode_hdr_maxsz + \
                                 7 + \
                                 1 + encode_stateid_maxsz + 1 + \
                                 encode_lockowner_maxsz)
 #define decode_lock_denied_maxsz \
-                               (8 + decode_lockowner_maxsz)
+                               (2 + 2 + 1 + 2 + 1 + lock_owner_id_maxsz)
 #define decode_lock_maxsz      (op_decode_hdr_maxsz + \
                                 decode_lock_denied_maxsz)
 #define encode_lockt_maxsz     (op_encode_hdr_maxsz + 5 + \
@@ -617,7 +617,7 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
                                 encode_lockowner_maxsz)
 #define NFS4_dec_release_lockowner_sz \
                                (compound_decode_hdr_maxsz + \
-                                decode_lockowner_maxsz)
+                                decode_release_lockowner_maxsz)
 #define NFS4_enc_access_sz     (compound_encode_hdr_maxsz + \
                                encode_sequence_maxsz + \
                                encode_putfh_maxsz + \
@@ -1412,7 +1412,7 @@ static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_opena
        __be32 *p;
  /*
  * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
- * owner 4 = 32
+ * owner 28
  */
        encode_nfs4_seqid(xdr, arg->seqid);
        encode_share_access(xdr, arg->share_access);
@@ -5077,7 +5077,7 @@ static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
 /*
  * We create the owner, so we know a proper owner.id length is 4.
  */
-static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
+static int decode_lock_denied(struct xdr_stream *xdr, struct file_lock *fl)
 {
        uint64_t offset, length, clientid;
        __be32 *p;