|
| 1 | +.TH "seccomp_transaction_start" 3 "21 September 2023" "[email protected]" "libseccomp Documentation" |
| 2 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 3 | +.SH NAME |
| 4 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 5 | +seccomp_transaction_start, seccomp_transaction_commit, seccomp_transaction_reject \- Manage seccomp filter transactions |
| 6 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 7 | +.SH SYNOPSIS |
| 8 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 9 | +.nf |
| 10 | +.B #include <seccomp.h> |
| 11 | +.sp |
| 12 | +.B typedef void * scmp_filter_ctx; |
| 13 | +.sp |
| 14 | +.BI "int seccomp_transaction_start(scmp_filter_ctx " ctx "); |
| 15 | +.BI "int seccomp_transaction_commit(scmp_filter_ctx " ctx "); |
| 16 | +.BI "void seccomp_transaction_reject(scmp_filter_ctx " ctx "); |
| 17 | +.sp |
| 18 | +Link with \fI\-lseccomp\fP. |
| 19 | +.fi |
| 20 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 21 | +.SH DESCRIPTION |
| 22 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 23 | +.P |
| 24 | +The |
| 25 | +.BR seccomp_transaction_start () |
| 26 | +function starts a new seccomp filter |
| 27 | +transaction that the caller can use to perform any number of filter |
| 28 | +modifications which can then be committed to the filter using |
| 29 | +.BR seccomp_transaction_commit () |
| 30 | +or rejected using |
| 31 | +.BR seccomp_transaction_reject (). |
| 32 | +It is important to note that transactions only affect the seccomp filter state |
| 33 | +while it is being managed by libseccomp; seccomp filters which have been loaded |
| 34 | +into the kernel can not be modified, only new seccomp filters can be added on |
| 35 | +top of the existing loaded filter stack. |
| 36 | +.P |
| 37 | +Finishing, or committing, a transaction is optional, although it is encouraged. |
| 38 | +At any point in time, regardless of the transaction state, the seccomp filter |
| 39 | +is determined by all of the libseccomp operations performed on the filter up to |
| 40 | +that point. Committing a transaction simply flushes the transaction rollback |
| 41 | +marker of the current transaction making the filter changes permanent; |
| 42 | +rejecting a transaction rolls the filter state back to immediately before the |
| 43 | +transaction was started. |
| 44 | +.P |
| 45 | +Transactions can be nested arbitrarily deep with the |
| 46 | +.BR seccomp_transaction_commit () |
| 47 | +and |
| 48 | +.BR seccomp_transaction_reject () |
| 49 | +functions always operating on the deepest, or more recently started transaction. |
| 50 | +A nested set of filter modifications, even if committed, is still subject to |
| 51 | +rejection by shallower, or older transactions that have yet to be committed or |
| 52 | +rejected. |
| 53 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 54 | +.SH RETURN VALUE |
| 55 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 56 | +The |
| 57 | +.BR seccomp_transaction_start () |
| 58 | +and |
| 59 | +.BR seccomp_transaction_commit () |
| 60 | +functions return zero on success or one of the following error codes on |
| 61 | +failure: |
| 62 | +.TP |
| 63 | +.B -ENOMEM |
| 64 | +The library was unable to allocate enough memory. |
| 65 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 66 | +.SH EXAMPLES |
| 67 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 68 | +.nf |
| 69 | +#include <seccomp.h> |
| 70 | + |
| 71 | +int libseccomp_generate(scmp_filter_ctx *ctx) |
| 72 | +{ |
| 73 | + int rc; |
| 74 | + |
| 75 | + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(close), 0); |
| 76 | + if (rc) |
| 77 | + return rc; |
| 78 | + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit_group), 0); |
| 79 | + if (rc) |
| 80 | + return rc; |
| 81 | + rc = seccomp_rule_add(ctx, SCMP_ACT_ALLOW, SCMP_SYS(exit), 0); |
| 82 | + if (rc) |
| 83 | + return rc; |
| 84 | + |
| 85 | + return 0; |
| 86 | +} |
| 87 | + |
| 88 | +int main(int argc, char *argv[]) |
| 89 | +{ |
| 90 | + int rc = \-1; |
| 91 | + scmp_filter_ctx ctx; |
| 92 | + |
| 93 | + ctx = seccomp_init(SCMP_ACT_KILL); |
| 94 | + if (ctx == NULL) |
| 95 | + goto out; |
| 96 | + |
| 97 | + rc = seccomp_transaction_start(ctx) |
| 98 | + if (rc) |
| 99 | + goto out; |
| 100 | + rc = libseccomp_generate(ctx); |
| 101 | + if (rc == 0) { |
| 102 | + rc = seccomp_transaction_commit(ctx); |
| 103 | + if (rc) |
| 104 | + goto out; |
| 105 | + } else |
| 106 | + seccomp_transaction_reject(ctx); |
| 107 | + |
| 108 | + /* ... */ |
| 109 | + |
| 110 | +out: |
| 111 | + seccomp_release(ctx); |
| 112 | + return \-rc; |
| 113 | +} |
| 114 | +.fi |
| 115 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 116 | +.SH NOTES |
| 117 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 118 | +.P |
| 119 | +While the seccomp filter can be generated independent of the kernel, kernel |
| 120 | +support is required to load and enforce the seccomp filter generated by |
| 121 | +libseccomp. |
| 122 | +.P |
| 123 | +The libseccomp project site, with more information and the source code |
| 124 | +repository, can be found at https://github.com/seccomp/libseccomp. This tool, |
| 125 | +as well as the libseccomp library, is currently under development, please |
| 126 | +report any bugs at the project site or directly to the author. |
| 127 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 128 | +.SH AUTHOR |
| 129 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 130 | + |
| 131 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 132 | +.SH SEE ALSO |
| 133 | +.\" ////////////////////////////////////////////////////////////////////////// |
| 134 | +.BR seccomp_init (3), |
0 commit comments