
To avoid the following kernel panic when calling kmem_cache_create() with
a NULL pointer from pool_cache(), Block the rxe_param_set_add() from
running if the rdma_rxe module is not initialized.
BUG: unable to handle kernel NULL pointer dereference at 000000000000000b
PGD 0 P4D 0
Oops: 0000 [#1] SMP NOPTI
CPU: 4 PID: 8512 Comm: modprobe Kdump: loaded Not tainted 4.18.0-231.el8.x86_64 #1
Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 10/02/2018
RIP: 0010:kmem_cache_alloc+0xd1/0x1b0
Code: 8b 57 18 45 8b 77 1c 48 8b 5c 24 30 0f 1f 44 00 00 5b 48 89 e8 5d 41 5c 41 5d 41 5e 41 5f c3 81 e3 00 00 10 00 75 0e 4d 89 fe <41> f6 47 0b 04 0f 84 6c ff ff ff 4c 89 ff e8 cc da 01 00 49 89 c6
RSP: 0018:ffffa2b8c773f9d0 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000005
RDX: 0000000000000004 RSI: 00000000006080c0 RDI: 0000000000000000
RBP: ffff8ea0a8634fd0 R08: ffffa2b8c773f988 R09: 00000000006000c0
R10: 0000000000000000 R11: 0000000000000230 R12: 00000000006080c0
R13: ffffffffc0a97fc8 R14: 0000000000000000 R15: 0000000000000000
FS: 00007f9138ed9740(0000) GS:ffff8ea4ae800000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000000000000000b CR3: 000000046d59a000 CR4: 00000000003406e0
Call Trace:
rxe_alloc+0xc8/0x160 [rdma_rxe]
rxe_get_dma_mr+0x25/0xb0 [rdma_rxe]
__ib_alloc_pd+0xcb/0x160 [ib_core]
ib_mad_init_device+0x296/0x8b0 [ib_core]
add_client_context+0x11a/0x160 [ib_core]
enable_device_and_get+0xdc/0x1d0 [ib_core]
ib_register_device+0x572/0x6b0 [ib_core]
? crypto_create_tfm+0x32/0xe0
? crypto_create_tfm+0x7a/0xe0
? crypto_alloc_tfm+0x58/0xf0
rxe_register_device+0x19d/0x1c0 [rdma_rxe]
rxe_net_add+0x3d/0x70 [rdma_rxe]
? dev_get_by_name_rcu+0x73/0x90
rxe_param_set_add+0xaf/0xc0 [rdma_rxe]
parse_args+0x179/0x370
? ref_module+0x1b0/0x1b0
load_module+0x135e/0x17e0
? ref_module+0x1b0/0x1b0
? __do_sys_init_module+0x13b/0x180
__do_sys_init_module+0x13b/0x180
do_syscall_64+0x5b/0x1a0
entry_SYSCALL_64_after_hwframe+0x65/0xca
RIP: 0033:0x7f9137ed296e
This can be triggered if a user tries to use the 'module option' which is
not actually a real module option but some idiotic (and thankfully no
obsolete) sysfs interface.
Fixes: 8700e3e7c4
("Soft RoCE driver")
Link: https://lore.kernel.org/r/20200825151725.254046-1-kamalheib1@gmail.com
Signed-off-by: Kamal Heib <kamalheib1@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
141 lines
3.7 KiB
C
141 lines
3.7 KiB
C
/*
|
|
* Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
|
|
* Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
|
|
*
|
|
* This software is available to you under a choice of one of two
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
* General Public License (GPL) Version 2, available from the file
|
|
* COPYING in the main directory of this source tree, or the
|
|
* OpenIB.org BSD license below:
|
|
*
|
|
* Redistribution and use in source and binary forms, with or
|
|
* without modification, are permitted provided that the following
|
|
* conditions are met:
|
|
*
|
|
* - Redistributions of source code must retain the above
|
|
* copyright notice, this list of conditions and the following
|
|
* disclaimer.
|
|
*
|
|
* - Redistributions in binary form must reproduce the above
|
|
* copyright notice, this list of conditions and the following
|
|
* disclaimer in the documentation and/or other materials
|
|
* provided with the distribution.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#include "rxe.h"
|
|
#include "rxe_net.h"
|
|
|
|
/* Copy argument and remove trailing CR. Return the new length. */
|
|
static int sanitize_arg(const char *val, char *intf, int intf_len)
|
|
{
|
|
int len;
|
|
|
|
if (!val)
|
|
return 0;
|
|
|
|
/* Remove newline. */
|
|
for (len = 0; len < intf_len - 1 && val[len] && val[len] != '\n'; len++)
|
|
intf[len] = val[len];
|
|
intf[len] = 0;
|
|
|
|
if (len == 0 || (val[len] != 0 && val[len] != '\n'))
|
|
return 0;
|
|
|
|
return len;
|
|
}
|
|
|
|
static int rxe_param_set_add(const char *val, const struct kernel_param *kp)
|
|
{
|
|
int len;
|
|
int err = 0;
|
|
char intf[32];
|
|
struct net_device *ndev;
|
|
struct rxe_dev *exists;
|
|
|
|
if (!rxe_initialized) {
|
|
pr_err("Module parameters are not supported, use rdma link add or rxe_cfg\n");
|
|
return -EAGAIN;
|
|
}
|
|
|
|
len = sanitize_arg(val, intf, sizeof(intf));
|
|
if (!len) {
|
|
pr_err("add: invalid interface name\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
ndev = dev_get_by_name(&init_net, intf);
|
|
if (!ndev) {
|
|
pr_err("interface %s not found\n", intf);
|
|
return -EINVAL;
|
|
}
|
|
|
|
exists = rxe_get_dev_from_net(ndev);
|
|
if (exists) {
|
|
ib_device_put(&exists->ib_dev);
|
|
pr_err("already configured on %s\n", intf);
|
|
err = -EINVAL;
|
|
goto err;
|
|
}
|
|
|
|
err = rxe_net_add("rxe%d", ndev);
|
|
if (err) {
|
|
pr_err("failed to add %s\n", intf);
|
|
goto err;
|
|
}
|
|
|
|
err:
|
|
dev_put(ndev);
|
|
return err;
|
|
}
|
|
|
|
static int rxe_param_set_remove(const char *val, const struct kernel_param *kp)
|
|
{
|
|
int len;
|
|
char intf[32];
|
|
struct ib_device *ib_dev;
|
|
|
|
len = sanitize_arg(val, intf, sizeof(intf));
|
|
if (!len) {
|
|
pr_err("add: invalid interface name\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (strncmp("all", intf, len) == 0) {
|
|
pr_info("rxe_sys: remove all");
|
|
ib_unregister_driver(RDMA_DRIVER_RXE);
|
|
return 0;
|
|
}
|
|
|
|
ib_dev = ib_device_get_by_name(intf, RDMA_DRIVER_RXE);
|
|
if (!ib_dev) {
|
|
pr_err("not configured on %s\n", intf);
|
|
return -EINVAL;
|
|
}
|
|
|
|
ib_unregister_device_and_put(ib_dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct kernel_param_ops rxe_add_ops = {
|
|
.set = rxe_param_set_add,
|
|
};
|
|
|
|
static const struct kernel_param_ops rxe_remove_ops = {
|
|
.set = rxe_param_set_remove,
|
|
};
|
|
|
|
module_param_cb(add, &rxe_add_ops, NULL, 0200);
|
|
MODULE_PARM_DESC(add, "DEPRECATED. Create RXE device over network interface");
|
|
module_param_cb(remove, &rxe_remove_ops, NULL, 0200);
|
|
MODULE_PARM_DESC(remove, "DEPRECATED. Remove RXE device over network interface");
|