Project

General

Profile

Actions

Bug #5527

open

warn on duplicate client (id) connections

Added by laforge about 2 years ago. Updated almost 2 years ago.

Status:
Stalled
Priority:
High
Assignee:
Category:
remsim-server
Target version:
-
Start date:
04/12/2022
Due date:
% Done:

70%

Spec Reference:

Description

Every client must have its own unique tuple of (client_id/slot_nr).

If a remsim-server receives a duplicate connection, it should pring a clear warning message to the log.

This might not always be a bug, as in csae of network outages / restarts a new connection might arrive before the old one is closed.

The same should apply to remsim-bankd.


Checklist

  • remsim-server
  • remsim-bankd

Related issues

Related to osmo-remsim - Feature #3884: redesign bankd thread architectureNewlaforge04/01/2019

Actions
Actions #1

Updated by laforge almost 2 years ago

  • Assignee set to laforge

in remsim-bankd it is not entirely trivial to handle the situation, as we simply have N parallel threads all listening on the same socket. Every incoming TCP connection gets dispatched to a random thread, and that thread then processes the requests. The threads have almost no shared state, so thread A doesn't really know what thread B is doing, or whom it is talking to.

Right now they will both try to open the PC/SC reader, and both will succeed (at least that's what happens in my current testing of this situation):

4164906 DBANKDW INFO bankd_main.c:965 [000 ACCEPTING] Accepted connection from 127.0.0.1:10000
4164906 DBANKDW INFO bankd_main.c:452 [000 ACCEPTING] Changing state to CONN_WAIT_ID
4164906 DBANKDW INFO bankd_main.c:665 [000 CONN_WAIT_ID] Rx RSPRO connectClientReq(T=0, N='ttcn-client', SW='TTCN3', VER='0.1')
4164906 DBANKDW INFO bankd_main.c:452 [000 CONN_WAIT_ID] Changing state to CONN_CLIENT
4164906 DBANKDW INFO bankd_main.c:635 [000 CONN_CLIENT] slotmap found: C(23:0) -> B(1:0)
4164906 DBANKDW INFO bankd_main.c:460 [000 CONN_CLIENT] Changing state to CONN_CLIENT_MAPPED (timeout=10)
4164906 DBANKDW INFO bankd_pcsc.c:261 [000 CONN_CLIENT_MAPPED] Attempting to open PC/SC context
4164906 DBANKDW INFO bankd_pcsc.c:264 [000 CONN_CLIENT_MAPPED] SCardEstablishContext: OK
4164906 DBANKDW INFO bankd_pcsc.c:215 [000 CONN_CLIENT_MAPPED] Attempting to find card/slot using regex 'Virtual PCD 00 00'
4164906 DBANKDW INFO bankd_pcsc.c:234 [000 CONN_CLIENT_MAPPED] Attempting to open card/slot 'Virtual PCD 00 00'
4164906 DBANKDW INFO bankd_pcsc.c:198 [000 CONN_CLIENT_MAPPED] SCardStatus: OK
4164906 DBANKDW INFO bankd_pcsc.c:200 [000 CONN_CLIENT_MAPPED] Card ATR: 3b9f96801f878031e073fe211b674a4c753034054ba9
4164906 DBANKDW INFO bankd_main.c:452 [000 CONN_CLIENT_MAPPED] Changing state to CONN_CLIENT_MAPPED_CARD

4164908 DBANKDW INFO bankd_main.c:965 [002 ACCEPTING] Accepted connection from 127.0.0.1:10001
4164908 DBANKDW INFO bankd_main.c:452 [002 ACCEPTING] Changing state to CONN_WAIT_ID
4164908 DBANKDW INFO bankd_main.c:665 [002 CONN_WAIT_ID] Rx RSPRO connectClientReq(T=0, N='ttcn-client', SW='TTCN3', VER='0.1')
4164908 DBANKDW INFO bankd_main.c:452 [002 CONN_WAIT_ID] Changing state to CONN_CLIENT
4164908 DBANKDW INFO bankd_main.c:635 [002 CONN_CLIENT] slotmap found: C(23:0) -> B(1:0)
4164908 DBANKDW INFO bankd_main.c:460 [002 CONN_CLIENT] Changing state to CONN_CLIENT_MAPPED (timeout=10)
4164908 DBANKDW INFO bankd_pcsc.c:261 [002 CONN_CLIENT_MAPPED] Attempting to open PC/SC context
4164908 DBANKDW INFO bankd_pcsc.c:264 [002 CONN_CLIENT_MAPPED] SCardEstablishContext: OK
4164908 DBANKDW INFO bankd_pcsc.c:215 [002 CONN_CLIENT_MAPPED] Attempting to find card/slot using regex 'Virtual PCD 00 00'
4164908 DBANKDW INFO bankd_pcsc.c:234 [002 CONN_CLIENT_MAPPED] Attempting to open card/slot 'Virtual PCD 00 00'
4164908 DBANKDW INFO bankd_pcsc.c:198 [002 CONN_CLIENT_MAPPED] SCardStatus: OK
4164908 DBANKDW INFO bankd_pcsc.c:200 [002 CONN_CLIENT_MAPPED] Card ATR: 3b9f96801f878031e073fe211b674a4c753034054ba9
4164908 DBANKDW INFO bankd_main.c:452 [002 CONN_CLIENT_MAPPED] Changing state to CONN_CLIENT_MAPPED_CARD

I'll continue to investigate.

Actions #2

Updated by laforge almost 2 years ago

  • Related to Feature #3884: redesign bankd thread architecture added
Actions #3

Updated by laforge almost 2 years ago

  • Checklist item remsim-server set to Done
  • Category set to remsim-server
  • Status changed from New to In Progress
  • Priority changed from Normal to High
  • % Done changed from 0 to 40

In change https://gerrit.osmocom.org/c/osmo-remsim/+/28027 we introduce rejecting of duplicate connections. I decided to reject the second (new) connection as otherwise one rogue client could DoS a currently perfectly working setup.

Related TTCN-3 test coverage has been introduced in https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/28025

Actions #4

Updated by laforge almost 2 years ago

  • Status changed from In Progress to Stalled

still missing the bankd part, which requres some code re-architecting.

Actions #5

Updated by laforge almost 2 years ago

  • % Done changed from 40 to 70

In the proposed change https://gerrit.osmocom.org/c/osmo-remsim/+/28590 (bankd: Open PC/SC by default in EXCLUSIVE mode) we prevent any two bankd workers (or any other applications) from concurrently opening SIM cards that we already have open. This circumvents the need for bankd-internal warnings or the like: Opening the same card from another client with duplicate ID would then fail when opening the same PCSC slot/card.

Actions

Also available in: Atom PDF

Add picture from clipboard (Maximum size: 48.8 MB)