Skip to contentSkip to conversation

crypto: AF_ALG - remove SGL terminator indicator when chaining

PATCH RESEND Applied Stephan Mueller 3 participants 7 messages Sep 21, 2017 – Oct 2, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 crypto: AF_ALG - remove SGL terminator indicator when chaining

The SGL is MAX_SGL_ENTS + 1 in size. The last SG entry is used for the chaining and is properly updated with the sg_chain invocation. During the filling-in of the initial SG entries, sg_mark_end is called for each SG entry. This is appropriate as long as no additional SGL is chained with the current SGL. However, when a new SGL is chained and the last SG entry is updated with sg_chain, the last but one entry still contains the end marker from the sg_mark_end. This end marker must be removed as otherwise a walk of the chained SGLs will cause a NULL pointer dereference at the last but one SG entry, because sg_next will return NULL.

The patch only applies to all kernels up to and including 4.13. The patch 2d97591ef43d0587be22ad1b0d758d6df4999a0b added to 4.14-rc1 introduced a complete new code base which addresses this bug in a different way. Yet, that patch is too invasive for stable kernels and was therefore not marked for stable.

Fixes 8ff590903d5fc ("crypto: algif_skcipher - User-space interface

for skcipher operations")

---
 crypto/algif_skcipher.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/algif_skcipher.c +3 -1
index 43839b00fe6c..62449a8f14ce 100644
@@ -139,8 +139,10 @@ static int skcipher_alloc_sgl(struct sock *sk)
 		sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
 		sgl->cur = 0;
 
-		if (sg)
+		if (sg) {
 			sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
+			sg_unmark_end(sg + (MAX_SGL_ENTS - 1));
+		}
 
 		list_add_tail(&sgl->list, &ctx->tsgl);
 	}
Signature · 1 line
2.13.5
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Stephan Mueller

The SGL is MAX_SGL_ENTS + 1 in size. The last SG entry is used for the chaining and is properly updated with the sg_chain invocation. During the filling-in of the initial SG entries, sg_mark_end is called for each SG entry. This is appropriate as long as no additional SGL is chained with the current SGL. However, when a new SGL is chained and the last SG entry is updated with sg_chain, the last but one entry still contains the end marker from the sg_mark_end. This end marker must be removed as otherwise a walk of the chained SGLs will cause a NULL pointer dereference at the last but one SG entry, because sg_next will return NULL.

The patch only applies to all kernels up to and including 4.13. The patch 2d97591ef43d0587be22ad1b0d758d6df4999a0b added to 4.14-rc1 introduced a complete new code base which addresses this bug in a different way. Yet, that patch is too invasive for stable kernels and was therefore not marked for stable.

Quoted 5 lines
Fixes 8ff590903d5fc ("crypto: algif_skcipher - User-space interface

for skcipher operations")

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
maintainer Applied
#2 lore raw

Patch "[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining" has been added to the 3.18-stable tree

In reply to Stephan Mueller

This is a note to let you know that I've just added the patch titled

[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining

to the 3.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch
and it can be found in the queue-3.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Fri Sep 22 11:04:43 2017

From: Stephan Mueller <[email protected]>
Date: Thu, 21 Sep 2017 10:16:53 +0200
Subject: [PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining
To: [email protected], [email protected]
Cc: [email protected]
Message-ID: <[email protected]>

From: Stephan Mueller <[email protected]>

Fixed differently upstream as commit 2d97591ef43d ("crypto: af_alg - consolidation of duplicate code")

The SGL is MAX_SGL_ENTS + 1 in size. The last SG entry is used for the chaining and is properly updated with the sg_chain invocation. During the filling-in of the initial SG entries, sg_mark_end is called for each SG entry. This is appropriate as long as no additional SGL is chained with the current SGL. However, when a new SGL is chained and the last SG entry is updated with sg_chain, the last but one entry still contains the end marker from the sg_mark_end. This end marker must be removed as otherwise a walk of the chained SGLs will cause a NULL pointer dereference at the last but one SG entry, because sg_next will return NULL.

The patch only applies to all kernels up to and including 4.13. The patch 2d97591ef43d0587be22ad1b0d758d6df4999a0b added to 4.14-rc1 introduced a complete new code base which addresses this bug in a different way. Yet, that patch is too invasive for stable kernels and was therefore not marked for stable.

Fixes 8ff590903d5fc ("crypto: algif_skcipher - User-space interface for skcipher operations")
---
 crypto/algif_skcipher.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/algif_skcipher.c +3 -1
@@ -92,8 +92,10 @@ static int skcipher_alloc_sgl(struct soc
 		sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
 		sgl->cur = 0;
 
-		if (sg)
+		if (sg) {
 			scatterwalk_sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
+			sg_unmark_end(sg + (MAX_SGL_ENTS - 1));
+		}
 
 		list_add_tail(&sgl->list, &ctx->tsgl);
 	}

Patches currently in stable-queue which might be from [email protected] are

queue-3.18/crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch

maintainer Applied
#3 lore raw

Patch "[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining" has been added to the 4.13-stable tree

In reply to Stephan Mueller

This is a note to let you know that I've just added the patch titled

[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining

to the 4.13-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch
and it can be found in the queue-4.13 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Fri Sep 22 11:04:43 2017

From: Stephan Mueller <[email protected]>
Date: Thu, 21 Sep 2017 10:16:53 +0200
Subject: [PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining
To: [email protected], [email protected]
Cc: [email protected]
Message-ID: <[email protected]>

From: Stephan Mueller <[email protected]>

Fixed differently upstream as commit 2d97591ef43d ("crypto: af_alg - consolidation of duplicate code")

The SGL is MAX_SGL_ENTS + 1 in size. The last SG entry is used for the chaining and is properly updated with the sg_chain invocation. During the filling-in of the initial SG entries, sg_mark_end is called for each SG entry. This is appropriate as long as no additional SGL is chained with the current SGL. However, when a new SGL is chained and the last SG entry is updated with sg_chain, the last but one entry still contains the end marker from the sg_mark_end. This end marker must be removed as otherwise a walk of the chained SGLs will cause a NULL pointer dereference at the last but one SG entry, because sg_next will return NULL.

The patch only applies to all kernels up to and including 4.13. The patch 2d97591ef43d0587be22ad1b0d758d6df4999a0b added to 4.14-rc1 introduced a complete new code base which addresses this bug in a different way. Yet, that patch is too invasive for stable kernels and was therefore not marked for stable.

Fixes 8ff590903d5fc ("crypto: algif_skcipher - User-space interface for skcipher operations")
---
 crypto/algif_skcipher.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/algif_skcipher.c +3 -1
@@ -144,8 +144,10 @@ static int skcipher_alloc_sgl(struct soc
 		sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
 		sgl->cur = 0;
 
-		if (sg)
+		if (sg) {
 			sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
+			sg_unmark_end(sg + (MAX_SGL_ENTS - 1));
+		}
 
 		list_add_tail(&sgl->list, &ctx->tsgl);
 	}

Patches currently in stable-queue which might be from [email protected] are

queue-4.13/crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch

maintainer Applied
#4 lore raw

Patch "[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining" has been added to the 4.4-stable tree

In reply to Stephan Mueller

This is a note to let you know that I've just added the patch titled

[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining

to the 4.4-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch
and it can be found in the queue-4.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Fri Sep 22 11:04:43 2017

From: Stephan Mueller <[email protected]>
Date: Thu, 21 Sep 2017 10:16:53 +0200
Subject: [PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining
To: [email protected], [email protected]
Cc: [email protected]
Message-ID: <[email protected]>

From: Stephan Mueller <[email protected]>

Fixed differently upstream as commit 2d97591ef43d ("crypto: af_alg - consolidation of duplicate code")

The SGL is MAX_SGL_ENTS + 1 in size. The last SG entry is used for the chaining and is properly updated with the sg_chain invocation. During the filling-in of the initial SG entries, sg_mark_end is called for each SG entry. This is appropriate as long as no additional SGL is chained with the current SGL. However, when a new SGL is chained and the last SG entry is updated with sg_chain, the last but one entry still contains the end marker from the sg_mark_end. This end marker must be removed as otherwise a walk of the chained SGLs will cause a NULL pointer dereference at the last but one SG entry, because sg_next will return NULL.

The patch only applies to all kernels up to and including 4.13. The patch 2d97591ef43d0587be22ad1b0d758d6df4999a0b added to 4.14-rc1 introduced a complete new code base which addresses this bug in a different way. Yet, that patch is too invasive for stable kernels and was therefore not marked for stable.

Fixes 8ff590903d5fc ("crypto: algif_skcipher - User-space interface for skcipher operations")
---
 crypto/algif_skcipher.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/algif_skcipher.c +3 -1
@@ -143,8 +143,10 @@ static int skcipher_alloc_sgl(struct soc
 		sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
 		sgl->cur = 0;
 
-		if (sg)
+		if (sg) {
 			sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
+			sg_unmark_end(sg + (MAX_SGL_ENTS - 1));
+		}
 
 		list_add_tail(&sgl->list, &ctx->tsgl);
 	}

Patches currently in stable-queue which might be from [email protected] are

queue-4.4/crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch

maintainer Applied
#5 lore raw

Patch "[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining" has been added to the 4.9-stable tree

In reply to Stephan Mueller

This is a note to let you know that I've just added the patch titled

[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining

to the 4.9-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch
and it can be found in the queue-4.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Fri Sep 22 11:04:43 2017

From: Stephan Mueller <[email protected]>
Date: Thu, 21 Sep 2017 10:16:53 +0200
Subject: [PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining
To: [email protected], [email protected]
Cc: [email protected]
Message-ID: <[email protected]>

From: Stephan Mueller <[email protected]>

Fixed differently upstream as commit 2d97591ef43d ("crypto: af_alg - consolidation of duplicate code")

The SGL is MAX_SGL_ENTS + 1 in size. The last SG entry is used for the chaining and is properly updated with the sg_chain invocation. During the filling-in of the initial SG entries, sg_mark_end is called for each SG entry. This is appropriate as long as no additional SGL is chained with the current SGL. However, when a new SGL is chained and the last SG entry is updated with sg_chain, the last but one entry still contains the end marker from the sg_mark_end. This end marker must be removed as otherwise a walk of the chained SGLs will cause a NULL pointer dereference at the last but one SG entry, because sg_next will return NULL.

The patch only applies to all kernels up to and including 4.13. The patch 2d97591ef43d0587be22ad1b0d758d6df4999a0b added to 4.14-rc1 introduced a complete new code base which addresses this bug in a different way. Yet, that patch is too invasive for stable kernels and was therefore not marked for stable.

Fixes 8ff590903d5fc ("crypto: algif_skcipher - User-space interface for skcipher operations")
---
 crypto/algif_skcipher.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
crypto/algif_skcipher.c +3 -1
@@ -143,8 +143,10 @@ static int skcipher_alloc_sgl(struct soc
 		sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
 		sgl->cur = 0;
 
-		if (sg)
+		if (sg) {
 			sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
+			sg_unmark_end(sg + (MAX_SGL_ENTS - 1));
+		}
 
 		list_add_tail(&sgl->list, &ctx->tsgl);
 	}

Patches currently in stable-queue which might be from [email protected] are

queue-4.9/crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch

maintainer Applied
#6 lore raw

Patch "[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining" has been added to the 4.13-stable tree

In reply to Stephan Mueller

This is a note to let you know that I've just added the patch titled

[PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining

to the 4.13-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch
and it can be found in the queue-4.13 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From [email protected] Mon Oct 2 11:36:13 2017

From: Stephan Mueller <[email protected]>
Date: Thu, 21 Sep 2017 10:16:53 +0200
Subject: [PATCH - RESEND] crypto: AF_ALG - remove SGL terminator indicator when chaining
To: [email protected], [email protected]
Cc: [email protected]
Message-ID: <[email protected]>

From: Stephan Mueller <[email protected]>

Not upstream as-is due to massive rewrite in commit 2d97591ef43d ("crypto:
af_alg - consolidation of duplicate code")

The SGL is MAX_SGL_ENTS + 1 in size. The last SG entry is used for the chaining and is properly updated with the sg_chain invocation. During the filling-in of the initial SG entries, sg_mark_end is called for each SG entry. This is appropriate as long as no additional SGL is chained with the current SGL. However, when a new SGL is chained and the last SG entry is updated with sg_chain, the last but one entry still contains the end marker from the sg_mark_end. This end marker must be removed as otherwise a walk of the chained SGLs will cause a NULL pointer dereference at the last but one SG entry, because sg_next will return NULL.

The patch only applies to all kernels up to and including 4.13. The patch 2d97591ef43d0587be22ad1b0d758d6df4999a0b added to 4.14-rc1 introduced a complete new code base which addresses this bug in a different way. Yet, that patch is too invasive for stable kernels and was therefore not marked for stable.

Fixes 8ff590903d5fc ("crypto: algif_skcipher - User-space interface for skcipher operations")
crypto/algif_skcipher.c +3 -1
@@ -139,8 +139,10 @@ static int skcipher_alloc_sgl(struct sock *sk)
 		sg_init_table(sgl->sg, MAX_SGL_ENTS + 1);
 		sgl->cur = 0;
 
-		if (sg)
+		if (sg) {
 			sg_chain(sg, MAX_SGL_ENTS + 1, sgl->sg);
+			sg_unmark_end(sg + (MAX_SGL_ENTS - 1));
+		}
 
 		list_add_tail(&sgl->list, &ctx->tsgl);
 	}
Signature · 8 lines
2.13.5



Patches currently in stable-queue which might be from [email protected] are

queue-4.13/crypto-drbg-fix-freeing-of-resources.patch
queue-4.13/crypto-af_alg-remove-sgl-terminator-indicator-when-chaining.patch