| 1 | /* |
| 2 | * Copyright (C) 2025 Thomas Habets <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
| 18 | #define _GNU_SOURCEcxx . . $ `src/landlock.c:18:9`! |
| 19 | #if HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`! |
| 20 | #include "config.h"cxx . . $ `<file>/config.h`/ |
| 21 | #endif |
| 22 | |
| 23 | #include <dirent.h> |
| 24 | #include <stdio.h> |
| 25 | #include <errno.h> |
| 26 | #include <string.h> |
| 27 | #include <unistd.h> |
| 28 | |
| 29 | #if HAVE_LINUX_LANDLOCK_Hcxx . . $ `config.h:80:9`! |
| 30 | #if HAS_LANDLOCKcxx . . $ `config.h:14:9`! |
| 31 | #include<linux/landlock.h> |
| 32 | #include<sys/syscall.h> |
| 33 | #define ACTUALLY_USE_LANDLOCKcxx . . $ `src/landlock.c:33:9`! 1 |
| 34 | #endif |
| 35 | #endif |
| 36 | |
| 37 | #include "arping.h"cxx . . $ `<file>/src/arping.h`/ |
| 38 | #include "cast.h"cxx . . $ `<file>/src/cast.h`/ |
| 39 | |
| 40 | #ifdef ACTUALLY_USE_LANDLOCKcxx . . $ `src/landlock.c:33:9`! |
| 41 | static int ll_create_rulesetcxx . . $ ll_create_ruleset(cd8985a7a52c1b7).(const struct landlock_ruleset_attrcxx . . $ landlock_ruleset_attr# *attr, size_t size, __u32cxx . . $ __u32# flags) { |
| 42 | return cast_long_intcxx . . $ cast_long_int(88bca37028cca5d2).(syscallcxx . . $ syscall(523f12be2d96faea).(SYS_landlock_create_rulesetcxx . . $ `<external>/16530160117609833761/syscall.h:851:10`!, attr, size, flags), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 43 | } |
| 44 | /* |
| 45 | static int ll_add_rule(int ruleset_fd, enum landlock_rule_type type, const void *rule_attr, __u32 flags) { |
| 46 | return syscall(SYS_landlock_add_rule, ruleset_fd, type, rule_attr, flags); |
| 47 | } |
| 48 | */ |
| 49 | static long ll_restrict_selfcxx . . $ ll_restrict_self(2792881f56f9bfe2).(int ruleset_fd, __u32cxx . . $ __u32# flags) { |
| 50 | return syscallcxx . . $ syscall(523f12be2d96faea).(SYS_landlock_restrict_selfcxx . . $ `<external>/16530160117609833761/syscall.h:855:10`!, ruleset_fd, flags); |
| 51 | } |
| 52 | #endif |
| 53 | |
| 54 | void |
| 55 | drop_landlockcxx . . $ drop_landlock(d878ad36e69247c7).() |
| 56 | { |
| 57 | #ifdef ACTUALLY_USE_LANDLOCKcxx . . $ `src/landlock.c:33:9`! |
| 58 | struct landlock_ruleset_attrcxx . . $ landlock_ruleset_attr# ruleset_attr = { |
| 59 | .handled_access_fs = 0 |
| 60 | | LANDLOCK_ACCESS_FS_WRITE_FILEcxx . . $ `<external>/2214291076746038128/landlock.h:343:9`! |
| 61 | | LANDLOCK_ACCESS_FS_READ_FILEcxx . . $ `<external>/2214291076746038128/landlock.h:344:9`! |
| 62 | | LANDLOCK_ACCESS_FS_READ_DIRcxx . . $ `<external>/2214291076746038128/landlock.h:345:9`! |
| 63 | | LANDLOCK_ACCESS_FS_REMOVE_DIRcxx . . $ `<external>/2214291076746038128/landlock.h:346:9`! |
| 64 | | LANDLOCK_ACCESS_FS_REMOVE_FILEcxx . . $ `<external>/2214291076746038128/landlock.h:347:9`! |
| 65 | | LANDLOCK_ACCESS_FS_MAKE_CHARcxx . . $ `<external>/2214291076746038128/landlock.h:348:9`! |
| 66 | | LANDLOCK_ACCESS_FS_MAKE_DIRcxx . . $ `<external>/2214291076746038128/landlock.h:349:9`! |
| 67 | | LANDLOCK_ACCESS_FS_MAKE_REGcxx . . $ `<external>/2214291076746038128/landlock.h:350:9`! |
| 68 | | LANDLOCK_ACCESS_FS_MAKE_SOCKcxx . . $ `<external>/2214291076746038128/landlock.h:351:9`! |
| 69 | | LANDLOCK_ACCESS_FS_MAKE_FIFOcxx . . $ `<external>/2214291076746038128/landlock.h:352:9`! |
| 70 | #ifdef LANDLOCK_ACCESS_FS_REFERcxx . . $ `<external>/2214291076746038128/landlock.h:355:9`! |
| 71 | | LANDLOCK_ACCESS_FS_REFERcxx . . $ `<external>/2214291076746038128/landlock.h:355:9`! |
| 72 | #endif |
| 73 | | LANDLOCK_ACCESS_FS_MAKE_BLOCKcxx . . $ `<external>/2214291076746038128/landlock.h:353:9`! |
| 74 | | LANDLOCK_ACCESS_FS_MAKE_SYMcxx . . $ `<external>/2214291076746038128/landlock.h:354:9`! |
| 75 | #ifdef LANDLOCK_ACCESS_FS_TRUNCATEcxx . . $ `<external>/2214291076746038128/landlock.h:356:9`! |
| 76 | | LANDLOCK_ACCESS_FS_TRUNCATEcxx . . $ `<external>/2214291076746038128/landlock.h:356:9`! |
| 77 | #endif |
| 78 | #ifdef LANDLOCK_ACCESS_FS_IOCTL_DEVcxx . . $ `<external>/2214291076746038128/landlock.h:357:9`! |
| 79 | | LANDLOCK_ACCESS_FS_IOCTL_DEVcxx . . $ `<external>/2214291076746038128/landlock.h:357:9`! |
| 80 | #endif |
| 81 | | LANDLOCK_ACCESS_FS_EXECUTEcxx . . $ `<external>/2214291076746038128/landlock.h:342:9`!, |
| 82 | #ifdef LANDLOCK_ACCESS_NET_BIND_TCPcxx . . $ `<external>/2214291076746038128/landlock.h:378:9`! |
| 83 | .handled_access_net = |
| 84 | LANDLOCK_ACCESS_NET_BIND_TCPcxx . . $ `<external>/2214291076746038128/landlock.h:378:9`! |
| 85 | | LANDLOCK_ACCESS_NET_CONNECT_TCPcxx . . $ `<external>/2214291076746038128/landlock.h:379:9`!, |
| 86 | #endif |
| 87 | #ifdef LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKETcxx . . $ `<external>/2214291076746038128/landlock.h:403:9`! |
| 88 | .scoped = |
| 89 | LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKETcxx . . $ `<external>/2214291076746038128/landlock.h:403:9`! |
| 90 | | LANDLOCK_SCOPE_SIGNALcxx . . $ `<external>/2214291076746038128/landlock.h:404:9`!, |
| 91 | #endif |
| 92 | }; |
| 93 | int ruleset = ll_create_rulesetcxx . . $ ll_create_ruleset(cd8985a7a52c1b7).(&ruleset_attr, sizeof(ruleset_attr), 0); |
| 94 | if (ruleset < 0) { |
| 95 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "arping: Failed to create landlock ruleset: %s\n", |
| 96 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 97 | return; |
| 98 | } |
| 99 | if (ll_restrict_selfcxx . . $ ll_restrict_self(2792881f56f9bfe2).(ruleset, 0)) { |
| 100 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "arping: Failed to restrict with landlock: %s\n", |
| 101 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 102 | closecxx . . $ close(7864480464b09eea).(ruleset); |
| 103 | return; |
| 104 | } |
| 105 | closecxx . . $ close(7864480464b09eea).(ruleset); |
| 106 | DIRcxx . . $ DIR# *de = opendircxx . . $ opendir(f465d4b65cec8dd2).("/"); |
| 107 | if (de) { |
| 108 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "arping: landlock failed to take effect\n"); |
| 109 | closedircxx . . $ closedir(ac30a447bc7c2f80).(de); |
| 110 | } else if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EACCEScxx . . $ `<external>/8987895939074593727/errno-base.h:17:9`!) { |
| 111 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "arping: landlock caused error not EACCES: %s\n", |
| 112 | strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 113 | } |
| 114 | if (verbosecxx . . $ verbose. > 0) { |
| 115 | printfcxx . . $ printf(581fddd72a8db8fc).("arping: Landlock enabled\n"); |
| 116 | } |
| 117 | #endif |
| 118 | } |
| 119 | |
| 120 | /* ---- Emacs Variables ---- |
| 121 | * Local Variables: |
| 122 | * c-basic-offset: 8 |
| 123 | * indent-tabs-mode: nil |
| 124 | * End: |
| 125 | * |
| 126 | * vim: ts=8 sw=8 |
| 127 | */ |