laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-remsim/+/28590 )
Change subject: bankd: Open PC/SC by default in EXCLUSIVE mode
......................................................................
bankd: Open PC/SC by default in EXCLUSIVE mode
Let's open the cards in EXCLUSIVE mode, we don't want other applications
tinkering with the card state while we have a bankd worker running on
it. This change also means that no two bankd workers can trip on
each other accidentially anymore.
Related: OS#5527
Change-Id: I43a1c8c7bd1c0124ee5f605e2e5b04ed8f7836ab
---
M doc/manuals/chapters/remsim-bankd.adoc
M src/bankd/bankd.h
M src/bankd/bankd_main.c
M src/bankd/bankd_pcsc.c
4 files changed, 29 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-remsim refs/changes/90/28590/1
diff --git a/doc/manuals/chapters/remsim-bankd.adoc b/doc/manuals/chapters/remsim-bankd.adoc
index 7c102de..cb3061c 100644
--- a/doc/manuals/chapters/remsim-bankd.adoc
+++ b/doc/manuals/chapters/remsim-bankd.adoc
@@ -89,6 +89,15 @@
*-P, --bind-port <1-65535>*::
Specify the local TCP port to which the socket for incoming connections
from `osmo-remsim-client`s is bound to.
+*-s, --permit-shared-pcsc*::
+ Specify whether the PC/SC readers should be accessed in SCARD_SHARE_SHARED
+ mode, instead of the default (SCARD_SHARE_EXCLUSIVE). Shared mode would
+ permit multiple application programs to access a single reader/slot/card
+ concurrently. This is potentially dangerous as the two programs operate
+ without knowledge of each other, and either of them might modify the card
+ state (such as the currently selected file, validated PIN, etc.) in a
+ way not expected by the other application.
+
==== Examples
.remsim-server is on 10.2.3.4, cardreader has 5 slots:
diff --git a/src/bankd/bankd.h b/src/bankd/bankd.h
index 9bf9bc9..0f94818 100644
--- a/src/bankd/bankd.h
+++ b/src/bankd/bankd.h
@@ -130,6 +130,10 @@
pthread_mutex_t workers_mutex;
struct llist_head pcsc_slot_names;
+
+ struct {
+ bool permit_shared_pcsc;
+ } cfg;
};
int bankd_pcsc_read_slotnames(struct bankd *bankd, const char *csv_file);
diff --git a/src/bankd/bankd_main.c b/src/bankd/bankd_main.c
index b28eec9..7ee67d3 100644
--- a/src/bankd/bankd_main.c
+++ b/src/bankd/bankd_main.c
@@ -291,6 +291,7 @@
" connections (default: INADDR_ANY)\n"
" -P --bind-port <1-65535> Local TCP port to bind for incoming client\n"
" connectionss (default: 9999)\n"
+" -s --permit-shared-pcsc Permit SHARED access to PC/SC readers (default: exclusive)\n"
);
}
@@ -312,10 +313,11 @@
{ "component-name", 1, 0, 'N' },
{ "bind-ip", 1, 0, 'I' },
{ "bind-port", 1, 0, 'P' },
+ { "permit-shared-pcsc", 0, 0, 's' },
{ 0, 0, 0, 0 }
};
- c = getopt_long(argc, argv, "hVd:i:o:b:n:N:I:P:", long_options, &option_index);
+ c = getopt_long(argc, argv, "hVd:i:o:b:n:N:I:P:s", long_options, &option_index);
if (c == -1)
break;
@@ -352,6 +354,9 @@
case 'P':
g_bind_port = atoi(optarg);
break;
+ case 's':
+ g_bankd->cfg.permit_shared_pcsc = true;
+ break;
}
}
}
diff --git a/src/bankd/bankd_pcsc.c b/src/bankd/bankd_pcsc.c
index ee01c93..e1477dd 100644
--- a/src/bankd/bankd_pcsc.c
+++ b/src/bankd/bankd_pcsc.c
@@ -184,6 +184,14 @@
LOGW((w), text ": OK\n"); \
}
+static DWORD bankd_share_mode(struct bankd *bankd)
+{
+ if (bankd->cfg.permit_shared_pcsc)
+ return SCARD_SHARE_SHARED;
+ else
+ return SCARD_SHARE_EXCLUSIVE;
+}
+
static int pcsc_get_atr(struct bankd_worker *worker)
{
long rc;
@@ -232,7 +240,7 @@
int r = regexec(&compiled_name, p, 0, NULL, 0);
if (r == 0) {
LOGW(worker, "Attempting to open card/slot '%s'\n", p);
- rc = SCardConnect(worker->reader.pcsc.hContext, p, SCARD_SHARE_SHARED,
+ rc = SCardConnect(worker->reader.pcsc.hContext, p, bankd_share_mode(worker->bankd),
SCARD_PROTOCOL_T0, &worker->reader.pcsc.hCard,
&dwActiveProtocol);
if (rc == SCARD_S_SUCCESS)
@@ -289,7 +297,7 @@
LOGW(worker, "Resetting card in '%s' (%s)\n", worker->reader.name,
cold_reset ? "cold reset" : "warm reset");
- rc = SCardReconnect(worker->reader.pcsc.hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0,
+ rc = SCardReconnect(worker->reader.pcsc.hCard, bankd_share_mode(worker->bankd), SCARD_PROTOCOL_T0,
cold_reset ? SCARD_UNPOWER_CARD : SCARD_RESET_CARD, &dwActiveProtocol);
PCSC_ERROR(worker, rc, "SCardReconnect");
--
To view, visit https://gerrit.osmocom.org/c/osmo-remsim/+/28590
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-remsim
Gerrit-Branch: master
Gerrit-Change-Id: I43a1c8c7bd1c0124ee5f605e2e5b04ed8f7836ab
Gerrit-Change-Number: 28590
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: newchange
Attention is currently required from: osmith.
pespin has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc-nat/+/28582 )
Change subject: bssap_conn: fix missing length check
......................................................................
Patch Set 2:
(1 comment)
File src/osmo-bsc-nat/bssap_conn.c:
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/28582/comment/0cfff071_f23be8f0
PS2, Line 60: len = IP_V4_ADDR_LEN;
> Thanks for the suggestion! […]
AFAIR and from waht you mention, msgb_put checks length by calling osmo_panic(), which is not desirable. That osmo_panic is just to signal that something is really wrong in the caller code. So we want proper checking here, not just osmo_panic.
I still think the proper way is to handle one check inside gsm0808_enc_aoip_trasp_addr() and another one directly in this function for the path calling tlv_encode_one(). Because for the first path, you always want to have that checked, and I'd expect that function to check that. For the other path, you are really doing different stuff and it's fine doing the check in the same function.
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc-nat/+/28582
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: I1fc4c81e139bab3d7d977ef9467f62d8088884db
Gerrit-Change-Number: 28582
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: osmith <osmith(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 13 Jul 2022 12:25:42 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: osmith <osmith(a)sysmocom.de>
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: comment
Attention is currently required from: pespin.
osmith has posted comments on this change. ( https://gerrit.osmocom.org/c/osmo-bsc-nat/+/28582 )
Change subject: bssap_conn: fix missing length check
......................................................................
Patch Set 2:
(1 comment)
File src/osmo-bsc-nat/bssap_conn.c:
https://gerrit.osmocom.org/c/osmo-bsc-nat/+/28582/comment/97cfde7b_f706dd80
PS2, Line 60: len = IP_V4_ADDR_LEN;
Thanks for the suggestion!
> gsm0808_enc_aoip_trasp_addr should take care of checking internally whether there's space in msg_new.
I read related libosmocore code, and now understand that all msgb code works like this, using msgb_put(msg, len) to get a pointer to a buffer to write len bytes to, and then actually write it with e.g. memcpy afterwards. msgb_put already checks that enough space is available: https://gitea.osmocom.org/osmocom/libosmocore/src/commit/0578c288ec9e33512c…
So that's how the check for gsm0808_enc_aoip_trasp_addr is performed. tlv_encode_one is also using msgb functions so the length check should also work there. I think CID#273004 is a false positive now, it seems coverity can't follow that msgb_tvlv_put() would already check the length through msgb_put(msg, TVLV_GROSS_LEN(len)) correctly before writing to it.
Do you agree that it's a false positive?
Regarding whether to check length here: I think we should either check the length for both cases (copy IE over and replacing it) like it's done in the current version of the patch, or not check the length at all and rely on msgb_put to do it. By adding the check here we could avoid osmo_panic() if there's not enough space, but it makes the code here more complicated.
Probably not worth it?
--
To view, visit https://gerrit.osmocom.org/c/osmo-bsc-nat/+/28582
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-bsc-nat
Gerrit-Branch: master
Gerrit-Change-Id: I1fc4c81e139bab3d7d977ef9467f62d8088884db
Gerrit-Change-Number: 28582
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Wed, 13 Jul 2022 09:13:21 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: osmith <osmith(a)sysmocom.de>
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: comment
osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ci/+/28589 )
Change subject: Cosmetic: coverity: how to add a new project
......................................................................
Cosmetic: coverity: how to add a new project
Mention that new projects should be added to the components list, as a
lot of projects were not listed there. I've just added all missing
ones. Put it as comment in prepare_source_Osmocom.sh because that's
probably the most likely spot where people will see it while adding a
new project.
Change-Id: I48630f4eb5b4f2b7b714697d15432c0d71f136f9
---
M coverity/prepare_source_Osmocom.sh
1 file changed, 6 insertions(+), 0 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
diff --git a/coverity/prepare_source_Osmocom.sh b/coverity/prepare_source_Osmocom.sh
index 01e3d73..31d6714 100755
--- a/coverity/prepare_source_Osmocom.sh
+++ b/coverity/prepare_source_Osmocom.sh
@@ -1,6 +1,12 @@
#!/bin/sh
BASEDIR=source-Osmocom
+# How to add a new project:
+# * add it to the list below
+# * add it to build_Osmocom.sh
+# * add it as component here:
+# https://scan.coverity.com/projects/osmocom?tab=analysis_settings
+
PROJECTS="
libasn1c
libosmo-abis
--
To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/28589
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-ci
Gerrit-Branch: master
Gerrit-Change-Id: I48630f4eb5b4f2b7b714697d15432c0d71f136f9
Gerrit-Change-Number: 28589
Gerrit-PatchSet: 2
Gerrit-Owner: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: merged