Skip to contentSkip to conversation

sctp: fix skb_over_panic when adding addresses with a pending delete of another family

PATCH Superseded Henry Martin 3 participants 5 messages Nov 6 – Nov 16

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

PATCH 1/1 sctp: fix skb_over_panic when adding addresses with a pending delete of another family

sctp_make_asconf_update_ip() accounts for a pending DEL_IP parameter by reusing the length of the address being added. The write-back side instead serializes the pending address itself, with its own address family. If the pending delete is IPv6 (20-byte parameter) while the added addresses are IPv4 (8-byte), the chunk is allocated 12 bytes short and sctp_addto_chunk() writes past the end of the skb. E.g. on mainline (05441d697f7f):

    skbuff: skb_over_panic: text:ffffffff84859c77 len:392 put:20
        tail:0x188 end:0x180 dev:<NULL>
    kernel BUG at net/core/skbuff.c:215!
    CPU: 0 UID: 1000 PID: 379 Comm: poc_sctp
    Call Trace:
     skb_panic
     skb_put
     sctp_addto_chunk
     sctp_make_asconf_update_ip
     sctp_send_asconf_add_ip
     sctp_setsockopt_bindx
     __x64_sys_setsockopt

Requires addip enabled on the endpoint (net.sctp.addip_enable=1).

Account for the pending delete with its own address family, as the write-back side already does.

This issue was discovered by Tencent CodeBuddy Security.

Fixes 8a07eb0a50ae ("sctp: Add ASCONF operation on the single-homed host")
---
 net/sctp/sm_make_chunk.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
net/sctp/sm_make_chunk.c +10 -2
index 90de272842512..18947ec5ff9f9 100644
@@ -2886,9 +2886,17 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
 
 		addr_buf += af->sockaddr_len;
 		if (asoc->asconf_addr_del_pending && !del_pickup) {
-			/* reuse the parameter length from the same scope one */
+			/* The DEL_IP parameter is serialized from the
+			 * pending address itself below; account for its
+			 * own address family, which may differ from the
+			 * added one.
+			 */
+			addr = asoc->asconf_addr_del_pending;
+			af = sctp_get_af_specific(addr->v4.sin_family);
+
 			totallen += paramlen;
-			totallen += addr_param_len;
+			totallen += af->to_addr_param(addr, &addr_param);
+
 			del_pickup = 1;
 
 			pr_debug("%s: picked same-scope del_pending addr, "
Signature · 1 line
2.43.7
maintainer
#1 lore raw
Quoted 61 lines · Henry Martin

sctp_make_asconf_update_ip() accounts for a pending DEL_IP parameter by reusing the length of the address being added. The write-back side instead serializes the pending address itself, with its own address family. If the pending delete is IPv6 (20-byte parameter) while the added addresses are IPv4 (8-byte), the chunk is allocated 12 bytes short and sctp_addto_chunk() writes past the end of the skb. E.g. on mainline (05441d697f7f):

    skbuff: skb_over_panic: text:ffffffff84859c77 len:392 put:20
        tail:0x188 end:0x180 dev:<NULL>
    kernel BUG at net/core/skbuff.c:215!
    CPU: 0 UID: 1000 PID: 379 Comm: poc_sctp
    Call Trace:
     skb_panic
     skb_put
     sctp_addto_chunk
     sctp_make_asconf_update_ip
     sctp_send_asconf_add_ip
     sctp_setsockopt_bindx
     __x64_sys_setsockopt

Requires addip enabled on the endpoint (net.sctp.addip_enable=1).

Account for the pending delete with its own address family, as the write-back side already does.

This issue was discovered by Tencent CodeBuddy Security.

Fixes 8a07eb0a50ae ("sctp: Add ASCONF operation on the single-homed host")
---
 net/sctp/sm_make_chunk.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
net/sctp/sm_make_chunk.c +10 -3
index 90de272842512..18947ec5ff9f9 100644
@@ -2886,9 +2886,17 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
 
                addr_buf += af->sockaddr_len;
                if (asoc->asconf_addr_del_pending && !del_pickup) {
-                       /* reuse the parameter length from the same scope one */
+                       /* The DEL_IP parameter is serialized from the
+                        * pending address itself below; account for its
+                        * own address family, which may differ from the
+                        * added one.
+                        */
+                       addr = asoc->asconf_addr_del_pending;
+                       af = sctp_get_af_specific(addr->v4.sin_family);
+
                        totallen += paramlen;
-                       totallen += addr_param_len;
+                       totallen += af->to_addr_param(addr, &addr_param);
+
                        del_pickup = 1;
 
                        pr_debug("%s: picked same-scope del_pending addr, "
--
Quoted 2 lines

2.43.7

I think with no longer using addr_param_len, you can move the if (asoc->asconf_addr_del_pending) branch out of this loop.

Thanks.

#2 lore raw

PATCH v2 1/1 sctp: fix skb_over_panic when adding addresses with a pending delete of another family

sctp_make_asconf_update_ip() accounts for a pending DEL_IP parameter by reusing the length of the address being added. The write-back side instead serializes the pending address itself, with its own address family. If the pending delete is IPv6 (20-byte parameter) while the added addresses are IPv4 (8-byte), the chunk is allocated 12 bytes short and sctp_addto_chunk() writes past the end of the skb. E.g. on mainline (05441d697f7f):

    skbuff: skb_over_panic: text:ffffffff84859c77 len:392 put:20
        tail:0x188 end:0x180 dev:<NULL>
    kernel BUG at net/core/skbuff.c:215!
    CPU: 0 UID: 1000 PID: 379 Comm: poc_sctp
    Call Trace:
     skb_panic
     skb_put
     sctp_addto_chunk
     sctp_make_asconf_update_ip
     sctp_send_asconf_add_ip
     sctp_setsockopt_bindx
     __x64_sys_setsockopt

Requires addip enabled on the endpoint (net.sctp.addip_enable=1).

Account for the pending delete with its own address family, as the write-back side already does.

This issue was discovered by Tencent CodeBuddy Security.

Fixes 8a07eb0a50ae ("sctp: Add ASCONF operation on the single-homed host")

---
v2: move the pending-delete accounting out of the length loop and
drop the del_pickup flag, which no longer guards anything.

 net/sctp/sm_make_chunk.c | 16 ++++++++++------
 1 file changed, 12 insertions(+), 4 deletions(-)
net/sctp/sm_make_chunk.c +16 -12
index 90de272842512..b8e4db81636e2 100644
@@ -2870,7 +2870,6 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
 	int addr_param_len = 0;
 	union sctp_addr *addr;
 	int totallen = 0, i;
-	int del_pickup = 0;
 	struct sctp_af *af;
 	void *addr_buf;
 
@@ -2885,16 +2884,21 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
 		totallen += addr_param_len;
 
 		addr_buf += af->sockaddr_len;
-		if (asoc->asconf_addr_del_pending && !del_pickup) {
-			/* reuse the parameter length from the same scope one */
-			totallen += paramlen;
-			totallen += addr_param_len;
-			del_pickup = 1;
-
-			pr_debug("%s: picked same-scope del_pending addr, "
-				 "totallen for all addresses is %d\n",
-				 __func__, totallen);
-		}
+	}
+
+	if (asoc->asconf_addr_del_pending) {
+		/* The DEL_IP parameter is serialized from the pending address
+		 * itself below; account for its own address family, which may
+		 * differ from the added ones.
+		 */
+		addr = asoc->asconf_addr_del_pending;
+		af = sctp_get_af_specific(addr->v4.sin_family);
+		totallen += paramlen;
+		totallen += af->to_addr_param(addr, &addr_param);
+
+		pr_debug("%s: picked del_pending addr, "
+			 "totallen for all addresses is %d\n",
+			 __func__, totallen);
 	}
 
 	/* Create an asconf chunk with the required length. */
@@ -2917,7 +2921,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
 
 		addr_buf += af->sockaddr_len;
 	}
-	if (flags == SCTP_PARAM_ADD_IP && del_pickup) {
+	if (flags == SCTP_PARAM_ADD_IP && asoc->asconf_addr_del_pending) {
 		addr = asoc->asconf_addr_del_pending;
 		af = sctp_get_af_specific(addr->v4.sin_family);
 		addr_param_len = af->to_addr_param(addr, &addr_param);
maintainer Acked-by on v2 1/1
#3 lore raw
Quoted 84 lines · Henry Martin

sctp_make_asconf_update_ip() accounts for a pending DEL_IP parameter by reusing the length of the address being added. The write-back side instead serializes the pending address itself, with its own address family. If the pending delete is IPv6 (20-byte parameter) while the added addresses are IPv4 (8-byte), the chunk is allocated 12 bytes short and sctp_addto_chunk() writes past the end of the skb. E.g. on mainline (05441d697f7f):

    skbuff: skb_over_panic: text:ffffffff84859c77 len:392 put:20
        tail:0x188 end:0x180 dev:<NULL>
    kernel BUG at net/core/skbuff.c:215!
    CPU: 0 UID: 1000 PID: 379 Comm: poc_sctp
    Call Trace:
     skb_panic
     skb_put
     sctp_addto_chunk
     sctp_make_asconf_update_ip
     sctp_send_asconf_add_ip
     sctp_setsockopt_bindx
     __x64_sys_setsockopt

Requires addip enabled on the endpoint (net.sctp.addip_enable=1).

Account for the pending delete with its own address family, as the write-back side already does.

This issue was discovered by Tencent CodeBuddy Security.

Fixes 8a07eb0a50ae ("sctp: Add ASCONF operation on the single-homed host")

---
v2: move the pending-delete accounting out of the length loop and
drop the del_pickup flag, which no longer guards anything.

 net/sctp/sm_make_chunk.c | 16 ++++++++++------
 1 file changed, 12 insertions(+), 4 deletions(-)
net/sctp/sm_make_chunk.c +15 -11
index 90de272842512..b8e4db81636e2 100644
@@ -2870,7 +2870,6 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
        int addr_param_len = 0;
        union sctp_addr *addr;
        int totallen = 0, i;
-       int del_pickup = 0;
        struct sctp_af *af;
        void *addr_buf;
 
@@ -2885,16 +2884,21 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
                totallen += addr_param_len;
 
                addr_buf += af->sockaddr_len;
-               if (asoc->asconf_addr_del_pending && !del_pickup) {
-                       /* reuse the parameter length from the same scope one */
-                       totallen += paramlen;
-                       totallen += addr_param_len;
-                       del_pickup = 1;
-
-                       pr_debug("%s: picked same-scope del_pending addr, "
-                                "totallen for all addresses is %d\n",
-                                __func__, totallen);
-               }
+       }
+
+       if (asoc->asconf_addr_del_pending) {
+               /* The DEL_IP parameter is serialized from the pending address
+                * itself below; account for its own address family, which may
+                * differ from the added ones.
+                */
+               addr = asoc->asconf_addr_del_pending;
+               af = sctp_get_af_specific(addr->v4.sin_family);
+               totallen += paramlen;
+               totallen += af->to_addr_param(addr, &addr_param);
+
+               pr_debug("%s: picked del_pending addr, "
+                        "totallen for all addresses is %d\n",
+                        __func__, totallen);
        }
 
        /* Create an asconf chunk with the required length. */

net/sctp/sm_make_chunk.c struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc, · line 2927

Quoted 8 lines
net/sctp/sm_make_chunk.c +1 -1
@@ -2917,7 +2921,7 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *asoc,
 
                addr_buf += af->sockaddr_len;
        }
-       if (flags == SCTP_PARAM_ADD_IP && del_pickup) {
+       if (flags == SCTP_PARAM_ADD_IP && asoc->asconf_addr_del_pending) {
                addr = asoc->asconf_addr_del_pending;
                af = sctp_get_af_specific(addr->v4.sin_family);
                addr_param_len = af->to_addr_param(addr, &addr_param);
#4 lore raw
In reply to Henry Martin
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Wed, 11 Nov 2026 16:23:13 +0800 you wrote:

sctp_make_asconf_update_ip() accounts for a pending DEL_IP parameter by reusing the length of the address being added. The write-back side instead serializes the pending address itself, with its own address family. If the pending delete is IPv6 (20-byte parameter) while the added addresses are IPv4 (8-byte), the chunk is allocated 12 bytes short and sctp_addto_chunk() writes past the end of the skb. E.g. on mainline (05441d697f7f):

[...]

Here is the summary with links:
- [v2] sctp: fix skb_over_panic when adding addresses with a pending delete of another family

    https://git.kernel.org/netdev/net/c/ce09d8c13a15

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html