Skip to content

Commit 315d160

Browse files
Daniel Jurgensjgunthorpe
authored andcommitted
IB/core: Only enforce security for InfiniBand
For now the only LSM security enforcement mechanism available is specific to InfiniBand. Bypass enforcement for non-IB link types. This fixes a regression where modify_qp fails for iWARP because querying the PKEY returns -EINVAL. Cc: Paul Moore <[email protected]> Cc: Don Dutile <[email protected]> Cc: [email protected] Reported-by: Potnuri Bharat Teja <[email protected]> Fixes: d291f1a("IB/core: Enforce PKey security on QPs") Fixes: 47a2b33("IB/core: Enforce security on management datagrams") Signed-off-by: Daniel Jurgens <[email protected]> Reviewed-by: Parav Pandit <[email protected]> Tested-by: Potnuri Bharat Teja <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 378efe7 commit 315d160

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

drivers/infiniband/core/security.c

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,17 @@ void ib_close_shared_qp_security(struct ib_qp_security *sec)
417417

418418
int ib_create_qp_security(struct ib_qp *qp, struct ib_device *dev)
419419
{
420+
u8 i = rdma_start_port(dev);
421+
bool is_ib = false;
420422
int ret;
421423

424+
while (i <= rdma_end_port(dev) && !is_ib)
425+
is_ib = rdma_protocol_ib(dev, i++);
426+
427+
/* If this isn't an IB device don't create the security context */
428+
if (!is_ib)
429+
return 0;
430+
422431
qp->qp_sec = kzalloc(sizeof(*qp->qp_sec), GFP_KERNEL);
423432
if (!qp->qp_sec)
424433
return -ENOMEM;
@@ -441,6 +450,10 @@ EXPORT_SYMBOL(ib_create_qp_security);
441450

442451
void ib_destroy_qp_security_begin(struct ib_qp_security *sec)
443452
{
453+
/* Return if not IB */
454+
if (!sec)
455+
return;
456+
444457
mutex_lock(&sec->mutex);
445458

446459
/* Remove the QP from the lists so it won't get added to
@@ -470,6 +483,10 @@ void ib_destroy_qp_security_abort(struct ib_qp_security *sec)
470483
int ret;
471484
int i;
472485

486+
/* Return if not IB */
487+
if (!sec)
488+
return;
489+
473490
/* If a concurrent cache update is in progress this
474491
* QP security could be marked for an error state
475492
* transition. Wait for this to complete.
@@ -505,6 +522,10 @@ void ib_destroy_qp_security_end(struct ib_qp_security *sec)
505522
{
506523
int i;
507524

525+
/* Return if not IB */
526+
if (!sec)
527+
return;
528+
508529
/* If a concurrent cache update is occurring we must
509530
* wait until this QP security structure is processed
510531
* in the QP to error flow before destroying it because
@@ -557,26 +578,35 @@ int ib_security_modify_qp(struct ib_qp *qp,
557578
{
558579
int ret = 0;
559580
struct ib_ports_pkeys *tmp_pps;
560-
struct ib_ports_pkeys *new_pps;
581+
struct ib_ports_pkeys *new_pps = NULL;
561582
struct ib_qp *real_qp = qp->real_qp;
562583
bool special_qp = (real_qp->qp_type == IB_QPT_SMI ||
563584
real_qp->qp_type == IB_QPT_GSI ||
564585
real_qp->qp_type >= IB_QPT_RESERVED1);
565586
bool pps_change = ((qp_attr_mask & (IB_QP_PKEY_INDEX | IB_QP_PORT)) ||
566587
(qp_attr_mask & IB_QP_ALT_PATH));
567588

589+
WARN_ONCE((qp_attr_mask & IB_QP_PORT &&
590+
rdma_protocol_ib(real_qp->device, qp_attr->port_num) &&
591+
!real_qp->qp_sec),
592+
"%s: QP security is not initialized for IB QP: %d\n",
593+
__func__, real_qp->qp_num);
594+
568595
/* The port/pkey settings are maintained only for the real QP. Open
569596
* handles on the real QP will be in the shared_qp_list. When
570597
* enforcing security on the real QP all the shared QPs will be
571598
* checked as well.
572599
*/
573600

574-
if (pps_change && !special_qp) {
601+
if (pps_change && !special_qp && real_qp->qp_sec) {
575602
mutex_lock(&real_qp->qp_sec->mutex);
576603
new_pps = get_new_pps(real_qp,
577604
qp_attr,
578605
qp_attr_mask);
579-
606+
if (!new_pps) {
607+
mutex_unlock(&real_qp->qp_sec->mutex);
608+
return -ENOMEM;
609+
}
580610
/* Add this QP to the lists for the new port
581611
* and pkey settings before checking for permission
582612
* in case there is a concurrent cache update
@@ -600,7 +630,7 @@ int ib_security_modify_qp(struct ib_qp *qp,
600630
qp_attr_mask,
601631
udata);
602632

603-
if (pps_change && !special_qp) {
633+
if (new_pps) {
604634
/* Clean up the lists and free the appropriate
605635
* ports_pkeys structure.
606636
*/
@@ -631,6 +661,9 @@ int ib_security_pkey_access(struct ib_device *dev,
631661
u16 pkey;
632662
int ret;
633663

664+
if (!rdma_protocol_ib(dev, port_num))
665+
return 0;
666+
634667
ret = ib_get_cached_pkey(dev, port_num, pkey_index, &pkey);
635668
if (ret)
636669
return ret;
@@ -665,6 +698,9 @@ int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
665698
{
666699
int ret;
667700

701+
if (!rdma_protocol_ib(agent->device, agent->port_num))
702+
return 0;
703+
668704
ret = security_ib_alloc_security(&agent->security);
669705
if (ret)
670706
return ret;
@@ -690,13 +726,19 @@ int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
690726

691727
void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent)
692728
{
729+
if (!rdma_protocol_ib(agent->device, agent->port_num))
730+
return;
731+
693732
security_ib_free_security(agent->security);
694733
if (agent->lsm_nb_reg)
695734
unregister_lsm_notifier(&agent->lsm_nb);
696735
}
697736

698737
int ib_mad_enforce_security(struct ib_mad_agent_private *map, u16 pkey_index)
699738
{
739+
if (!rdma_protocol_ib(map->agent.device, map->agent.port_num))
740+
return 0;
741+
700742
if (map->agent.qp->qp_type == IB_QPT_SMI && !map->agent.smp_allowed)
701743
return -EACCES;
702744

0 commit comments

Comments
 (0)