Commit 64303b9
SUNRPC: auth_gss: fix memory leaks in XDR decoding error paths
commit 3e6397b upstream.
The gssx_dec_ctx(), gssx_dec_status(), and gssx_dec_name()
functions allocate memory via gssx_dec_buffer(), which calls
kmemdup(). When a subsequent decode operation fails, these
functions return immediately without freeing previously
allocated buffers, causing memory leaks.
The leak in gssx_dec_ctx() is particularly relevant because
the caller (gssp_accept_sec_context_upcall) initializes several
buffer length fields to non-zero values, resulting in memory
allocation:
struct gssx_ctx rctxh = {
.exported_context_token.len = GSSX_max_output_handle_sz,
.mech.len = GSS_OID_MAX_LEN,
.src_name.display_name.len = GSSX_max_princ_sz,
.targ_name.display_name.len = GSSX_max_princ_sz
};
If, for example, gssx_dec_name() succeeds for src_name but
fails for targ_name, the memory allocated for
exported_context_token, mech, and src_name.display_name
remains unreferenced and cannot be reclaimed.
Add error handling with goto-based cleanup to free any
previously allocated buffers before returning an error.
Reported-by: Xingjing Deng <micro6947@gmail.com>
Closes: https://lore.kernel.org/linux-nfs/CAK+ZN9qttsFDu6h1FoqGadXjMx1QXqPMoYQ=6O9RY4SxVTvKng@mail.gmail.com/
Fixes: 1d65833 ("SUNRPC: Add RPC based upcall mechanism for RPCGSS auth")
Cc: stable@vger.kernel.org
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent f343fd0 commit 64303b9
1 file changed
+64
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
324 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
325 | 327 | | |
326 | 328 | | |
327 | 329 | | |
328 | 330 | | |
329 | 331 | | |
330 | | - | |
| 332 | + | |
331 | 333 | | |
332 | 334 | | |
333 | 335 | | |
334 | 336 | | |
335 | | - | |
| 337 | + | |
336 | 338 | | |
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
340 | | - | |
| 342 | + | |
341 | 343 | | |
342 | 344 | | |
343 | 345 | | |
344 | 346 | | |
| 347 | + | |
| 348 | + | |
345 | 349 | | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
346 | 364 | | |
347 | 365 | | |
348 | 366 | | |
| |||
505 | 523 | | |
506 | 524 | | |
507 | 525 | | |
508 | | - | |
| 526 | + | |
509 | 527 | | |
510 | 528 | | |
511 | 529 | | |
512 | 530 | | |
513 | | - | |
| 531 | + | |
514 | 532 | | |
515 | 533 | | |
516 | 534 | | |
517 | 535 | | |
518 | | - | |
| 536 | + | |
519 | 537 | | |
520 | 538 | | |
521 | 539 | | |
522 | 540 | | |
523 | 541 | | |
524 | | - | |
| 542 | + | |
525 | 543 | | |
526 | 544 | | |
527 | 545 | | |
528 | 546 | | |
| 547 | + | |
| 548 | + | |
529 | 549 | | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
530 | 555 | | |
531 | 556 | | |
532 | 557 | | |
| |||
649 | 674 | | |
650 | 675 | | |
651 | 676 | | |
652 | | - | |
| 677 | + | |
653 | 678 | | |
654 | 679 | | |
655 | 680 | | |
656 | 681 | | |
657 | | - | |
| 682 | + | |
658 | 683 | | |
659 | 684 | | |
660 | 685 | | |
661 | 686 | | |
662 | | - | |
| 687 | + | |
663 | 688 | | |
664 | 689 | | |
665 | 690 | | |
666 | 691 | | |
667 | | - | |
| 692 | + | |
668 | 693 | | |
669 | 694 | | |
670 | 695 | | |
671 | 696 | | |
672 | | - | |
| 697 | + | |
673 | 698 | | |
674 | 699 | | |
675 | 700 | | |
676 | | - | |
677 | | - | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
678 | 705 | | |
679 | 706 | | |
680 | 707 | | |
| |||
683 | 710 | | |
684 | 711 | | |
685 | 712 | | |
686 | | - | |
| 713 | + | |
687 | 714 | | |
688 | 715 | | |
689 | 716 | | |
690 | 717 | | |
691 | | - | |
| 718 | + | |
692 | 719 | | |
693 | 720 | | |
694 | 721 | | |
695 | 722 | | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
696 | 727 | | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
697 | 743 | | |
698 | 744 | | |
699 | 745 | | |
| |||
0 commit comments