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 6031B61FDF; Wed, 3 Jul 2024 11:05:23 +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=1720004723; cv=none; b=N5WE55hrW+FOdZCcMWerwk1LC2UEHHWp0uI27Xb1kJUMWtSvf3ahEqaJLTUhSXUBdWSnA/OyWAgM8gRhzx4XD4oS2BkKutWaFsGinBQQhYq1pH1QyUWuhv7z37QYnJ5iof1YBP6SPWmGb866qCCKvd6SAw1wUQOvsC0XS4ti7RY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004723; c=relaxed/simple; bh=Zgg/Oe2q5SYnFtuT6lomzmxqAK9I6A6YTd5LvT1bkLc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZDiE/QaTnjQ3/frVioaveJskWr4YJvfsVJcwYjKdbqMrtHX78Gk8tqdN+WBAUbQr9o2Xg5VPZT4uomNfuC9aCArc/9ywNFMpRZX7qKxLsXDGCK3RNdzwI7QRamXrpE6ufNWmZGekPZxOWJNSmSuHF8fQtPT/G6uF3PmwDmbbdtw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=TZaAmW0Q; 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="TZaAmW0Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA704C4AF0C; Wed, 3 Jul 2024 11:05:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720004723; bh=Zgg/Oe2q5SYnFtuT6lomzmxqAK9I6A6YTd5LvT1bkLc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TZaAmW0QoAAr0sztxotu9ASY11KHrr/DQgbAKXF8BJ+oQ5T/VlnHfDrkikEa+pwrP 7eL3HX72Wh6R3xd/ChTQbxkVeQZ7Bvc2OOezMjit9B3Lx2nj7pSnraNQcHK7JHFhcx lNi1AE68mMLTR9iPpyGbZdM3HB+BwBjufxxNoG2c= 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.10 138/290] cipso: fix total option length computation Date: Wed, 3 Jul 2024 12:38:39 +0200 Message-ID: <20240703102909.398472946@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703102904.170852981@linuxfoundation.org> References: <20240703102904.170852981@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-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 d4a4160159a92..c5da958e3bbdb 100644 --- a/net/ipv4/cipso_ipv4.c +++ b/net/ipv4/cipso_ipv4.c @@ -2016,12 +2016,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