Commit 9a868cd
committed
landlock: Fix handling of disconnected directories
We can get disconnected files or directories when they are visible and
opened from a bind mount, before being renamed/moved from the source of
the bind mount in a way that makes them inaccessible from the mount
point (i.e. out of scope).
Until now, access rights tied to files or directories opened through a
disconnected directory were collected by walking the related hierarchy
down to the root of this filesystem because the mount point couldn't be
found. This could lead to inconsistent access results, and
hard-to-debug renames, especially because such paths cannot be printed.
For a sandboxed task to create a disconnected directory, it needs to
have write access (i.e. FS_MAKE_REG, FS_REMOVE_FILE, and FS_REFER) to
the underlying source of the bind mount, and read access to the related
mount point. Because a sandboxed task cannot get more access than those
defined by its Landlock domain, this could only lead to inconsistent
access rights because of missing those that should be inherited from the
mount point hierarchy and inheriting from the hierarchy of the mounted
filesystem instead.
Landlock now handles files/directories opened from disconnected
directories like the mount point these disconnected directories were
opened from. This gives the guarantee that access rights on a
file/directory cannot be more than those at open time. The rationale is
that disconnected hierarchies might not be visible nor accessible to a
sandboxed task, and relying on the collected access rights from them
could introduce unexpected results, especially for rename actions
because of the access right comparison between the source and the
destination (see LANDLOCK_ACCESS_FS_REFER). This new behavior is much
less surprising to users and safer from an access point of view.
Unlike follow_dotdot(), we don't need to check for each directory if it
is part of the mount's root, but instead this is only checked when we
reached a root dentry (not a mount point), or when the access
request is about to be allowed. This limits the number of calls to
is_subdir() which walks down the hierarchy (again). This also avoids
checking path connection at the beginning of the walk for each mount
point, which would be racy.
Remove a wrong WARN_ON_ONCE() canary in collect_domain_accesses() and
fix comment.
This change increases the stack size with two Landlock layer masks
backups and a boolean, that are needed to reset the collected and
requested access rights from the latest mount point.
Because opened files have their access rights stored in the related file
security properties, their is no impact for disconnected or unlinked
files.
Make path_connected() public to stay consistent with the VFS. This
helper is used when we are about to allowed an access.
Cc: Günther Noack <[email protected]>
Cc: Song Liu <[email protected]>
Acked-by: Christian Brauner <[email protected]>
Reported-by: Tingmao Wang <[email protected]>
Closes: https://lore.kernel.org/r/[email protected]
Closes: https://lore.kernel.org/r/09b24128f86973a6022e6aa8338945fcfb9a33e4.1749925391.git.m@maowtm.org
Fixes: b91c3e4 ("landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER")
Fixes: cb2c7d1 ("landlock: Support filesystem access-control")
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mickaël Salaün <[email protected]>1 parent 6803b6e commit 9a868cd
4 files changed
+176
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
716 | 716 | | |
717 | 717 | | |
718 | 718 | | |
719 | | - | |
| 719 | + | |
720 | 720 | | |
721 | 721 | | |
722 | 722 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3252 | 3252 | | |
3253 | 3253 | | |
3254 | 3254 | | |
| 3255 | + | |
3255 | 3256 | | |
3256 | 3257 | | |
3257 | 3258 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
764 | 764 | | |
765 | 765 | | |
766 | 766 | | |
767 | | - | |
| 767 | + | |
| 768 | + | |
768 | 769 | | |
769 | 770 | | |
770 | 771 | | |
771 | | - | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
772 | 775 | | |
773 | 776 | | |
774 | 777 | | |
| |||
784 | 787 | | |
785 | 788 | | |
786 | 789 | | |
787 | | - | |
788 | | - | |
789 | 790 | | |
790 | 791 | | |
791 | 792 | | |
792 | 793 | | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
793 | 802 | | |
794 | 803 | | |
795 | 804 | | |
| |||
809 | 818 | | |
810 | 819 | | |
811 | 820 | | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
812 | 831 | | |
813 | 832 | | |
814 | 833 | | |
| |||
874 | 893 | | |
875 | 894 | | |
876 | 895 | | |
877 | | - | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | 896 | | |
882 | 897 | | |
883 | | - | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
884 | 903 | | |
885 | 904 | | |
886 | 905 | | |
| |||
893 | 912 | | |
894 | 913 | | |
895 | 914 | | |
896 | | - | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
897 | 924 | | |
| 925 | + | |
898 | 926 | | |
899 | 927 | | |
900 | 928 | | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
901 | 937 | | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
902 | 956 | | |
903 | 957 | | |
904 | 958 | | |
| |||
910 | 964 | | |
911 | 965 | | |
912 | 966 | | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
918 | | - | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
919 | 973 | | |
920 | 974 | | |
| 975 | + | |
921 | 976 | | |
922 | | - | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
923 | 983 | | |
924 | 984 | | |
925 | 985 | | |
926 | 986 | | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
927 | 1030 | | |
928 | 1031 | | |
929 | 1032 | | |
| |||
1011 | 1114 | | |
1012 | 1115 | | |
1013 | 1116 | | |
1014 | | - | |
| 1117 | + | |
1015 | 1118 | | |
1016 | 1119 | | |
1017 | 1120 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
1023 | 1129 | | |
1024 | 1130 | | |
1025 | 1131 | | |
| |||
1031 | 1137 | | |
1032 | 1138 | | |
1033 | 1139 | | |
1034 | | - | |
| 1140 | + | |
1035 | 1141 | | |
1036 | 1142 | | |
1037 | | - | |
| 1143 | + | |
1038 | 1144 | | |
1039 | 1145 | | |
1040 | | - | |
| 1146 | + | |
1041 | 1147 | | |
1042 | 1148 | | |
1043 | 1149 | | |
| |||
1054 | 1160 | | |
1055 | 1161 | | |
1056 | 1162 | | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
1057 | 1170 | | |
1058 | 1171 | | |
1059 | 1172 | | |
| |||
1062 | 1175 | | |
1063 | 1176 | | |
1064 | 1177 | | |
1065 | | - | |
1066 | | - | |
| 1178 | + | |
| 1179 | + | |
1067 | 1180 | | |
1068 | 1181 | | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
1069 | 1186 | | |
1070 | 1187 | | |
1071 | 1188 | | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1072 | 1199 | | |
1073 | 1200 | | |
1074 | 1201 | | |
| |||
1199 | 1326 | | |
1200 | 1327 | | |
1201 | 1328 | | |
1202 | | - | |
1203 | | - | |
1204 | | - | |
1205 | | - | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
1206 | 1332 | | |
1207 | 1333 | | |
1208 | | - | |
1209 | 1334 | | |
1210 | 1335 | | |
1211 | 1336 | | |
| |||
0 commit comments