Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Dec 2021 14:05:01 GMT
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 13c196a41e26 - main - sctp: improve handling of assoc ids in socket options
Message-ID:  <202112011405.1B1E51ck072860@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=13c196a41e2604e6f9a4484b997279b82173dc40

commit 13c196a41e2604e6f9a4484b997279b82173dc40
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-12-01 13:54:55 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2021-12-01 13:54:55 +0000

    sctp: improve handling of assoc ids in socket options
    
    For socket options related to local and remote addresses providing
    generic association ids does not make sense. Report EINVAL in this
    case.
    
    MFC after:      1 week
---
 sys/netinet/sctp_usrreq.c | 30 +++++++++++++++++++++++-------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c
index dae35c566d4e..c5c45a2f2072 100644
--- a/sys/netinet/sctp_usrreq.c
+++ b/sys/netinet/sctp_usrreq.c
@@ -2187,8 +2187,13 @@ flags_out:
 				*value = (uint32_t)size;
 				*optsize = sizeof(uint32_t);
 			} else {
-				SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN);
-				error = ENOTCONN;
+				if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
+				    ((sctp_assoc_t)*value <= SCTP_ALL_ASSOC)) {
+					error = EINVAL;
+				} else {
+					error = ENOENT;
+				}
+				SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
 			}
 			break;
 		}
@@ -2262,8 +2267,13 @@ flags_out:
 				}
 				SCTP_TCB_UNLOCK(stcb);
 			} else {
-				SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT);
-				error = ENOENT;
+				if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
+				    (saddr->sget_assoc_id <= SCTP_ALL_ASSOC)) {
+					error = EINVAL;
+				} else {
+					error = ENOENT;
+				}
+				SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, error);
 			}
 			break;
 		}
@@ -2275,12 +2285,18 @@ flags_out:
 			SCTP_CHECK_AND_CAST(saddr, optval, struct sctp_getaddresses, *optsize);
 			SCTP_FIND_STCB(inp, stcb, saddr->sget_assoc_id);
 
-			limit = *optsize - offsetof(struct sctp_getaddresses, addr);
-			actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
+			if ((inp->sctp_flags & SCTP_PCB_FLAGS_UDPTYPE) &&
+			    ((saddr->sget_assoc_id == SCTP_CURRENT_ASSOC) ||
+			    (saddr->sget_assoc_id == SCTP_ALL_ASSOC))) {
+				error = EINVAL;
+			} else {
+				limit = *optsize - offsetof(struct sctp_getaddresses, addr);
+				actual = sctp_fill_up_addresses(inp, stcb, limit, &saddr->addr[0].sa);
+				*optsize = offsetof(struct sctp_getaddresses, addr) + actual;
+			}
 			if (stcb != NULL) {
 				SCTP_TCB_UNLOCK(stcb);
 			}
-			*optsize = offsetof(struct sctp_getaddresses, addr) + actual;
 			break;
 		}
 	case SCTP_PEER_ADDR_PARAMS:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202112011405.1B1E51ck072860>