From: "flichtenheld (Code Review)" Date: Tue, 9 Jan 2024 11:09:03 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <4f6be5e2fc56379333283583d98e6ceb7fce3d3b-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="MJvaDEJM6tw="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: adjust_payload_max_cbc: Fix Coverity issue "Division or modulo by zero" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --MJvaDEJM6tw= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/492?usp=3Demail to review the following change. Change subject: adjust_payload_max_cbc: Fix Coverity issue "Division or mod= ulo by zero" ...................................................................... adjust_payload_max_cbc: Fix Coverity issue "Division or modulo by zero" In error cases cipher_kt_block_size can return 0. This would lead to a divison by zero in round_down_uint. By reordering the conditional we can make sure we only take this path if we have a valid cipher to begin with. Change-Id: Iaef904ee2448dc0b9ad396d3ad9ae21b9dd6281e Signed-off-by: Frank Lichtenheld --- M src/openvpn/mss.c 1 file changed, 4 insertions(+), 7 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/92/492/1 diff --git a/src/openvpn/mss.c b/src/openvpn/mss.c index 1566c64..797ebf7 100644 --- a/src/openvpn/mss.c +++ b/src/openvpn/mss.c @@ -210,13 +210,7 @@ static inline size_t adjust_payload_max_cbc(const struct key_type *kt, size_t target) { - if (!cipher_kt_mode_cbc(kt->cipher)) - { - /* With stream ciphers (or block cipher in stream modes like CFB, = AEAD) - * we can just use the target as is */ - return target; - } - else + if (cipher_kt_mode_cbc(kt->cipher)) { /* With CBC we need at least one extra byte for padding and then n= eed * to ensure that the resulting CBC ciphertext length, which is al= ways @@ -225,6 +219,9 @@ target =3D round_down_size(target, block_size); return target - 1; } + /* With stream ciphers (or block cipher in stream modes like CFB, AEAD) + * we can just use the target as is */ + return target; } static size_t -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/492?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Iaef904ee2448dc0b9ad396d3ad9ae21b9dd6281e Gerrit-Change-Number: 492 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --MJvaDEJM6tw= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

Vi= ew Change

adjust_payload_max_cbc: Fix Coverity issue "Division or =
modulo by zero"

In error cases cipher_kt_block_size can return = 0.
This would lead to a divison by zero in round_down_uint.
By reorde= ring the conditional we can make sure we only
take this path if we have = a valid cipher to begin with.

Change-Id: Iaef904ee2448dc0b9ad396d3ad= 9ae21b9dd6281e
Signed-off-by: Frank Lichtenheld <frank@...2641...>=
---
M src/openvpn/mss.c
1 file changed, 4 insertions(+), 7 deleti= ons(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/chang=
es/92/492/1
diff --git a/src/openvpn/mss.c b/src/openvpn/mss.c
index 1566c64..797ebf7 100644
--- a/src/openvpn= /mss.c
+++ b/src/openvpn/mss.c
@@ -210,13 += 210,7 @@
static inline size_t
adjust_payl= oad_max_cbc(const struct key_type *kt, size_t target)
{
- if (!cipher_kt_mode_= cbc(kt->cipher))
- = {
- /* With st= ream ciphers (or block cipher in stream modes like CFB, AEAD)
- * we can just use the targ= et as is */

- re= turn target;
- }
- else
+ if (cipher_kt_mode_cbc(kt->ci= pher))
{
/* With CBC we need = at least one extra byte for padding and then need
= * to ensure that the resulting CBC ciphertext length, which is always
@@ -225,6 +219,9 @@
target =3D round_d= own_size(target, block_size);
return target - 1;
}
+ /* With stream ciphers (or block cipher in stream modes like CFB, AEA= D)
+ * we can jus= t use the target as is */
+ return target;
}

static size_t


To view, visit change 492.= To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iaef904ee2448dc0b9ad396d3ad9= ae21b9dd6281e
Gerrit-Change-Number: 492
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-MessageType: newchange
--MJvaDEJM6tw=--