lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250215233621.6277-1-ansuelsmth@gmail.com>
Date: Sun, 16 Feb 2025 00:36:18 +0100
From: Christian Marangi <ansuelsmth@...il.com>
To: Christian Marangi <ansuelsmth@...il.com>,
	Antoine Tenart <atenart@...nel.org>,
	Herbert Xu <herbert@...dor.apana.org.au>,
	"David S. Miller" <davem@...emloft.net>,
	Richard van Schagen <vschagen@...oud.com>,
	linux-crypto@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: Dan Carpenter <dan.carpenter@...aro.org>
Subject: [PATCH] crypto: inside-secure: eip93: Correctly handle return of for sg_nents_for_len

Fix smatch warning for sg_nents_for_len return value in Inside Secure
EIP93 driver.

The return value of sg_nents_for_len was assigned to an u32 and the
error was ignored and converted to a positive integer.

Rework the code to correctly handle the error from sg_nents_for_len to
mute smatch warning.

Fixes: 9739f5f93b78 ("crypto: eip93 - Add Inside Secure SafeXcel EIP-93 crypto engine support")
Reported-by: Dan Carpenter <dan.carpenter@...aro.org>
Signed-off-by: Christian Marangi <ansuelsmth@...il.com>
---
 .../crypto/inside-secure/eip93/eip93-common.c | 25 ++++++++++++++-----
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/inside-secure/eip93/eip93-common.c b/drivers/crypto/inside-secure/eip93/eip93-common.c
index 446a047c242d..66153aa2493f 100644
--- a/drivers/crypto/inside-secure/eip93/eip93-common.c
+++ b/drivers/crypto/inside-secure/eip93/eip93-common.c
@@ -202,7 +202,6 @@ int check_valid_request(struct eip93_cipher_reqctx *rctx)
 {
 	struct scatterlist *src = rctx->sg_src;
 	struct scatterlist *dst = rctx->sg_dst;
-	u32 src_nents, dst_nents;
 	u32 textsize = rctx->textsize;
 	u32 authsize = rctx->authsize;
 	u32 blksize = rctx->blksize;
@@ -210,6 +209,7 @@ int check_valid_request(struct eip93_cipher_reqctx *rctx)
 	u32 totlen_dst = rctx->assoclen + rctx->textsize;
 	u32 copy_len;
 	bool src_align, dst_align;
+	int src_nents, dst_nents;
 	int err = -EINVAL;
 
 	if (!IS_CTR(rctx->flags)) {
@@ -225,19 +225,24 @@ int check_valid_request(struct eip93_cipher_reqctx *rctx)
 	}
 
 	src_nents = sg_nents_for_len(src, totlen_src);
+	if (src_nents < 0)
+		return src_nents;
+
 	dst_nents = sg_nents_for_len(dst, totlen_dst);
+	if (dst_nents < 0)
+		return dst_nents;
 
 	if (src == dst) {
 		src_nents = max(src_nents, dst_nents);
 		dst_nents = src_nents;
-		if (unlikely((totlen_src || totlen_dst) && src_nents <= 0))
+		if (unlikely((totlen_src || totlen_dst) && !src_nents))
 			return err;
 
 	} else {
-		if (unlikely(totlen_src && src_nents <= 0))
+		if (unlikely(totlen_src && !src_nents))
 			return err;
 
-		if (unlikely(totlen_dst && dst_nents <= 0))
+		if (unlikely(totlen_dst && !dst_nents))
 			return err;
 	}
 
@@ -273,8 +278,16 @@ int check_valid_request(struct eip93_cipher_reqctx *rctx)
 			return err;
 	}
 
-	rctx->src_nents = sg_nents_for_len(rctx->sg_src, totlen_src);
-	rctx->dst_nents = sg_nents_for_len(rctx->sg_dst, totlen_dst);
+	src_nents = sg_nents_for_len(rctx->sg_src, totlen_src);
+	if (src_nents < 0)
+		return src_nents;
+
+	dst_nents = sg_nents_for_len(rctx->sg_dst, totlen_dst);
+	if (dst_nents < 0)
+		return dst_nents;
+
+	rctx->src_nents = src_nents;
+	rctx->dst_nents = dst_nents;
 
 	return 0;
 }
-- 
2.47.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ