Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NFS: Introduce new-style XDR decoding functions for NFSv2

We'd like to prevent local buffer overflows caused by malicious or
broken servers. New xdr_stream style decoders can do that.

For efficiency, we also eventually want to be able to pass xdr_streams
from call_decode() to all XDR decoding functions, rather than building
an xdr_stream in every XDR decoding function in the kernel.

Static helper functions are left without the "inline" directive. This
allows the compiler to choose automatically how to optimize these for
size or speed.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Tested-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>

authored by

Chuck Lever and committed by
Trond Myklebust
e4f93234 9d5a6434

+1446 -79
+1445 -79
fs/nfs/nfs3xdr.c
··· 104 104 [NF3FIFO] = S_IFIFO, 105 105 }; 106 106 107 - static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 108 - { 109 - dprintk("nfs: %s: prematurely hit end of receive buffer. " 110 - "Remaining buffer length is %tu words.\n", 111 - func, xdr->end - xdr->p); 112 - } 113 - 114 107 /* 115 108 * While encoding arguments, set up the reply buffer in advance to 116 109 * receive reply data directly into the page cache. ··· 117 124 118 125 replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize; 119 126 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len); 127 + } 128 + 129 + /* 130 + * Handle decode buffer overflows out-of-line. 131 + */ 132 + static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) 133 + { 134 + dprintk("NFS: %s prematurely hit the end of our receive buffer. " 135 + "Remaining buffer length is %tu words.\n", 136 + func, xdr->end - xdr->p); 120 137 } 121 138 122 139 ··· 287 284 *p = cpu_to_be32(value); 288 285 } 289 286 287 + static int decode_uint32(struct xdr_stream *xdr, u32 *value) 288 + { 289 + __be32 *p; 290 + 291 + p = xdr_inline_decode(xdr, 4); 292 + if (unlikely(p == NULL)) 293 + goto out_overflow; 294 + *value = be32_to_cpup(p); 295 + return 0; 296 + out_overflow: 297 + print_overflow_msg(__func__, xdr); 298 + return -EIO; 299 + } 300 + 301 + static int decode_uint64(struct xdr_stream *xdr, u64 *value) 302 + { 303 + __be32 *p; 304 + 305 + p = xdr_inline_decode(xdr, 8); 306 + if (unlikely(p == NULL)) 307 + goto out_overflow; 308 + xdr_decode_hyper(p, value); 309 + return 0; 310 + out_overflow: 311 + print_overflow_msg(__func__, xdr); 312 + return -EIO; 313 + } 314 + 315 + /* 316 + * fileid3 317 + * 318 + * typedef uint64 fileid3; 319 + */ 320 + static int decode_fileid3(struct xdr_stream *xdr, u64 *fileid) 321 + { 322 + return decode_uint64(xdr, fileid); 323 + } 324 + 290 325 /* 291 326 * filename3 292 327 * ··· 340 299 xdr_encode_opaque(p, name, length); 341 300 } 342 301 302 + static int decode_inline_filename3(struct xdr_stream *xdr, 303 + const char **name, u32 *length) 304 + { 305 + __be32 *p; 306 + u32 count; 307 + 308 + p = xdr_inline_decode(xdr, 4); 309 + if (unlikely(p == NULL)) 310 + goto out_overflow; 311 + count = be32_to_cpup(p); 312 + if (count > NFS3_MAXNAMLEN) 313 + goto out_nametoolong; 314 + p = xdr_inline_decode(xdr, count); 315 + if (unlikely(p == NULL)) 316 + goto out_overflow; 317 + *name = (const char *)p; 318 + *length = count; 319 + return 0; 320 + 321 + out_nametoolong: 322 + dprintk("NFS: returned filename too long: %u\n", count); 323 + return -ENAMETOOLONG; 324 + out_overflow: 325 + print_overflow_msg(__func__, xdr); 326 + return -EIO; 327 + } 328 + 343 329 /* 344 330 * nfspath3 345 331 * ··· 380 312 xdr_write_pages(xdr, pages, 0, length); 381 313 } 382 314 315 + static int decode_nfspath3(struct xdr_stream *xdr) 316 + { 317 + u32 recvd, count; 318 + size_t hdrlen; 319 + __be32 *p; 320 + 321 + p = xdr_inline_decode(xdr, 4); 322 + if (unlikely(p == NULL)) 323 + goto out_overflow; 324 + count = be32_to_cpup(p); 325 + if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN)) 326 + goto out_nametoolong; 327 + hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; 328 + recvd = xdr->buf->len - hdrlen; 329 + if (unlikely(count > recvd)) 330 + goto out_cheating; 331 + 332 + xdr_read_pages(xdr, count); 333 + xdr_terminate_string(xdr->buf, count); 334 + return 0; 335 + 336 + out_nametoolong: 337 + dprintk("NFS: returned pathname too long: %u\n", count); 338 + return -ENAMETOOLONG; 339 + out_cheating: 340 + dprintk("NFS: server cheating in pathname result: " 341 + "count %u > recvd %u\n", count, recvd); 342 + return -EIO; 343 + out_overflow: 344 + print_overflow_msg(__func__, xdr); 345 + return -EIO; 346 + } 347 + 383 348 /* 384 349 * cookie3 385 350 * ··· 421 320 static __be32 *xdr_encode_cookie3(__be32 *p, u64 cookie) 422 321 { 423 322 return xdr_encode_hyper(p, cookie); 323 + } 324 + 325 + static int decode_cookie3(struct xdr_stream *xdr, u64 *cookie) 326 + { 327 + return decode_uint64(xdr, cookie); 424 328 } 425 329 426 330 /* ··· 439 333 return p + XDR_QUADLEN(NFS3_COOKIEVERFSIZE); 440 334 } 441 335 336 + static int decode_cookieverf3(struct xdr_stream *xdr, __be32 *verifier) 337 + { 338 + __be32 *p; 339 + 340 + p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); 341 + if (unlikely(p == NULL)) 342 + goto out_overflow; 343 + memcpy(verifier, p, NFS3_COOKIEVERFSIZE); 344 + return 0; 345 + out_overflow: 346 + print_overflow_msg(__func__, xdr); 347 + return -EIO; 348 + } 349 + 442 350 /* 443 351 * createverf3 444 352 * ··· 464 344 465 345 p = xdr_reserve_space(xdr, NFS3_CREATEVERFSIZE); 466 346 memcpy(p, verifier, NFS3_CREATEVERFSIZE); 347 + } 348 + 349 + static int decode_writeverf3(struct xdr_stream *xdr, __be32 *verifier) 350 + { 351 + __be32 *p; 352 + 353 + p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE); 354 + if (unlikely(p == NULL)) 355 + goto out_overflow; 356 + memcpy(verifier, p, NFS3_WRITEVERFSIZE); 357 + return 0; 358 + out_overflow: 359 + print_overflow_msg(__func__, xdr); 360 + return -EIO; 361 + } 362 + 363 + /* 364 + * size3 365 + * 366 + * typedef uint64 size3; 367 + */ 368 + static __be32 *xdr_decode_size3(__be32 *p, u64 *size) 369 + { 370 + return xdr_decode_hyper(p, size); 371 + } 372 + 373 + /* 374 + * nfsstat3 375 + * 376 + * enum nfsstat3 { 377 + * NFS3_OK = 0, 378 + * ... 379 + * } 380 + */ 381 + #define NFS3_OK NFS_OK 382 + 383 + static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status) 384 + { 385 + __be32 *p; 386 + 387 + p = xdr_inline_decode(xdr, 4); 388 + if (unlikely(p == NULL)) 389 + goto out_overflow; 390 + *status = be32_to_cpup(p); 391 + return 0; 392 + out_overflow: 393 + print_overflow_msg(__func__, xdr); 394 + return -EIO; 467 395 } 468 396 469 397 /* ··· 564 396 BUG_ON(fh->size > NFS3_FHSIZE); 565 397 p = xdr_reserve_space(xdr, 4 + fh->size); 566 398 xdr_encode_opaque(p, fh->data, fh->size); 399 + } 400 + 401 + static int decode_nfs_fh3(struct xdr_stream *xdr, struct nfs_fh *fh) 402 + { 403 + u32 length; 404 + __be32 *p; 405 + 406 + p = xdr_inline_decode(xdr, 4); 407 + if (unlikely(p == NULL)) 408 + goto out_overflow; 409 + length = be32_to_cpup(p++); 410 + if (unlikely(length > NFS3_FHSIZE)) 411 + goto out_toobig; 412 + p = xdr_inline_decode(xdr, length); 413 + if (unlikely(p == NULL)) 414 + goto out_overflow; 415 + fh->size = length; 416 + memcpy(fh->data, p, length); 417 + return 0; 418 + out_toobig: 419 + dprintk("NFS: file handle size (%u) too big\n", length); 420 + return -E2BIG; 421 + out_overflow: 422 + print_overflow_msg(__func__, xdr); 423 + return -EIO; 424 + } 425 + 426 + static void zero_nfs_fh3(struct nfs_fh *fh) 427 + { 428 + memset(fh, 0, sizeof(*fh)); 567 429 } 568 430 569 431 /* ··· 736 538 *p = xdr_one; 737 539 } else 738 540 *p = xdr_zero; 541 + } 542 + 543 + /* 544 + * fattr3 545 + * 546 + * struct fattr3 { 547 + * ftype3 type; 548 + * mode3 mode; 549 + * uint32 nlink; 550 + * uid3 uid; 551 + * gid3 gid; 552 + * size3 size; 553 + * size3 used; 554 + * specdata3 rdev; 555 + * uint64 fsid; 556 + * fileid3 fileid; 557 + * nfstime3 atime; 558 + * nfstime3 mtime; 559 + * nfstime3 ctime; 560 + * }; 561 + */ 562 + static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr) 563 + { 564 + __be32 *p; 565 + 566 + p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2); 567 + if (unlikely(p == NULL)) 568 + goto out_overflow; 569 + xdr_decode_fattr(p, fattr); 570 + return 0; 571 + out_overflow: 572 + print_overflow_msg(__func__, xdr); 573 + return -EIO; 574 + } 575 + 576 + /* 577 + * post_op_attr 578 + * 579 + * union post_op_attr switch (bool attributes_follow) { 580 + * case TRUE: 581 + * fattr3 attributes; 582 + * case FALSE: 583 + * void; 584 + * }; 585 + */ 586 + static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr) 587 + { 588 + __be32 *p; 589 + 590 + p = xdr_inline_decode(xdr, 4); 591 + if (unlikely(p == NULL)) 592 + goto out_overflow; 593 + if (*p != xdr_zero) 594 + return decode_fattr3(xdr, fattr); 595 + return 0; 596 + out_overflow: 597 + print_overflow_msg(__func__, xdr); 598 + return -EIO; 599 + } 600 + 601 + /* 602 + * wcc_attr 603 + * struct wcc_attr { 604 + * size3 size; 605 + * nfstime3 mtime; 606 + * nfstime3 ctime; 607 + * }; 608 + */ 609 + static int decode_wcc_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr) 610 + { 611 + __be32 *p; 612 + 613 + p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2); 614 + if (unlikely(p == NULL)) 615 + goto out_overflow; 616 + xdr_decode_wcc_attr(p, fattr); 617 + return 0; 618 + out_overflow: 619 + print_overflow_msg(__func__, xdr); 620 + return -EIO; 621 + } 622 + 623 + /* 624 + * pre_op_attr 625 + * union pre_op_attr switch (bool attributes_follow) { 626 + * case TRUE: 627 + * wcc_attr attributes; 628 + * case FALSE: 629 + * void; 630 + * }; 631 + * 632 + * wcc_data 633 + * 634 + * struct wcc_data { 635 + * pre_op_attr before; 636 + * post_op_attr after; 637 + * }; 638 + */ 639 + static int decode_pre_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr) 640 + { 641 + __be32 *p; 642 + 643 + p = xdr_inline_decode(xdr, 4); 644 + if (unlikely(p == NULL)) 645 + goto out_overflow; 646 + if (*p != xdr_zero) 647 + return decode_wcc_attr(xdr, fattr); 648 + return 0; 649 + out_overflow: 650 + print_overflow_msg(__func__, xdr); 651 + return -EIO; 652 + } 653 + 654 + static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr) 655 + { 656 + int error; 657 + 658 + error = decode_pre_op_attr(xdr, fattr); 659 + if (unlikely(error)) 660 + goto out; 661 + error = decode_post_op_attr(xdr, fattr); 662 + out: 663 + return error; 664 + } 665 + 666 + /* 667 + * post_op_fh3 668 + * 669 + * union post_op_fh3 switch (bool handle_follows) { 670 + * case TRUE: 671 + * nfs_fh3 handle; 672 + * case FALSE: 673 + * void; 674 + * }; 675 + */ 676 + static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh) 677 + { 678 + __be32 *p = xdr_inline_decode(xdr, 4); 679 + if (unlikely(p == NULL)) 680 + goto out_overflow; 681 + if (*p != xdr_zero) 682 + return decode_nfs_fh3(xdr, fh); 683 + zero_nfs_fh3(fh); 684 + return 0; 685 + out_overflow: 686 + print_overflow_msg(__func__, xdr); 687 + return -EIO; 739 688 } 740 689 741 690 /* ··· 1453 1108 return pglen; 1454 1109 } 1455 1110 1456 - __be32 * 1457 - nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, struct nfs_server *server, int plus) 1458 - { 1459 - __be32 *p; 1460 - struct nfs_entry old = *entry; 1461 - 1462 - p = xdr_inline_decode(xdr, 4); 1463 - if (unlikely(!p)) 1464 - goto out_overflow; 1465 - if (!ntohl(*p++)) { 1466 - p = xdr_inline_decode(xdr, 4); 1467 - if (unlikely(!p)) 1468 - goto out_overflow; 1469 - if (!ntohl(*p++)) 1470 - return ERR_PTR(-EAGAIN); 1471 - entry->eof = 1; 1472 - return ERR_PTR(-EBADCOOKIE); 1473 - } 1474 - 1475 - p = xdr_inline_decode(xdr, 12); 1476 - if (unlikely(!p)) 1477 - goto out_overflow; 1478 - p = xdr_decode_hyper(p, &entry->ino); 1479 - entry->len = ntohl(*p++); 1480 - 1481 - p = xdr_inline_decode(xdr, entry->len + 8); 1482 - if (unlikely(!p)) 1483 - goto out_overflow; 1484 - entry->name = (const char *) p; 1485 - p += XDR_QUADLEN(entry->len); 1486 - entry->prev_cookie = entry->cookie; 1487 - p = xdr_decode_hyper(p, &entry->cookie); 1488 - 1489 - entry->d_type = DT_UNKNOWN; 1490 - if (plus) { 1491 - entry->fattr->valid = 0; 1492 - p = xdr_decode_post_op_attr_stream(xdr, entry->fattr); 1493 - if (IS_ERR(p)) 1494 - goto out_overflow_exit; 1495 - entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 1496 - /* In fact, a post_op_fh3: */ 1497 - p = xdr_inline_decode(xdr, 4); 1498 - if (unlikely(!p)) 1499 - goto out_overflow; 1500 - if (*p++) { 1501 - p = xdr_decode_fhandle_stream(xdr, entry->fh); 1502 - if (IS_ERR(p)) 1503 - goto out_overflow_exit; 1504 - /* Ugh -- server reply was truncated */ 1505 - if (p == NULL) { 1506 - dprintk("NFS: FH truncated\n"); 1507 - *entry = old; 1508 - return ERR_PTR(-EAGAIN); 1509 - } 1510 - } else 1511 - memset((u8*)(entry->fh), 0, sizeof(*entry->fh)); 1512 - } 1513 - 1514 - p = xdr_inline_peek(xdr, 8); 1515 - if (p != NULL) 1516 - entry->eof = !p[0] && p[1]; 1517 - else 1518 - entry->eof = 0; 1519 - 1520 - return p; 1521 - 1522 - out_overflow: 1523 - print_overflow_msg(__func__, xdr); 1524 - out_overflow_exit: 1525 - return ERR_PTR(-EAGAIN); 1526 - } 1527 - 1528 1111 /* 1529 1112 * 3.3.21 COMMIT3args 1530 1113 * ··· 1548 1275 } 1549 1276 1550 1277 /* 1278 + * 3.3.1 GETATTR3res 1279 + * 1280 + * struct GETATTR3resok { 1281 + * fattr3 obj_attributes; 1282 + * }; 1283 + * 1284 + * union GETATTR3res switch (nfsstat3 status) { 1285 + * case NFS3_OK: 1286 + * GETATTR3resok resok; 1287 + * default: 1288 + * void; 1289 + * }; 1290 + */ 1291 + static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req, __be32 *p, 1292 + struct nfs_fattr *result) 1293 + { 1294 + struct xdr_stream xdr; 1295 + enum nfs_stat status; 1296 + int error; 1297 + 1298 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1299 + error = decode_nfsstat3(&xdr, &status); 1300 + if (unlikely(error)) 1301 + goto out; 1302 + if (status != NFS3_OK) 1303 + goto out_default; 1304 + error = decode_fattr3(&xdr, result); 1305 + out: 1306 + return error; 1307 + out_default: 1308 + return nfs_stat_to_errno(status); 1309 + } 1310 + 1311 + /* 1551 1312 * Decode status+wcc_data reply 1552 1313 * SATTR, REMOVE, RMDIR 1553 1314 */ ··· 1594 1287 status = nfs_stat_to_errno(status); 1595 1288 xdr_decode_wcc_data(p, fattr); 1596 1289 return status; 1290 + } 1291 + 1292 + /* 1293 + * 3.3.2 SETATTR3res 1294 + * 1295 + * struct SETATTR3resok { 1296 + * wcc_data obj_wcc; 1297 + * }; 1298 + * 1299 + * struct SETATTR3resfail { 1300 + * wcc_data obj_wcc; 1301 + * }; 1302 + * 1303 + * union SETATTR3res switch (nfsstat3 status) { 1304 + * case NFS3_OK: 1305 + * SETATTR3resok resok; 1306 + * default: 1307 + * SETATTR3resfail resfail; 1308 + * }; 1309 + */ 1310 + static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req, __be32 *p, 1311 + struct nfs_fattr *result) 1312 + { 1313 + struct xdr_stream xdr; 1314 + enum nfs_stat status; 1315 + int error; 1316 + 1317 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1318 + error = decode_nfsstat3(&xdr, &status); 1319 + if (unlikely(error)) 1320 + goto out; 1321 + error = decode_wcc_data(&xdr, result); 1322 + if (unlikely(error)) 1323 + goto out; 1324 + if (status != NFS3_OK) 1325 + goto out_status; 1326 + out: 1327 + return error; 1328 + out_status: 1329 + return nfs_stat_to_errno(status); 1597 1330 } 1598 1331 1599 1332 static int ··· 1662 1315 } 1663 1316 1664 1317 /* 1318 + * 3.3.3 LOOKUP3res 1319 + * 1320 + * struct LOOKUP3resok { 1321 + * nfs_fh3 object; 1322 + * post_op_attr obj_attributes; 1323 + * post_op_attr dir_attributes; 1324 + * }; 1325 + * 1326 + * struct LOOKUP3resfail { 1327 + * post_op_attr dir_attributes; 1328 + * }; 1329 + * 1330 + * union LOOKUP3res switch (nfsstat3 status) { 1331 + * case NFS3_OK: 1332 + * LOOKUP3resok resok; 1333 + * default: 1334 + * LOOKUP3resfail resfail; 1335 + * }; 1336 + */ 1337 + static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req, __be32 *p, 1338 + struct nfs3_diropres *result) 1339 + { 1340 + struct xdr_stream xdr; 1341 + enum nfs_stat status; 1342 + int error; 1343 + 1344 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1345 + error = decode_nfsstat3(&xdr, &status); 1346 + if (unlikely(error)) 1347 + goto out; 1348 + if (status != NFS3_OK) 1349 + goto out_default; 1350 + error = decode_nfs_fh3(&xdr, result->fh); 1351 + if (unlikely(error)) 1352 + goto out; 1353 + error = decode_post_op_attr(&xdr, result->fattr); 1354 + if (unlikely(error)) 1355 + goto out; 1356 + error = decode_post_op_attr(&xdr, result->dir_attr); 1357 + out: 1358 + return error; 1359 + out_default: 1360 + error = decode_post_op_attr(&xdr, result->dir_attr); 1361 + if (unlikely(error)) 1362 + goto out; 1363 + return nfs_stat_to_errno(status); 1364 + } 1365 + 1366 + /* 1665 1367 * Decode ACCESS reply 1666 1368 */ 1667 1369 static int ··· 1723 1327 return nfs_stat_to_errno(status); 1724 1328 res->access = ntohl(*p++); 1725 1329 return 0; 1330 + } 1331 + 1332 + /* 1333 + * 3.3.4 ACCESS3res 1334 + * 1335 + * struct ACCESS3resok { 1336 + * post_op_attr obj_attributes; 1337 + * uint32 access; 1338 + * }; 1339 + * 1340 + * struct ACCESS3resfail { 1341 + * post_op_attr obj_attributes; 1342 + * }; 1343 + * 1344 + * union ACCESS3res switch (nfsstat3 status) { 1345 + * case NFS3_OK: 1346 + * ACCESS3resok resok; 1347 + * default: 1348 + * ACCESS3resfail resfail; 1349 + * }; 1350 + */ 1351 + static int nfs3_xdr_dec_access3res(struct rpc_rqst *req, __be32 *p, 1352 + struct nfs3_accessres *result) 1353 + { 1354 + struct xdr_stream xdr; 1355 + enum nfs_stat status; 1356 + int error; 1357 + 1358 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1359 + error = decode_nfsstat3(&xdr, &status); 1360 + if (unlikely(error)) 1361 + goto out; 1362 + error = decode_post_op_attr(&xdr, result->fattr); 1363 + if (unlikely(error)) 1364 + goto out; 1365 + if (status != NFS3_OK) 1366 + goto out_default; 1367 + error = decode_uint32(&xdr, &result->access); 1368 + out: 1369 + return error; 1370 + out_default: 1371 + return nfs_stat_to_errno(status); 1726 1372 } 1727 1373 1728 1374 /* ··· 1811 1373 1812 1374 xdr_terminate_string(rcvbuf, len); 1813 1375 return 0; 1376 + } 1377 + 1378 + /* 1379 + * 3.3.5 READLINK3res 1380 + * 1381 + * struct READLINK3resok { 1382 + * post_op_attr symlink_attributes; 1383 + * nfspath3 data; 1384 + * }; 1385 + * 1386 + * struct READLINK3resfail { 1387 + * post_op_attr symlink_attributes; 1388 + * }; 1389 + * 1390 + * union READLINK3res switch (nfsstat3 status) { 1391 + * case NFS3_OK: 1392 + * READLINK3resok resok; 1393 + * default: 1394 + * READLINK3resfail resfail; 1395 + * }; 1396 + */ 1397 + static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req, __be32 *p, 1398 + struct nfs_fattr *result) 1399 + { 1400 + struct xdr_stream xdr; 1401 + enum nfs_stat status; 1402 + int error; 1403 + 1404 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1405 + error = decode_nfsstat3(&xdr, &status); 1406 + if (unlikely(error)) 1407 + goto out; 1408 + error = decode_post_op_attr(&xdr, result); 1409 + if (unlikely(error)) 1410 + goto out; 1411 + if (status != NFS3_OK) 1412 + goto out_default; 1413 + error = decode_nfspath3(&xdr); 1414 + out: 1415 + return error; 1416 + out_default: 1417 + return nfs_stat_to_errno(status); 1814 1418 } 1815 1419 1816 1420 /* ··· 1909 1429 } 1910 1430 1911 1431 /* 1432 + * 3.3.6 READ3res 1433 + * 1434 + * struct READ3resok { 1435 + * post_op_attr file_attributes; 1436 + * count3 count; 1437 + * bool eof; 1438 + * opaque data<>; 1439 + * }; 1440 + * 1441 + * struct READ3resfail { 1442 + * post_op_attr file_attributes; 1443 + * }; 1444 + * 1445 + * union READ3res switch (nfsstat3 status) { 1446 + * case NFS3_OK: 1447 + * READ3resok resok; 1448 + * default: 1449 + * READ3resfail resfail; 1450 + * }; 1451 + */ 1452 + static int decode_read3resok(struct xdr_stream *xdr, 1453 + struct nfs_readres *result) 1454 + { 1455 + u32 eof, count, ocount, recvd; 1456 + size_t hdrlen; 1457 + __be32 *p; 1458 + 1459 + p = xdr_inline_decode(xdr, 4 + 4 + 4); 1460 + if (unlikely(p == NULL)) 1461 + goto out_overflow; 1462 + count = be32_to_cpup(p++); 1463 + eof = be32_to_cpup(p++); 1464 + ocount = be32_to_cpup(p++); 1465 + if (unlikely(ocount != count)) 1466 + goto out_mismatch; 1467 + hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; 1468 + recvd = xdr->buf->len - hdrlen; 1469 + if (unlikely(count > recvd)) 1470 + goto out_cheating; 1471 + 1472 + out: 1473 + xdr_read_pages(xdr, count); 1474 + result->eof = eof; 1475 + result->count = count; 1476 + return count; 1477 + out_mismatch: 1478 + dprintk("NFS: READ count doesn't match length of opaque: " 1479 + "count %u != ocount %u\n", count, ocount); 1480 + return -EIO; 1481 + out_cheating: 1482 + dprintk("NFS: server cheating in read result: " 1483 + "count %u > recvd %u\n", count, recvd); 1484 + count = recvd; 1485 + eof = 0; 1486 + goto out; 1487 + out_overflow: 1488 + print_overflow_msg(__func__, xdr); 1489 + return -EIO; 1490 + } 1491 + 1492 + static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, __be32 *p, 1493 + struct nfs_readres *result) 1494 + { 1495 + struct xdr_stream xdr; 1496 + enum nfs_stat status; 1497 + int error; 1498 + 1499 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1500 + error = decode_nfsstat3(&xdr, &status); 1501 + if (unlikely(error)) 1502 + goto out; 1503 + error = decode_post_op_attr(&xdr, result->fattr); 1504 + if (unlikely(error)) 1505 + goto out; 1506 + if (status != NFS3_OK) 1507 + goto out_status; 1508 + error = decode_read3resok(&xdr, result); 1509 + out: 1510 + return error; 1511 + out_status: 1512 + return nfs_stat_to_errno(status); 1513 + } 1514 + 1515 + /* 1912 1516 * Decode WRITE response 1913 1517 */ 1914 1518 static int ··· 2012 1448 res->verf->verifier[1] = *p++; 2013 1449 2014 1450 return res->count; 1451 + } 1452 + 1453 + /* 1454 + * 3.3.7 WRITE3res 1455 + * 1456 + * enum stable_how { 1457 + * UNSTABLE = 0, 1458 + * DATA_SYNC = 1, 1459 + * FILE_SYNC = 2 1460 + * }; 1461 + * 1462 + * struct WRITE3resok { 1463 + * wcc_data file_wcc; 1464 + * count3 count; 1465 + * stable_how committed; 1466 + * writeverf3 verf; 1467 + * }; 1468 + * 1469 + * struct WRITE3resfail { 1470 + * wcc_data file_wcc; 1471 + * }; 1472 + * 1473 + * union WRITE3res switch (nfsstat3 status) { 1474 + * case NFS3_OK: 1475 + * WRITE3resok resok; 1476 + * default: 1477 + * WRITE3resfail resfail; 1478 + * }; 1479 + */ 1480 + static int decode_write3resok(struct xdr_stream *xdr, 1481 + struct nfs_writeres *result) 1482 + { 1483 + __be32 *p; 1484 + 1485 + p = xdr_inline_decode(xdr, 4 + 4 + NFS3_WRITEVERFSIZE); 1486 + if (unlikely(p == NULL)) 1487 + goto out_overflow; 1488 + result->count = be32_to_cpup(p++); 1489 + result->verf->committed = be32_to_cpup(p++); 1490 + if (unlikely(result->verf->committed > NFS_FILE_SYNC)) 1491 + goto out_badvalue; 1492 + memcpy(result->verf->verifier, p, NFS3_WRITEVERFSIZE); 1493 + return result->count; 1494 + out_badvalue: 1495 + dprintk("NFS: bad stable_how value: %u\n", result->verf->committed); 1496 + return -EIO; 1497 + out_overflow: 1498 + print_overflow_msg(__func__, xdr); 1499 + return -EIO; 1500 + } 1501 + 1502 + static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, __be32 *p, 1503 + struct nfs_writeres *result) 1504 + { 1505 + struct xdr_stream xdr; 1506 + enum nfs_stat status; 1507 + int error; 1508 + 1509 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1510 + error = decode_nfsstat3(&xdr, &status); 1511 + if (unlikely(error)) 1512 + goto out; 1513 + error = decode_wcc_data(&xdr, result->fattr); 1514 + if (unlikely(error)) 1515 + goto out; 1516 + if (status != NFS3_OK) 1517 + goto out_status; 1518 + error = decode_write3resok(&xdr, result); 1519 + out: 1520 + return error; 1521 + out_status: 1522 + return nfs_stat_to_errno(status); 2015 1523 } 2016 1524 2017 1525 /* ··· 2114 1478 } 2115 1479 2116 1480 /* 1481 + * 3.3.8 CREATE3res 1482 + * 1483 + * struct CREATE3resok { 1484 + * post_op_fh3 obj; 1485 + * post_op_attr obj_attributes; 1486 + * wcc_data dir_wcc; 1487 + * }; 1488 + * 1489 + * struct CREATE3resfail { 1490 + * wcc_data dir_wcc; 1491 + * }; 1492 + * 1493 + * union CREATE3res switch (nfsstat3 status) { 1494 + * case NFS3_OK: 1495 + * CREATE3resok resok; 1496 + * default: 1497 + * CREATE3resfail resfail; 1498 + * }; 1499 + */ 1500 + static int decode_create3resok(struct xdr_stream *xdr, 1501 + struct nfs3_diropres *result) 1502 + { 1503 + int error; 1504 + 1505 + error = decode_post_op_fh3(xdr, result->fh); 1506 + if (unlikely(error)) 1507 + goto out; 1508 + error = decode_post_op_attr(xdr, result->fattr); 1509 + if (unlikely(error)) 1510 + goto out; 1511 + /* The server isn't required to return a file handle. 1512 + * If it didn't, force the client to perform a LOOKUP 1513 + * to determine the correct file handle and attribute 1514 + * values for the new object. */ 1515 + if (result->fh->size == 0) 1516 + result->fattr->valid = 0; 1517 + error = decode_wcc_data(xdr, result->dir_attr); 1518 + out: 1519 + return error; 1520 + } 1521 + 1522 + static int nfs3_xdr_dec_create3res(struct rpc_rqst *req, __be32 *p, 1523 + struct nfs3_diropres *result) 1524 + { 1525 + struct xdr_stream xdr; 1526 + enum nfs_stat status; 1527 + int error; 1528 + 1529 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1530 + error = decode_nfsstat3(&xdr, &status); 1531 + if (unlikely(error)) 1532 + goto out; 1533 + if (status != NFS3_OK) 1534 + goto out_default; 1535 + error = decode_create3resok(&xdr, result); 1536 + out: 1537 + return error; 1538 + out_default: 1539 + error = decode_wcc_data(&xdr, result->dir_attr); 1540 + if (unlikely(error)) 1541 + goto out; 1542 + return nfs_stat_to_errno(status); 1543 + } 1544 + 1545 + /* 1546 + * 3.3.12 REMOVE3res 1547 + * 1548 + * struct REMOVE3resok { 1549 + * wcc_data dir_wcc; 1550 + * }; 1551 + * 1552 + * struct REMOVE3resfail { 1553 + * wcc_data dir_wcc; 1554 + * }; 1555 + * 1556 + * union REMOVE3res switch (nfsstat3 status) { 1557 + * case NFS3_OK: 1558 + * REMOVE3resok resok; 1559 + * default: 1560 + * REMOVE3resfail resfail; 1561 + * }; 1562 + */ 1563 + static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req, __be32 *p, 1564 + struct nfs_removeres *result) 1565 + { 1566 + struct xdr_stream xdr; 1567 + enum nfs_stat status; 1568 + int error; 1569 + 1570 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1571 + error = decode_nfsstat3(&xdr, &status); 1572 + if (unlikely(error)) 1573 + goto out; 1574 + error = decode_wcc_data(&xdr, result->dir_attr); 1575 + if (unlikely(error)) 1576 + goto out; 1577 + if (status != NFS3_OK) 1578 + goto out_status; 1579 + out: 1580 + return error; 1581 + out_status: 1582 + return nfs_stat_to_errno(status); 1583 + } 1584 + 1585 + /* 2117 1586 * Decode RENAME reply 2118 1587 */ 2119 1588 static int ··· 2234 1493 } 2235 1494 2236 1495 /* 1496 + * 3.3.14 RENAME3res 1497 + * 1498 + * struct RENAME3resok { 1499 + * wcc_data fromdir_wcc; 1500 + * wcc_data todir_wcc; 1501 + * }; 1502 + * 1503 + * struct RENAME3resfail { 1504 + * wcc_data fromdir_wcc; 1505 + * wcc_data todir_wcc; 1506 + * }; 1507 + * 1508 + * union RENAME3res switch (nfsstat3 status) { 1509 + * case NFS3_OK: 1510 + * RENAME3resok resok; 1511 + * default: 1512 + * RENAME3resfail resfail; 1513 + * }; 1514 + */ 1515 + static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req, __be32 *p, 1516 + struct nfs_renameres *result) 1517 + { 1518 + struct xdr_stream xdr; 1519 + enum nfs_stat status; 1520 + int error; 1521 + 1522 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1523 + error = decode_nfsstat3(&xdr, &status); 1524 + if (unlikely(error)) 1525 + goto out; 1526 + error = decode_wcc_data(&xdr, result->old_fattr); 1527 + if (unlikely(error)) 1528 + goto out; 1529 + error = decode_wcc_data(&xdr, result->new_fattr); 1530 + if (unlikely(error)) 1531 + goto out; 1532 + if (status != NFS3_OK) 1533 + goto out_status; 1534 + out: 1535 + return error; 1536 + out_status: 1537 + return nfs_stat_to_errno(status); 1538 + } 1539 + 1540 + /* 2237 1541 * Decode LINK reply 2238 1542 */ 2239 1543 static int ··· 2291 1505 p = xdr_decode_post_op_attr(p, res->fattr); 2292 1506 p = xdr_decode_wcc_data(p, res->dir_attr); 2293 1507 return status; 1508 + } 1509 + 1510 + /* 1511 + * 3.3.15 LINK3res 1512 + * 1513 + * struct LINK3resok { 1514 + * post_op_attr file_attributes; 1515 + * wcc_data linkdir_wcc; 1516 + * }; 1517 + * 1518 + * struct LINK3resfail { 1519 + * post_op_attr file_attributes; 1520 + * wcc_data linkdir_wcc; 1521 + * }; 1522 + * 1523 + * union LINK3res switch (nfsstat3 status) { 1524 + * case NFS3_OK: 1525 + * LINK3resok resok; 1526 + * default: 1527 + * LINK3resfail resfail; 1528 + * }; 1529 + */ 1530 + static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, __be32 *p, 1531 + struct nfs3_linkres *result) 1532 + { 1533 + struct xdr_stream xdr; 1534 + enum nfs_stat status; 1535 + int error; 1536 + 1537 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1538 + error = decode_nfsstat3(&xdr, &status); 1539 + if (unlikely(error)) 1540 + goto out; 1541 + error = decode_post_op_attr(&xdr, result->fattr); 1542 + if (unlikely(error)) 1543 + goto out; 1544 + error = decode_wcc_data(&xdr, result->dir_attr); 1545 + if (unlikely(error)) 1546 + goto out; 1547 + if (status != NFS3_OK) 1548 + goto out_status; 1549 + out: 1550 + return error; 1551 + out_status: 1552 + return nfs_stat_to_errno(status); 1553 + } 1554 + 1555 + /** 1556 + * nfs3_decode_dirent - Decode a single NFSv3 directory entry stored in 1557 + * the local page cache 1558 + * @xdr: XDR stream where entry resides 1559 + * @entry: buffer to fill in with entry data 1560 + * @server: nfs_server data for this directory 1561 + * @plus: boolean indicating whether this should be a readdirplus entry 1562 + * 1563 + * Returns the position of the next item in the buffer, or an ERR_PTR. 1564 + * 1565 + * This function is not invoked during READDIR reply decoding, but 1566 + * rather whenever an application invokes the getdents(2) system call 1567 + * on a directory already in our cache. 1568 + * 1569 + * 3.3.16 entry3 1570 + * 1571 + * struct entry3 { 1572 + * fileid3 fileid; 1573 + * filename3 name; 1574 + * cookie3 cookie; 1575 + * fhandle3 filehandle; 1576 + * post_op_attr3 attributes; 1577 + * entry3 *nextentry; 1578 + * }; 1579 + * 1580 + * 3.3.17 entryplus3 1581 + * struct entryplus3 { 1582 + * fileid3 fileid; 1583 + * filename3 name; 1584 + * cookie3 cookie; 1585 + * post_op_attr name_attributes; 1586 + * post_op_fh3 name_handle; 1587 + * entryplus3 *nextentry; 1588 + * }; 1589 + */ 1590 + __be32 *nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, 1591 + struct nfs_server *server, int plus) 1592 + { 1593 + struct nfs_entry old = *entry; 1594 + __be32 *p; 1595 + int error; 1596 + 1597 + p = xdr_inline_decode(xdr, 4); 1598 + if (unlikely(p == NULL)) 1599 + goto out_overflow; 1600 + if (*p == xdr_zero) { 1601 + p = xdr_inline_decode(xdr, 4); 1602 + if (unlikely(p == NULL)) 1603 + goto out_overflow; 1604 + if (*p == xdr_zero) 1605 + return ERR_PTR(-EAGAIN); 1606 + entry->eof = 1; 1607 + return ERR_PTR(-EBADCOOKIE); 1608 + } 1609 + 1610 + error = decode_fileid3(xdr, &entry->ino); 1611 + if (unlikely(error)) 1612 + return ERR_PTR(error); 1613 + 1614 + error = decode_inline_filename3(xdr, &entry->name, &entry->len); 1615 + if (unlikely(error)) 1616 + return ERR_PTR(error); 1617 + 1618 + entry->prev_cookie = entry->cookie; 1619 + error = decode_cookie3(xdr, &entry->cookie); 1620 + if (unlikely(error)) 1621 + return ERR_PTR(error); 1622 + 1623 + entry->d_type = DT_UNKNOWN; 1624 + 1625 + if (plus) { 1626 + entry->fattr->valid = 0; 1627 + error = decode_post_op_attr(xdr, entry->fattr); 1628 + if (unlikely(error)) 1629 + return ERR_PTR(error); 1630 + if (entry->fattr->valid & NFS_ATTR_FATTR_V3) 1631 + entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); 1632 + 1633 + /* In fact, a post_op_fh3: */ 1634 + p = xdr_inline_decode(xdr, 4); 1635 + if (unlikely(p == NULL)) 1636 + goto out_overflow; 1637 + if (*p != xdr_zero) { 1638 + error = decode_nfs_fh3(xdr, entry->fh); 1639 + if (unlikely(error)) { 1640 + if (error == -E2BIG) 1641 + goto out_truncated; 1642 + return ERR_PTR(error); 1643 + } 1644 + } else 1645 + zero_nfs_fh3(entry->fh); 1646 + } 1647 + 1648 + /* Peek at the next entry to see if we're at EOD */ 1649 + p = xdr_inline_peek(xdr, 4 + 4); 1650 + entry->eof = 0; 1651 + if (p != NULL) 1652 + entry->eof = (p[0] == xdr_zero) && (p[1] != xdr_zero); 1653 + return p; 1654 + 1655 + out_overflow: 1656 + print_overflow_msg(__func__, xdr); 1657 + return ERR_PTR(-EAGAIN); 1658 + out_truncated: 1659 + dprintk("NFS: directory entry contains invalid file handle\n"); 1660 + *entry = old; 1661 + return ERR_PTR(-EAGAIN); 1662 + } 1663 + 1664 + /* 1665 + * 3.3.16 READDIR3res 1666 + * 1667 + * struct dirlist3 { 1668 + * entry3 *entries; 1669 + * bool eof; 1670 + * }; 1671 + * 1672 + * struct READDIR3resok { 1673 + * post_op_attr dir_attributes; 1674 + * cookieverf3 cookieverf; 1675 + * dirlist3 reply; 1676 + * }; 1677 + * 1678 + * struct READDIR3resfail { 1679 + * post_op_attr dir_attributes; 1680 + * }; 1681 + * 1682 + * union READDIR3res switch (nfsstat3 status) { 1683 + * case NFS3_OK: 1684 + * READDIR3resok resok; 1685 + * default: 1686 + * READDIR3resfail resfail; 1687 + * }; 1688 + * 1689 + * Read the directory contents into the page cache, but otherwise 1690 + * don't touch them. The actual decoding is done by nfs3_decode_entry() 1691 + * during subsequent nfs_readdir() calls. 1692 + */ 1693 + static int decode_dirlist3(struct xdr_stream *xdr) 1694 + { 1695 + u32 recvd, pglen; 1696 + size_t hdrlen; 1697 + 1698 + pglen = xdr->buf->page_len; 1699 + hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; 1700 + recvd = xdr->buf->len - hdrlen; 1701 + if (unlikely(pglen > recvd)) 1702 + goto out_cheating; 1703 + out: 1704 + xdr_read_pages(xdr, pglen); 1705 + return pglen; 1706 + out_cheating: 1707 + dprintk("NFS: server cheating in readdir result: " 1708 + "pglen %u > recvd %u\n", pglen, recvd); 1709 + pglen = recvd; 1710 + goto out; 1711 + } 1712 + 1713 + static int decode_readdir3resok(struct xdr_stream *xdr, 1714 + struct nfs3_readdirres *result) 1715 + { 1716 + int error; 1717 + 1718 + error = decode_post_op_attr(xdr, result->dir_attr); 1719 + if (unlikely(error)) 1720 + goto out; 1721 + /* XXX: do we need to check if result->verf != NULL ? */ 1722 + error = decode_cookieverf3(xdr, result->verf); 1723 + if (unlikely(error)) 1724 + goto out; 1725 + error = decode_dirlist3(xdr); 1726 + out: 1727 + return error; 1728 + } 1729 + 1730 + static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req, __be32 *p, 1731 + struct nfs3_readdirres *result) 1732 + { 1733 + struct xdr_stream xdr; 1734 + enum nfs_stat status; 1735 + int error; 1736 + 1737 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1738 + error = decode_nfsstat3(&xdr, &status); 1739 + if (unlikely(error)) 1740 + goto out; 1741 + if (status != NFS3_OK) 1742 + goto out_default; 1743 + error = decode_readdir3resok(&xdr, result); 1744 + out: 1745 + return error; 1746 + out_default: 1747 + error = decode_post_op_attr(&xdr, result->dir_attr); 1748 + if (unlikely(error)) 1749 + goto out; 1750 + return nfs_stat_to_errno(status); 2294 1751 } 2295 1752 2296 1753 /* ··· 2559 1530 2560 1531 /* ignore invarsec */ 2561 1532 return 0; 1533 + } 1534 + 1535 + /* 1536 + * 3.3.18 FSSTAT3res 1537 + * 1538 + * struct FSSTAT3resok { 1539 + * post_op_attr obj_attributes; 1540 + * size3 tbytes; 1541 + * size3 fbytes; 1542 + * size3 abytes; 1543 + * size3 tfiles; 1544 + * size3 ffiles; 1545 + * size3 afiles; 1546 + * uint32 invarsec; 1547 + * }; 1548 + * 1549 + * struct FSSTAT3resfail { 1550 + * post_op_attr obj_attributes; 1551 + * }; 1552 + * 1553 + * union FSSTAT3res switch (nfsstat3 status) { 1554 + * case NFS3_OK: 1555 + * FSSTAT3resok resok; 1556 + * default: 1557 + * FSSTAT3resfail resfail; 1558 + * }; 1559 + */ 1560 + static int decode_fsstat3resok(struct xdr_stream *xdr, 1561 + struct nfs_fsstat *result) 1562 + { 1563 + __be32 *p; 1564 + 1565 + p = xdr_inline_decode(xdr, 8 * 6 + 4); 1566 + if (unlikely(p == NULL)) 1567 + goto out_overflow; 1568 + p = xdr_decode_size3(p, &result->tbytes); 1569 + p = xdr_decode_size3(p, &result->fbytes); 1570 + p = xdr_decode_size3(p, &result->abytes); 1571 + p = xdr_decode_size3(p, &result->tfiles); 1572 + p = xdr_decode_size3(p, &result->ffiles); 1573 + xdr_decode_size3(p, &result->afiles); 1574 + /* ignore invarsec */ 1575 + return 0; 1576 + out_overflow: 1577 + print_overflow_msg(__func__, xdr); 1578 + return -EIO; 1579 + } 1580 + 1581 + static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req, __be32 *p, 1582 + struct nfs_fsstat *result) 1583 + { 1584 + struct xdr_stream xdr; 1585 + enum nfs_stat status; 1586 + int error; 1587 + 1588 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1589 + error = decode_nfsstat3(&xdr, &status); 1590 + if (unlikely(error)) 1591 + goto out; 1592 + error = decode_post_op_attr(&xdr, result->fattr); 1593 + if (unlikely(error)) 1594 + goto out; 1595 + if (status != NFS3_OK) 1596 + goto out_status; 1597 + error = decode_fsstat3resok(&xdr, result); 1598 + out: 1599 + return error; 1600 + out_status: 1601 + return nfs_stat_to_errno(status); 2562 1602 } 2563 1603 2564 1604 /* ··· 2660 1562 } 2661 1563 2662 1564 /* 1565 + * 3.3.19 FSINFO3res 1566 + * 1567 + * struct FSINFO3resok { 1568 + * post_op_attr obj_attributes; 1569 + * uint32 rtmax; 1570 + * uint32 rtpref; 1571 + * uint32 rtmult; 1572 + * uint32 wtmax; 1573 + * uint32 wtpref; 1574 + * uint32 wtmult; 1575 + * uint32 dtpref; 1576 + * size3 maxfilesize; 1577 + * nfstime3 time_delta; 1578 + * uint32 properties; 1579 + * }; 1580 + * 1581 + * struct FSINFO3resfail { 1582 + * post_op_attr obj_attributes; 1583 + * }; 1584 + * 1585 + * union FSINFO3res switch (nfsstat3 status) { 1586 + * case NFS3_OK: 1587 + * FSINFO3resok resok; 1588 + * default: 1589 + * FSINFO3resfail resfail; 1590 + * }; 1591 + */ 1592 + static int decode_fsinfo3resok(struct xdr_stream *xdr, 1593 + struct nfs_fsinfo *result) 1594 + { 1595 + __be32 *p; 1596 + 1597 + p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4); 1598 + if (unlikely(p == NULL)) 1599 + goto out_overflow; 1600 + result->rtmax = be32_to_cpup(p++); 1601 + result->rtpref = be32_to_cpup(p++); 1602 + result->rtmult = be32_to_cpup(p++); 1603 + result->wtmax = be32_to_cpup(p++); 1604 + result->wtpref = be32_to_cpup(p++); 1605 + result->wtmult = be32_to_cpup(p++); 1606 + result->dtpref = be32_to_cpup(p++); 1607 + p = xdr_decode_size3(p, &result->maxfilesize); 1608 + xdr_decode_time3(p, &result->time_delta); 1609 + 1610 + /* ignore properties */ 1611 + result->lease_time = 0; 1612 + return 0; 1613 + out_overflow: 1614 + print_overflow_msg(__func__, xdr); 1615 + return -EIO; 1616 + } 1617 + 1618 + static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req, __be32 *p, 1619 + struct nfs_fsinfo *result) 1620 + { 1621 + struct xdr_stream xdr; 1622 + enum nfs_stat status; 1623 + int error; 1624 + 1625 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1626 + error = decode_nfsstat3(&xdr, &status); 1627 + if (unlikely(error)) 1628 + goto out; 1629 + error = decode_post_op_attr(&xdr, result->fattr); 1630 + if (unlikely(error)) 1631 + goto out; 1632 + if (status != NFS3_OK) 1633 + goto out_status; 1634 + error = decode_fsinfo3resok(&xdr, result); 1635 + out: 1636 + return error; 1637 + out_status: 1638 + return nfs_stat_to_errno(status); 1639 + } 1640 + 1641 + /* 2663 1642 * Decode PATHCONF reply 2664 1643 */ 2665 1644 static int ··· 2757 1582 } 2758 1583 2759 1584 /* 1585 + * 3.3.20 PATHCONF3res 1586 + * 1587 + * struct PATHCONF3resok { 1588 + * post_op_attr obj_attributes; 1589 + * uint32 linkmax; 1590 + * uint32 name_max; 1591 + * bool no_trunc; 1592 + * bool chown_restricted; 1593 + * bool case_insensitive; 1594 + * bool case_preserving; 1595 + * }; 1596 + * 1597 + * struct PATHCONF3resfail { 1598 + * post_op_attr obj_attributes; 1599 + * }; 1600 + * 1601 + * union PATHCONF3res switch (nfsstat3 status) { 1602 + * case NFS3_OK: 1603 + * PATHCONF3resok resok; 1604 + * default: 1605 + * PATHCONF3resfail resfail; 1606 + * }; 1607 + */ 1608 + static int decode_pathconf3resok(struct xdr_stream *xdr, 1609 + struct nfs_pathconf *result) 1610 + { 1611 + __be32 *p; 1612 + 1613 + p = xdr_inline_decode(xdr, 4 * 6); 1614 + if (unlikely(p == NULL)) 1615 + goto out_overflow; 1616 + result->max_link = be32_to_cpup(p++); 1617 + result->max_namelen = be32_to_cpup(p); 1618 + /* ignore remaining fields */ 1619 + return 0; 1620 + out_overflow: 1621 + print_overflow_msg(__func__, xdr); 1622 + return -EIO; 1623 + } 1624 + 1625 + static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req, __be32 *p, 1626 + struct nfs_pathconf *result) 1627 + { 1628 + struct xdr_stream xdr; 1629 + enum nfs_stat status; 1630 + int error; 1631 + 1632 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1633 + error = decode_nfsstat3(&xdr, &status); 1634 + if (unlikely(error)) 1635 + goto out; 1636 + error = decode_post_op_attr(&xdr, result->fattr); 1637 + if (unlikely(error)) 1638 + goto out; 1639 + if (status != NFS3_OK) 1640 + goto out_status; 1641 + error = decode_pathconf3resok(&xdr, result); 1642 + out: 1643 + return error; 1644 + out_status: 1645 + return nfs_stat_to_errno(status); 1646 + } 1647 + 1648 + /* 2760 1649 * Decode COMMIT reply 2761 1650 */ 2762 1651 static int ··· 2836 1597 res->verf->verifier[0] = *p++; 2837 1598 res->verf->verifier[1] = *p++; 2838 1599 return 0; 1600 + } 1601 + 1602 + /* 1603 + * 3.3.21 COMMIT3res 1604 + * 1605 + * struct COMMIT3resok { 1606 + * wcc_data file_wcc; 1607 + * writeverf3 verf; 1608 + * }; 1609 + * 1610 + * struct COMMIT3resfail { 1611 + * wcc_data file_wcc; 1612 + * }; 1613 + * 1614 + * union COMMIT3res switch (nfsstat3 status) { 1615 + * case NFS3_OK: 1616 + * COMMIT3resok resok; 1617 + * default: 1618 + * COMMIT3resfail resfail; 1619 + * }; 1620 + */ 1621 + static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req, __be32 *p, 1622 + struct nfs_writeres *result) 1623 + { 1624 + struct xdr_stream xdr; 1625 + enum nfs_stat status; 1626 + int error; 1627 + 1628 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1629 + error = decode_nfsstat3(&xdr, &status); 1630 + if (unlikely(error)) 1631 + goto out; 1632 + error = decode_wcc_data(&xdr, result->fattr); 1633 + if (unlikely(error)) 1634 + goto out; 1635 + if (status != NFS3_OK) 1636 + goto out_status; 1637 + error = decode_writeverf3(&xdr, result->verf->verifier); 1638 + out: 1639 + return error; 1640 + out_status: 1641 + return nfs_stat_to_errno(status); 2839 1642 } 2840 1643 2841 1644 #ifdef CONFIG_NFS_V3_ACL ··· 2913 1632 return (err > 0) ? 0 : err; 2914 1633 } 2915 1634 1635 + static inline int decode_getacl3resok(struct xdr_stream *xdr, 1636 + struct nfs3_getaclres *result) 1637 + { 1638 + struct posix_acl **acl; 1639 + unsigned int *aclcnt; 1640 + size_t hdrlen; 1641 + int error; 1642 + 1643 + error = decode_post_op_attr(xdr, result->fattr); 1644 + if (unlikely(error)) 1645 + goto out; 1646 + error = decode_uint32(xdr, &result->mask); 1647 + if (unlikely(error)) 1648 + goto out; 1649 + error = -EINVAL; 1650 + if (result->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT)) 1651 + goto out; 1652 + 1653 + hdrlen = (u8 *)xdr->p - (u8 *)xdr->iov->iov_base; 1654 + 1655 + acl = NULL; 1656 + if (result->mask & NFS_ACL) 1657 + acl = &result->acl_access; 1658 + aclcnt = NULL; 1659 + if (result->mask & NFS_ACLCNT) 1660 + aclcnt = &result->acl_access_count; 1661 + error = nfsacl_decode(xdr->buf, hdrlen, aclcnt, acl); 1662 + if (unlikely(error <= 0)) 1663 + goto out; 1664 + 1665 + acl = NULL; 1666 + if (result->mask & NFS_DFACL) 1667 + acl = &result->acl_default; 1668 + aclcnt = NULL; 1669 + if (result->mask & NFS_DFACLCNT) 1670 + aclcnt = &result->acl_default_count; 1671 + error = nfsacl_decode(xdr->buf, hdrlen + error, aclcnt, acl); 1672 + if (unlikely(error <= 0)) 1673 + return error; 1674 + error = 0; 1675 + out: 1676 + return error; 1677 + } 1678 + 1679 + static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req, __be32 *p, 1680 + struct nfs3_getaclres *result) 1681 + { 1682 + struct xdr_stream xdr; 1683 + enum nfs_stat status; 1684 + int error; 1685 + 1686 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1687 + error = decode_nfsstat3(&xdr, &status); 1688 + if (unlikely(error)) 1689 + goto out; 1690 + if (status != NFS3_OK) 1691 + goto out_default; 1692 + error = decode_getacl3resok(&xdr, result); 1693 + out: 1694 + return error; 1695 + out_default: 1696 + return nfs_stat_to_errno(status); 1697 + } 1698 + 2916 1699 /* 2917 1700 * Decode setacl reply. 2918 1701 */ ··· 2990 1645 xdr_decode_post_op_attr(p, fattr); 2991 1646 return 0; 2992 1647 } 1648 + 1649 + static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req, __be32 *p, 1650 + struct nfs_fattr *result) 1651 + { 1652 + struct xdr_stream xdr; 1653 + enum nfs_stat status; 1654 + int error; 1655 + 1656 + xdr_init_decode(&xdr, &req->rq_rcv_buf, p); 1657 + error = decode_nfsstat3(&xdr, &status); 1658 + if (unlikely(error)) 1659 + goto out; 1660 + if (status != NFS3_OK) 1661 + goto out_default; 1662 + error = decode_post_op_attr(&xdr, result); 1663 + out: 1664 + return error; 1665 + out_default: 1666 + return nfs_stat_to_errno(status); 1667 + } 1668 + 2993 1669 #endif /* CONFIG_NFS_V3_ACL */ 2994 1670 2995 1671 #define PROC(proc, argtype, restype, timer) \
+1
include/linux/nfs3.h
··· 13 13 #define NFS3_COOKIESIZE 4 14 14 #define NFS3_CREATEVERFSIZE 8 15 15 #define NFS3_COOKIEVERFSIZE 8 16 + #define NFS3_WRITEVERFSIZE 8 16 17 #define NFS3_FIFO_DEV (-1) 17 18 #define NFS3MODE_FMT 0170000 18 19 #define NFS3MODE_DIR 0040000