crypto: af_alg - cast ki_complete call's ternary operator variables to long.
The ki_complete called from af_alg_async_cb use ternary operator to get the value of second argument.As err is signed int while resultlen is unsigned int, by the precedence rule err is also processed as unsigned int and lose its original value.Hence, it is advised to cast both err and resultlen as long which is expected by the definition of ki_complete call as its 2nd argument. This will retain the original signed value of err.
Declaration of ki_complete in file linux/include/linux/fs.h in struct
kiocb {...
void (*ki_complete)(struct kiocb *iocb, long ret, long ret2); ...
}
--- crypto/af_alg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/af_alg.c +1 -1
@@ -1048,7 +1048,7 @@ void af_alg_async_cb(struct crypto_async_request *_req, int err)af_alg_free_resources (areq);sock_put (sk); - iocb->ki_complete (iocb, err ? err : resultlen,0 ); + iocb->ki_complete (iocb, err ? (long )err : (long )resultlen,0 ); }EXPORT_SYMBOL_GPL (af_alg_async_cb);
Signature · 1 line
1.8.3.1
Herbert Xu
maintainerQuoted 24 lines · Atul Gupta
The
ki_completecalled fromaf_alg_async_cbuse ternary operator to get the value of second argument.As err is signed int while resultlen is unsigned int, by the precedence rule err is also processed as unsigned int and lose its original value.Hence, it is advised to cast both err and resultlen as long which is expected by the definition ofki_completecall as its 2nd argument. This will retain the original signed value of err.Declaration of
ki_completein filelinux/include/linux/fs.hin struct
kiocb {...void (*ki_complete)(struct kiocb *iocb, long ret, long ret2); ...}
Signed-off-by Atul Gupta <[email protected]>--- crypto/af_alg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)crypto/af_alg.c +0
-0
crypto/af_alg.c void af_alg_async_cb(struct crypto_async_request *_req, int err) · line 1051
Quoted 5 lines
crypto/af_alg.c +1
-1@@ -1048,7 +1048,7 @@ void af_alg_async_cb(struct crypto_async_request *_req, int err)af_alg_free_resources (areq);sock_put (sk); - iocb->ki_complete (iocb, err ? err : resultlen,0 ); + iocb->ki_complete (iocb, err ? (long )err : (long )resultlen,0 );
Why are you casting err when it's already signed? You can rewrite it as
err ?: (int)resultlen
Please also add a fixes header for the commit that introduced this bug.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt