]> www.infradead.org Git - users/willy/xarray.git/commitdiff
cipso: fix total option length computation
authorOndrej Mosnacek <omosnace@redhat.com>
Fri, 7 Jun 2024 16:07:52 +0000 (18:07 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 14 Jun 2024 07:18:49 +0000 (08:18 +0100)
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: 014ab19a69c3 ("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>
net/ipv4/cipso_ipv4.c

index dd6d4601505806c79f008db69a98c0aff20eb516..5e9ac68444f8942b11ee4b8125e8f1820b24d899 100644 (file)
@@ -2013,12 +2013,16 @@ static int cipso_v4_delopt(struct ip_options_rcu __rcu **opt_ptr)
                 * from there we can determine the new total option length */
                iter = 0;
                optlen_new = 0;
-               while (iter < opt->opt.optlen)
-                       if (opt->opt.__data[iter] != IPOPT_NOP) {
+               while (iter < opt->opt.optlen) {
+                       if (opt->opt.__data[iter] == IPOPT_END) {
+                               break;
+                       } else if (opt->opt.__data[iter] == IPOPT_NOP) {
+                               iter++;
+                       } else {
                                iter += opt->opt.__data[iter + 1];
                                optlen_new = iter;
-                       } else
-                               iter++;
+                       }
+               }
                hdr_delta = opt->opt.optlen;
                opt->opt.optlen = (optlen_new + 3) & ~3;
                hdr_delta -= opt->opt.optlen;