Commit 8e1a1bc
Florian Westphal
netfilter: nf_tables: avoid chain re-validation if possible
Hamza Mahfooz reports cpu soft lock-ups in
nft_chain_validate():
watchdog: BUG: soft lockup - CPU#1 stuck for 27s! [iptables-nft-re:37547]
[..]
RIP: 0010:nft_chain_validate+0xcb/0x110 [nf_tables]
[..]
nft_immediate_validate+0x36/0x50 [nf_tables]
nft_chain_validate+0xc9/0x110 [nf_tables]
nft_immediate_validate+0x36/0x50 [nf_tables]
nft_chain_validate+0xc9/0x110 [nf_tables]
nft_immediate_validate+0x36/0x50 [nf_tables]
nft_chain_validate+0xc9/0x110 [nf_tables]
nft_immediate_validate+0x36/0x50 [nf_tables]
nft_chain_validate+0xc9/0x110 [nf_tables]
nft_immediate_validate+0x36/0x50 [nf_tables]
nft_chain_validate+0xc9/0x110 [nf_tables]
nft_immediate_validate+0x36/0x50 [nf_tables]
nft_chain_validate+0xc9/0x110 [nf_tables]
nft_table_validate+0x6b/0xb0 [nf_tables]
nf_tables_validate+0x8b/0xa0 [nf_tables]
nf_tables_commit+0x1df/0x1eb0 [nf_tables]
[..]
Currently nf_tables will traverse the entire table (chain graph), starting
from the entry points (base chains), exploring all possible paths
(chain jumps). But there are cases where we could avoid revalidation.
Consider:
1 input -> j2 -> j3
2 input -> j2 -> j3
3 input -> j1 -> j2 -> j3
Then the second rule does not need to revalidate j2, and, by extension j3,
because this was already checked during validation of the first rule.
We need to validate it only for rule 3.
This is needed because chain loop detection also ensures we do not exceed
the jump stack: Just because we know that j2 is cycle free, its last jump
might now exceed the allowed stack size. We also need to update all
reachable chains with the new largest observed call depth.
Care has to be taken to revalidate even if the chain depth won't be an
issue: chain validation also ensures that expressions are not called from
invalid base chains. For example, the masquerade expression can only be
called from NAT postrouting base chains.
Therefore we also need to keep record of the base chain context (type,
hooknum) and revalidate if the chain becomes reachable from a different
hook location.
Reported-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
Closes: https://lore.kernel.org/netfilter-devel/20251118221735.GA5477@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net/
Tested-by: Hamza Mahfooz <hamzamahfooz@linux.microsoft.com>
Signed-off-by: Florian Westphal <fw@strlen.de>1 parent a67fd55 commit 8e1a1bc
File tree
2 files changed
+91
-12
lines changed- include/net/netfilter
- net/netfilter
2 files changed
+91
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1091 | 1091 | | |
1092 | 1092 | | |
1093 | 1093 | | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
1094 | 1117 | | |
1095 | 1118 | | |
1096 | 1119 | | |
| |||
1109 | 1132 | | |
1110 | 1133 | | |
1111 | 1134 | | |
| 1135 | + | |
1112 | 1136 | | |
1113 | 1137 | | |
1114 | 1138 | | |
| |||
1128 | 1152 | | |
1129 | 1153 | | |
1130 | 1154 | | |
| 1155 | + | |
1131 | 1156 | | |
1132 | 1157 | | |
1133 | | - | |
| 1158 | + | |
1134 | 1159 | | |
1135 | 1160 | | |
1136 | 1161 | | |
1137 | 1162 | | |
1138 | 1163 | | |
1139 | 1164 | | |
1140 | 1165 | | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
1148 | 1166 | | |
1149 | 1167 | | |
1150 | 1168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
126 | 149 | | |
127 | 150 | | |
128 | 151 | | |
| |||
4079 | 4102 | | |
4080 | 4103 | | |
4081 | 4104 | | |
| 4105 | + | |
| 4106 | + | |
| 4107 | + | |
| 4108 | + | |
| 4109 | + | |
| 4110 | + | |
| 4111 | + | |
| 4112 | + | |
| 4113 | + | |
| 4114 | + | |
| 4115 | + | |
| 4116 | + | |
| 4117 | + | |
| 4118 | + | |
| 4119 | + | |
| 4120 | + | |
| 4121 | + | |
| 4122 | + | |
| 4123 | + | |
| 4124 | + | |
| 4125 | + | |
| 4126 | + | |
| 4127 | + | |
4082 | 4128 | | |
4083 | 4129 | | |
4084 | 4130 | | |
| |||
4088 | 4134 | | |
4089 | 4135 | | |
4090 | 4136 | | |
4091 | | - | |
| 4137 | + | |
4092 | 4138 | | |
4093 | 4139 | | |
4094 | 4140 | | |
4095 | 4141 | | |
4096 | 4142 | | |
| 4143 | + | |
4097 | 4144 | | |
4098 | 4145 | | |
4099 | 4146 | | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
| 4152 | + | |
| 4153 | + | |
| 4154 | + | |
| 4155 | + | |
4100 | 4156 | | |
4101 | 4157 | | |
4102 | 4158 | | |
| |||
4117 | 4173 | | |
4118 | 4174 | | |
4119 | 4175 | | |
| 4176 | + | |
4120 | 4177 | | |
4121 | 4178 | | |
4122 | 4179 | | |
| |||
4128 | 4185 | | |
4129 | 4186 | | |
4130 | 4187 | | |
4131 | | - | |
| 4188 | + | |
4132 | 4189 | | |
4133 | 4190 | | |
4134 | 4191 | | |
| |||
4137 | 4194 | | |
4138 | 4195 | | |
4139 | 4196 | | |
4140 | | - | |
| 4197 | + | |
4141 | 4198 | | |
4142 | 4199 | | |
4143 | 4200 | | |
4144 | 4201 | | |
4145 | | - | |
| 4202 | + | |
| 4203 | + | |
| 4204 | + | |
| 4205 | + | |
| 4206 | + | |
4146 | 4207 | | |
4147 | 4208 | | |
4148 | 4209 | | |
| |||
0 commit comments