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

selftests/coredump: add debug logging to coredump socket protocol tests

So it's easier to figure out bugs.

Link: https://patch.msgid.link/20251028-work-coredump-signal-v1-19-ca449b7b7aa0@kernel.org
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

+367 -118
+367 -118
tools/testing/selftests/coredump/coredump_socket_protocol_test.c
··· 101 101 close(ipc_sockets[0]); 102 102 103 103 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 104 - if (fd_server < 0) 104 + if (fd_server < 0) { 105 + fprintf(stderr, "socket_request_kernel: create_and_listen_unix_socket failed: %m\n"); 105 106 goto out; 107 + } 106 108 107 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 109 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 110 + fprintf(stderr, "socket_request_kernel: write_nointr to ipc socket failed: %m\n"); 108 111 goto out; 112 + } 109 113 110 114 close(ipc_sockets[1]); 111 115 112 116 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 113 - if (fd_coredump < 0) 117 + if (fd_coredump < 0) { 118 + fprintf(stderr, "socket_request_kernel: accept4 failed: %m\n"); 114 119 goto out; 120 + } 115 121 116 122 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 117 - if (fd_peer_pidfd < 0) 123 + if (fd_peer_pidfd < 0) { 124 + fprintf(stderr, "socket_request_kernel: get_peer_pidfd failed\n"); 118 125 goto out; 126 + } 119 127 120 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 128 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 129 + fprintf(stderr, "socket_request_kernel: get_pidfd_info failed\n"); 121 130 goto out; 131 + } 122 132 123 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 133 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 134 + fprintf(stderr, "socket_request_kernel: PIDFD_INFO_COREDUMP not set in mask\n"); 124 135 goto out; 136 + } 125 137 126 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 138 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 139 + fprintf(stderr, "socket_request_kernel: PIDFD_COREDUMPED not set in coredump_mask\n"); 127 140 goto out; 141 + } 128 142 129 143 fd_core_file = creat("/tmp/coredump.file", 0644); 130 - if (fd_core_file < 0) 144 + if (fd_core_file < 0) { 145 + fprintf(stderr, "socket_request_kernel: creat coredump file failed: %m\n"); 131 146 goto out; 147 + } 132 148 133 - if (!read_coredump_req(fd_coredump, &req)) 149 + if (!read_coredump_req(fd_coredump, &req)) { 150 + fprintf(stderr, "socket_request_kernel: read_coredump_req failed\n"); 134 151 goto out; 152 + } 135 153 136 154 if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0, 137 155 COREDUMP_KERNEL | COREDUMP_USERSPACE | 138 - COREDUMP_REJECT | COREDUMP_WAIT)) 156 + COREDUMP_REJECT | COREDUMP_WAIT)) { 157 + fprintf(stderr, "socket_request_kernel: check_coredump_req failed\n"); 139 158 goto out; 159 + } 140 160 141 161 if (!send_coredump_ack(fd_coredump, &req, 142 - COREDUMP_KERNEL | COREDUMP_WAIT, 0)) 162 + COREDUMP_KERNEL | COREDUMP_WAIT, 0)) { 163 + fprintf(stderr, "socket_request_kernel: send_coredump_ack failed\n"); 143 164 goto out; 165 + } 144 166 145 - if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) 167 + if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) { 168 + fprintf(stderr, "socket_request_kernel: read_marker COREDUMP_MARK_REQACK failed\n"); 146 169 goto out; 170 + } 147 171 148 172 for (;;) { 149 173 char buffer[4096]; 150 174 ssize_t bytes_read, bytes_write; 151 175 152 176 bytes_read = read(fd_coredump, buffer, sizeof(buffer)); 153 - if (bytes_read < 0) 177 + if (bytes_read < 0) { 178 + fprintf(stderr, "socket_request_kernel: read from coredump socket failed: %m\n"); 154 179 goto out; 180 + } 155 181 156 182 if (bytes_read == 0) 157 183 break; 158 184 159 185 bytes_write = write(fd_core_file, buffer, bytes_read); 160 - if (bytes_read != bytes_write) 186 + if (bytes_read != bytes_write) { 187 + fprintf(stderr, "socket_request_kernel: write to core file failed (read=%zd, write=%zd): %m\n", 188 + bytes_read, bytes_write); 161 189 goto out; 190 + } 162 191 } 163 192 164 193 exit_code = EXIT_SUCCESS; 194 + fprintf(stderr, "socket_request_kernel: completed successfully\n"); 165 195 out: 166 196 if (fd_core_file >= 0) 167 197 close(fd_core_file); ··· 255 225 close(ipc_sockets[0]); 256 226 257 227 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 258 - if (fd_server < 0) 228 + if (fd_server < 0) { 229 + fprintf(stderr, "socket_request_userspace: create_and_listen_unix_socket failed: %m\n"); 259 230 goto out; 231 + } 260 232 261 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 233 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 234 + fprintf(stderr, "socket_request_userspace: write_nointr to ipc socket failed: %m\n"); 262 235 goto out; 236 + } 263 237 264 238 close(ipc_sockets[1]); 265 239 266 240 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 267 - if (fd_coredump < 0) 241 + if (fd_coredump < 0) { 242 + fprintf(stderr, "socket_request_userspace: accept4 failed: %m\n"); 268 243 goto out; 244 + } 269 245 270 246 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 271 - if (fd_peer_pidfd < 0) 247 + if (fd_peer_pidfd < 0) { 248 + fprintf(stderr, "socket_request_userspace: get_peer_pidfd failed\n"); 272 249 goto out; 250 + } 273 251 274 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 252 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 253 + fprintf(stderr, "socket_request_userspace: get_pidfd_info failed\n"); 275 254 goto out; 255 + } 276 256 277 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 257 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 258 + fprintf(stderr, "socket_request_userspace: PIDFD_INFO_COREDUMP not set in mask\n"); 278 259 goto out; 260 + } 279 261 280 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 262 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 263 + fprintf(stderr, "socket_request_userspace: PIDFD_COREDUMPED not set in coredump_mask\n"); 281 264 goto out; 265 + } 282 266 283 - if (!read_coredump_req(fd_coredump, &req)) 267 + if (!read_coredump_req(fd_coredump, &req)) { 268 + fprintf(stderr, "socket_request_userspace: read_coredump_req failed\n"); 284 269 goto out; 270 + } 285 271 286 272 if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0, 287 273 COREDUMP_KERNEL | COREDUMP_USERSPACE | 288 - COREDUMP_REJECT | COREDUMP_WAIT)) 274 + COREDUMP_REJECT | COREDUMP_WAIT)) { 275 + fprintf(stderr, "socket_request_userspace: check_coredump_req failed\n"); 289 276 goto out; 277 + } 290 278 291 279 if (!send_coredump_ack(fd_coredump, &req, 292 - COREDUMP_USERSPACE | COREDUMP_WAIT, 0)) 280 + COREDUMP_USERSPACE | COREDUMP_WAIT, 0)) { 281 + fprintf(stderr, "socket_request_userspace: send_coredump_ack failed\n"); 293 282 goto out; 283 + } 294 284 295 - if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) 285 + if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) { 286 + fprintf(stderr, "socket_request_userspace: read_marker COREDUMP_MARK_REQACK failed\n"); 296 287 goto out; 288 + } 297 289 298 290 for (;;) { 299 291 char buffer[4096]; 300 292 ssize_t bytes_read; 301 293 302 294 bytes_read = read(fd_coredump, buffer, sizeof(buffer)); 303 - if (bytes_read > 0) 295 + if (bytes_read > 0) { 296 + fprintf(stderr, "socket_request_userspace: unexpected data received (expected no coredump data)\n"); 304 297 goto out; 298 + } 305 299 306 - if (bytes_read < 0) 300 + if (bytes_read < 0) { 301 + fprintf(stderr, "socket_request_userspace: read from coredump socket failed: %m\n"); 307 302 goto out; 303 + } 308 304 309 305 if (bytes_read == 0) 310 306 break; 311 307 } 312 308 313 309 exit_code = EXIT_SUCCESS; 310 + fprintf(stderr, "socket_request_userspace: completed successfully\n"); 314 311 out: 315 312 if (fd_peer_pidfd >= 0) 316 313 close(fd_peer_pidfd); ··· 395 338 close(ipc_sockets[0]); 396 339 397 340 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 398 - if (fd_server < 0) 341 + if (fd_server < 0) { 342 + fprintf(stderr, "socket_request_reject: create_and_listen_unix_socket failed: %m\n"); 399 343 goto out; 344 + } 400 345 401 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 346 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 347 + fprintf(stderr, "socket_request_reject: write_nointr to ipc socket failed: %m\n"); 402 348 goto out; 349 + } 403 350 404 351 close(ipc_sockets[1]); 405 352 406 353 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 407 - if (fd_coredump < 0) 354 + if (fd_coredump < 0) { 355 + fprintf(stderr, "socket_request_reject: accept4 failed: %m\n"); 408 356 goto out; 357 + } 409 358 410 359 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 411 - if (fd_peer_pidfd < 0) 360 + if (fd_peer_pidfd < 0) { 361 + fprintf(stderr, "socket_request_reject: get_peer_pidfd failed\n"); 412 362 goto out; 363 + } 413 364 414 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 365 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 366 + fprintf(stderr, "socket_request_reject: get_pidfd_info failed\n"); 415 367 goto out; 368 + } 416 369 417 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 370 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 371 + fprintf(stderr, "socket_request_reject: PIDFD_INFO_COREDUMP not set in mask\n"); 418 372 goto out; 373 + } 419 374 420 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 375 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 376 + fprintf(stderr, "socket_request_reject: PIDFD_COREDUMPED not set in coredump_mask\n"); 421 377 goto out; 378 + } 422 379 423 - if (!read_coredump_req(fd_coredump, &req)) 380 + if (!read_coredump_req(fd_coredump, &req)) { 381 + fprintf(stderr, "socket_request_reject: read_coredump_req failed\n"); 424 382 goto out; 383 + } 425 384 426 385 if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0, 427 386 COREDUMP_KERNEL | COREDUMP_USERSPACE | 428 - COREDUMP_REJECT | COREDUMP_WAIT)) 387 + COREDUMP_REJECT | COREDUMP_WAIT)) { 388 + fprintf(stderr, "socket_request_reject: check_coredump_req failed\n"); 429 389 goto out; 390 + } 430 391 431 392 if (!send_coredump_ack(fd_coredump, &req, 432 - COREDUMP_REJECT | COREDUMP_WAIT, 0)) 393 + COREDUMP_REJECT | COREDUMP_WAIT, 0)) { 394 + fprintf(stderr, "socket_request_reject: send_coredump_ack failed\n"); 433 395 goto out; 396 + } 434 397 435 - if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) 398 + if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) { 399 + fprintf(stderr, "socket_request_reject: read_marker COREDUMP_MARK_REQACK failed\n"); 436 400 goto out; 401 + } 437 402 438 403 for (;;) { 439 404 char buffer[4096]; 440 405 ssize_t bytes_read; 441 406 442 407 bytes_read = read(fd_coredump, buffer, sizeof(buffer)); 443 - if (bytes_read > 0) 408 + if (bytes_read > 0) { 409 + fprintf(stderr, "socket_request_reject: unexpected data received (expected no coredump data for REJECT)\n"); 444 410 goto out; 411 + } 445 412 446 - if (bytes_read < 0) 413 + if (bytes_read < 0) { 414 + fprintf(stderr, "socket_request_reject: read from coredump socket failed: %m\n"); 447 415 goto out; 416 + } 448 417 449 418 if (bytes_read == 0) 450 419 break; 451 420 } 452 421 453 422 exit_code = EXIT_SUCCESS; 423 + fprintf(stderr, "socket_request_reject: completed successfully\n"); 454 424 out: 455 425 if (fd_peer_pidfd >= 0) 456 426 close(fd_peer_pidfd); ··· 535 451 close(ipc_sockets[0]); 536 452 537 453 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 538 - if (fd_server < 0) 454 + if (fd_server < 0) { 455 + fprintf(stderr, "socket_request_invalid_flag_combination: create_and_listen_unix_socket failed: %m\n"); 539 456 goto out; 457 + } 540 458 541 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 459 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 460 + fprintf(stderr, "socket_request_invalid_flag_combination: write_nointr to ipc socket failed: %m\n"); 542 461 goto out; 462 + } 543 463 544 464 close(ipc_sockets[1]); 545 465 546 466 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 547 - if (fd_coredump < 0) 467 + if (fd_coredump < 0) { 468 + fprintf(stderr, "socket_request_invalid_flag_combination: accept4 failed: %m\n"); 548 469 goto out; 470 + } 549 471 550 472 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 551 - if (fd_peer_pidfd < 0) 473 + if (fd_peer_pidfd < 0) { 474 + fprintf(stderr, "socket_request_invalid_flag_combination: get_peer_pidfd failed\n"); 552 475 goto out; 476 + } 553 477 554 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 478 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 479 + fprintf(stderr, "socket_request_invalid_flag_combination: get_pidfd_info failed\n"); 555 480 goto out; 481 + } 556 482 557 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 483 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 484 + fprintf(stderr, "socket_request_invalid_flag_combination: PIDFD_INFO_COREDUMP not set in mask\n"); 558 485 goto out; 486 + } 559 487 560 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 488 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 489 + fprintf(stderr, "socket_request_invalid_flag_combination: PIDFD_COREDUMPED not set in coredump_mask\n"); 561 490 goto out; 491 + } 562 492 563 - if (!read_coredump_req(fd_coredump, &req)) 493 + if (!read_coredump_req(fd_coredump, &req)) { 494 + fprintf(stderr, "socket_request_invalid_flag_combination: read_coredump_req failed\n"); 564 495 goto out; 496 + } 565 497 566 498 if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0, 567 499 COREDUMP_KERNEL | COREDUMP_USERSPACE | 568 - COREDUMP_REJECT | COREDUMP_WAIT)) 500 + COREDUMP_REJECT | COREDUMP_WAIT)) { 501 + fprintf(stderr, "socket_request_invalid_flag_combination: check_coredump_req failed\n"); 569 502 goto out; 503 + } 570 504 571 505 if (!send_coredump_ack(fd_coredump, &req, 572 - COREDUMP_KERNEL | COREDUMP_REJECT | COREDUMP_WAIT, 0)) 506 + COREDUMP_KERNEL | COREDUMP_REJECT | COREDUMP_WAIT, 0)) { 507 + fprintf(stderr, "socket_request_invalid_flag_combination: send_coredump_ack failed\n"); 573 508 goto out; 509 + } 574 510 575 - if (!read_marker(fd_coredump, COREDUMP_MARK_CONFLICTING)) 511 + if (!read_marker(fd_coredump, COREDUMP_MARK_CONFLICTING)) { 512 + fprintf(stderr, "socket_request_invalid_flag_combination: read_marker COREDUMP_MARK_CONFLICTING failed\n"); 576 513 goto out; 514 + } 577 515 578 516 exit_code = EXIT_SUCCESS; 517 + fprintf(stderr, "socket_request_invalid_flag_combination: completed successfully\n"); 579 518 out: 580 519 if (fd_peer_pidfd >= 0) 581 520 close(fd_peer_pidfd); ··· 656 549 close(ipc_sockets[0]); 657 550 658 551 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 659 - if (fd_server < 0) 552 + if (fd_server < 0) { 553 + fprintf(stderr, "socket_request_unknown_flag: create_and_listen_unix_socket failed: %m\n"); 660 554 goto out; 555 + } 661 556 662 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 557 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 558 + fprintf(stderr, "socket_request_unknown_flag: write_nointr to ipc socket failed: %m\n"); 663 559 goto out; 560 + } 664 561 665 562 close(ipc_sockets[1]); 666 563 667 564 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 668 - if (fd_coredump < 0) 565 + if (fd_coredump < 0) { 566 + fprintf(stderr, "socket_request_unknown_flag: accept4 failed: %m\n"); 669 567 goto out; 568 + } 670 569 671 570 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 672 - if (fd_peer_pidfd < 0) 571 + if (fd_peer_pidfd < 0) { 572 + fprintf(stderr, "socket_request_unknown_flag: get_peer_pidfd failed\n"); 673 573 goto out; 574 + } 674 575 675 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 576 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 577 + fprintf(stderr, "socket_request_unknown_flag: get_pidfd_info failed\n"); 676 578 goto out; 579 + } 677 580 678 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 581 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 582 + fprintf(stderr, "socket_request_unknown_flag: PIDFD_INFO_COREDUMP not set in mask\n"); 679 583 goto out; 584 + } 680 585 681 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 586 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 587 + fprintf(stderr, "socket_request_unknown_flag: PIDFD_COREDUMPED not set in coredump_mask\n"); 682 588 goto out; 589 + } 683 590 684 - if (!read_coredump_req(fd_coredump, &req)) 591 + if (!read_coredump_req(fd_coredump, &req)) { 592 + fprintf(stderr, "socket_request_unknown_flag: read_coredump_req failed\n"); 685 593 goto out; 594 + } 686 595 687 596 if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0, 688 597 COREDUMP_KERNEL | COREDUMP_USERSPACE | 689 - COREDUMP_REJECT | COREDUMP_WAIT)) 598 + COREDUMP_REJECT | COREDUMP_WAIT)) { 599 + fprintf(stderr, "socket_request_unknown_flag: check_coredump_req failed\n"); 690 600 goto out; 601 + } 691 602 692 - if (!send_coredump_ack(fd_coredump, &req, (1ULL << 63), 0)) 603 + if (!send_coredump_ack(fd_coredump, &req, (1ULL << 63), 0)) { 604 + fprintf(stderr, "socket_request_unknown_flag: send_coredump_ack failed\n"); 693 605 goto out; 606 + } 694 607 695 - if (!read_marker(fd_coredump, COREDUMP_MARK_UNSUPPORTED)) 608 + if (!read_marker(fd_coredump, COREDUMP_MARK_UNSUPPORTED)) { 609 + fprintf(stderr, "socket_request_unknown_flag: read_marker COREDUMP_MARK_UNSUPPORTED failed\n"); 696 610 goto out; 611 + } 697 612 698 613 exit_code = EXIT_SUCCESS; 614 + fprintf(stderr, "socket_request_unknown_flag: completed successfully\n"); 699 615 out: 700 616 if (fd_peer_pidfd >= 0) 701 617 close(fd_peer_pidfd); ··· 776 646 close(ipc_sockets[0]); 777 647 778 648 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 779 - if (fd_server < 0) 649 + if (fd_server < 0) { 650 + fprintf(stderr, "socket_request_invalid_size_small: create_and_listen_unix_socket failed: %m\n"); 780 651 goto out; 652 + } 781 653 782 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 654 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 655 + fprintf(stderr, "socket_request_invalid_size_small: write_nointr to ipc socket failed: %m\n"); 783 656 goto out; 657 + } 784 658 785 659 close(ipc_sockets[1]); 786 660 787 661 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 788 - if (fd_coredump < 0) 662 + if (fd_coredump < 0) { 663 + fprintf(stderr, "socket_request_invalid_size_small: accept4 failed: %m\n"); 789 664 goto out; 665 + } 790 666 791 667 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 792 - if (fd_peer_pidfd < 0) 668 + if (fd_peer_pidfd < 0) { 669 + fprintf(stderr, "socket_request_invalid_size_small: get_peer_pidfd failed\n"); 793 670 goto out; 671 + } 794 672 795 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 673 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 674 + fprintf(stderr, "socket_request_invalid_size_small: get_pidfd_info failed\n"); 796 675 goto out; 676 + } 797 677 798 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 678 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 679 + fprintf(stderr, "socket_request_invalid_size_small: PIDFD_INFO_COREDUMP not set in mask\n"); 799 680 goto out; 681 + } 800 682 801 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 683 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 684 + fprintf(stderr, "socket_request_invalid_size_small: PIDFD_COREDUMPED not set in coredump_mask\n"); 802 685 goto out; 686 + } 803 687 804 - if (!read_coredump_req(fd_coredump, &req)) 688 + if (!read_coredump_req(fd_coredump, &req)) { 689 + fprintf(stderr, "socket_request_invalid_size_small: read_coredump_req failed\n"); 805 690 goto out; 691 + } 806 692 807 693 if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0, 808 694 COREDUMP_KERNEL | COREDUMP_USERSPACE | 809 - COREDUMP_REJECT | COREDUMP_WAIT)) 695 + COREDUMP_REJECT | COREDUMP_WAIT)) { 696 + fprintf(stderr, "socket_request_invalid_size_small: check_coredump_req failed\n"); 810 697 goto out; 698 + } 811 699 812 700 if (!send_coredump_ack(fd_coredump, &req, 813 701 COREDUMP_REJECT | COREDUMP_WAIT, 814 - COREDUMP_ACK_SIZE_VER0 / 2)) 702 + COREDUMP_ACK_SIZE_VER0 / 2)) { 703 + fprintf(stderr, "socket_request_invalid_size_small: send_coredump_ack failed\n"); 815 704 goto out; 705 + } 816 706 817 - if (!read_marker(fd_coredump, COREDUMP_MARK_MINSIZE)) 707 + if (!read_marker(fd_coredump, COREDUMP_MARK_MINSIZE)) { 708 + fprintf(stderr, "socket_request_invalid_size_small: read_marker COREDUMP_MARK_MINSIZE failed\n"); 818 709 goto out; 710 + } 819 711 820 712 exit_code = EXIT_SUCCESS; 713 + fprintf(stderr, "socket_request_invalid_size_small: completed successfully\n"); 821 714 out: 822 715 if (fd_peer_pidfd >= 0) 823 716 close(fd_peer_pidfd); ··· 898 745 close(ipc_sockets[0]); 899 746 900 747 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 901 - if (fd_server < 0) 748 + if (fd_server < 0) { 749 + fprintf(stderr, "socket_request_invalid_size_large: create_and_listen_unix_socket failed: %m\n"); 902 750 goto out; 751 + } 903 752 904 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 753 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 754 + fprintf(stderr, "socket_request_invalid_size_large: write_nointr to ipc socket failed: %m\n"); 905 755 goto out; 756 + } 906 757 907 758 close(ipc_sockets[1]); 908 759 909 760 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 910 - if (fd_coredump < 0) 761 + if (fd_coredump < 0) { 762 + fprintf(stderr, "socket_request_invalid_size_large: accept4 failed: %m\n"); 911 763 goto out; 764 + } 912 765 913 766 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 914 - if (fd_peer_pidfd < 0) 767 + if (fd_peer_pidfd < 0) { 768 + fprintf(stderr, "socket_request_invalid_size_large: get_peer_pidfd failed\n"); 915 769 goto out; 770 + } 916 771 917 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 772 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 773 + fprintf(stderr, "socket_request_invalid_size_large: get_pidfd_info failed\n"); 918 774 goto out; 775 + } 919 776 920 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 777 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 778 + fprintf(stderr, "socket_request_invalid_size_large: PIDFD_INFO_COREDUMP not set in mask\n"); 921 779 goto out; 780 + } 922 781 923 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 782 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 783 + fprintf(stderr, "socket_request_invalid_size_large: PIDFD_COREDUMPED not set in coredump_mask\n"); 924 784 goto out; 785 + } 925 786 926 - if (!read_coredump_req(fd_coredump, &req)) 787 + if (!read_coredump_req(fd_coredump, &req)) { 788 + fprintf(stderr, "socket_request_invalid_size_large: read_coredump_req failed\n"); 927 789 goto out; 790 + } 928 791 929 792 if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0, 930 793 COREDUMP_KERNEL | COREDUMP_USERSPACE | 931 - COREDUMP_REJECT | COREDUMP_WAIT)) 794 + COREDUMP_REJECT | COREDUMP_WAIT)) { 795 + fprintf(stderr, "socket_request_invalid_size_large: check_coredump_req failed\n"); 932 796 goto out; 797 + } 933 798 934 799 if (!send_coredump_ack(fd_coredump, &req, 935 800 COREDUMP_REJECT | COREDUMP_WAIT, 936 - COREDUMP_ACK_SIZE_VER0 + PAGE_SIZE)) 801 + COREDUMP_ACK_SIZE_VER0 + PAGE_SIZE)) { 802 + fprintf(stderr, "socket_request_invalid_size_large: send_coredump_ack failed\n"); 937 803 goto out; 804 + } 938 805 939 - if (!read_marker(fd_coredump, COREDUMP_MARK_MAXSIZE)) 806 + if (!read_marker(fd_coredump, COREDUMP_MARK_MAXSIZE)) { 807 + fprintf(stderr, "socket_request_invalid_size_large: read_marker COREDUMP_MARK_MAXSIZE failed\n"); 940 808 goto out; 809 + } 941 810 942 811 exit_code = EXIT_SUCCESS; 812 + fprintf(stderr, "socket_request_invalid_size_large: completed successfully\n"); 943 813 out: 944 814 if (fd_peer_pidfd >= 0) 945 815 close(fd_peer_pidfd); ··· 1026 850 close(ipc_sockets[0]); 1027 851 1028 852 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 1029 - if (fd_server < 0) 853 + if (fd_server < 0) { 854 + fprintf(stderr, "socket_coredump_signal_sigsegv: create_and_listen_unix_socket failed: %m\n"); 1030 855 goto out; 856 + } 1031 857 1032 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 858 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 859 + fprintf(stderr, "socket_coredump_signal_sigsegv: write_nointr to ipc socket failed: %m\n"); 1033 860 goto out; 861 + } 1034 862 1035 863 close(ipc_sockets[1]); 1036 864 1037 865 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 1038 - if (fd_coredump < 0) 866 + if (fd_coredump < 0) { 867 + fprintf(stderr, "socket_coredump_signal_sigsegv: accept4 failed: %m\n"); 1039 868 goto out; 869 + } 1040 870 1041 871 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 1042 - if (fd_peer_pidfd < 0) 872 + if (fd_peer_pidfd < 0) { 873 + fprintf(stderr, "socket_coredump_signal_sigsegv: get_peer_pidfd failed\n"); 1043 874 goto out; 875 + } 1044 876 1045 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 877 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 878 + fprintf(stderr, "socket_coredump_signal_sigsegv: get_pidfd_info failed\n"); 1046 879 goto out; 880 + } 1047 881 1048 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 882 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 883 + fprintf(stderr, "socket_coredump_signal_sigsegv: PIDFD_INFO_COREDUMP not set in mask\n"); 1049 884 goto out; 885 + } 1050 886 1051 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 887 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 888 + fprintf(stderr, "socket_coredump_signal_sigsegv: PIDFD_COREDUMPED not set in coredump_mask\n"); 1052 889 goto out; 890 + } 1053 891 1054 892 /* Verify coredump_signal is available and correct */ 1055 - if (!(info.mask & PIDFD_INFO_COREDUMP_SIGNAL)) 893 + if (!(info.mask & PIDFD_INFO_COREDUMP_SIGNAL)) { 894 + fprintf(stderr, "socket_coredump_signal_sigsegv: PIDFD_INFO_COREDUMP_SIGNAL not set in mask\n"); 1056 895 goto out; 896 + } 1057 897 1058 - if (info.coredump_signal != SIGSEGV) 898 + if (info.coredump_signal != SIGSEGV) { 899 + fprintf(stderr, "socket_coredump_signal_sigsegv: coredump_signal=%d, expected SIGSEGV=%d\n", 900 + info.coredump_signal, SIGSEGV); 1059 901 goto out; 902 + } 1060 903 1061 - if (!read_coredump_req(fd_coredump, &req)) 904 + if (!read_coredump_req(fd_coredump, &req)) { 905 + fprintf(stderr, "socket_coredump_signal_sigsegv: read_coredump_req failed\n"); 1062 906 goto out; 907 + } 1063 908 1064 909 if (!send_coredump_ack(fd_coredump, &req, 1065 - COREDUMP_REJECT | COREDUMP_WAIT, 0)) 910 + COREDUMP_REJECT | COREDUMP_WAIT, 0)) { 911 + fprintf(stderr, "socket_coredump_signal_sigsegv: send_coredump_ack failed\n"); 1066 912 goto out; 913 + } 1067 914 1068 - if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) 915 + if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) { 916 + fprintf(stderr, "socket_coredump_signal_sigsegv: read_marker COREDUMP_MARK_REQACK failed\n"); 1069 917 goto out; 918 + } 1070 919 1071 920 exit_code = EXIT_SUCCESS; 921 + fprintf(stderr, "socket_coredump_signal_sigsegv: completed successfully\n"); 1072 922 out: 1073 923 if (fd_peer_pidfd >= 0) 1074 924 close(fd_peer_pidfd); ··· 1159 957 close(ipc_sockets[0]); 1160 958 1161 959 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 1162 - if (fd_server < 0) 960 + if (fd_server < 0) { 961 + fprintf(stderr, "socket_coredump_signal_sigabrt: create_and_listen_unix_socket failed: %m\n"); 1163 962 goto out; 963 + } 1164 964 1165 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 965 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 966 + fprintf(stderr, "socket_coredump_signal_sigabrt: write_nointr to ipc socket failed: %m\n"); 1166 967 goto out; 968 + } 1167 969 1168 970 close(ipc_sockets[1]); 1169 971 1170 972 fd_coredump = accept4(fd_server, NULL, NULL, SOCK_CLOEXEC); 1171 - if (fd_coredump < 0) 973 + if (fd_coredump < 0) { 974 + fprintf(stderr, "socket_coredump_signal_sigabrt: accept4 failed: %m\n"); 1172 975 goto out; 976 + } 1173 977 1174 978 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 1175 - if (fd_peer_pidfd < 0) 979 + if (fd_peer_pidfd < 0) { 980 + fprintf(stderr, "socket_coredump_signal_sigabrt: get_peer_pidfd failed\n"); 1176 981 goto out; 982 + } 1177 983 1178 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 984 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 985 + fprintf(stderr, "socket_coredump_signal_sigabrt: get_pidfd_info failed\n"); 1179 986 goto out; 987 + } 1180 988 1181 - if (!(info.mask & PIDFD_INFO_COREDUMP)) 989 + if (!(info.mask & PIDFD_INFO_COREDUMP)) { 990 + fprintf(stderr, "socket_coredump_signal_sigabrt: PIDFD_INFO_COREDUMP not set in mask\n"); 1182 991 goto out; 992 + } 1183 993 1184 - if (!(info.coredump_mask & PIDFD_COREDUMPED)) 994 + if (!(info.coredump_mask & PIDFD_COREDUMPED)) { 995 + fprintf(stderr, "socket_coredump_signal_sigabrt: PIDFD_COREDUMPED not set in coredump_mask\n"); 1185 996 goto out; 997 + } 1186 998 1187 999 /* Verify coredump_signal is available and correct */ 1188 - if (!(info.mask & PIDFD_INFO_COREDUMP_SIGNAL)) 1000 + if (!(info.mask & PIDFD_INFO_COREDUMP_SIGNAL)) { 1001 + fprintf(stderr, "socket_coredump_signal_sigabrt: PIDFD_INFO_COREDUMP_SIGNAL not set in mask\n"); 1189 1002 goto out; 1003 + } 1190 1004 1191 - if (info.coredump_signal != SIGABRT) 1005 + if (info.coredump_signal != SIGABRT) { 1006 + fprintf(stderr, "socket_coredump_signal_sigabrt: coredump_signal=%d, expected SIGABRT=%d\n", 1007 + info.coredump_signal, SIGABRT); 1192 1008 goto out; 1009 + } 1193 1010 1194 - if (!read_coredump_req(fd_coredump, &req)) 1011 + if (!read_coredump_req(fd_coredump, &req)) { 1012 + fprintf(stderr, "socket_coredump_signal_sigabrt: read_coredump_req failed\n"); 1195 1013 goto out; 1014 + } 1196 1015 1197 1016 if (!send_coredump_ack(fd_coredump, &req, 1198 - COREDUMP_REJECT | COREDUMP_WAIT, 0)) 1017 + COREDUMP_REJECT | COREDUMP_WAIT, 0)) { 1018 + fprintf(stderr, "socket_coredump_signal_sigabrt: send_coredump_ack failed\n"); 1199 1019 goto out; 1020 + } 1200 1021 1201 - if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) 1022 + if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) { 1023 + fprintf(stderr, "socket_coredump_signal_sigabrt: read_marker COREDUMP_MARK_REQACK failed\n"); 1202 1024 goto out; 1025 + } 1203 1026 1204 1027 exit_code = EXIT_SUCCESS; 1028 + fprintf(stderr, "socket_coredump_signal_sigabrt: completed successfully\n"); 1205 1029 out: 1206 1030 if (fd_peer_pidfd >= 0) 1207 1031 close(fd_peer_pidfd); ··· 1441 1213 n_conns = 0; 1442 1214 close(ipc_sockets[0]); 1443 1215 fd_server = create_and_listen_unix_socket("/tmp/coredump.socket"); 1444 - if (fd_server < 0) 1216 + if (fd_server < 0) { 1217 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: create_and_listen_unix_socket failed: %m\n"); 1445 1218 goto out; 1219 + } 1446 1220 1447 - if (write_nointr(ipc_sockets[1], "1", 1) < 0) 1221 + if (write_nointr(ipc_sockets[1], "1", 1) < 0) { 1222 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: write_nointr to ipc socket failed: %m\n"); 1448 1223 goto out; 1224 + } 1449 1225 close(ipc_sockets[1]); 1450 1226 1451 1227 while (n_conns < NUM_CRASHING_COREDUMPS) { ··· 1459 1227 if (fd_coredump < 0) { 1460 1228 if (errno == EAGAIN || errno == EWOULDBLOCK) 1461 1229 continue; 1230 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: accept4 failed: %m\n"); 1462 1231 goto out; 1463 1232 } 1464 1233 fd_peer_pidfd = get_peer_pidfd(fd_coredump); 1465 - if (fd_peer_pidfd < 0) 1234 + if (fd_peer_pidfd < 0) { 1235 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: get_peer_pidfd failed\n"); 1466 1236 goto out; 1467 - if (!get_pidfd_info(fd_peer_pidfd, &info)) 1237 + } 1238 + if (!get_pidfd_info(fd_peer_pidfd, &info)) { 1239 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: get_pidfd_info failed\n"); 1468 1240 goto out; 1469 - if (!(info.mask & PIDFD_INFO_COREDUMP) || !(info.coredump_mask & PIDFD_COREDUMPED)) 1241 + } 1242 + if (!(info.mask & PIDFD_INFO_COREDUMP) || !(info.coredump_mask & PIDFD_COREDUMPED)) { 1243 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: missing PIDFD_INFO_COREDUMP or PIDFD_COREDUMPED\n"); 1470 1244 goto out; 1471 - if (!read_coredump_req(fd_coredump, &req)) 1245 + } 1246 + if (!read_coredump_req(fd_coredump, &req)) { 1247 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: read_coredump_req failed\n"); 1472 1248 goto out; 1249 + } 1473 1250 if (!check_coredump_req(&req, COREDUMP_ACK_SIZE_VER0, 1474 1251 COREDUMP_KERNEL | COREDUMP_USERSPACE | 1475 - COREDUMP_REJECT | COREDUMP_WAIT)) 1252 + COREDUMP_REJECT | COREDUMP_WAIT)) { 1253 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: check_coredump_req failed\n"); 1476 1254 goto out; 1477 - if (!send_coredump_ack(fd_coredump, &req, COREDUMP_KERNEL | COREDUMP_WAIT, 0)) 1255 + } 1256 + if (!send_coredump_ack(fd_coredump, &req, COREDUMP_KERNEL | COREDUMP_WAIT, 0)) { 1257 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: send_coredump_ack failed\n"); 1478 1258 goto out; 1479 - if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) 1259 + } 1260 + if (!read_marker(fd_coredump, COREDUMP_MARK_REQACK)) { 1261 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: read_marker failed\n"); 1480 1262 goto out; 1263 + } 1481 1264 fd_core_file = open_coredump_tmpfile(self->fd_tmpfs_detached); 1482 - if (fd_core_file < 0) 1265 + if (fd_core_file < 0) { 1266 + fprintf(stderr, "socket_multiple_crashing_coredumps_epoll_workers: open_coredump_tmpfile failed: %m\n"); 1483 1267 goto out; 1268 + } 1484 1269 pid_t worker = fork(); 1485 1270 if (worker == 0) { 1486 1271 close(fd_server);