diff mbox series

[v2] crypto: af_alg - check possible NULL pointer

Message ID 20211231014036.1870631-1-jiasheng@iscas.ac.cn
State Accepted
Commit 5f21d7d283dd82865bdb0123795b3accf0d42b67
Headers show
Series [v2] crypto: af_alg - check possible NULL pointer | expand

Commit Message

Jiasheng Jiang Dec. 31, 2021, 1:40 a.m. UTC
Because of the possible alloc failure of the alloc_page(), it could
return NULL pointer.
And there is a check below the sg_assign_page().
But it will be more logical to move the NULL check before the
sg_assign_page().

Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
---
Changelog:

v1 -> v2

* Change 1. Move the previous check in front of sg_assign_page().
---
 crypto/af_alg.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Herbert Xu Jan. 7, 2022, 3:34 a.m. UTC | #1
On Fri, Dec 31, 2021 at 09:40:36AM +0800, Jiasheng Jiang wrote:
> Because of the possible alloc failure of the alloc_page(), it could
> return NULL pointer.
> And there is a check below the sg_assign_page().
> But it will be more logical to move the NULL check before the
> sg_assign_page().
> 
> Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
> ---
> Changelog:
> 
> v1 -> v2
> 
> * Change 1. Move the previous check in front of sg_assign_page().
> ---
>  crypto/af_alg.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Patch applied with modified Subject line.  Thanks.
diff mbox series

Patch

diff --git a/crypto/af_alg.c b/crypto/af_alg.c
index 18cc82dc4a42..f79e446d8132 100644
--- a/crypto/af_alg.c
+++ b/crypto/af_alg.c
@@ -931,16 +931,19 @@  int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
 			sg_unmark_end(sg + sgl->cur - 1);
 
 		do {
+			struct page *pg;
 			unsigned int i = sgl->cur;
 
 			plen = min_t(size_t, len, PAGE_SIZE);
 
-			sg_assign_page(sg + i, alloc_page(GFP_KERNEL));
-			if (!sg_page(sg + i)) {
+			pg = alloc_page(GFP_KERNEL);
+			if (!pg) {
 				err = -ENOMEM;
 				goto unlock;
 			}
 
+			sg_assign_page(sg + i, pg);
+
 			err = memcpy_from_msg(page_address(sg_page(sg + i)),
 					      msg, plen);
 			if (err) {