Skip to content

Commit 9f36169

Browse files
WOnder93davem330
authored andcommitted
cipso: fix total option length computation
As evident from the definition of ip_options_get(), the IP option IPOPT_END is used to pad the IP option data array, not IPOPT_NOP. Yet the loop that walks the IP options to determine the total IP options length in cipso_v4_delopt() doesn't take IPOPT_END into account. Fix it by recognizing the IPOPT_END value as the end of actual options. Fixes: 014ab19 ("selinux: Set socket NetLabel based on connection endpoint") Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4467c09 commit 9f36169

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

net/ipv4/cipso_ipv4.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,12 +2013,16 @@ static int cipso_v4_delopt(struct ip_options_rcu __rcu **opt_ptr)
20132013
* from there we can determine the new total option length */
20142014
iter = 0;
20152015
optlen_new = 0;
2016-
while (iter < opt->opt.optlen)
2017-
if (opt->opt.__data[iter] != IPOPT_NOP) {
2016+
while (iter < opt->opt.optlen) {
2017+
if (opt->opt.__data[iter] == IPOPT_END) {
2018+
break;
2019+
} else if (opt->opt.__data[iter] == IPOPT_NOP) {
2020+
iter++;
2021+
} else {
20182022
iter += opt->opt.__data[iter + 1];
20192023
optlen_new = iter;
2020-
} else
2021-
iter++;
2024+
}
2025+
}
20222026
hdr_delta = opt->opt.optlen;
20232027
opt->opt.optlen = (optlen_new + 3) & ~3;
20242028
hdr_delta -= opt->opt.optlen;

0 commit comments

Comments
 (0)