[PATCH] gsm: Verify the MNCC_VERSION of the BSC/MS and close the socket on mismatch

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Holger Hans Peter Freyther zecke at selfish.org
Fri Oct 21 12:11:04 UTC 2011


The BSC/MS will send a Hello packet that includes the version number,
make LCR verify this version number and close the socket in case it
does not match a supported version.
---
 gsm.cpp |   12 ++++++++++++
 mncc.h  |    7 +++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/gsm.cpp b/gsm.cpp
index e6806c3..227d618 100644
--- a/gsm.cpp
+++ b/gsm.cpp
@@ -1042,6 +1042,7 @@ static int mncc_fd_read(struct lcr_fd *lfd, void *inst, int idx)
 	int rc;
 	static char buf[sizeof(struct gsm_mncc)+1024];
 	struct gsm_mncc *mncc_prim = (struct gsm_mncc *) buf;
+	struct gsm_mncc_hello *hello = (struct gsm_mncc_hello *) buf;
 
 	memset(buf, 0, sizeof(buf));
 	rc = recv(lfd->fd, buf, sizeof(buf), 0);
@@ -1050,6 +1051,17 @@ static int mncc_fd_read(struct lcr_fd *lfd, void *inst, int idx)
 	if (rc < 0)
 		return rc;
 
+	/* TODO: size check? */
+	switch (mncc_prim->msg_type) {
+	case MNCC_SOCKET_HELLO:
+		if (hello->version != MNCC_SOCK_VERSION) {
+			PERROR("MNCC version different. BSC version is %u\n", hello->version);
+			mncc_fd_close(lcr_gsm, lfd);
+			return 0;
+		}
+		break;
+	}
+
 	/* Hand the MNCC message into LCR */
 	switch (lcr_gsm->type) {
 #ifdef WITH_GSM_BS
diff --git a/mncc.h b/mncc.h
index e5f8216..fac7145 100644
--- a/mncc.h
+++ b/mncc.h
@@ -56,6 +56,8 @@
 #define GSM_TCHF_FRAME		0x0300
 #define GSM_TCHF_FRAME_EFR	0x0301
 
+#define MNCC_SOCKET_HELLO	0x0400
+
 #define GSM_MAX_FACILITY	128
 #define GSM_MAX_SSVERSION	128
 #define GSM_MAX_USERUSER	128
@@ -185,3 +187,8 @@ struct gsm_data_frame {
 	unsigned char	data[0];
 };
 
+#define MNCC_SOCK_VERSION	1
+struct gsm_mncc_hello {
+	u_int32_t	msg_type;
+	u_int32_t	version;
+};
-- 
1.7.5.4


--------------020402070302030203020301--




More information about the OpenBSC mailing list