Skip to content

Commit

Permalink
RDMA/device: Ensure that security memory is always freed
Browse files Browse the repository at this point in the history
Since this only frees memory it should be done during the release
callback. Otherwise there are possible error flows where it might not get
called if registration aborts.

Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
  • Loading branch information
Jason Gunthorpe committed Feb 8, 2019
1 parent e3593b5 commit b34b269
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
4 changes: 2 additions & 2 deletions drivers/infiniband/core/core_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ int ib_get_cached_subnet_prefix(struct ib_device *device,
u64 *sn_pfx);

#ifdef CONFIG_SECURITY_INFINIBAND
void ib_security_destroy_port_pkey_list(struct ib_device *device);
void ib_security_release_port_pkey_list(struct ib_device *device);

void ib_security_cache_change(struct ib_device *device,
u8 port_num,
Expand All @@ -204,7 +204,7 @@ void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent);
int ib_mad_enforce_security(struct ib_mad_agent_private *map, u16 pkey_index);
void ib_mad_agent_security_change(void);
#else
static inline void ib_security_destroy_port_pkey_list(struct ib_device *device)
static inline void ib_security_release_port_pkey_list(struct ib_device *device)
{
}

Expand Down
10 changes: 3 additions & 7 deletions drivers/infiniband/core/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ static void ib_device_release(struct device *device)
ib_cache_release_one(dev);
kfree(dev->port_immutable);
}
ib_security_release_port_pkey_list(dev);
kfree(dev->port_pkey_list);
kfree(dev);
}

Expand Down Expand Up @@ -522,7 +524,6 @@ static void cleanup_device(struct ib_device *device)
{
ib_cache_cleanup_one(device);
ib_cache_release_one(device);
kfree(device->port_pkey_list);
kfree(device->port_immutable);
}

Expand Down Expand Up @@ -560,12 +561,10 @@ static int setup_device(struct ib_device *device)
if (ret) {
dev_warn(&device->dev,
"Couldn't set up InfiniBand P_Key/GID cache\n");
goto pkey_cleanup;
return ret;
}
return 0;

pkey_cleanup:
kfree(device->port_pkey_list);
port_cleanup:
kfree(device->port_immutable);
return ret;
Expand Down Expand Up @@ -682,9 +681,6 @@ void ib_unregister_device(struct ib_device *device)

ib_cache_cleanup_one(device);

ib_security_destroy_port_pkey_list(device);
kfree(device->port_pkey_list);

down_write(&lists_rwsem);
write_lock_irqsave(&device->client_data_lock, flags);
list_for_each_entry_safe(context, tmp, &device->client_data_list,
Expand Down
4 changes: 1 addition & 3 deletions drivers/infiniband/core/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,21 +558,19 @@ void ib_security_cache_change(struct ib_device *device,
}
}

void ib_security_destroy_port_pkey_list(struct ib_device *device)
void ib_security_release_port_pkey_list(struct ib_device *device)
{
struct pkey_index_qp_list *pkey, *tmp_pkey;
int i;

for (i = rdma_start_port(device); i <= rdma_end_port(device); i++) {
spin_lock(&device->port_pkey_list[i].list_lock);
list_for_each_entry_safe(pkey,
tmp_pkey,
&device->port_pkey_list[i].pkey_list,
pkey_index_list) {
list_del(&pkey->pkey_index_list);
kfree(pkey);
}
spin_unlock(&device->port_pkey_list[i].list_lock);
}
}

Expand Down

0 comments on commit b34b269

Please sign in to comment.