Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/lockd/xdr4.c |
| 4 | * |
| 5 | * XDR support for lockd and the lock client. |
| 6 | * |
| 7 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> |
| 8 | * Copyright (C) 1999, Trond Myklebust <trond.myklebust@fys.uio.no> |
| 9 | */ |
| 10 | |
| 11 | #include <linux/types.h> |
| 12 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/nfs.h> |
| 14 | |
| 15 | #include <linux/sunrpc/xdr.h> |
| 16 | #include <linux/sunrpc/clnt.h> |
| 17 | #include <linux/sunrpc/svc.h> |
| 18 | #include <linux/sunrpc/stats.h> |
| 19 | #include <linux/lockd/lockd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Chuck Lever | 7956521 | 2021-06-03 16:52:16 -0400 | [diff] [blame] | 21 | #include "svcxdr.h" |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static inline loff_t |
| 24 | s64_to_loff_t(__s64 offset) |
| 25 | { |
| 26 | return (loff_t)offset; |
| 27 | } |
| 28 | |
| 29 | |
| 30 | static inline s64 |
| 31 | loff_t_to_s64(loff_t offset) |
| 32 | { |
| 33 | s64 res; |
| 34 | if (offset > NLM4_OFFSET_MAX) |
| 35 | res = NLM4_OFFSET_MAX; |
| 36 | else if (offset < -NLM4_OFFSET_MAX) |
| 37 | res = -NLM4_OFFSET_MAX; |
| 38 | else |
| 39 | res = offset; |
| 40 | return res; |
| 41 | } |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* |
Chuck Lever | 345b415 | 2021-06-03 16:52:22 -0400 | [diff] [blame] | 44 | * NLM file handles are defined by specification to be a variable-length |
| 45 | * XDR opaque no longer than 1024 bytes. However, this implementation |
| 46 | * limits their length to the size of an NFSv3 file handle. |
| 47 | */ |
| 48 | static bool |
| 49 | svcxdr_decode_fhandle(struct xdr_stream *xdr, struct nfs_fh *fh) |
| 50 | { |
| 51 | __be32 *p; |
| 52 | u32 len; |
| 53 | |
| 54 | if (xdr_stream_decode_u32(xdr, &len) < 0) |
| 55 | return false; |
| 56 | if (len > NFS_MAXFHSIZE) |
| 57 | return false; |
| 58 | |
| 59 | p = xdr_inline_decode(xdr, len); |
| 60 | if (!p) |
| 61 | return false; |
| 62 | fh->size = len; |
| 63 | memcpy(fh->data, p, len); |
| 64 | memset(fh->data + len, 0, sizeof(fh->data) - len); |
| 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
Chuck Lever | 345b415 | 2021-06-03 16:52:22 -0400 | [diff] [blame] | 69 | static bool |
| 70 | svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock) |
| 71 | { |
| 72 | struct file_lock *fl = &lock->fl; |
| 73 | u64 len, start; |
| 74 | s64 end; |
| 75 | |
| 76 | if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len)) |
| 77 | return false; |
| 78 | if (!svcxdr_decode_fhandle(xdr, &lock->fh)) |
| 79 | return false; |
| 80 | if (!svcxdr_decode_owner(xdr, &lock->oh)) |
| 81 | return false; |
| 82 | if (xdr_stream_decode_u32(xdr, &lock->svid) < 0) |
| 83 | return false; |
| 84 | if (xdr_stream_decode_u64(xdr, &start) < 0) |
| 85 | return false; |
| 86 | if (xdr_stream_decode_u64(xdr, &len) < 0) |
| 87 | return false; |
| 88 | |
| 89 | locks_init_lock(fl); |
| 90 | fl->fl_flags = FL_POSIX; |
| 91 | fl->fl_type = F_RDLCK; |
| 92 | end = start + len - 1; |
| 93 | fl->fl_start = s64_to_loff_t(start); |
| 94 | if (len == 0 || end < 0) |
| 95 | fl->fl_end = OFFSET_MAX; |
| 96 | else |
| 97 | fl->fl_end = s64_to_loff_t(end); |
| 98 | |
| 99 | return true; |
| 100 | } |
| 101 | |
Chuck Lever | 1beef14 | 2021-06-03 16:53:17 -0400 | [diff] [blame] | 102 | static bool |
| 103 | svcxdr_encode_holder(struct xdr_stream *xdr, const struct nlm_lock *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
Chuck Lever | 1beef14 | 2021-06-03 16:53:17 -0400 | [diff] [blame] | 105 | const struct file_lock *fl = &lock->fl; |
| 106 | s64 start, len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Chuck Lever | 1beef14 | 2021-06-03 16:53:17 -0400 | [diff] [blame] | 108 | /* exclusive */ |
| 109 | if (xdr_stream_encode_bool(xdr, fl->fl_type != F_RDLCK) < 0) |
| 110 | return false; |
| 111 | if (xdr_stream_encode_u32(xdr, lock->svid) < 0) |
| 112 | return false; |
| 113 | if (!svcxdr_encode_owner(xdr, &lock->oh)) |
| 114 | return false; |
| 115 | start = loff_t_to_s64(fl->fl_start); |
| 116 | if (fl->fl_end == OFFSET_MAX) |
| 117 | len = 0; |
| 118 | else |
| 119 | len = loff_t_to_s64(fl->fl_end - fl->fl_start + 1); |
| 120 | if (xdr_stream_encode_u64(xdr, start) < 0) |
| 121 | return false; |
| 122 | if (xdr_stream_encode_u64(xdr, len) < 0) |
| 123 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Chuck Lever | 1beef14 | 2021-06-03 16:53:17 -0400 | [diff] [blame] | 125 | return true; |
| 126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Chuck Lever | 1beef14 | 2021-06-03 16:53:17 -0400 | [diff] [blame] | 128 | static bool |
| 129 | svcxdr_encode_testrply(struct xdr_stream *xdr, const struct nlm_res *resp) |
| 130 | { |
| 131 | if (!svcxdr_encode_stats(xdr, resp->status)) |
| 132 | return false; |
| 133 | switch (resp->status) { |
| 134 | case nlm_lck_denied: |
| 135 | if (!svcxdr_encode_holder(xdr, &resp->lock)) |
| 136 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Chuck Lever | 1beef14 | 2021-06-03 16:53:17 -0400 | [diff] [blame] | 139 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | |
| 143 | /* |
Chuck Lever | 7956521 | 2021-06-03 16:52:16 -0400 | [diff] [blame] | 144 | * Decode Call arguments |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | */ |
Chuck Lever | 7956521 | 2021-06-03 16:52:16 -0400 | [diff] [blame] | 146 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 147 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 148 | nlm4svc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 7956521 | 2021-06-03 16:52:16 -0400 | [diff] [blame] | 149 | { |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 150 | return true; |
Chuck Lever | 7956521 | 2021-06-03 16:52:16 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 153 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 154 | nlm4svc_decode_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 156 | struct nlm_args *argp = rqstp->rq_argp; |
Chuck Lever | 345b415 | 2021-06-03 16:52:22 -0400 | [diff] [blame] | 157 | u32 exclusive; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Chuck Lever | 345b415 | 2021-06-03 16:52:22 -0400 | [diff] [blame] | 159 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 160 | return false; |
Chuck Lever | 345b415 | 2021-06-03 16:52:22 -0400 | [diff] [blame] | 161 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 162 | return false; |
Chuck Lever | 345b415 | 2021-06-03 16:52:22 -0400 | [diff] [blame] | 163 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 164 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | if (exclusive) |
| 166 | argp->lock.fl.fl_type = F_WRLCK; |
| 167 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 168 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 171 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 172 | nlm4svc_decode_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 173 | { |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 174 | struct nlm_args *argp = rqstp->rq_argp; |
| 175 | u32 exclusive; |
| 176 | |
| 177 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 178 | return false; |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 179 | if (xdr_stream_decode_bool(xdr, &argp->block) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 180 | return false; |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 181 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 182 | return false; |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 183 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 184 | return false; |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 185 | if (exclusive) |
| 186 | argp->lock.fl.fl_type = F_WRLCK; |
| 187 | if (xdr_stream_decode_bool(xdr, &argp->reclaim) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 188 | return false; |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 189 | if (xdr_stream_decode_u32(xdr, &argp->state) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 190 | return false; |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 191 | argp->monitor = 1; /* monitor client by default */ |
| 192 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 193 | return true; |
Chuck Lever | 0e5977a | 2021-06-03 16:52:28 -0400 | [diff] [blame] | 194 | } |
| 195 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 196 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 197 | nlm4svc_decode_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 1e1f38d | 2021-06-03 16:52:34 -0400 | [diff] [blame] | 198 | { |
Chuck Lever | 1e1f38d | 2021-06-03 16:52:34 -0400 | [diff] [blame] | 199 | struct nlm_args *argp = rqstp->rq_argp; |
| 200 | u32 exclusive; |
| 201 | |
| 202 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 203 | return false; |
Chuck Lever | 1e1f38d | 2021-06-03 16:52:34 -0400 | [diff] [blame] | 204 | if (xdr_stream_decode_bool(xdr, &argp->block) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 205 | return false; |
Chuck Lever | 1e1f38d | 2021-06-03 16:52:34 -0400 | [diff] [blame] | 206 | if (xdr_stream_decode_bool(xdr, &exclusive) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 207 | return false; |
Chuck Lever | 1e1f38d | 2021-06-03 16:52:34 -0400 | [diff] [blame] | 208 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 209 | return false; |
Chuck Lever | 1e1f38d | 2021-06-03 16:52:34 -0400 | [diff] [blame] | 210 | if (exclusive) |
| 211 | argp->lock.fl.fl_type = F_WRLCK; |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 212 | |
| 213 | return true; |
Chuck Lever | 1e1f38d | 2021-06-03 16:52:34 -0400 | [diff] [blame] | 214 | } |
| 215 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 216 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 217 | nlm4svc_decode_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | d76d8c2 | 2021-06-03 16:52:40 -0400 | [diff] [blame] | 218 | { |
Chuck Lever | d76d8c2 | 2021-06-03 16:52:40 -0400 | [diff] [blame] | 219 | struct nlm_args *argp = rqstp->rq_argp; |
| 220 | |
| 221 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 222 | return false; |
Chuck Lever | d76d8c2 | 2021-06-03 16:52:40 -0400 | [diff] [blame] | 223 | if (!svcxdr_decode_lock(xdr, &argp->lock)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 224 | return false; |
Chuck Lever | d76d8c2 | 2021-06-03 16:52:40 -0400 | [diff] [blame] | 225 | argp->lock.fl.fl_type = F_UNLCK; |
| 226 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 227 | return true; |
Chuck Lever | d76d8c2 | 2021-06-03 16:52:40 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 230 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 231 | nlm4svc_decode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | b4c24b5 | 2021-06-03 16:52:46 -0400 | [diff] [blame] | 232 | { |
Chuck Lever | b4c24b5 | 2021-06-03 16:52:46 -0400 | [diff] [blame] | 233 | struct nlm_res *resp = rqstp->rq_argp; |
| 234 | |
| 235 | if (!svcxdr_decode_cookie(xdr, &resp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 236 | return false; |
Chuck Lever | b4c24b5 | 2021-06-03 16:52:46 -0400 | [diff] [blame] | 237 | if (!svcxdr_decode_stats(xdr, &resp->status)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 238 | return false; |
Chuck Lever | b4c24b5 | 2021-06-03 16:52:46 -0400 | [diff] [blame] | 239 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 240 | return true; |
Chuck Lever | b4c24b5 | 2021-06-03 16:52:46 -0400 | [diff] [blame] | 241 | } |
| 242 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 243 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 244 | nlm4svc_decode_reboot(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 245 | { |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 246 | struct nlm_reboot *argp = rqstp->rq_argp; |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 247 | __be32 *p; |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 248 | u32 len; |
| 249 | |
| 250 | if (xdr_stream_decode_u32(xdr, &len) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 251 | return false; |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 252 | if (len > SM_MAXSTRLEN) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 253 | return false; |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 254 | p = xdr_inline_decode(xdr, len); |
| 255 | if (!p) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 256 | return false; |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 257 | argp->len = len; |
| 258 | argp->mon = (char *)p; |
| 259 | if (xdr_stream_decode_u32(xdr, &argp->state) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 260 | return false; |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 261 | p = xdr_inline_decode(xdr, SM_PRIV_SIZE); |
| 262 | if (!p) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 263 | return false; |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 264 | memcpy(&argp->priv.data, p, sizeof(argp->priv.data)); |
| 265 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 266 | return true; |
Chuck Lever | bc3665f | 2021-06-03 16:52:52 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 269 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 270 | nlm4svc_decode_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 271 | { |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 272 | struct nlm_args *argp = rqstp->rq_argp; |
| 273 | struct nlm_lock *lock = &argp->lock; |
| 274 | |
| 275 | memset(lock, 0, sizeof(*lock)); |
| 276 | locks_init_lock(&lock->fl); |
| 277 | lock->svid = ~(u32)0; |
| 278 | |
| 279 | if (!svcxdr_decode_cookie(xdr, &argp->cookie)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 280 | return false; |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 281 | if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 282 | return false; |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 283 | if (!svcxdr_decode_fhandle(xdr, &lock->fh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 284 | return false; |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 285 | if (!svcxdr_decode_owner(xdr, &lock->oh)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 286 | return false; |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 287 | /* XXX: Range checks are missing in the original code */ |
| 288 | if (xdr_stream_decode_u32(xdr, &argp->fsm_mode) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 289 | return false; |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 290 | if (xdr_stream_decode_u32(xdr, &argp->fsm_access) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 291 | return false; |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 292 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 293 | return true; |
Chuck Lever | 7cf96b6 | 2021-06-03 16:52:58 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 296 | bool |
Chuck Lever | 16c6636 | 2021-10-12 11:57:22 -0400 | [diff] [blame] | 297 | nlm4svc_decode_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 3049e97 | 2021-06-03 16:53:04 -0400 | [diff] [blame] | 298 | { |
Chuck Lever | 3049e97 | 2021-06-03 16:53:04 -0400 | [diff] [blame] | 299 | struct nlm_args *argp = rqstp->rq_argp; |
| 300 | struct nlm_lock *lock = &argp->lock; |
| 301 | |
| 302 | if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len)) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 303 | return false; |
Chuck Lever | 3049e97 | 2021-06-03 16:53:04 -0400 | [diff] [blame] | 304 | if (xdr_stream_decode_u32(xdr, &argp->state) < 0) |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 305 | return false; |
Chuck Lever | 3049e97 | 2021-06-03 16:53:04 -0400 | [diff] [blame] | 306 | |
Chuck Lever | c44b31c | 2021-10-12 11:57:28 -0400 | [diff] [blame] | 307 | return true; |
Chuck Lever | 3049e97 | 2021-06-03 16:53:04 -0400 | [diff] [blame] | 308 | } |
| 309 | |
Chuck Lever | ec757e4 | 2021-06-03 16:53:11 -0400 | [diff] [blame] | 310 | |
| 311 | /* |
| 312 | * Encode Reply results |
| 313 | */ |
| 314 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 315 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 316 | nlm4svc_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | ec757e4 | 2021-06-03 16:53:11 -0400 | [diff] [blame] | 317 | { |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 318 | return true; |
Chuck Lever | ec757e4 | 2021-06-03 16:53:11 -0400 | [diff] [blame] | 319 | } |
| 320 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 321 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 322 | nlm4svc_encode_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 324 | struct nlm_res *resp = rqstp->rq_resp; |
| 325 | |
Chuck Lever | 1beef14 | 2021-06-03 16:53:17 -0400 | [diff] [blame] | 326 | return svcxdr_encode_cookie(xdr, &resp->cookie) && |
| 327 | svcxdr_encode_testrply(xdr, resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 330 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 331 | nlm4svc_encode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Chuck Lever | 447c14d | 2021-06-03 16:53:23 -0400 | [diff] [blame] | 332 | { |
Chuck Lever | 447c14d | 2021-06-03 16:53:23 -0400 | [diff] [blame] | 333 | struct nlm_res *resp = rqstp->rq_resp; |
| 334 | |
| 335 | return svcxdr_encode_cookie(xdr, &resp->cookie) && |
| 336 | svcxdr_encode_stats(xdr, resp->status); |
| 337 | } |
| 338 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 339 | bool |
Chuck Lever | fda4944 | 2021-10-13 10:41:06 -0400 | [diff] [blame] | 340 | nlm4svc_encode_shareres(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 342 | struct nlm_res *resp = rqstp->rq_resp; |
| 343 | |
Chuck Lever | 0ff5b50 | 2021-06-03 16:53:29 -0400 | [diff] [blame] | 344 | if (!svcxdr_encode_cookie(xdr, &resp->cookie)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 345 | return false; |
Chuck Lever | 0ff5b50 | 2021-06-03 16:53:29 -0400 | [diff] [blame] | 346 | if (!svcxdr_encode_stats(xdr, resp->status)) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 347 | return false; |
Chuck Lever | 0ff5b50 | 2021-06-03 16:53:29 -0400 | [diff] [blame] | 348 | /* sequence */ |
| 349 | if (xdr_stream_encode_u32(xdr, 0) < 0) |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 350 | return false; |
Chuck Lever | 0ff5b50 | 2021-06-03 16:53:29 -0400 | [diff] [blame] | 351 | |
Chuck Lever | 130e205 | 2021-10-13 10:41:13 -0400 | [diff] [blame] | 352 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |