Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sanitizing user provided pointers #1215

Merged
merged 7 commits into from
Sep 14, 2024
Merged

Conversation

Oipo
Copy link
Contributor

@Oipo Oipo commented Aug 29, 2024

This PR introduces the initial plumbing for supporting address sanitizer checking the opague, user-provided pointers.
It does this by looping over the sqe's in userspace in __io_uring_submit, check their opcodes and use the sanitizer interface to check for memory poison values.

As this is a proof of concept, please take a look and suggest improvements/changes.

TODO

  • Fix tests, as there are quite a couple that do not clean up allocated buffers/iovecs
  • Look at IOSQE_USER_DATA_IS_POINTER and see if there is a better way
    • Couldn't think of a better way than to set it in sqe_user_data and remove it before submitting.
  • Add a test for IOSQE_USER_DATA_IS_POINTER
  • Verify changes to github actions works as intended

Click to show/hide original test output
Running test 232c93d07b74.t                                         4 sec
Running test 35fa71a030ca.t                                         5 sec
Running test 500f9fbadef8.t                                         0 sec
Running test 7ad0e4b2f83c.t                                         1 sec
Running test 8a9973408177.t                                         0 sec
Running test 917257daa0fe.t                                         0 sec
Running test a0908ae19763.t                                         0 sec
Running test a4c0b3decb33.t                                         0 sec
Running test accept.t                                               1 sec
Running test accept-link.t                                          0 sec
Running test accept-non-empty.t                                     Skipped
Running test accept-reuse.t                                         0 sec
Running test accept-test.t                                          0 sec
Running test across-fork.t                                          0 sec
Running test b19062a56726.t                                         0 sec
Running test b5837bd5311d.t                                         0 sec
Running test bind-listen.t                                          Skipped
Running test buf-ring.t                                             0 sec
Running test buf-ring-nommap.t                                      0 sec
Running test buf-ring-put.t                                         1 sec
Running test ce593a6c480a.t                                         1 sec
Running test close-opath.t                                          0 sec
Running test connect.t                                              0 sec
Running test connect-rep.t                                          0 sec
Running test coredump.t                                             0 sec
Running test cq-full.t                                              0 sec
Running test cq-overflow.t                                          11 sec
Running test cq-peek-batch.t                                        0 sec
Running test cq-ready.t                                             0 sec
Running test cq-size.t                                              0 sec
Running test d4ae271dfaae.t                                         0 sec
Running test d77a67ed5f27.t                                         0 sec
Running test defer.t                                                3 sec
Running test defer-taskrun.t                                        0 sec
Running test defer-tw-timeout.t                                     2 sec
Running test double-poll-crash.t                                    0 sec
Running test drop-submit.t                                          0 sec
Running test eeed8b54e0df.t                                         0 sec
Running test empty-eownerdead.t                                     0 sec
Running test eploop.t                                               0 sec
Running test eventfd.t                                              0 sec
Running test eventfd-disable.t                                      0 sec
Running test eventfd-reg.t                                          0 sec
Running test eventfd-ring.t                                         0 sec
Running test evloop.t                                               0 sec
Running test exec-target.t                                          0 sec
Running test exit-no-cleanup.t                                      0 sec
Running test fadvise.t                                              0 sec
Running test fallocate.t                                            0 sec
Running test fc2a85cb02ef.t                                         Test needs failslab/fail_futex/fail_page_alloc enabled, skipped
Skipped
Running test fd-install.t                                           0 sec
Running test fd-pass.t                                              0 sec
Running test fdinfo.t                                               0 sec
Running test file-register.t                                        3 sec
Running test files-exit-hang-poll.t                                 1 sec
Running test files-exit-hang-timeout.t                              1 sec
Running test file-update.t                                          0 sec
Running test file-verify.t                                          1 sec
Running test fixed-buf-iter.t                                       0 sec
Running test fixed-buf-merge.t                                      0 sec
Running test fixed-hugepage.t                                       0 sec
Running test fixed-link.t                                           0 sec
Running test fixed-reuse.t                                          0 sec
Running test fpos.t                                                 0 sec
Running test fsnotify.t                                             0 sec
Running test fsync.t                                                0 sec
Running test futex.t                                                0 sec
Running test hardlink.t                                             0 sec
Running test ignore-single-mmap.t                                   0 sec
Running test init-mem.t                                             Skipped
Running test io-cancel.t                                            2 sec
Running test iopoll.t                                               0 sec
Running test iopoll-leak.t                                          0 sec
Running test iopoll-overflow.t                                      1 sec
Running test io_uring_enter.t                                       0 sec
Running test io_uring_passthrough.t                                 Skipped
Running test io_uring_register.t                                    0 sec
Running test io_uring_setup.t                                       0 sec
Running test kallsyms.t                                             0 sec
Running test lfs-openat.t                                           0 sec
Running test lfs-openat-write.t                                     0 sec
Running test link.t                                                 0 sec
Running test link_drain.t                                           0 sec
Running test link-timeout.t                                         2 sec
Running test madvise.t                                              0 sec
Running test min-timeout.t                                          Skipped
Running test min-timeout-wait.t                                     Skipped
Running test mkdir.t                                                0 sec
Running test msg-ring.t                                             0 sec
Running test msg-ring-fd.t                                          0 sec
Running test msg-ring-flags.t                                       0 sec
Running test msg-ring-overflow.t                                    0 sec
Running test multicqes_drain.t                                      20 sec
Running test napi-test.t                                            0 sec
Running test no-mmap-inval.t                                        0 sec
Running test nolibc.t                                               0 sec
Running test nop-all-sizes.t                                        0 sec
Running test nop.t                                                  expected injected result, got -22
test_nop_inject failed
Normal ring test failed: default
Test nop.t failed with ret 1
Running test ooo-file-unreg.t                                       1 sec
Running test openat2.t                                              0 sec
Running test open-close.t                                           0 sec
Running test open-direct-link.t                                     0 sec
Running test open-direct-pick.t                                     0 sec
Running test personality.t                                          0 sec
Running test pipe-bug.t                                             1 sec
Running test pipe-eof.t                                             0 sec
Running test pipe-reuse.t                                           0 sec
Running test poll.t                                                 0 sec
Running test poll-cancel.t                                          0 sec
Running test poll-cancel-all.t                                      0 sec
Running test poll-cancel-ton.t                                      0 sec
Running test poll-link.t                                            0 sec
Running test poll-many.t                                            1 sec
Running test poll-mshot-overflow.t                                  0 sec
Running test poll-mshot-update.t                                    1 sec
Running test poll-race.t                                            0 sec
Running test poll-race-mshot.t                                      0 sec
Running test poll-ring.t                                            0 sec
Running test poll-v-poll.t                                          1 sec
Running test pollfree.t                                             10 sec
Running test probe.t                                                0 sec
Running test read-before-exit.t                                     0 sec
Running test read-mshot.t                                           Buffer ring register failed -22
test_inc 0 0 failed
Test read-mshot.t failed with ret 1
Running test read-mshot-empty.t                                     0 sec
Running test read-write.t                                           1 sec
Running test recv-msgall.t                                          0 sec
Running test recv-msgall-stream.t                                   0 sec
Running test recv-multishot.t                                       0 sec
Running test reg-fd-only.t                                          0 sec
Running test reg-hint.t                                             0 sec
Running test reg-reg-ring.t                                         0 sec
Running test regbuf-merge.t                                         0 sec
Running test register-restrictions.t                                0 sec
Running test rename.t                                               0 sec
Running test ringbuf-read.t                                         0 sec
Running test ringbuf-status.t                                       0 sec
Running test ring-leak2.t                                           1 sec
Running test ring-leak.t                                            Skipped
Running test rsrc_tags.t                                            0 sec
Running test rw_merge_test.t                                        0 sec
Running test self.t                                                 0 sec
Running test recvsend_bundle.t                                      Skipped
Running test recvsend_bundle-inc.t                                  Skipped
Running test send_recv.t                                            0 sec
Running test send_recvmsg.t                                         0 sec
Running test send-zerocopy.t                                        14 sec
Running test shared-wq.t                                            0 sec
Running test short-read.t                                           0 sec
Running test shutdown.t                                             0 sec
Running test sigfd-deadlock.t                                       0 sec
Running test single-issuer.t                                        0 sec
Running test skip-cqe.t                                             0 sec
Running test socket.t                                               0 sec
Running test socket-io-cmd.t                                        0 sec
Running test socket-getsetsock-cmd.t                                Test socket-getsetsock-cmd.t timed out (may not be a failure)
Running test socket-rw.t                                            0 sec
Running test socket-rw-eagain.t                                     0 sec
Running test socket-rw-offset.t                                     0 sec
Running test splice.t                                               0 sec
Running test sq-full.t                                              0 sec
Running test sq-full-cpp.t                                          0 sec
Running test sqpoll-disable-exit.t                                  0 sec
Running test sqpoll-exec.t                                          0 sec
Running test sq-poll-dup.t                                          0 sec
Running test sqpoll-exit-hang.t                                     1 sec
Running test sq-poll-kthread.t                                      2 sec
Running test sq-poll-share.t                                        1 sec
Running test sqpoll-sleep.t                                         0 sec
Running test sq-space_left.t                                        0 sec
Running test stdout.t                                               This is a pipe test
This is a fixed pipe test
0 sec
Running test submit-and-wait.t                                      1 sec
Running test submit-link-fail.t                                     0 sec
Running test submit-reuse.t                                         1 sec
Running test symlink.t                                              0 sec
Running test sync-cancel.t                                          0 sec
Running test teardowns.t                                            0 sec
Running test thread-exit.t                                          0 sec
Running test timeout.t                                              9 sec
Running test timeout-new.t                                          2 sec
Running test truncate.t                                             0 sec
Running test tty-write-dpoll.t                                      0 sec
Running test unlink.t                                               0 sec
Running test uring_cmd_ublk.t                                       Skipped
Running test version.t                                              0 sec
Running test waitid.t                                               1 sec
Running test wait-timeout.t                                         Skipped
Running test wakeup-hang.t                                          2 sec
Running test wq-aff.t                                               0 sec
Running test xattr.t                                                0 sec
Running test statx.t                                                0 sec
Running test sq-full-cpp.t                                          0 sec [0]
Tests timed out (1): <socket-getsetsock-cmd.t>
Tests failed (2): <nop.t> <read-mshot.t>
make[1]: *** [Makefile:290: runtests] Error 1
make[1]: Leaving directory '/home/oipo/Programming/liburing/test'
make: *** [Makefile:21: runtests] Error 2

Click to show/hide new, sanitized test output
Running test 232c93d07b74.t                                         4 sec
Running test 35fa71a030ca.t                                         5 sec
Running test 500f9fbadef8.t                                         0 sec
Running test 7ad0e4b2f83c.t                                         1 sec
Running test 8a9973408177.t                                         0 sec
Running test 917257daa0fe.t                                         0 sec
Running test a0908ae19763.t                                         0 sec
Running test a4c0b3decb33.t                                         1 sec
Running test accept.t                                               1 sec
Running test accept-link.t                                          0 sec
Running test accept-non-empty.t                                     Skipped
Running test accept-reuse.t                                         0 sec
Running test accept-test.t                                          0 sec
Running test across-fork.t                                          0 sec
Running test b19062a56726.t                                         0 sec
Running test b5837bd5311d.t                                         0 sec
Running test bind-listen.t                                          Skipped
Running test buf-ring.t                                             lret
lret
0 sec
Running test buf-ring-nommap.t                                      0 sec
Running test buf-ring-put.t                                         2 sec
Running test ce593a6c480a.t                                         1 sec
Running test close-opath.t                                          0 sec
Running test connect.t                                              0 sec
Running test connect-rep.t                                          0 sec
Running test coredump.t                                             Skipped
Running test cq-full.t                                              0 sec
Running test cq-overflow.t                                          10 sec
Running test cq-peek-batch.t                                        0 sec
Running test cq-ready.t                                             0 sec
Running test cq-size.t                                              0 sec
Running test d4ae271dfaae.t                                         0 sec
Running test d77a67ed5f27.t                                         0 sec
Running test defer.t                                                3 sec
Running test defer-taskrun.t                                        0 sec
Running test defer-tw-timeout.t                                     2 sec
Running test double-poll-crash.t                                    0 sec
Running test drop-submit.t                                          0 sec
Running test eeed8b54e0df.t                                         0 sec
Running test empty-eownerdead.t                                     0 sec
Running test eploop.t                                               0 sec
Running test eventfd.t                                              0 sec
Running test eventfd-disable.t                                      0 sec
Running test eventfd-reg.t                                          0 sec
Running test eventfd-ring.t                                         0 sec
Running test evloop.t                                               0 sec
Running test exec-target.t                                          0 sec
Running test exit-no-cleanup.t                                      exit-no-cleanup.t: exit-no-cleanup.c:56: thread_func: Assertion `!res' failed.
1 sec
Running test fadvise.t                                              0 sec
Running test fallocate.t                                            0 sec
Running test fc2a85cb02ef.t                                         Test needs failslab/fail_futex/fail_page_alloc enabled, skipped
Skipped
Running test fd-install.t                                           0 sec
Running test fd-pass.t                                              0 sec
Running test fdinfo.t                                               0 sec
Running test file-register.t                                        3 sec
Running test files-exit-hang-poll.t                                 1 sec
Running test files-exit-hang-timeout.t                              1 sec
Running test file-update.t                                          0 sec
Running test file-verify.t                                          0 sec
Running test fixed-buf-iter.t                                       0 sec
Running test fixed-buf-merge.t                                      0 sec
Running test fixed-hugepage.t                                       0 sec
Running test fixed-link.t                                           0 sec
Running test fixed-reuse.t                                          0 sec
Running test fpos.t                                                 0 sec
Running test fsnotify.t                                             0 sec
Running test fsync.t                                                0 sec
Running test futex.t                                                1 sec
Running test hardlink.t                                             0 sec
Running test ignore-single-mmap.t                                   0 sec
Running test init-mem.t                                             Skipped
Running test io-cancel.t                                            2 sec
Running test iopoll.t                                               0 sec
Running test iopoll-leak.t                                          0 sec
Running test iopoll-overflow.t                                      1 sec
Running test io_uring_enter.t                                       0 sec
Running test io_uring_passthrough.t                                 Skipped
Running test io_uring_register.t                                    0 sec
Running test io_uring_setup.t                                       0 sec
Running test kallsyms.t                                             0 sec
Running test lfs-openat.t                                           0 sec
Running test lfs-openat-write.t                                     0 sec
Running test link.t                                                 0 sec
Running test link_drain.t                                           0 sec
Running test link-timeout.t                                         2 sec
Running test madvise.t                                              0 sec
Running test min-timeout.t                                          Skipped
Running test min-timeout-wait.t                                     Skipped
Running test mkdir.t                                                0 sec
Running test msg-ring.t                                             0 sec
Running test msg-ring-fd.t                                          0 sec
Running test msg-ring-flags.t                                       0 sec
Running test msg-ring-overflow.t                                    0 sec
Running test multicqes_drain.t                                      21 sec
Running test napi-test.t                                            0 sec
Running test no-mmap-inval.t                                        0 sec
Running test nolibc.t                                               0 sec
Running test nop-all-sizes.t                                        0 sec
Running test nop.t                                                  expected injected result, got -22
test_nop_inject failed
Normal ring test failed: default
Test nop.t failed with ret 1
Running test ooo-file-unreg.t                                       1 sec
Running test openat2.t                                              0 sec
Running test open-close.t                                           0 sec
Running test open-direct-link.t                                     0 sec
Running test open-direct-pick.t                                     0 sec
Running test personality.t                                          0 sec
Running test pipe-bug.t                                             0 sec
Running test pipe-eof.t                                             0 sec
Running test pipe-reuse.t                                           0 sec
Running test poll.t                                                 0 sec
Running test poll-cancel.t                                          0 sec
Running test poll-cancel-all.t                                      0 sec
Running test poll-cancel-ton.t                                      0 sec
Running test poll-link.t                                            1 sec
Running test poll-many.t                                            0 sec
Running test poll-mshot-overflow.t                                  0 sec
Running test poll-mshot-update.t                                    2 sec
Running test poll-race.t                                            0 sec
Running test poll-race-mshot.t                                      0 sec
Running test poll-ring.t                                            0 sec
Running test poll-v-poll.t                                          1 sec
Running test pollfree.t                                             10 sec
Running test probe.t                                                0 sec
Running test read-before-exit.t                                     0 sec
Running test read-mshot.t                                           lret
lret
Buffer ring register failed -22
test_inc 0 0 failed

=================================================================
==855979==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 65536 byte(s) in 1 object(s) allocated from:
    #0 0x7f7d6e0b557c in __interceptor_posix_memalign ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:226
    #1 0x55654a5f85fa in test_inc /home/oipo/Programming/Ichor/external/liburing/test/read-mshot.c:73
    #2 0x60300000582f  (<unknown module>)

SUMMARY: AddressSanitizer: 65536 byte(s) leaked in 1 allocation(s).
Test read-mshot.t failed with ret 1
Running test read-mshot-empty.t                                     0 sec
Running test read-write.t                                           1 sec
Running test recv-msgall.t                                          0 sec
Running test recv-msgall-stream.t                                   0 sec
Running test recv-multishot.t                                       0 sec
Running test reg-fd-only.t                                          0 sec
Running test reg-hint.t                                             0 sec
Running test reg-reg-ring.t                                         0 sec
Running test regbuf-merge.t                                         0 sec
Running test register-restrictions.t                                0 sec
Running test rename.t                                               0 sec
Running test ringbuf-read.t                                         0 sec
Running test ringbuf-status.t                                       0 sec
Running test ring-leak2.t                                           1 sec
Running test ring-leak.t                                            Skipped
Running test rsrc_tags.t                                            0 sec
Running test rw_merge_test.t                                        0 sec
Running test self.t                                                 0 sec
Running test recvsend_bundle.t                                      Skipped
Running test recvsend_bundle-inc.t                                  lret
Skipped
Running test send_recv.t                                            0 sec
Running test send_recvmsg.t                                         0 sec
Running test send-zerocopy.t                                        41 sec
Running test shared-wq.t                                            0 sec
Running test short-read.t                                           0 sec
Running test shutdown.t                                             0 sec
Running test sigfd-deadlock.t                                       0 sec
Running test single-issuer.t                                        0 sec
Running test skip-cqe.t                                             0 sec
Running test socket.t                                               0 sec
Running test socket-io-cmd.t                                        0 sec
Running test socket-getsetsock-cmd.t                                Test socket-getsetsock-cmd.t timed out (may not be a failure)
Running test socket-rw.t                                            0 sec
Running test socket-rw-eagain.t                                     0 sec
Running test socket-rw-offset.t                                     0 sec
Running test splice.t                                               0 sec
Running test sq-full.t                                              0 sec
Running test sq-full-cpp.t                                          0 sec
Running test sqpoll-disable-exit.t                                  0 sec
Running test sqpoll-exec.t                                          0 sec
Running test sq-poll-dup.t                                          1 sec
Running test sqpoll-exit-hang.t                                     1 sec
Running test sq-poll-kthread.t                                      2 sec
Running test sq-poll-share.t                                        1 sec
Running test sqpoll-sleep.t                                         0 sec
Running test sq-space_left.t                                        0 sec
Running test stdout.t                                               This is a pipe test
This is a fixed pipe test
0 sec
Running test submit-and-wait.t                                      1 sec
Running test submit-link-fail.t                                     0 sec
Running test submit-reuse.t                                         0 sec
Running test symlink.t                                              0 sec
Running test sync-cancel.t                                          0 sec
Running test teardowns.t                                            0 sec
Running test thread-exit.t                                          0 sec
Running test timeout.t                                              9 sec
Running test timeout-new.t                                          2 sec
Running test truncate.t                                             0 sec
Running test tty-write-dpoll.t                                      0 sec
Running test unlink.t                                               0 sec
Running test uring_cmd_ublk.t                                       Skipped
Running test version.t                                              0 sec
Running test waitid.t                                               3 sec
Running test wait-timeout.t                                         Skipped
Running test wakeup-hang.t                                          2 sec
Running test wq-aff.t                                               0 sec
Running test xattr.t                                                0 sec
Running test statx.t                                                0 sec
Running test sq-full-cpp.t                                          0 sec [0]
Running test xfail_prep_link_timeout_out_of_scope.t                 Address 0x7ffcf92ddbe0 is located in stack of thread T0 at offset 32 in frame
    #0 0x564bd318c48f in main /home/oipo/Programming/Ichor/external/liburing/test/xfail_prep_link_timeout_out_of_scope.c:17

  This frame has 2 object(s):
    [32, 48) 'timespec' (line 31) <== Memory access at offset 32 is inside this variable
    [64, 280) 'ring' (line 21)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
0 sec
Running test xfail_register_buffers_out_of_scope.t                  0x60c000000400 is located 0 bytes inside of 128-byte region [0x60c000000400,0x60c000000480)
freed by thread T0 here:
    #0 0x7fe8744b4537 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x55e12db9d65a in main /home/oipo/Programming/Ichor/external/liburing/test/xfail_register_buffers_out_of_scope.c:39

previously allocated by thread T0 here:
    #0 0x7fe8744b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x55e12db9d58d in main /home/oipo/Programming/Ichor/external/liburing/test/xfail_register_buffers_out_of_scope.c:36

0 sec
Running test xfail_user_data_out_of_scope.t                         Address 0x7ffead7a13d0 is located in stack of thread T0 at offset 48 in frame
    #0 0x564f1090348f in main /home/oipo/Programming/Ichor/external/liburing/test/xfail_user_data_out_of_scope.c:17

  This frame has 2 object(s):
    [48, 52) 'i' (line 30) <== Memory access at offset 48 is inside this variable
    [64, 280) 'ring' (line 21)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
0 sec
Tests timed out (1): <socket-getsetsock-cmd.t>
Tests failed (2): <nop.t> <read-mshot.t>

git request-pull output:

The following changes since commit f2dc904171f36f32a6f2566d1e6b12398ec3bb4f:

  man/io_uring_prep_close: note on direct descriptor failure cases (2024-09-05 09:00:54 -0600)

are available in the Git repository at:

  [email protected]:Oipo/liburing.git 

for you to fetch changes up to 0a69f5fcef4c5bbe7c4f24fe01758514ef55d55c:

  CHANGELOG: add sanitizer adition (2024-09-12 20:28:27 +0200)

----------------------------------------------------------------
Michael de Lang (7):
      Clean up resources in various tests
      Skip tests that are not able to be run with sanitizers
      test/read-mshot-empty: set line-endings to unix
      src/setup: don't munmap user provided buffer
      Add support for sanitizing user provided pointers
      Add tests for testing sanitizer functionality
      CHANGELOG: add sanitizer adition

 .github/workflows/build.yml                 |  28 ++++++++++++++++++++++++++++
 CHANGELOG                                   |   1 +
 configure                                   |   9 +++++++++
 examples/Makefile                           |   6 ++++++
 src/Makefile                                |  17 ++++++++++++++---
 src/include/liburing.h                      |   4 ++++
 src/queue.c                                 |   3 +++
 src/register.c                              |  20 ++++++++++++++++++++
 src/sanitize.c                              | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/sanitize.h                              |  13 +++++++++++++
 src/setup.c                                 |   2 +-
 test/35fa71a030ca.c                         |   7 +++++++
 test/500f9fbadef8.c                         |   2 ++
 test/917257daa0fe.c                         |   7 +++++++
 test/Makefile                               |  24 +++++++++++++++++++++---
 test/a0908ae19763.c                         |   7 +++++++
 test/a4c0b3decb33.c                         |   7 +++++++
 test/accept.c                               |  18 ++++++++++++++----
 test/b19062a56726.c                         |   7 +++++++
 test/buf-ring-nommap.c                      |  13 ++++++++++---
 test/buf-ring.c                             |   2 ++
 test/coredump.c                             |   7 +++++++
 test/cq-overflow.c                          |  14 +++++++++++++-
 test/d4ae271dfaae.c                         |   7 ++++++-
 test/defer-tw-timeout.c                     |   3 +++
 test/double-poll-crash.c                    |   2 +-
 test/eeed8b54e0df.c                         |   2 ++
 test/exit-no-cleanup.c                      |  11 +++++++++++
 test/fadvise.c                              |   7 +++++--
 test/fdinfo.c                               |   2 ++
 test/file-register.c                        |  16 ++++++++++++++--
 test/fixed-buf-iter.c                       |   4 +++-
 test/fsnotify.c                             |   1 +
 test/futex.c                                |   8 +++++++-
 test/init-mem.c                             |   7 +++++--
 test/iopoll-leak.c                          |   2 ++
 test/kallsyms.c                             |   2 ++
 test/madvise.c                              |   5 ++++-
 test/no-mmap-inval.c                        |   2 ++
 test/read-mshot-empty.c                     | 309 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------
 test/read-write.c                           |   7 +++++++
 test/recv-msgall-stream.c                   |   3 +++
 test/recv-msgall.c                          |   5 +++++
 test/recvsend_bundle.c                      |  11 ++++++++++-
 test/regbuf-merge.c                         |   7 +++++++
 test/ringbuf-read.c                         |   1 +
 test/ringbuf-status.c                       |   6 +++++-
 test/runtests.sh                            |   5 ++++-
 test/short-read.c                           |   1 +
 test/splice.c                               |   4 +++-
 test/sqpoll-disable-exit.c                  |   8 ++++++++
 test/stdout.c                               |   2 ++
 test/uring_cmd_ublk.c                       |   4 +++-
 test/xfail_prep_link_timeout_out_of_scope.c |  46 ++++++++++++++++++++++++++++++++++++++++++++++
 test/xfail_register_buffers_out_of_scope.c  |  51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 55 files changed, 780 insertions(+), 184 deletions(-)
 create mode 100644 src/sanitize.c
 create mode 100644 src/sanitize.h
 create mode 100644 test/xfail_prep_link_timeout_out_of_scope.c
 create mode 100644 test/xfail_register_buffers_out_of_scope.c


By submitting this pull request, I acknowledge that:

  1. I have followed the above pull request guidelines.
  2. I have the rights to submit this work under the same license.
  3. I agree to a Developer Certificate of Origin (see https://developercertificate.org for more information).

@Oipo
Copy link
Contributor Author

Oipo commented Sep 1, 2024

As far as I can see, this PR is now complete and ready to be taken a look at. As I can't start the workflows, I cannot test the github actions changes so that's still a TODO.

@axboe
Copy link
Owner

axboe commented Sep 1, 2024

Thanks for doing this work! I'll kick off the tests. A bit in and out the next few days, but I'll take a closer look as soon as I can.

@axboe
Copy link
Owner

axboe commented Sep 1, 2024

For the failures, I think it'll auto-run it for followups since I approved the first one.

@Oipo
Copy link
Contributor Author

Oipo commented Sep 1, 2024

No hurry, during the week I usually have less free time. Anyways, unfortunately it seems that the workflows do not auto-start.

src/Makefile Outdated Show resolved Hide resolved
src/include/liburing.h Outdated Show resolved Hide resolved
src/queue.c Outdated Show resolved Hide resolved
src/queue.c Outdated Show resolved Hide resolved
src/queue.c Outdated Show resolved Hide resolved
test/accept.c Outdated Show resolved Hide resolved
@Oipo
Copy link
Contributor Author

Oipo commented Sep 5, 2024

Ready for the next round of review comments!

@axboe
Copy link
Owner

axboe commented Sep 5, 2024

As far as I can tell, just little code style issues here and there. I'll do some random comments here and there.

And I do think that it'd be nicer to have a configure switch for this, ./configure --enable-sanitizer or something. Then it'd also show up in the ./configure --help output, rather than be something you need to know about. And it could also tell you if it works with your compiler or not. For example, if I compile with gcc here, then I get segfaults. If I use clang, then it works (tried one of the xfail test cases).

test/accept.c Show resolved Hide resolved
test/cq-overflow.c Outdated Show resolved Hide resolved
test/d4ae271dfaae.c Outdated Show resolved Hide resolved
test/file-register.c Outdated Show resolved Hide resolved
@@ -87,6 +87,9 @@ static int test(struct io_uring *ring)
return 1;
}
io_uring_cqe_seen(ring, cqe);
for (i = 0; i < BUFFERS; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't understand what you mean. I copied this from line 39, which I didn't touch.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it's braces, don't need {} for a single line statement.

test/init-mem.c Outdated Show resolved Hide resolved
test/read-write.c Outdated Show resolved Hide resolved
src/include/liburing.h Outdated Show resolved Hide resolved
src/queue.c Outdated Show resolved Hide resolved
src/queue.c Outdated Show resolved Hide resolved
src/queue.c Outdated Show resolved Hide resolved
test/file-register.c Outdated Show resolved Hide resolved
test/init-mem.c Show resolved Hide resolved
test/regbuf-merge.c Outdated Show resolved Hide resolved
test/sqpoll-disable-exit.c Outdated Show resolved Hide resolved
@axboe
Copy link
Owner

axboe commented Sep 11, 2024

Thanks for your patience, it's been a journey working on a project with guidelines so different than my own.

Thanks for following through! If we can just get rid of these unrelated style changes (or put them in a separate commit, at least), and separate the changes to tests that can't work with the sanitizer, then we should be done with this.

@@ -28,6 +28,7 @@
#include "helpers.h"
#include "../src/syscall.h"

#ifdef CONFIG_USE_SANITIZER
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I've mentioned many times (sorry!), these changes should be BEFORE the commit adding sanitizer support. Not a huge deal and if that's the only thing left, then I'm inclined to just roll with it in the spirit of moving this forward.

BUT... the main commit adding sanitizer support should be JUST adding sanitizer support to the core, not fiddling with any tests at all. So ideally you'd yank the test changes out of this:

  1. The ones touching existing tests, should go BEFORE the commit adding the sanitizer support. It prepares them for when the sanitizer code exists, and will obviously be a no-op before that
  2. The ones adding new sanitizer tests, ideally would go AFTER the commit adding sanitizer support. This stands alone imho, as it's adding tests that test the sanitizer code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, it would be helpful to have a CONTRIBUTION.md detailing all the explanations you've given in this PR.

I'm currently still working on this PR, might do multiple pushes before it's done, I catch differences easier with the github web interface. I'll add a message when I'm done with it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I'll write something like that. Usually people just send smaller things and it's just about the commit message, but I can cover both.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you take a look at:

https://github.com/axboe/liburing/blob/master/CONTRIBUTING.md

when you have time? Would appreciate your feedback, especially if there are things I've missed. Consider it a first cut at trying to provide the rules for liburing commits, and reasonings behind it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you take a look at:

https://github.com/axboe/liburing/blob/master/CONTRIBUTING.md

when you have time? Would appreciate your feedback, especially if there are things I've missed. Consider it a first cut at trying to provide the rules for liburing commits, and reasonings behind it.

Here's a couple of things that I think would be valuable to add:

  • A list of style examples (space after if/while/for, braces on next line for functions, same line for if statements, no braces for 1-statement ifs/for's, where to put the *, variable definitions on top, etc)
  • Explicitly mentioning that there is a preference for separating tests from code changes in separate commits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and you could point towards an example PR (this one maybe) for how reviews go and how it should end up as.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicitly mentioning that there is a preference for separating tests from code changes in separate commits

To me, this should not be necessary, as it falls under the "commit should do 1 thing, and 1 thing only" rule.

For coding style, I think I'll just mention that any changes should follow the style of the code around it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and you could point towards an example PR (this one maybe) for how reviews go and how it should end up as.

With fear of that scaring people away ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Good additions otherwise!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a couple of things that I think would be valuable to add:

  • A list of style examples (space after if/while/for, braces on next line for functions, same line for if statements, no braces for 1-statement ifs/for's, where to put the *, variable definitions on top, etc)

I believe you can follow the Linux kernel coding style, as liburing is mainly written by Linux kernel developers.

See the list of style examples here:
https://www.kernel.org/doc/html/latest/process/coding-style.html

@Oipo
Copy link
Contributor Author

Oipo commented Sep 12, 2024

Alright, I think I have it now. Please let me know if there's anything else.

@Oipo
Copy link
Contributor Author

Oipo commented Sep 12, 2024

Updated a commit message, no code change.

src/include/liburing.h Outdated Show resolved Hide resolved
test/recvsend_bundle.c Outdated Show resolved Hide resolved
These tests leak resources, sometimes in the good path, sometimes
in the fail path. To satisfy LeakSanitizer, clean them up.

Signed-off-by: Michael de Lang <[email protected]>
These tests use some form of dereferencing custom pointers or force usage
after free, tripping up the address sanitizer.

Signed-off-by: Michael de Lang <[email protected]>
If the user provides a malloc()'d piece of memory, munmap will not be able
to unmap it, leaking a resource.

Signed-off-by: Michael de Lang <[email protected]>
@Oipo Oipo force-pushed the master branch 2 times, most recently from da02641 to cd6c9e1 Compare September 12, 2024 19:48
@Oipo
Copy link
Contributor Author

Oipo commented Sep 12, 2024

Had to add __attribute__((__unused__)), as including lib.h didn't seem wise in a header that is going to be installed. Let me know if there is a better way.

Anyways, I'm stopping for today, I'll check in again this weekend.

@axboe
Copy link
Owner

axboe commented Sep 12, 2024

I think it'd look cleaner if you just put this on top, and more readable:

diff --git a/src/include/liburing/sanitize.h b/src/include/liburing/sanitize.h
index f79471dcc088..162bf2f8a4e1 100644
--- a/src/include/liburing/sanitize.h
+++ b/src/include/liburing/sanitize.h
@@ -15,10 +15,21 @@ void liburing_sanitize_address(const void *addr);
 void liburing_sanitize_region(const void *addr, unsigned int len);
 void liburing_sanitize_iovecs(const struct iovec *iovecs, unsigned nr);
 #else
-static inline void liburing_sanitize_ring(struct io_uring __attribute__((__unused__)) *ring) {}
-static inline void liburing_sanitize_address(const void __attribute__((__unused__)) *addr) {}
-static inline void liburing_sanitize_region(const void __attribute__((__unused__)) *addr, unsigned int __attribute__((__unused__)) len) {}
-static inline void liburing_sanitize_iovecs(const struct iovec __attribute__((__unused__)) *iovecs, unsigned __attribute__((__unused__)) nr) {}
+#define __unused	__attribute__((__unused__))
+static inline void liburing_sanitize_ring(struct io_uring __unused *ring)
+{
+}
+static inline void liburing_sanitize_address(const void __unused *addr)
+{
+}
+static inline void liburing_sanitize_region(const void __unused *addr,
+					    unsigned int __unused len)
+{
+}
+static inline void liburing_sanitize_iovecs(const struct iovec __unused *iovecs,
+					    unsigned __unused nr)
+{
+}
 #endif
 
 #ifdef __cplusplus

This change introduces support for using the address sanitizer
checking the opague, user-provided pointers as well as various
pointers provided through functions.
It does this by looping over the sqe's in userspace in
`__io_uring_submit`, check their opcodes and use the sanitizer
interface to check for memory poison values.

Enabled through using the --enable-sanitizer flag when calling configure.

Signed-off-by: Michael de Lang <[email protected]>
This requires adding an "expected fail" mode to runtests.sh.
The tests use obvious bugs, like use after free, to force asan to report
an error and kill the test, exiting with error code 1.

Signed-off-by: Michael de Lang <[email protected]>
Signed-off-by: Michael de Lang <[email protected]>
@Oipo
Copy link
Contributor Author

Oipo commented Sep 14, 2024

Alright, barring any new comments, this looks about ready to go in I think.

@axboe axboe merged commit 54a82ff into axboe:master Sep 14, 2024
15 checks passed
@axboe
Copy link
Owner

axboe commented Sep 14, 2024

Alright, barring any new comments, this looks about ready to go in I think.

Agree, and honestly anything beyond that can be fixed up after the fact, should something come up. No need to further delay this one. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants