79
79
#include <linux/pagemap.h>
80
80
#include <linux/io_uring.h>
81
81
#include <linux/tracehook.h>
82
+ #include <linux/audit.h>
82
83
83
84
#define CREATE_TRACE_POINTS
84
85
#include <trace/events/io_uring.h>
@@ -917,6 +918,8 @@ struct io_op_def {
917
918
unsigned needs_async_setup : 1 ;
918
919
/* should block plug */
919
920
unsigned plug : 1 ;
921
+ /* skip auditing */
922
+ unsigned audit_skip : 1 ;
920
923
/* size of async data needed, if any */
921
924
unsigned short async_size ;
922
925
};
@@ -930,6 +933,7 @@ static const struct io_op_def io_op_defs[] = {
930
933
.buffer_select = 1 ,
931
934
.needs_async_setup = 1 ,
932
935
.plug = 1 ,
936
+ .audit_skip = 1 ,
933
937
.async_size = sizeof (struct io_async_rw ),
934
938
},
935
939
[IORING_OP_WRITEV ] = {
@@ -939,16 +943,19 @@ static const struct io_op_def io_op_defs[] = {
939
943
.pollout = 1 ,
940
944
.needs_async_setup = 1 ,
941
945
.plug = 1 ,
946
+ .audit_skip = 1 ,
942
947
.async_size = sizeof (struct io_async_rw ),
943
948
},
944
949
[IORING_OP_FSYNC ] = {
945
950
.needs_file = 1 ,
951
+ .audit_skip = 1 ,
946
952
},
947
953
[IORING_OP_READ_FIXED ] = {
948
954
.needs_file = 1 ,
949
955
.unbound_nonreg_file = 1 ,
950
956
.pollin = 1 ,
951
957
.plug = 1 ,
958
+ .audit_skip = 1 ,
952
959
.async_size = sizeof (struct io_async_rw ),
953
960
},
954
961
[IORING_OP_WRITE_FIXED ] = {
@@ -957,15 +964,20 @@ static const struct io_op_def io_op_defs[] = {
957
964
.unbound_nonreg_file = 1 ,
958
965
.pollout = 1 ,
959
966
.plug = 1 ,
967
+ .audit_skip = 1 ,
960
968
.async_size = sizeof (struct io_async_rw ),
961
969
},
962
970
[IORING_OP_POLL_ADD ] = {
963
971
.needs_file = 1 ,
964
972
.unbound_nonreg_file = 1 ,
973
+ .audit_skip = 1 ,
974
+ },
975
+ [IORING_OP_POLL_REMOVE ] = {
976
+ .audit_skip = 1 ,
965
977
},
966
- [IORING_OP_POLL_REMOVE ] = {},
967
978
[IORING_OP_SYNC_FILE_RANGE ] = {
968
979
.needs_file = 1 ,
980
+ .audit_skip = 1 ,
969
981
},
970
982
[IORING_OP_SENDMSG ] = {
971
983
.needs_file = 1 ,
@@ -983,18 +995,23 @@ static const struct io_op_def io_op_defs[] = {
983
995
.async_size = sizeof (struct io_async_msghdr ),
984
996
},
985
997
[IORING_OP_TIMEOUT ] = {
998
+ .audit_skip = 1 ,
986
999
.async_size = sizeof (struct io_timeout_data ),
987
1000
},
988
1001
[IORING_OP_TIMEOUT_REMOVE ] = {
989
1002
/* used by timeout updates' prep() */
1003
+ .audit_skip = 1 ,
990
1004
},
991
1005
[IORING_OP_ACCEPT ] = {
992
1006
.needs_file = 1 ,
993
1007
.unbound_nonreg_file = 1 ,
994
1008
.pollin = 1 ,
995
1009
},
996
- [IORING_OP_ASYNC_CANCEL ] = {},
1010
+ [IORING_OP_ASYNC_CANCEL ] = {
1011
+ .audit_skip = 1 ,
1012
+ },
997
1013
[IORING_OP_LINK_TIMEOUT ] = {
1014
+ .audit_skip = 1 ,
998
1015
.async_size = sizeof (struct io_timeout_data ),
999
1016
},
1000
1017
[IORING_OP_CONNECT ] = {
@@ -1009,14 +1026,19 @@ static const struct io_op_def io_op_defs[] = {
1009
1026
},
1010
1027
[IORING_OP_OPENAT ] = {},
1011
1028
[IORING_OP_CLOSE ] = {},
1012
- [IORING_OP_FILES_UPDATE ] = {},
1013
- [IORING_OP_STATX ] = {},
1029
+ [IORING_OP_FILES_UPDATE ] = {
1030
+ .audit_skip = 1 ,
1031
+ },
1032
+ [IORING_OP_STATX ] = {
1033
+ .audit_skip = 1 ,
1034
+ },
1014
1035
[IORING_OP_READ ] = {
1015
1036
.needs_file = 1 ,
1016
1037
.unbound_nonreg_file = 1 ,
1017
1038
.pollin = 1 ,
1018
1039
.buffer_select = 1 ,
1019
1040
.plug = 1 ,
1041
+ .audit_skip = 1 ,
1020
1042
.async_size = sizeof (struct io_async_rw ),
1021
1043
},
1022
1044
[IORING_OP_WRITE ] = {
@@ -1025,39 +1047,50 @@ static const struct io_op_def io_op_defs[] = {
1025
1047
.unbound_nonreg_file = 1 ,
1026
1048
.pollout = 1 ,
1027
1049
.plug = 1 ,
1050
+ .audit_skip = 1 ,
1028
1051
.async_size = sizeof (struct io_async_rw ),
1029
1052
},
1030
1053
[IORING_OP_FADVISE ] = {
1031
1054
.needs_file = 1 ,
1055
+ .audit_skip = 1 ,
1032
1056
},
1033
1057
[IORING_OP_MADVISE ] = {},
1034
1058
[IORING_OP_SEND ] = {
1035
1059
.needs_file = 1 ,
1036
1060
.unbound_nonreg_file = 1 ,
1037
1061
.pollout = 1 ,
1062
+ .audit_skip = 1 ,
1038
1063
},
1039
1064
[IORING_OP_RECV ] = {
1040
1065
.needs_file = 1 ,
1041
1066
.unbound_nonreg_file = 1 ,
1042
1067
.pollin = 1 ,
1043
1068
.buffer_select = 1 ,
1069
+ .audit_skip = 1 ,
1044
1070
},
1045
1071
[IORING_OP_OPENAT2 ] = {
1046
1072
},
1047
1073
[IORING_OP_EPOLL_CTL ] = {
1048
1074
.unbound_nonreg_file = 1 ,
1075
+ .audit_skip = 1 ,
1049
1076
},
1050
1077
[IORING_OP_SPLICE ] = {
1051
1078
.needs_file = 1 ,
1052
1079
.hash_reg_file = 1 ,
1053
1080
.unbound_nonreg_file = 1 ,
1081
+ .audit_skip = 1 ,
1082
+ },
1083
+ [IORING_OP_PROVIDE_BUFFERS ] = {
1084
+ .audit_skip = 1 ,
1085
+ },
1086
+ [IORING_OP_REMOVE_BUFFERS ] = {
1087
+ .audit_skip = 1 ,
1054
1088
},
1055
- [IORING_OP_PROVIDE_BUFFERS ] = {},
1056
- [IORING_OP_REMOVE_BUFFERS ] = {},
1057
1089
[IORING_OP_TEE ] = {
1058
1090
.needs_file = 1 ,
1059
1091
.hash_reg_file = 1 ,
1060
1092
.unbound_nonreg_file = 1 ,
1093
+ .audit_skip = 1 ,
1061
1094
},
1062
1095
[IORING_OP_SHUTDOWN ] = {
1063
1096
.needs_file = 1 ,
@@ -6591,6 +6624,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
6591
6624
if ((req -> flags & REQ_F_CREDS ) && req -> creds != current_cred ())
6592
6625
creds = override_creds (req -> creds );
6593
6626
6627
+ if (!io_op_defs [req -> opcode ].audit_skip )
6628
+ audit_uring_entry (req -> opcode );
6629
+
6594
6630
switch (req -> opcode ) {
6595
6631
case IORING_OP_NOP :
6596
6632
ret = io_nop (req , issue_flags );
@@ -6706,6 +6742,9 @@ static int io_issue_sqe(struct io_kiocb *req, unsigned int issue_flags)
6706
6742
break ;
6707
6743
}
6708
6744
6745
+ if (!io_op_defs [req -> opcode ].audit_skip )
6746
+ audit_uring_exit (!ret , ret );
6747
+
6709
6748
if (creds )
6710
6749
revert_creds (creds );
6711
6750
if (ret )
@@ -7360,6 +7399,8 @@ static int io_sq_thread(void *data)
7360
7399
set_cpus_allowed_ptr (current , cpu_online_mask );
7361
7400
current -> flags |= PF_NO_SETAFFINITY ;
7362
7401
7402
+ audit_alloc_kernel (current );
7403
+
7363
7404
mutex_lock (& sqd -> lock );
7364
7405
while (1 ) {
7365
7406
bool cap_entries , sqt_spin = false;
@@ -7425,6 +7466,8 @@ static int io_sq_thread(void *data)
7425
7466
io_run_task_work ();
7426
7467
mutex_unlock (& sqd -> lock );
7427
7468
7469
+ audit_free (current );
7470
+
7428
7471
complete (& sqd -> exited );
7429
7472
do_exit (0 );
7430
7473
}
0 commit comments