[PATCH] sctp: avoid NULL pointer dereference in sctp_sf_violation

Subsystems: networking [general], sctp protocol, the rest

STALE1735d

4 messages, 3 authors, 2021-11-07 · open the first message on its own page

[PATCH] sctp: avoid NULL pointer dereference in sctp_sf_violation

From: Alexey Khoroshilov <hidden>
Date: 2021-11-02 20:27:23

Some callers (e.g. sctp_sf_violation_chunk) passes NULL to
asoc argument of sctp_sf_violation. So, it should check it
before calling sctp_vtag_verify().

Probably it could be exploited by a malicious SCTP packet
to cause NULL pointer dereference.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Alexey Khoroshilov <redacted>
Fixes: aa0f697e4528 ("sctp: add vtag check in sctp_sf_violation")
---
 net/sctp/sm_statefuns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index fb3da4d8f4a3..77f3cd6c516e 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -4669,7 +4669,7 @@ enum sctp_disposition sctp_sf_violation(struct net *net,
 {
 	struct sctp_chunk *chunk = arg;
 
-	if (!sctp_vtag_verify(chunk, asoc))
+	if (asoc && !sctp_vtag_verify(chunk, asoc))
 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
 
 	/* Make sure that the chunk has a valid length. */
-- 
2.7.4

Re: [PATCH] sctp: avoid NULL pointer dereference in sctp_sf_violation

From: Xin Long <lucien.xin@gmail.com>
Date: 2021-11-03 12:44:02

On Tue, Nov 2, 2021 at 4:27 PM Alexey Khoroshilov [off-list ref] wrote:
Some callers (e.g. sctp_sf_violation_chunk) passes NULL to
asoc argument of sctp_sf_violation. So, it should check it
before calling sctp_vtag_verify().

Probably it could be exploited by a malicious SCTP packet
to cause NULL pointer dereference.
I don't think asoc can be NULL in here, did you see any call trace
caused by it?

If this was found by a tool, please remove the unnecessary call from
sctp_sf_violation_chunk() instead:
@@ -4893,9 +4893,6 @@ static enum sctp_disposition sctp_sf_violation_chunk(
 {
        static const char err_str[] = "The following chunk violates protocol:";

-       if (!asoc)
-               return sctp_sf_violation(net, ep, asoc, type, arg, commands);
-
Thanks.
quoted hunk
Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Alexey Khoroshilov <redacted>
Fixes: aa0f697e4528 ("sctp: add vtag check in sctp_sf_violation")
---
 net/sctp/sm_statefuns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index fb3da4d8f4a3..77f3cd6c516e 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -4669,7 +4669,7 @@ enum sctp_disposition sctp_sf_violation(struct net *net,
 {
        struct sctp_chunk *chunk = arg;

-       if (!sctp_vtag_verify(chunk, asoc))
+       if (asoc && !sctp_vtag_verify(chunk, asoc))
                return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);

        /* Make sure that the chunk has a valid length. */
--
2.7.4

[PATCH] sctp: remove unreachable code from sctp_sf_violation_chunk()

From: Alexey Khoroshilov <hidden>
Date: 2021-11-05 17:30:51

sctp_sf_violation_chunk() is not called with asoc argument equal to NULL,
but if that happens it would lead to NULL pointer dereference
in sctp_vtag_verify().

The patch removes code that handles NULL asoc in sctp_sf_violation_chunk().

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Alexey Khoroshilov <redacted>
Proposed-by: Xin Long [off-list ref]
---
 net/sctp/sm_statefuns.c | 3 ---
 1 file changed, 3 deletions(-)
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index fb3da4d8f4a3..ec8561dd7e76 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -4893,9 +4893,6 @@ static enum sctp_disposition sctp_sf_violation_chunk(
 {
 	static const char err_str[] = "The following chunk violates protocol:";
 
-	if (!asoc)
-		return sctp_sf_violation(net, ep, asoc, type, arg, commands);
-
 	return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
 				       sizeof(err_str));
 }
-- 
2.7.4

Re: [PATCH] sctp: remove unreachable code from sctp_sf_violation_chunk()

From: patchwork-bot+netdevbpf@kernel.org
Date: 2021-11-07 19:40:36

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller [off-list ref]:

On Fri,  5 Nov 2021 20:30:27 +0300 you wrote:
sctp_sf_violation_chunk() is not called with asoc argument equal to NULL,
but if that happens it would lead to NULL pointer dereference
in sctp_vtag_verify().

The patch removes code that handles NULL asoc in sctp_sf_violation_chunk().

Found by Linux Verification Center (linuxtesting.org) with SVACE.

[...]
Here is the summary with links:
  - sctp: remove unreachable code from sctp_sf_violation_chunk()
    https://git.kernel.org/netdev/net/c/e7ea51cd879c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help