From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 874B2173336; Wed, 3 Jul 2024 10:53:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004035; cv=none; b=Qu+eC/yEmpWbqe/LDoOlbrn8pksQ/Wldu6Bn9QPGXfkqAKGEU163xQl0zeQOK93Zj0r0JbjLiABBOD9pt8XHUeFsn/8LNNP3mvwt6o44AgICNLj7V0pQvM6kfnXJAaLCKKT8nIv7QiAJsmAMXvO3HtYPLz6+H+JjQj3E1mxK+2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004035; c=relaxed/simple; bh=iLFwtsOpH/Rx7G+hJ4rRlnsGZLy2p2kkTSTTvI9dDdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cWB+zaj4xn7Dh/EWxhRnWQ0Ew+iQ7dbn4DEN9yh0HbCXGxi64P04XWLm5od7XAQwHghOd+WT1e3vMHAXSeLeNeeVisIl+bmlTy0gbEqlRFycoYR7Bm5wN1WaKfl/zxv7INFVcre3RFowTzZH3mAk4kRE7QMdziheb14ocpdGJj4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pP3fY4l7; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="pP3fY4l7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A77FC32781; Wed, 3 Jul 2024 10:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720004035; bh=iLFwtsOpH/Rx7G+hJ4rRlnsGZLy2p2kkTSTTvI9dDdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pP3fY4l7Hwt05sLNqId8qhD5RrJHyGoB6JUVrD6A6Ev6PJljmWke5ZgXEYQqMIBPB RIFimpvQIE8IGcCgPSXFP3QCHmk1eGxc02ojKMw0mbyJDcD7vwEpgeapILwckx4Kyc THPg3d8UhMLI6nqkGQm4b2+eCHZjsuonioJwhpfE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ondrej Mosnacek , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 103/189] cipso: fix total option length computation Date: Wed, 3 Jul 2024 12:39:24 +0200 Message-ID: <20240703102845.390127799@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703102841.492044697@linuxfoundation.org> References: <20240703102841.492044697@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ondrej Mosnacek [ Upstream commit 9f36169912331fa035d7b73a91252d7c2512eb1a ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/cipso_ipv4.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c index 42eaad5e515f8..39a6f0d34208e 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c @@ -2015,12 +2015,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; -- 2.43.0